Skip to content

Transform

Introduction

vtkTransform describes linear transformations via a 4x4 matrix.

A vtkTransform can be used to describe the full range of linear (also known as affine) coordinate transformations in three dimensions, which are internally represented as a 4x4 homogeneous transformation matrix. When you create a new vtkTransform, it is always initialized to the identity transformation.

Most of the methods for manipulating this transformation (e.g. transformMatrices, transformMatrix) (TODO: Translate, Rotate, Concatenate...) can operate in either PreMultiply (the default) or PostMultiply mode. In PreMultiply mode, the translation, concatenation, etc. will occur before any transformations which are represented by the current matrix. In PostMultiply mode, the additional transformation will occur after any transformations represented by the current matrix.

This class performs all of its operations in a right handed coordinate system with right handed rotations. Some other graphics libraries use left handed coordinate systems and rotations. Note: vtkTransform uses column-major format.

Usage

js
import vtkTransform from '@kitware/vtk.js/Common/Transform/Transform';
import vtkMatrixBuilder from '@kitware/vtk.js/Common/Core/MatrixBuilder';

const transform = vtkTransform.newInstance();
const matrix = vtkMatrixBuilder
  .buildFromDegree()
  .rotateZ(45)
  .getMatrix();
transform.setMatrix(matrix);
const pointsIn = [[1, 2, 3], [4, 5, 6]];
const pointsOut = new Float32Array(6);
transform.transformPoints(pointsIn, pointsOut);

Methods

extend

Method used to decorate a given object (publicAPI+model) with vtkTransform characteristics.

ArgumentTypeRequiredDescription
publicAPIYesobject on which methods will be bounds (public)
modelYesobject on which data structure will be bounds (protected)
initialValuesITransformInitialValuesNo(default: {})

getInverse

Returns

TypeDescription
A new transform with an inversed internal matrix. Also copy the premultiply flag @see getPreMultiplyFlag.

getMatrix

Mat4 matrix, used by vtkTransform to transform points, vertices, matrices... Default is identity.

getPreMultiplyFlag

The value of preMultiplyFlag indicates how matrix multiplications should occur.

When in premultiply mode: All subsequent operations will occur before those already represented in the current transformation. In homogeneous matrix notation, M = M*A where M is the current transformation matrix and A is the applied matrix.

When in postmultiply mode: All subsequent operations will occur after those already represented in the current transformation. In homogeneous matrix notation, M = A*M where M is the current transformation matrix and A is the applied matrix.

This flag is also used in @see transformMatrix and @see transformMatrices to indicate how transform is applied to matrices: Premultiply: O_i = M * A_i Postmultiply: O_i = A_i * M where M is the current transformation matrix, A_i are the matrices in argument, O_i are the output matrices.

The default is PreMultiply.

newInstance

Method used to create a new instance of vtkTransform.

ArgumentTypeRequiredDescription
initialValuesITransformInitialValuesNofor pre-setting some of its content

postMultiply

Set preMultiplyFlag to false

preMultiply

Set preMultiplyFlag to true

rotateWXYZ

Create a rotation matrix and concatenate it with the current transformation according to preMultiply or postMultiply semantics. The angle is expressed in degrees.

ArgumentTypeRequiredDescription
angleNumberYesAngle in degrees
xNumberYesX component of the rotation axis
yNumberYesY component of the rotation axis
zNumberYesZ component of the rotation axis

rotateX

Create a rotation matrix and concatenate it with the current transformation according to preMultiply or postMultiply semantics. The angle is expressed in degrees.

ArgumentTypeRequiredDescription
angleNumberYesAngle in degrees

rotateY

Create a rotation matrix about the X, Y, or Z axis and concatenate it with the current transformation according to preMultiply or postMultiply semantics.

ArgumentTypeRequiredDescription
angleNumberYesAngle in degrees

rotateZ

Create a rotation matrix about the X, Y, or Z axis and concatenate it with the current transformation according to preMultiply or postMultiply semantics.

