diff options
author | Alexandre Marie <alexandre.marie@synchrotron-soleil.fr> | 2018-12-17 12:28:24 +0100 |
---|---|---|
committer | Alexandre Marie <alexandre.marie@synchrotron-soleil.fr> | 2018-12-17 12:28:24 +0100 |
commit | cebdc9244c019224846cb8d2668080fe386a6adc (patch) | |
tree | aedec55da0f9dd4fc4d6c7eb0f58489a956e2e8c /silx/gui/plot3d/scene/transform.py | |
parent | 159ef14fb9e198bb0066ea14e6b980f065de63dd (diff) |
New upstream version 0.9.0+dfsg
Diffstat (limited to 'silx/gui/plot3d/scene/transform.py')
-rw-r--r-- | silx/gui/plot3d/scene/transform.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/silx/gui/plot3d/scene/transform.py b/silx/gui/plot3d/scene/transform.py index 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. |