pyvista.Transform.apply#
- Transform.apply(
- obj: VectorLike[float] | MatrixLike[float] | DataSet | MultiBlock | Prop3D,
- /,
- mode: Literal['points', 'vectors', 'active_vectors', 'all_vectors', 'replace', 'pre-multiply', 'post-multiply'] | None = None,
- *,
- inverse: bool = False,
- copy: bool = True,
Apply the current transformation
matrixto points, vectors, a dataset, or actor.注釈
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.- パラメータ:
- obj
VectorLike[float] |MatrixLike[float] |DataSet|MultiBlock|Prop3D Object to apply the transformation to.
- mode
str,optional Define how to apply the transformation. Different modes may be used depending on the input type.
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.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 settingtransform_all_input_vectors=Truewithpyvista.DataObjectFilters.transform().
By default, only
'active_vectors'are transformed.For actor inputs:
'pre-multiply'pre-multiplies this transform with the actor'suser_matrix.'post-multiply'post-multiplies this transform with the actor's user-matrix.'replace'replaces the actor's user-matrix with this transform'smatrix.
By default,
'post-multiply'mode is used for actors.
- inversebool, default:
False Apply the transformation using the
inverse_matrixinstead of thematrix.- copybool, default:
True Return a copy of the input with the transformation applied. Set this to
Falseto transform the input directly and return it. Setting this toFalseonly applies to NumPy float arrays, datasets, and actors; a copy is always returned for tuple and list inputs or arrays with integers.
- obj
- 戻り値:
np.ndarray|DataSet|MultiBlock|Prop3DTransformed array, dataset, or actor.
参考
apply_to_pointsEquivalent to
apply(obj, 'points')for point-array inputs.apply_to_vectorsEquivalent to
apply(obj, 'vectors')for vector-array inputs.apply_to_datasetEquivalent to
apply(obj, mode)for dataset inputs wheremodemay be'active_vectors'or'all_vectors'.apply_to_actorEquivalent to
apply(obj, mode)for actor inputs wheremodemay be'pre-multiply','post-multiply', or'replace'.pyvista.DataObjectFilters.transformTransform a dataset.
pyvista.Prop3D.transformアクターを変換します。
例
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]])
Apply a transformation to an actor.
>>> actor = pv.Actor() >>> transformed_actor = transform.apply(actor) >>> transformed_actor.user_matrix array([[2., 0., 0., 0.], [0., 2., 0., 0.], [0., 0., 2., 0.], [0., 0., 0., 1.]])