Skip to content

Commit

Permalink
Viewer.add_volume: rename parameter dims -> spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Apr 16, 2024
1 parent d732b35 commit 0cff1cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 7 additions & 5 deletions octarine/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,9 @@ def add_points(
elif not isinstance(name, str):
name = str(name)

visual = points2gfx(points, color=color, size=size, size_space=size_space, marker=marker)
visual = points2gfx(
points, color=color, size=size, size_space=size_space, marker=marker
)
visual._object_id = name if name else uuid.uuid4()

self._add_to_scene(visual, center)
Expand Down Expand Up @@ -873,7 +875,7 @@ def add_lines(
def add_volume(
self,
volume,
dims,
spacing=(1, 1, 1),
name=None,
color=None,
offset=(0, 0, 0),
Expand All @@ -888,8 +890,8 @@ def add_volume(
----------
volume : (N, M, K) array
Volume to plot.
dims : tuple
Scale factors for the volume.
spacing : tuple
Spacing between voxels.
name : str, optional
Name for the visual.
color : color | list of colors | pygfx.Texture, optional
Expand Down Expand Up @@ -933,7 +935,7 @@ def add_volume(

visual = volume2gfx(
volume,
dims=dims,
spacing=spacing,
offset=offset,
color=color,
clim=clim,
Expand Down
16 changes: 8 additions & 8 deletions octarine/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def color_to_texture(color, N=256, gamma=1.0, fade=True):

def volume2gfx(
vol,
dims,
color,
spacing=(1, 1, 1),
offset=(0, 0, 0),
clim="auto",
interpolation="linear",
Expand All @@ -120,8 +120,8 @@ def volume2gfx(
----------
vol : np.ndarray
3D array representing the volume.
dims : tuple
Dimensions of the volume along the (x, y, z) axes.
spacing : tuple
Spacing between voxels in the volume.
color : color | list of colors | pygfx.Texture, optional
Colormap to render the volume. This can be:
- name of a colormap (e.g. "viridis" or "magma")
Expand Down Expand Up @@ -159,10 +159,10 @@ def volume2gfx(

assert isinstance(vol, np.ndarray), "Expected 3D numpy array."
assert vol.ndim == 3, "Expected 3D numpy array."
assert isinstance(dims, (tuple, list, np.ndarray, int, float))
if isinstance(dims, (int, float)):
dims = [dims] * 3
assert len(dims) == 3, "Expected dimensions as tuple of length 3."
assert isinstance(spacing, (tuple, list, np.ndarray, int, float))
if isinstance(spacing, (int, float)):
spacing = [spacing] * 3
assert len(spacing) == 3, "Expected spacing as tuple of length 3."

# Similar to vispy, pygfx seems to expect zyx coordinate space
grid = vol.T
Expand Down Expand Up @@ -226,7 +226,7 @@ def volume2gfx(
vis.local.scale_x,
vis.local.scale_y,
vis.local.scale_z,
) = dims
) = spacing
(vis.local.x, vis.local.y, vis.local.z) = offset

# Add custom attributes
Expand Down

0 comments on commit 0cff1cf

Please sign in to comment.