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())
示例#2
0
 def _STTransform_to_pg(self, tr):
     import pyqtgraph
     if tr.dims == (2, 2):
         ptr = pyqtgraph.SRTTransform()
         ptr.setScale(tr.scale)
         ptr.setTranslate(tr.offset)
         return ptr
     elif tr.dims == (3, 3):
         ptr = pyqtgraph.SRTTransform3D()
         ptr.setScale(tr.scale)
         ptr.setTranslate(tr.offset)
         return ptr
     else:
         raise TypeError("Converting STTransform of dimension %r to pyqtgraph is not supported." % tr.dims)
示例#3
0
 def setFromMatrix4x4(self, m):
     m = pg.SRTTransform3D(m)
     angle, axis = m.getRotation()
     if angle != 0 and (axis[0] != 0 or axis[1] != 0 or axis[2] != 1):
         print("angle: %s  axis: %s" % (str(angle), str(axis)))
         raise Exception(
             "Can only convert 4x4 matrix to 3x3 if rotation is around Z-axis."
         )
     self._state = {
         'pos': Point(m.getTranslation()),
         'scale': Point(m.getScale()),
         'angle': angle
     }
     self.update()
示例#4
0
 def get_transform(self):
     tr = pg.SRTTransform3D()
     tr.rotate(self.yaw, (0, 0, 1))
     tr.rotate(self.pitch, (0, 1, 0))
     tr.rotate(self.roll, (1, 0, 0))
     return tr