def getTransformFromNumpy(mat): ''' Given a numpy 4x4 array, return a vtkTransform. ''' m = vtk.vtkMatrix4x4() for r in xrange(4): for c in xrange(4): m.SetElement(r, c, mat[r][c]) t = vtk.vtkTransform() t.SetMatrix(m) return t
def getTransformFromAxes(xaxis, yaxis, zaxis): t = vtk.vtkTransform() m = vtk.vtkMatrix4x4() axes = np.array([xaxis, yaxis, zaxis]).transpose().copy() vtk.vtkMath.Orthogonalize3x3(axes, axes) for r in xrange(3): for c in xrange(3): m.SetElement(r, c, axes[r][c]) t.SetMatrix(m) return t