ArgumentTypeRequiredDescription
angleNumberYesAngle in degrees

scale

Create a scale matrix (i.e. set the diagonal elements to x, y, z) and concatenate it with the current transformation according to preMultiply or postMultiply semantics.

ArgumentTypeRequiredDescription
xNumberYesDiagonal element for X axis
yNumberYesDiagonal element for Y axis
zNumberYesDiagonal element for Z axis

setMatrix

ArgumentTypeRequiredDescription
e00Yes
e01Yes
e02Yes
e03Yes
e10Yes
e11Yes
e12Yes
e13Yes
e20Yes
e21Yes
e22Yes
e23Yes
e30Yes
e31Yes
e32Yes
e33Yes

setMatrix

ArgumentTypeRequiredDescription
matrixmat4Yes

setPreMultiplyFlag

ArgumentTypeRequiredDescription
preMultiplyFlagYes

transformMatrices

Transform multiple matrices using the internal transform matrix See @see transformMatrix for more info Modify the out array only

ArgumentTypeRequiredDescription
matricesYesAn array (typed or not) containing n*16 elements or of shape (n, 16)
outYesAn array (typed or not) containing n*16 elements or of shape (n, 16)

transformMatrix

Transform a single matrix using the internal transform matrix The resulting matrix is: Mout = M * Min when in premultiply mode Mout = Min * M when in postmultiply mode

ArgumentTypeRequiredDescription
matrixYesThe matrix to transform, is not modified (except if matrix === out)
outYesThe receiving output matrix, is modified, can be the same as matrix

Returns

TypeDescription
The out parameter

transformNormal

Apply the transformation to a normal.

ArgumentTypeRequiredDescription
inNormalvec3YesThe normal vector to transform
outNormalvec3YesThe output vector

Returns

TypeDescription
vec3The transformed normal vector

transformNormals

Apply the transformation to a series of normals, and append the results to outNormals.

ArgumentTypeRequiredDescription
inNormalsvtkDataArrayYesThe normal vectors to transform
outNormalsvtkDataArrayYesThe output array

transformPoint

Transform a single point using the internal transform matrix The resulting point is: Pout = M * Pin where M is the internal matrix, Pin and Pout the in and out points

ArgumentTypeRequiredDescription
pointYesThe point to transform, is not modified (except if point === out)
outYesThe receiving output point, is modified, can be the same as point

Returns

TypeDescription
The out parameter

transformPoints

Transform multiple points using the internal transform matrix See @see transformPoint for more info Modify the out array only

ArgumentTypeRequiredDescription
pointsYesAn array (typed or not) containing n*3 elements or of shape (n, 3)
outYesAn array (typed or not) containing n*3 elements or of shape (n, 3)

transformPointsNormalsVectors

Transform points, normals, and vectors simultaneously.

ArgumentTypeRequiredDescription
inPointsvtkPointsYesInput points
outPointsvtkPointsYesOutput points
inNormalsvtkDataArrayYesInput normals
outNormalsvtkDataArrayYesOutput normals
inVectorsvtkDataArrayYesInput vectors
outVectorsvtkDataArrayYesOutput vectors
inVectorsArrArray<vtkDataArray>YesOptional input vectors arrays
outVectorsArrArray<vtkDataArray>YesOptional output vectors arrays

transformVector

Apply the transformation to a vector.

ArgumentTypeRequiredDescription
inVectorvec3YesThe vector to transform
outVectorvec3YesThe output vector
matrix=nullmat3Noif null (default), the Transform matrix is being used.

Returns

TypeDescription
vec3The transformed vector

transformVectors

Apply the transformation to a series of vectors, and append the results to outVectors.

ArgumentTypeRequiredDescription
inVectorsvtkDataArrayYesThe vectors to transform
outVectorsvtkDataArrayYesThe output array

translate

Create a translation matrix and concatenate it with the current transformation according to preMultiply or postMultiply semantics.

ArgumentTypeRequiredDescription
xNumberYesX component of the translation
yNumberYesY component of the translation
zNumberYesZ component of the translation