diff options
Diffstat (limited to 'silx/gui/plot3d/items')
-rw-r--r-- | silx/gui/plot3d/items/image.py | 4 | ||||
-rw-r--r-- | silx/gui/plot3d/items/mesh.py | 5 | ||||
-rw-r--r-- | silx/gui/plot3d/items/mixins.py | 38 | ||||
-rw-r--r-- | silx/gui/plot3d/items/scatter.py | 7 | ||||
-rw-r--r-- | silx/gui/plot3d/items/volume.py | 51 |
5 files changed, 29 insertions, 76 deletions
diff --git a/silx/gui/plot3d/items/image.py b/silx/gui/plot3d/items/image.py index 210f2f3..cfd1188 100644 --- a/silx/gui/plot3d/items/image.py +++ b/silx/gui/plot3d/items/image.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2017-2018 European Synchrotron Radiation Facility +# Copyright (c) 2017-2020 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -118,7 +118,7 @@ class ImageData(_Image, ColormapMixIn): False to use as is (do not modify!). """ self._image.setData(data, copy=copy) - ColormapMixIn._setRangeFromData(self, self.getData(copy=False)) + self._setColormappedData(self.getData(copy=False), copy=False) self._updated(ItemChangedType.DATA) def getData(self, copy=True): diff --git a/silx/gui/plot3d/items/mesh.py b/silx/gui/plot3d/items/mesh.py index 3577dbf..4e19939 100644 --- a/silx/gui/plot3d/items/mesh.py +++ b/silx/gui/plot3d/items/mesh.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2017-2019 European Synchrotron Radiation Facility +# Copyright (c) 2017-2020 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -312,8 +312,7 @@ class ColormapMesh(_MeshBase, ColormapMixIn): copy=copy) self._setMesh(mesh) - # Store data range info - ColormapMixIn._setRangeFromData(self, self.getValueData(copy=False)) + self._setColormappedData(self.getValueData(copy=False), copy=False) def getData(self, copy=True): """Get the mesh geometry. diff --git a/silx/gui/plot3d/items/mixins.py b/silx/gui/plot3d/items/mixins.py index b355627..14cafc8 100644 --- a/silx/gui/plot3d/items/mixins.py +++ b/silx/gui/plot3d/items/mixins.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2017-2019 European Synchrotron Radiation Facility +# Copyright (c) 2017-2020 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -111,7 +111,6 @@ class ColormapMixIn(_ColormapMixIn): def __init__(self, sceneColormap=None): super(ColormapMixIn, self).__init__() - self._dataRange = None self.__sceneColormap = sceneColormap self._syncSceneColormap() @@ -120,37 +119,6 @@ class ColormapMixIn(_ColormapMixIn): self._syncSceneColormap() super(ColormapMixIn, self)._colormapChanged() - def _setRangeFromData(self, data=None): - """Compute the data range the colormap should use from provided data. - - :param data: Data set from which to compute the range or None - """ - if data is None or data.size == 0: - dataRange = None - else: - dataRange = min_max(data, min_positive=True, finite=True) - if dataRange.minimum is None: # Only non-finite data - dataRange = None - - if dataRange is not None: - min_positive = dataRange.min_positive - if min_positive is None: - min_positive = float('nan') - dataRange = dataRange.minimum, min_positive, dataRange.maximum - - self._dataRange = dataRange - - colormap = self.getColormap() - if None in (colormap.getVMin(), colormap.getVMax()): - self._colormapChanged() - - def _getDataRange(self): - """Returns the data range as used in the scene for colormap - - :rtype: Union[List[float],None] - """ - return self._dataRange - def _setSceneColormap(self, sceneColormap): """Set the scene colormap to sync with Colormap object. @@ -171,8 +139,8 @@ class ColormapMixIn(_ColormapMixIn): self.__sceneColormap.colormap = colormap.getNColors() self.__sceneColormap.norm = colormap.getNormalization() - range_ = colormap.getColormapRange(data=self._dataRange) - self.__sceneColormap.range_ = range_ + self.__sceneColormap.gamma = colormap.getGammaNormalizationParameter() + self.__sceneColormap.range_ = colormap.getColormapRange(self) class ComplexMixIn(_ComplexMixIn): diff --git a/silx/gui/plot3d/items/scatter.py b/silx/gui/plot3d/items/scatter.py index 5fce629..24abaa5 100644 --- a/silx/gui/plot3d/items/scatter.py +++ b/silx/gui/plot3d/items/scatter.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2017-2019 European Synchrotron Radiation Facility +# Copyright (c) 2017-2020 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -100,7 +100,7 @@ class Scatter3D(DataItem3D, ColormapMixIn, SymbolMixIn): self._scatter.setAttribute('z', z, copy=copy) self._scatter.setAttribute('value', value, copy=copy) - ColormapMixIn._setRangeFromData(self, self.getValueData(copy=False)) + self._setColormappedData(self.getValueData(copy=False), copy=False) self._updated(ItemChangedType.DATA) def getData(self, copy=True): @@ -366,8 +366,7 @@ class Scatter2D(DataItem3D, ColormapMixIn, SymbolMixIn, self._cachedLinesIndices = None self._cachedTrianglesIndices = None - # Store data range info - ColormapMixIn._setRangeFromData(self, self.getValueData(copy=False)) + self._setColormappedData(self.getValueData(copy=False), copy=False) self._updateScene() diff --git a/silx/gui/plot3d/items/volume.py b/silx/gui/plot3d/items/volume.py index e0a2a1f..6c6562f 100644 --- a/silx/gui/plot3d/items/volume.py +++ b/silx/gui/plot3d/items/volume.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2017-2019 European Synchrotron Radiation Facility +# Copyright (c) 2017-2020 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -93,8 +93,12 @@ class CutPlane(Item3D, ColormapMixIn, InterpolationMixIn, PlaneMixIn): # Store data range info as 3-tuple of values self._dataRange = range_ - self._setRangeFromData( - None if self._dataRange is None else numpy.array(self._dataRange)) + if range_ is None: + range_ = None, None, None + self._setColormappedData(self._data, copy=False, + min_=range_[0], + minPositive=range_[1], + max_=range_[2]) self._updated(ItemChangedType.DATA) @@ -724,15 +728,20 @@ class ComplexIsosurface(Isosurface, ComplexMixIn, ColormapMixIn): def _syncDataWithParent(self): """Synchronize this instance data with that of its parent""" - if self.getComplexMode() != self.ComplexMode.NONE: - self._setRangeFromData(self.getColormappedData(copy=False)) - parent = self.parent() if parent is None: self._data = None else: self._data = parent.getData( mode=parent.getComplexMode(), copy=False) + + if parent is None or self.getComplexMode() == self.ComplexMode.NONE: + self._setColormappedData(None, copy=False) + else: + self._setColormappedData( + parent.getData(mode=self.getComplexMode(), copy=False), + copy=False) + self._updateScenePrimitive() def _parentChanged(self, event): @@ -741,38 +750,16 @@ class ComplexIsosurface(Isosurface, ComplexMixIn, ColormapMixIn): self._syncDataWithParent() super(ComplexIsosurface, self)._parentChanged(event) - def getColormappedData(self, copy=True): - """Return 3D dataset used to apply the colormap on the isosurface. - - This depends on :meth:`getComplexMode`. - - :param bool copy: - True (default) to get a copy, - False to get the internal data (DO NOT modify!) - :return: The data set (or None if not set) - :rtype: Union[numpy.ndarray,None] - """ - if self.getComplexMode() == self.ComplexMode.NONE: - return None - else: - parent = self.parent() - if parent is None: - return None - else: - return parent.getData(mode=self.getComplexMode(), copy=copy) - def _updated(self, event=None): """Handle update of the isosurface (and take care of mode change) :param ItemChangedType event: The kind of update """ - if (event == ItemChangedType.COMPLEX_MODE and - self.getComplexMode() != self.ComplexMode.NONE): - self._setRangeFromData(self.getColormappedData(copy=False)) + if event == ItemChangedType.COMPLEX_MODE: + self._syncDataWithParent() - if event in (ItemChangedType.COMPLEX_MODE, - ItemChangedType.COLORMAP, - Item3DChangedType.INTERPOLATION): + elif event in (ItemChangedType.COLORMAP, + Item3DChangedType.INTERPOLATION): self._updateScenePrimitive() super(ComplexIsosurface, self)._updated(event) |