summaryrefslogtreecommitdiff log msg author committer range
path: root/silx/gui/plot3d/scene/transform.py
diff options
 context: 12345678910152025303540 space: includeignore mode: unifiedssdiffstat only
Diffstat (limited to 'silx/gui/plot3d/scene/transform.py')
-rw-r--r--silx/gui/plot3d/scene/transform.py42
1 files changed, 39 insertions, 3 deletions
 diff --git a/silx/gui/plot3d/scene/transform.py b/silx/gui/plot3d/scene/transform.pyindex 4061e81..1b82397 100644--- a/silx/gui/plot3d/scene/transform.py+++ b/silx/gui/plot3d/scene/transform.py@@ -305,6 +305,44 @@ class Transform(event.Notifier): # Multiplication with vectors + def transformPoints(self, points, direct=True, perspectiveDivide=False):+ """Apply the transform to an array of points.++ :param points: 2D array of N vectors of 3 or 4 coordinates+ :param bool direct: Whether to apply the direct (True, the default)+ or inverse (False) transform.+ :param bool perspectiveDivide: Whether to apply the perspective divide+ (True) or not (False, the default).+ :return: The transformed points.+ :rtype: numpy.ndarray of same shape as points.+ """+ if direct:+ matrix = self.getMatrix(copy=False)+ else:+ matrix = self.getInverseMatrix(copy=False)++ points = numpy.array(points, copy=False)+ assert points.ndim == 2++ points = numpy.transpose(points)++ dimension = points.shape[0]+ assert dimension in (3, 4)++ if dimension == 3: # Add 4th coordinate+ points = numpy.append(+ points,+ numpy.ones((1, points.shape[1]), dtype=points.dtype),+ axis=0)++ result = numpy.transpose(numpy.dot(matrix, points))++ if perspectiveDivide:+ mask = result[:, 3] != 0.+ result[mask] /= result[mask, 3][:, numpy.newaxis]++ return result[:, :3] if dimension == 3 else result+ @staticmethod def _prepareVector(vector, w): """Add 4th coordinate (w) to vector if missing."""@@ -317,8 +355,6 @@ class Transform(event.Notifier): def transformPoint(self, point, direct=True, perspectiveDivide=False): """Apply the transform to a point. - If len(point) == 3, apply perspective divide if possible.- :param point: Array-like vector of 3 or 4 coordinates. :param bool direct: Whether to apply the direct (True, the default) or inverse (False) transform.@@ -373,7 +409,7 @@ class Transform(event.Notifier): _CUBE_CORNERS = numpy.array(list(itertools.product((0., 1.), repeat=3)), dtype=numpy.float32)- """Unit cube corners used by :meth:`transformRectangularBox`"""+ """Unit cube corners used by :meth:`transformBounds`""" def transformBounds(self, bounds, direct=True): """Apply the transform to an axes-aligned rectangular box.