DataObjectFilters.transform

DataObjectFilters.transform#

DataObjectFilters.transform(
trans: TransformLike,
*,
transform_all_input_vectors: bool = False,
inplace: bool | None = None,
progress_bar: bool = False,
) → _MeshType_co[source]#

Transform this mesh with a 4x4 transform.

Warning

When using transform_all_input_vectors=True, there is no distinction in VTK between vectors and arrays with three components. This may be an issue if you have scalar data with three components (for example, RGB data). This will be improperly transformed as if it was vector data rather than scalar data. One possible (albeit ugly) workaround is to store the three components as separate scalar arrays.

Warning

In general, transformations give non-integer results. This method converts integer-typed vector data to float before performing the transformation. This applies to the points array, as well as any vector-valued data that is affected by the transformation. To prevent subtle bugs arising from in-place transformations truncating the result to integers, this conversion always applies to the input mesh.

Warning

Shear transformations are not supported for ImageData or RectilinearGrid, and RectilinearGrid only supports rotations which map each axis onto a coordinate axis, i.e. multiples of 90 degrees. If an unsupported transformation is present, a ValueError is raised. To fully support these transformations, the input should be cast to StructuredGrid before applying this filter.

Note

Transforming ImageData modifies its origin, spacing, and direction_matrix properties.

Changed in version 0.50: Rotations which map each axis onto a coordinate axis are supported for RectilinearGrid. Its coordinates always ascend, and its dimensions, points and arrays are ordered to match.

Changed in version 0.48.0: The parameter inplace must be specified whereas it previously defaulted to True.

Changed in version 0.45.0: Transforming ImageData now returns ImageData. Previously, StructuredGrid was returned.

Changed in version 0.46.0: Transforming RectilinearGrid now returns RectilinearGrid. Previously, StructuredGrid was returned.

Changed in version 0.47.0: An error is now raised instead of a warning if a transformation cannot be applied.

Parameters:
transTransformLike

Accepts a vtk transformation object or a 4x4 transformation matrix.

transform_all_input_vectorsbool, default: False

When True, all arrays with three components are transformed. Otherwise, only the normals and vectors are transformed. See the warning for more details.

inplacebool

When True, modifies the dataset in-place and returned dataset is the same dataset. When False a new transformed dataset is returned with the original unchanged. The value of this parameter must be explicitly set.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
outputDataSet | MultiBlock

Transformed dataset. Return type matches input.

Examples#

Download Python source code | Download Jupyter notebook

Translate a mesh by (50, 100, 200).

>>> import numpy as np
>>> from pyvista import examples
>>> mesh = examples.load_airplane()

Here a 4x4 numpy.ndarray is used, but any TransformLike is accepted.

>>> transform_matrix = np.array(
...     [
...         [1, 0, 0, 50],
...         [0, 1, 0, 100],
...         [0, 0, 1, 200],
...         [0, 0, 0, 1],
...     ]
... )
>>> transformed = mesh.transform(transform_matrix, inplace=False)
>>> transformed.plot(show_edges=True)
../../../_images/pyvista-DataObjectFilters-transform-4d4b7aa3c09642bc_00_00.png

See Also#

pyvista.Transform

Describe linear transformations via a 4x4 matrix.

pyvista.Prop3D.transform

Transform an actor.