pyvista.Transform.apply

pyvista.Transform.apply#

Transform.apply(
obj: VectorLike[float] | MatrixLike[float] | DataSet | MultiBlock,
/,
mode: Literal['points', 'vectors', 'active_vectors', 'all_vectors'] | None = None,
*,
inverse: bool = False,
copy: bool = True,
)[source]#

Apply the current transformation matrix to points, vectors, or a dataset.

Note

Points with integer values are cast to a float type before the transformation is applied. A similar casting is also performed when transforming datasets. See also the notes at transform() which is used by this filter under the hood.

Parameters:
objVectorLike[float] | MatrixLike[float] | DataSet | MultiBlock

Object to apply the transformation to.

modestr, optional

Define how to apply the transformation. Different modes may be used depending on the input type.

  1. For array inputs:

    • 'points' transforms point arrays.

    • 'vectors' transforms vector arrays. The translation component of the transformation is removed for vectors.

    By default, 'points' mode is used for array inputs.

  2. For dataset inputs:

    The dataset’s points are always transformed, and its vectors are transformed based on the mode:

    • 'active_vectors' transforms active normals and active vectors arrays only.

    • 'all_vectors' transforms all input vectors, i.e. all arrays with three components. This mode is equivalent to setting transform_all_input_vectors=True with pyvista.DataObjectFilters.transform().

    By default, only 'active_vectors' are transformed.

inversebool, default: False

Apply the transformation using the inverse_matrix instead of the matrix.

copybool, default: True

Return a copy of the input with the transformation applied. Set this to False to transform the input directly and return it. Setting this to False only applies to NumPy float arrays and datasets; a copy is always returned for tuple and list inputs or arrays with integers.

Returns:
np.ndarray | DataSet | MultiBlock

Transformed array or dataset.

See also

apply_to_points

Equivalent to apply(obj, 'points') for point-array inputs.

apply_to_vectors

Equivalent to apply(obj, 'vectors') for vector-array inputs.

apply_to_dataset

Equivalent to apply(obj, mode) for dataset inputs where mode may be 'active_vectors' or 'all_vectors'.

pyvista.DataObjectFilters.transform

Transform a dataset.

Examples

Apply a transformation to a point.

>>> import numpy as np
>>> import pyvista as pv
>>> point = (1.0, 2.0, 3.0)
>>> transform = pv.Transform().scale(2).translate((0.0, 0.0, 1.0))
>>> transformed = transform.apply(point)
>>> transformed
array([2., 4., 7.])

Apply a transformation to a points array.

>>> array = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
>>> transformed = transform.apply(array)
>>> transformed
array([[ 2.,  4.,  7.],
       [ 8., 10., 13.]])

Apply a transformation to a vector array. Use the same array as before but use the 'vectors' mode. Note how the translation component is not applied to vectors.

>>> transformed = transform.apply(array, 'vectors')
>>> transformed
array([[ 2.,  4.,  6.],
       [ 8., 10., 12.]])

Apply a transformation to a dataset.

>>> dataset = pv.PolyData(array)
>>> transformed = transform.apply(dataset)
>>> transformed.points
pyvista_ndarray([[ 2.,  4.,  6.],
                 [ 8., 10., 12.]])

Apply the inverse.

>>> transformed = transform.apply(dataset, inverse=True)
>>> transformed.points
pyvista_ndarray([[0.5, 1. , 1. ],
                 [2. , 2.5, 2.5]])