Python vtk.vtkMatrix4x4() Examples

The following are 5 code examples of vtk.vtkMatrix4x4(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vtk , or try the search function .
Example #1
Source File: renderer.py    From pyvista with MIT License 7 votes vote down vote up
def scale_point(camera, point, invert=False):
    """Scale a point using the camera's transform matrix.

    Parameters
    ----------
    camera : vtk.vtkCamera
        The camera who's matrix to use.

    point : tuple(float)
        Length 3 tuple of the point coordinates.

    invert : bool
        If True, invert the matrix to transform the point out of the
        camera's transformed space. Default is False to transform a
        point from world coordinates to the camera's transformed space.

    """
    if invert:
        mtx = vtk.vtkMatrix4x4()
        mtx.DeepCopy(camera.GetModelTransformMatrix())
        mtx.Invert()
    else:
        mtx = camera.GetModelTransformMatrix()
    scaled = mtx.MultiplyDoublePoint((point[0], point[1], point[2], 0.0))
    return (scaled[0], scaled[1], scaled[2]) 
Example #2
Source File: visualizercontrol.py    From Det3D with Apache License 2.0 6 votes vote down vote up
def _array2vtkTransform(self, arr):
        T = vtk.vtkTransform()
        matrix = vtk.vtkMatrix4x4()
        for i in range(0, 4):
            for j in range(0, 4):
                matrix.SetElement(i, j, arr[i, j])
        T.SetMatrix(matrix)
        return T 
Example #3
Source File: volumerendering.py    From Medical-Image-Analysis-IPython-Tutorials with Apache License 2.0 5 votes vote down vote up
def move(actor, matrix):
    transfo_mat = vtk.vtkMatrix4x4()
    for i in range(0,4):
        for j in range(0,4):
            transfo_mat.SetElement(i,j, matrix[i,j])        
    actor.SetUserMatrix(transfo_mat) 
Example #4
Source File: transforms.py    From robopy with MIT License 5 votes vote down vote up
def np2vtk(mat):
    if mat.shape == (4, 4):
        obj = vtk.vtkMatrix4x4()
        for i in range(4):
            for j in range(4):
                obj.SetElement(i, j, mat[i, j])
        return obj


# ---------------------------------------------------------------------------------------# 
Example #5
Source File: common.py    From pyvista with MIT License 5 votes vote down vote up
def transform(self, trans):
        """Compute a transformation in place using a 4x4 transform.

        Parameters
        ----------
        trans : vtk.vtkMatrix4x4, vtk.vtkTransform, or np.ndarray
            Accepts a vtk transformation object or a 4x4 transformation matrix.

        """
        if isinstance(trans, vtk.vtkMatrix4x4):
            t = pyvista.trans_from_matrix(trans)
        elif isinstance(trans, vtk.vtkTransform):
            t = pyvista.trans_from_matrix(trans.GetMatrix())
        elif isinstance(trans, np.ndarray):
            if trans.ndim != 2:
                raise ValueError('Transformation array must be 4x4')
            elif trans.shape[0] != 4 or trans.shape[1] != 4:
                raise ValueError('Transformation array must be 4x4')
            t = trans
        else:
            raise TypeError('Input transform must be either:\n'
                            '\tvtk.vtkMatrix4x4\n'
                            '\tvtk.vtkTransform\n'
                            '\t4x4 np.ndarray\n')

        x = (self.points*t[0, :3]).sum(1) + t[0, -1]
        y = (self.points*t[1, :3]).sum(1) + t[1, -1]
        z = (self.points*t[2, :3]).sum(1) + t[2, -1]

        # overwrite points
        self.points[:, 0] = x
        self.points[:, 1] = y
        self.points[:, 2] = z