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
49#ifndef vtkTransform_h
50#define vtkTransform_h
51
52#include "vtkCommonTransformsModule.h" // For export macro
53#include "vtkLinearTransform.h"
54
55#include "vtkMatrix4x4.h" // Needed for inline methods
56
57VTK_ABI_NAMESPACE_BEGIN
58class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
59{
60public:
61 static vtkTransform* New();
63 void PrintSelf(ostream& os, vtkIndent indent) override;
64
70 void Identity();
71
77 void Inverse() override;
78
80
84 void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
85 void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
86 void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
88
90
96 void RotateWXYZ(double angle, double x, double y, double z)
97 {
98 this->Concatenation->Rotate(angle, x, y, z);
99 }
100 void RotateWXYZ(double angle, const double axis[3])
101 {
102 this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
103 }
104 void RotateWXYZ(double angle, const float axis[3])
105 {
106 this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
107 }
109
111
116 void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
117 void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
118 void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
120
122
127 void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
128 void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
129 void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
131
133
137 void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
138 void SetMatrix(const double elements[16])
139 {
140 this->Concatenation->Identity();
141 this->Concatenate(elements);
142 }
144
146
150 void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
151 void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
153
162
171 {
172 if (this->Concatenation->GetPreMultiplyFlag())
173 {
174 return;
175 }
176 this->Concatenation->SetPreMultiplyFlag(1);
177 this->Modified();
178 }
179
188 {
189 if (!this->Concatenation->GetPreMultiplyFlag())
190 {
191 return;
192 }
193 this->Concatenation->SetPreMultiplyFlag(0);
194 this->Modified();
195 }
196
202 {
203 return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
204 }
205
207
215 {
217 if (this->Input == nullptr)
218 {
219 t = this->Concatenation->GetTransform(i);
220 }
221 else if (i < this->Concatenation->GetNumberOfPreTransforms())
222 {
223 t = this->Concatenation->GetTransform(i);
224 }
225 else if (i > this->Concatenation->GetNumberOfPreTransforms())
226 {
227 t = this->Concatenation->GetTransform(i - 1);
228 }
229 else if (this->GetInverseFlag())
230 {
231 t = this->Input->GetInverse();
232 }
233 else
234 {
235 t = this->Input;
236 }
237 return static_cast<vtkLinearTransform*>(t);
238 }
240
242
246 void GetOrientation(double orient[3]);
247 void GetOrientation(float orient[3])
248 {
249 double temp[3];
250 this->GetOrientation(temp);
251 orient[0] = static_cast<float>(temp[0]);
252 orient[1] = static_cast<float>(temp[1]);
253 orient[2] = static_cast<float>(temp[2]);
254 }
256 {
257 this->GetOrientation(this->ReturnValue);
258 return this->ReturnValue;
259 }
261
266 static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
267
269
273 void GetOrientationWXYZ(double wxyz[4]);
274 void GetOrientationWXYZ(float wxyz[4])
275 {
276 double temp[4];
277 this->GetOrientationWXYZ(temp);
278 wxyz[0] = static_cast<float>(temp[0]);
279 wxyz[1] = static_cast<float>(temp[1]);
280 wxyz[2] = static_cast<float>(temp[2]);
281 wxyz[3] = static_cast<float>(temp[3]);
282 }
284 {
285 this->GetOrientationWXYZ(this->ReturnValue);
286 return this->ReturnValue;
287 }
289
291
296 void GetPosition(double pos[3]);
297 void GetPosition(float pos[3])
298 {
299 double temp[3];
300 this->GetPosition(temp);
301 pos[0] = static_cast<float>(temp[0]);
302 pos[1] = static_cast<float>(temp[1]);
303 pos[2] = static_cast<float>(temp[2]);
304 }
306 {
307 this->GetPosition(this->ReturnValue);
308 return this->ReturnValue;
309 }
311
313
319 void GetScale(double scale[3]);
320 void GetScale(float scale[3])
321 {
322 double temp[3];
323 this->GetScale(temp);
324 scale[0] = static_cast<float>(temp[0]);
325 scale[1] = static_cast<float>(temp[1]);
326 scale[2] = static_cast<float>(temp[2]);
327 }
329 {
330 this->GetScale(this->ReturnValue);
331 return this->ReturnValue;
332 }
334
339 void GetInverse(vtkMatrix4x4* inverse);
340
346 void GetTranspose(vtkMatrix4x4* transpose);
347
349
358 vtkLinearTransform* GetInput() { return this->Input; }
360
368 vtkTypeBool GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
369
371
374 void Push()
375 {
376 if (this->Stack == nullptr)
377 {
379 }
380 this->Stack->Push(&this->Concatenation);
381 this->Modified();
382 }
384
386
390 void Pop()
391 {
392 if (this->Stack == nullptr)
393 {
394 return;
395 }
396 this->Stack->Pop(&this->Concatenation);
397 this->Modified();
398 }
400
409 int CircuitCheck(vtkAbstractTransform* transform) override;
410
411 // Return an inverse transform which will always update itself
412 // to match this transform.
414
419
424
426
431 void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
432 void MultiplyPoint(const double in[4], double out[4])
433 {
434 this->GetMatrix()->MultiplyPoint(in, out);
435 }
437
438protected:
440 ~vtkTransform() override;
441
443
444 void InternalUpdate() override;
445
449
450 // this allows us to check whether people have been fooling
451 // around with our matrix
453
454 float Point[4];
455 double DoublePoint[4];
456 double ReturnValue[4];
457
458private:
459 vtkTransform(const vtkTransform&) = delete;
460 void operator=(const vtkTransform&) = delete;
461};
462
463VTK_ABI_NAMESPACE_END
464#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:38
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(...)