Skip to content

Commit 8557848

Browse files
authored
Merge pull request #53 from AngelFP/fix_saving_opacity
Allow saving opacity if it is out of range
2 parents 5d60ff5 + 48fe18f commit 8557848

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

visualpic/visualization/volume_appearance.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ def get_opacity_values(self, op_name):
9494

9595
def save_opacity(self, name, field_values, opacity_values,
9696
folder_path):
97+
# Make sure opacity is within bounds.
98+
opacity_values[opacity_values < 0.] = 0.
99+
opacity_values[opacity_values > 1] = 1.
97100
if (field_values.min() >= 0 and field_values.max() <= 255
98-
and opacity_values.min() >= 0 and opacity_values.max() <= 1
99101
and len(field_values) == len(opacity_values)
100102
and len(opacity_values) <= self.max_len):
101103
file_path = self.create_file_path(name, folder_path)

visualpic/visualization/vtk_visualizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def set_background(self, background):
411411
colors.
412412
413413
"""
414-
if (type(background) == list) and (len(background) == 2):
414+
if isinstance(background, list) and (len(background) == 2):
415415
self._set_background_colors(*background)
416416
elif background == 'default gradient':
417417
self._set_background_colors('black', [0.12, 0.3, 0.475])
@@ -753,15 +753,15 @@ def _load_data_into_multi_volume(self, timestep):
753753
# only a single volume. The fix replaces the 'vtkMultiVolume' for a
754754
# 'vtkVolume' and then calls '_load_data_into_single_volume'.
755755
if len(self.volume_field_list) == 1:
756-
if type(self.vtk_volume) != vtk.vtkVolume:
756+
if not isinstance(self.vtk_volume, vtk.vtkVolume):
757757
self.renderer.RemoveVolume(self.vtk_volume)
758758
self.vtk_volume = vtk.vtkVolume()
759759
self.renderer.AddVolume(self.vtk_volume)
760760
self.vtk_volume.SetMapper(self.vtk_volume_mapper)
761761
return self._load_data_into_single_volume(timestep)
762762
# If the 'vtkMultiVolume' was replaced by a 'vtkVolume' but now the
763763
# number of volumes is >1, go back to having a 'vtkMultiVolume'.
764-
if type(self.vtk_volume) != vtk.vtkMultiVolume:
764+
if not isinstance(self.vtk_volume, vtk.vtkMultiVolume):
765765
self.renderer.RemoveVolume(self.vtk_volume)
766766
self.vtk_volume = vtk.vtkMultiVolume()
767767
self.renderer.AddVolume(self.vtk_volume)

0 commit comments

Comments
 (0)