diff --git a/docs/changes.md b/docs/changes.md index 231d4239..f2dc0fcf 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,6 +1,11 @@ ## Changes and Fixes +- add `settings.force_single_precision_points = False` in #1137 by @JeffreyWardman and @sean-d-zydex +- fix Volume masking in #1146 by @ivishalanand + + + ## Soft-breaking Changes Changes that will break existing code whose fixing is trivial: diff --git a/examples/basic/sliders_range.py b/examples/basic/sliders_range.py index bf0601b1..54dcc943 100644 --- a/examples/basic/sliders_range.py +++ b/examples/basic/sliders_range.py @@ -1,4 +1,4 @@ -"""Create a range slider to scale two spheres""" +"""Create a double range slider to scale two spheres""" from vedo import * diff --git a/vedo/visual.py b/vedo/visual.py index e2acd92d..2bee1cdd 100644 --- a/vedo/visual.py +++ b/vedo/visual.py @@ -2727,7 +2727,7 @@ def hide_voxels(self, ids) -> Self: ```python from vedo import * embryo = Volume(dataurl+'embryo.tif') - embryo.hide_voxels(list(range(10000))) + embryo.hide_voxels(list(range(400000))) show(embryo, axes=1).close() ``` @@ -2742,6 +2742,44 @@ def hide_voxels(self, ids) -> Self: self.dataset.GetCellData().Modified() return self + def mask(self, data) -> Self: + """ + Mask a volume visualization with a binary value. + Needs to specify `volume.mapper = "gpu"`. + + Example: + ```python + from vedo import np, Volume, show + data_matrix = np.zeros([75, 75, 75], dtype=np.uint8) + # all voxels have value zero except: + data_matrix[ 0:35, 0:35, 0:35] = 1 + data_matrix[35:55, 35:55, 35:55] = 2 + data_matrix[55:74, 55:74, 55:74] = 3 + vol = Volume(data_matrix).cmap('Blues') + vol.mapper = "gpu" + data_mask = np.zeros_like(data_matrix) + data_mask[10:65, 10:60, 20:70] = 1 + vol.mask(data_mask) + show(vol, axes=1).close() + ``` + See also: + `volume.hide_voxels()` + """ + rdata = data.astype(np.uint8).ravel(order="F") + varr = utils.numpy2vtk(rdata, name="input_mask") + + img = vtki.vtkImageData() + img.SetDimensions(self.dimensions()) + img.GetPointData().AddArray(varr) + img.GetPointData().SetActiveScalars(varr.GetName()) + + try: + self.mapper.SetMaskTypeToBinary() + self.mapper.SetMaskInput(img) + except AttributeError: + vedo.logger.error("volume.mask() must specify volume.mapper = 'gpu'") + return self + def mode(self, mode=None) -> Union[Self, int]: """ @@ -2819,37 +2857,6 @@ def shade(self, status=None) -> Union[Self, bool]: self.properties.SetShade(status) return self - - def mask(self, data) -> Self: - """ - Mask a volume visualization with a binary value. - Needs to specify keyword mapper='gpu'. - - Example: - ```python - from vedo import np, Volume, show - data_matrix = np.zeros([75, 75, 75], dtype=np.uint8) - # all voxels have value zero except: - data_matrix[0:35, 0:35, 0:35] = 1 - data_matrix[35:55, 35:55, 35:55] = 2 - data_matrix[55:74, 55:74, 55:74] = 3 - vol = Volume(data_matrix, c=['white','b','g','r'], mapper='gpu') - data_mask = np.zeros_like(data_matrix) - data_mask[10:65, 10:45, 20:75] = 1 - vol.mask(data_mask) - show(vol, axes=1).close() - ``` - See also: - `volume.hide_voxels()` - """ - mask = vedo.Volume(data.astype(np.uint8)) - try: - self.mapper.SetMaskTypeToBinary() - self.mapper.SetMaskInput(mask.dataset) - except AttributeError: - vedo.logger.error("volume.mask() must create the volume with Volume(..., mapper='gpu')") - return self - def interpolation(self, itype) -> Self: """ Set interpolation type. diff --git a/vedo/volume.py b/vedo/volume.py index de25204b..6d7a64c0 100644 --- a/vedo/volume.py +++ b/vedo/volume.py @@ -224,6 +224,7 @@ def mapper(self, mapper): else: print("Error unknown mapper type", [mapper]) raise RuntimeError() + mapper.SetInputData(self.dataset) self.actor.SetMapper(mapper) def c(self, *args, **kwargs) -> Self: