VTK  9.3.0
vtkTransform.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
40#ifndef vtkTransform_h
41#define vtkTransform_h
42
43#include "vtkCommonTransformsModule.h" // For export macro
44#include "vtkLinearTransform.h"
45
46#include "vtkMatrix4x4.h" // Needed for inline methods
47
48VTK_ABI_NAMESPACE_BEGIN
49class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
50{
51public:
52 static vtkTransform* New();
54 void PrintSelf(ostream& os, vtkIndent indent) override;
55
61 void Identity();
62
68 void Inverse() override;
69
71
75 void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
76 void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
77 void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
79
81
87 void RotateWXYZ(double angle, double x, double y, double z)
88 {
89 this->Concatenation->Rotate(angle, x, y, z);
90 }
91 void RotateWXYZ(double angle, const double axis[3])
92 {
93 this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
94 }
95 void RotateWXYZ(double angle, const float axis[3])
96 {
97 this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
98 }
100
102
107 void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
108 void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
109 void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
111
113
118 void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
119 void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
120 void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
122
124
128 void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
129 void SetMatrix(const double elements[16])
130 {
131 this->Concatenation->Identity();
132 this->Concatenate(elements);
133 }
135
137
141 void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
142 void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
144
153
162 {
163 if (this->Concatenation->GetPreMultiplyFlag())
164 {
165 return;
166 }
167 this->Concatenation->SetPreMultiplyFlag(1);
168 this->Modified();
169 }
170
179 {
180 if (!this->Concatenation->GetPreMultiplyFlag())
181 {
182 return;
183 }
184 this->Concatenation->SetPreMultiplyFlag(0);
185 this->Modified();
186 }
187
193 {
194 return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
195 }
196
198
206 {
208 if (this->Input == nullptr)
209 {
210 t = this->Concatenation->GetTransform(i);
211 }
212 else if (i < this->Concatenation->GetNumberOfPreTransforms())
213 {
214 t = this->Concatenation->GetTransform(i);
215 }
216 else if (i > this->Concatenation->GetNumberOfPreTransforms())
217 {
218 t = this->Concatenation->GetTransform(i - 1);
219 }
220 else if (this->GetInverseFlag())
221 {
222 t = this->Input->GetInverse();
223 }
224 else
225 {
226 t = this->Input;
227 }
228 return static_cast<vtkLinearTransform*>(t);
229 }
231
233
237 void GetOrientation(double orient[3]);
238 void GetOrientation(float orient[3])
239 {
240 double temp[3];
241 this->GetOrientation(temp);
242 orient[0] = static_cast<float>(temp[0]);
243 orient[1] = static_cast<float>(temp[1]);
244 orient[2] = static_cast<float>(temp[2]);
245 }
247 {
248 this->GetOrientation(this->ReturnValue);
249 return this->ReturnValue;
250 }
252
257 static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
258
260
264 void GetOrientationWXYZ(double wxyz[4]);
265 void GetOrientationWXYZ(float wxyz[4])
266 {
267 double temp[4];
268 this->GetOrientationWXYZ(temp);
269 wxyz[0] = static_cast<float>(temp[0]);
270 wxyz[1] = static_cast<float>(temp[1]);
271 wxyz[2] = static_cast<float>(temp[2]);
272 wxyz[3] = static_cast<float>(temp[3]);
273 }
275 {
276 this->GetOrientationWXYZ(this->ReturnValue);
277 return this->ReturnValue;
278 }
280
282
287 void GetPosition(double pos[3]);
288 void GetPosition(float pos[3])
289 {
290 double temp[3];
291 this->GetPosition(temp);
292 pos[0] = static_cast<float>(temp[0]);
293 pos[1] = static_cast<float>(temp[1]);
294 pos[2] = static_cast<float>(temp[2]);
295 }
297 {
298 this->GetPosition(this->ReturnValue);
299 return this->ReturnValue;
300 }
302
304
310 void GetScale(double scale[3]);
311 void GetScale(float scale[3])
312 {
313 double temp[3];
314 this->GetScale(temp);
315 scale[0] = static_cast<float>(temp[0]);
316 scale[1] = static_cast<float>(temp[1]);
317 scale[2] = static_cast<float>(temp[2]);
318 }
320 {
321 this->GetScale(this->ReturnValue);
322 return this->ReturnValue;
323 }
325
330 void GetInverse(vtkMatrix4x4* inverse);
331
337 void GetTranspose(vtkMatrix4x4* transpose);
338
340
349 vtkLinearTransform* GetInput() { return this->Input; }
351
359 vtkTypeBool GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
360
362
365 void Push()
366 {
367 if (this->Stack == nullptr)
368 {
370 }
371 this->Stack->Push(&this->Concatenation);
372 this->Modified();
373 }
375
377
381 void Pop()
382 {
383 if (this->Stack == nullptr)
384 {
385 return;
386 }
387 this->Stack->Pop(&this->Concatenation);
388 this->Modified();
389 }
391
400 int CircuitCheck(vtkAbstractTransform* transform) override;
401
402 // Return an inverse transform which will always update itself
403 // to match this transform.
405
410
415
417
422 void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
423 void MultiplyPoint(const double in[4], double out[4])
424 {
425 this->GetMatrix()->MultiplyPoint(in, out);
426 }
428
429protected:
431 ~vtkTransform() override;
432
434
435 void InternalUpdate() override;
436
440
441 // this allows us to check whether people have been fooling
442 // around with our matrix
444
445 float Point[4];
446 double DoublePoint[4];
447 double ReturnValue[4];
448
449private:
450 vtkTransform(const vtkTransform&) = delete;
451 void operator=(const vtkTransform&) = delete;
452};
453
454VTK_ABI_NAMESPACE_END
455#endif
superclass for all geometric transformations
vtkAbstractTransform * GetInverse()
Get the inverse of this transform.
vtkMatrix4x4 * GetMatrix()
Get a pointer to an internal vtkMatrix4x4 that represents the transformation.
a simple class to control print indentation
Definition vtkIndent.h:29
abstract superclass for linear transformations
represent and manipulate 4x4 transformation matrices
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
double Element[4][4]
The internal data is public for historical reasons. Do not use!
virtual void Modified()
Update the modification time for this object.
static vtkTransformConcatenationStack * New()
describes linear transformations via a 4x4 matrix
void Push()
Pushes the current transformation onto the transformation stack.
vtkTransformConcatenation * Concatenation
void RotateZ(double angle)
Create a rotation matrix about the X, Y, or Z axis and concatenate it with the current transformation...
vtkLinearTransform * Input
void GetScale(float scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers.
~vtkTransform() override
vtkMTimeType MatrixUpdateMTime
void MultiplyPoint(const float in[4], float out[4])
Use this method only if you wish to compute the transformation in homogeneous (x,y,...
void GetOrientation(float orient[3])
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
void GetTranspose(vtkMatrix4x4 *transpose)
Return a matrix which is the transpose of the current transformation matrix.
vtkTypeBool GetInverseFlag()
Get the inverse flag of the transformation.
int GetNumberOfConcatenatedTransforms()
Get the total number of transformations that are linked into this one via Concatenate() operations or...
void Concatenate(const double elements[16])
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
void PreMultiply()
Sets the internal state of the transform to PreMultiply.
void RotateWXYZ(double angle, const float axis[3])
Create a rotation matrix and concatenate it with the current transformation according to PreMultiply ...
void RotateY(double angle)
Create a rotation matrix about the X, Y, or Z axis and concatenate it with the current transformation...
vtkAbstractTransform * MakeTransform() override
Make a new transform of the same type.
double * GetScale()
Return the scale factors of the current transformation matrix as an array of three float numbers.
void GetInverse(vtkMatrix4x4 *inverse)
Return a matrix which is the inverse of the current transformation matrix.
double * GetOrientationWXYZ()
Return the wxyz angle+axis representing the current orientation.
void GetScale(double scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers.
void Scale(const double s[3])
Create a scale matrix (i.e.
vtkLinearTransform * GetConcatenatedTransform(int i)
Get one of the concatenated transformations as a vtkAbstractTransform.
vtkTransformConcatenationStack * Stack
vtkLinearTransform * GetInput()
Set the input for this transformation.
void GetPosition(float pos[3])
Return the position from the current transformation matrix as an array of three floating point number...
void Scale(const float s[3])
Create a scale matrix (i.e.
int CircuitCheck(vtkAbstractTransform *transform) override
Check for self-reference.
void Inverse() override
Invert the transformation.
void Concatenate(vtkLinearTransform *transform)
Concatenate the specified transform with the current transformation according to PreMultiply or PostM...
static void GetOrientation(double orient[3], vtkMatrix4x4 *matrix)
Convenience function to get the x, y, z orientation angles from a transformation matrix as an array o...
vtkMTimeType GetMTime() override
Override GetMTime to account for input and concatenation.
void Concatenate(vtkMatrix4x4 *matrix)
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
vtkAbstractTransform * GetInverse()
void PostMultiply()
Sets the internal state of the transform to PostMultiply.
void Pop()
Deletes the transformation on the top of the stack and sets the top to the next transformation on the...
void RotateWXYZ(double angle, double x, double y, double z)
Create a rotation matrix and concatenate it with the current transformation according to PreMultiply ...
void Scale(double x, double y, double z)
Create a scale matrix (i.e.
void GetOrientationWXYZ(double wxyz[4])
Return the wxyz angle+axis representing the current orientation.
double * GetPosition()
Return the position from the current transformation matrix as an array of three floating point number...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Translate(const float x[3])
Create a translation matrix and concatenate it with the current transformation according to PreMultip...
double * GetOrientation()
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
void GetPosition(double pos[3])
Return the position from the current transformation matrix as an array of three floating point number...
void Identity()
Set the transformation to the identity transformation.
void Translate(const double x[3])
Create a translation matrix and concatenate it with the current transformation according to PreMultip...
void RotateX(double angle)
Create a rotation matrix about the X, Y, or Z axis and concatenate it with the current transformation...
void SetMatrix(const double elements[16])
Set the current matrix directly.
void GetOrientationWXYZ(float wxyz[4])
Return the wxyz angle+axis representing the current orientation.
void Translate(double x, double y, double z)
Create a translation matrix and concatenate it with the current transformation according to PreMultip...
void RotateWXYZ(double angle, const double axis[3])
Create a rotation matrix and concatenate it with the current transformation according to PreMultiply ...
void GetOrientation(double orient[3])
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
void SetInput(vtkLinearTransform *input)
Set the input for this transformation.
void InternalUpdate() override
Perform any subclass-specific Update.
static vtkTransform * New()
void MultiplyPoint(const double in[4], double out[4])
Use this method only if you wish to compute the transformation in homogeneous (x,y,...
void InternalDeepCopy(vtkAbstractTransform *t) override
Perform any subclass-specific DeepCopy.
void SetMatrix(vtkMatrix4x4 *matrix)
Set the current matrix directly.
int vtkTypeBool
Definition vtkABI.h:64
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270
#define VTK_SIZEHINT(...)