Skip to content

Commit 8128922

Browse files
authored
Merge pull request #153 from Carifio24/cutting-plane-voxel
Respect cutting plane for voxel exports
2 parents f1b9a30 + e3c2b08 commit 8128922

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

‎glue_ar/common/voxels.py‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,16 @@ def add_voxel_layers_gltf(builder: GLTFBuilder,
7171

7272
isorange = isomax - isomin
7373
nonempty_indices = argwhere(data > isomin)
74-
74+
cut_plane = None
75+
if getattr(viewer_state, "cut_enabled", False):
76+
from glue_vispy_viewers.volume.viewer_state import cutting_plane_from_state
77+
cut_plane = cutting_plane_from_state(viewer_state)
78+
if cut_plane is not None:
79+
resolution_factors = [viewer_state.resolution / bound[2] for bound in bounds]
80+
cut_plane_coeffs = [factor * coeff for factor, coeff in zip(resolution_factors, cut_plane[:3])]
81+
def cut_plane_index_check(indices):
82+
return cut_plane_coeffs[1] * indices[0] + cut_plane_coeffs[2] * indices[1] + cut_plane_coeffs[0] * indices[2] + cut_plane[3] > 0
83+
7584
color = layer_color(layer_state)
7685
color_components = hex_to_components(color)
7786

@@ -80,7 +89,10 @@ def add_voxel_layers_gltf(builder: GLTFBuilder,
8089
voxel_colors = [[int(256 * float(c)) for c in vc[:3]] for vc in voxel_colors]
8190

8291
for indices in nonempty_indices:
83-
value = data[tuple(indices)]
92+
index_tuple = tuple(indices)
93+
if cut_plane is not None and cut_plane_index_check(index_tuple):
94+
continue
95+
value = data[index_tuple]
8496
t_voxel = (value - isomin) / isorange
8597
if t_voxel > 0 and hasattr(layer_state, 'stretch'):
8698
t_voxel = layer_state.stretch_object([t_voxel], **layer_state.stretch_parameters)[0]
@@ -282,6 +294,15 @@ def add_voxel_layers_usd(builder: USDBuilder,
282294

283295
isorange = isomax - isomin
284296
nonempty_indices = argwhere(data - isomin > 0)
297+
cut_plane = None
298+
if getattr(viewer_state, "cut_enabled", False):
299+
from glue_vispy_viewers.volume.viewer_state import cutting_plane_from_state
300+
cut_plane = cutting_plane_from_state(viewer_state)
301+
if cut_plane is not None:
302+
resolution_factors = [viewer_state.resolution / bound[2] for bound in bounds]
303+
cut_plane_coeffs = [factor * coeff for factor, coeff in zip(resolution_factors, cut_plane[:3])]
304+
def cut_plane_index_check(indices):
305+
return cut_plane_coeffs[1] * indices[0] + cut_plane_coeffs[2] * indices[1] + cut_plane_coeffs[0] * indices[2] + cut_plane[3] > 0
285306

286307
color = layer_color(layer_state)
287308
color_components = hex_to_components(color)
@@ -291,8 +312,10 @@ def add_voxel_layers_usd(builder: USDBuilder,
291312
voxel_colors = [[int(256 * float(c)) for c in vc[:3]] for vc in voxel_colors]
292313

293314
for indices in nonempty_indices:
294-
295-
value = data[tuple(indices)]
315+
index_tuple = tuple(indices)
316+
if cut_plane is not None and cut_plane_index_check(index_tuple):
317+
continue
318+
value = data[index_tuple]
296319
t_voxel = (value - isomin) / isorange
297320
if t_voxel > 0 and hasattr(layer_state, 'stretch'):
298321
t_voxel = layer_state.stretch_object([t_voxel], **layer_state.stretch_parameters)[0]

0 commit comments

Comments
 (0)