Exemplo n.º 1
0
def vtkmatrix_from_array(array):
    """Convert a ``numpy.ndarray`` or array-like to a vtk matrix.

    Parameters
    ----------
    array : numpy.ndarray or array-like
        The array or array-like to be converted to a vtk matrix.
        Shape (3, 3) gets converted to a ``vtk.vtkMatrix3x3``, shape (4, 4)
        gets converted to a ``vtk.vtkMatrix4x4``. No other shapes are valid.

    Returns
    -------
    vtk.vtkMatrix3x3 or vtk.vtkMatrix4x4
        VTK matrix.

    """
    array = np.asarray(array)
    if array.shape == (3, 3):
        matrix = _vtk.vtkMatrix3x3()
    elif array.shape == (4, 4):
        matrix = _vtk.vtkMatrix4x4()
    else:
        raise ValueError(
            f'Invalid shape {array.shape}, must be (3, 3) or (4, 4).')
    m, n = array.shape
    for i in range(m):
        for j in range(n):
            matrix.SetElement(i, j, array[i, j])
    return matrix
Exemplo n.º 2
0
    def model_transform_matrix(self, matrix):
        """Set the camera's model transformation matrix.

        Examples
        --------
        >>> import pyvista
        >>> pl = pyvista.Plotter()
        >>> trans_mat = np.array([[1., 0., 0., 0.],
                                  [0., 1., 0., 0.],
                                  [0., 0., 1., 0.],
                                  [0., 0., 0., 1.]])
        >>> pl.camera.model_transform_matrix = trans_mat
        """
        vtk_matrix = _vtk.vtkMatrix4x4()
        vtk_matrix.DeepCopy(matrix.ravel())
        self.SetModelTransformMatrix(vtk_matrix)
Exemplo n.º 3
0
 def model_transform_matrix(self, matrix):
     """Set the camera's model transformation matrix."""
     vtk_matrix = _vtk.vtkMatrix4x4()
     vtk_matrix.DeepCopy(matrix.ravel())
     self.SetModelTransformMatrix(vtk_matrix)