Commit 0bc923b7 by Luke Campagnola

### Added SRTTransform3D test, corrected fromMatrix bug

parent 18ddff76
 ... @@ -122,7 +122,8 @@ class SRTTransform3D(Transform3D): ... @@ -122,7 +122,8 @@ class SRTTransform3D(Transform3D): self.setRow(i, m.row(i)) self.setRow(i, m.row(i)) m = self.matrix().reshape(4,4) m = self.matrix().reshape(4,4) ## translation is 4th column ## translation is 4th column self._state['pos'] = m[:3,3] self._state['pos'] = m[:3,3] ## scale is vector-length of first three columns ## scale is vector-length of first three columns scale = (m[:3,:3]**2).sum(axis=0)**0.5 scale = (m[:3,:3]**2).sum(axis=0)**0.5 ## see whether there is an inversion ## see whether there is an inversion ... @@ -132,7 +133,7 @@ class SRTTransform3D(Transform3D): ... @@ -132,7 +133,7 @@ class SRTTransform3D(Transform3D): self._state['scale'] = scale self._state['scale'] = scale ## rotation axis is the eigenvector with eigenvalue=1 ## rotation axis is the eigenvector with eigenvalue=1 r = m[:3, :3] / scale[:, np.newaxis] r = m[:3, :3] / scale[np.newaxis, :] try: try: evals, evecs = numpy.linalg.eig(r) evals, evecs = numpy.linalg.eig(r) except: except: ... ...
 import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtGui import numpy as np from numpy.testing import assert_array_almost_equal, assert_almost_equal testPoints = np.array([ [0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [-1, -1, 0], [0, -1, -1]]) def testMatrix(): """ SRTTransform3D => Transform3D => SRTTransform3D """ tr = pg.SRTTransform3D() tr.setRotate(45, (0, 0, 1)) tr.setScale(0.2, 0.4, 1) tr.setTranslate(10, 20, 40) assert tr.getRotation() == (45, QtGui.QVector3D(0, 0, 1)) assert tr.getScale() == QtGui.QVector3D(0.2, 0.4, 1) assert tr.getTranslation() == QtGui.QVector3D(10, 20, 40) tr2 = pg.Transform3D(tr) assert np.all(tr.matrix() == tr2.matrix()) # This is the most important test: # The transition from Transform3D to SRTTransform3D is a tricky one. tr3 = pg.SRTTransform3D(tr2) assert_array_almost_equal(tr.matrix(), tr3.matrix()) assert_almost_equal(tr3.getRotation()[0], tr.getRotation()[0]) assert_array_almost_equal(tr3.getRotation()[1], tr.getRotation()[1]) assert_array_almost_equal(tr3.getScale(), tr.getScale()) assert_array_almost_equal(tr3.getTranslation(), tr.getTranslation())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!