Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Merge requests
!61
Added aspectmode kwarg and changed default mode of k3d.volume
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Added aspectmode kwarg and changed default mode of k3d.volume
fix_k3d_aspect_ratio
into
main
Overview
0
Commits
3
Pipelines
0
Changes
2
Merged
s184058
requested to merge
fix_k3d_aspect_ratio
into
main
1 year ago
Overview
0
Commits
3
Pipelines
0
Changes
2
0
0
Merge request reports
Compare
main
version 1
5c2bc3b3
1 year ago
main (base)
and
latest version
latest version
443f532c
3 commits,
1 year ago
version 1
5c2bc3b3
1 commit,
1 year ago
2 files
+
37
−
18
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
qim3d/viz/k3d.py
+
36
−
18
View file @ 443f532c
Edit in single-file editor
Open in Web IDE
Show full file
@@ -10,50 +10,68 @@ Volumetric visualization using K3D
import
k3d
import
numpy
as
np
def
vol
(
img
,
show
=
True
,
save
=
False
):
def
vol
(
img
,
aspectmode
=
"
data
"
,
show
=
True
,
save
=
False
,
grid_visible
=
False
,
**
kwargs
):
"""
V
olumetric visualization of a given volume
.
V
isualizes a 3D volume using volumetric rendering
.
Args:
img (numpy.ndarray): The input 3D image data. It should be a 3D numpy array.
show (bool, optional): If True, displays the visualization. Defaults to True.
save (bool or str, optional): If True, saves the visualization as an HTML file.
If a string is provided, it
'
s interpreted as the file path where the HTML
aspectmode (str, optional): Determines the proportions of the scene
'
s axes.
If
"
data
"
, the axes are drawn in proportion with the axes
'
ranges.
If
"
cube
"
, the axes are drawn as a cube, regardless of the axes
'
ranges.
Defaults to
"
data
"
.
show (bool, optional): If True, displays the visualization inline. Defaults to True.
save (bool or str, optional): If True, saves the visualization as an HTML file.
If a string is provided, it
'
s interpreted as the file path where the HTML
file will be saved. Defaults to False.
grid_visible (bool, optional): If True, the grid is visible in the plot. Defaults to False.
**kwargs: Additional keyword arguments to be passed to the k3d.plot function.
Returns:
k3d.plot: If show is False, returns the K3D plot object.
Example:
Raises:
ValueError: If aspectmode is not
"
data
"
or
"
cube
"
.
Examples:
Display a volume inline:
```python
import qim3d
vol = qim3d.examples.bone_128x128x128
qim3d.viz.vol(vol)
```
# shows the volume inline
qim3d.viz.vol(vol)
Save a plot to an HTML file:
```
Example:
```python
import qim3d
vol = qim3d.examples.bone_128x128x128
# saves html plot to disk
plot = qim3d.viz.vol(vol, show=False, save=
"
plot.html
"
)
```
"""
plt_volume
=
k3d
.
volume
(
img
.
astype
(
np
.
float32
))
plot
=
k3d
.
plot
()
if
aspectmode
.
lower
()
not
in
[
"
data
"
,
"
cube
"
]:
raise
ValueError
(
"
aspectmode should be either
'
data
'
or
'
cube
'"
)
plt_volume
=
k3d
.
volume
(
img
.
astype
(
np
.
float32
),
bounds
=
(
[
0
,
img
.
shape
[
0
],
0
,
img
.
shape
[
1
],
0
,
img
.
shape
[
2
]]
if
aspectmode
.
lower
()
==
"
data
"
else
None
),
)
plot
=
k3d
.
plot
(
grid_visible
=
grid_visible
,
**
kwargs
)
plot
+=
plt_volume
if
save
:
# Save html to disk
with
open
(
str
(
save
),
'
w
'
,
encoding
=
"
utf-8
"
)
as
fp
:
with
open
(
str
(
save
),
"
w
"
,
encoding
=
"
utf-8
"
)
as
fp
:
fp
.
write
(
plot
.
get_snapshot
())
if
show
:
plot
.
display
()
else
:
return
plot
\ No newline at end of file
return
plot
Loading