VTK  9.6.1
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
39
40#ifndef vtkTransform_h
41#define vtkTransform_h
42
43#include "vtkCommonTransformsModule.h" // For export macro
44#include "vtkLinearTransform.h"
45#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
46
47#include "vtkMatrix4x4.h" // Needed for inline methods
48
49VTK_ABI_NAMESPACE_BEGIN
50class VTKCOMMONTRANSFORMS_EXPORT VTK_MARSHALAUTO vtkTransform : public vtkLinearTransform
51{
52public:
53 static vtkTransform* New();
55 void PrintSelf(ostream& os, vtkIndent indent) override;
56
62 void Identity();
63
69 void Inverse() override;
70
72
76 void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
77 void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
78 void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
80
82
88 void RotateWXYZ(double angle, double x, double y, double z)
89 {
90 this->Concatenation->Rotate(angle, x, y, z);
91 }
92 void RotateWXYZ(double angle, const double axis[3])
93 {
94 this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
95 }
96 void RotateWXYZ(double angle, const float axis[3])
97 {
98 this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
99 }
100
101
103
108 void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
109 void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
110 void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
112
114
119 void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
120 void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
121 void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
123
125
129 void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
130 void SetMatrix(const double elements[16])
131 {
132 this->Concatenation->Identity();
133 this->Concatenate(elements);
134 }
135
136
138
142 void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
143 void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
145
154
163 {
164 if (this->Concatenation->GetPreMultiplyFlag())
165 {
166 return;
167 }
168 this->Concatenation->SetPreMultiplyFlag(1);
169 this->Modified();
170 }
171
180 {
181 if (!this->Concatenation->GetPreMultiplyFlag())
182 {
183 return;
184 }
185 this->Concatenation->SetPreMultiplyFlag(0);
186 this->Modified();
187 }
188
194 {
195 return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
196 }
197
199
207 {
209 if (this->Input == nullptr)
210 {
211 t = this->Concatenation->GetTransform(i);
212 }
213 else if (i < this->Concatenation->GetNumberOfPreTransforms())
214 {
215 t = this->Concatenation->GetTransform(i);
216 }
217 else if (i > this->Concatenation->GetNumberOfPreTransforms())
218 {
219 t = this->Concatenation->GetTransform(i - 1);
220 }
221 else if (this->GetInverseFlag())
222 {
223 t = this->Input->GetInverse();
224 }
225 else
226 {
227 t = this->Input;
228 }
229 return static_cast<vtkLinearTransform*>(t);
230 }
231
232
234
238 void GetOrientation(double orient[3]);
239 void GetOrientation(float orient[3])
240 {
241 double temp[3];
242 this->GetOrientation(temp);
243 orient[0] = static_cast<float>(temp[0]);
244 orient[1] = static_cast<float>(temp[1]);
245 orient[2] = static_cast<float>(temp[2]);
246 }
248 {
249 this->GetOrientation(this->ReturnValue);
250 return this->ReturnValue;
251 }
252
253
258 static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
259
261
265 void GetOrientationWXYZ(double wxyz[4]);
266 void GetOrientationWXYZ(float wxyz[4])
267 {
268 double temp[4];
269 this->GetOrientationWXYZ(temp);
270 wxyz[0] = static_cast<float>(temp[0]);
271 wxyz[1] = static_cast<float>(temp[1]);
272 wxyz[2] = static_cast<float>(temp[2]);
273 wxyz[3] = static_cast<float>(temp[3]);
274 }
276 {
277 this->GetOrientationWXYZ(this->ReturnValue);
278 return this->ReturnValue;
279 }
280
281
283
288 void GetPosition(double pos[3]);
289 void GetPosition(float pos[3])
290 {
291 double temp[3];
292 this->GetPosition(temp);
293 pos[0] = static_cast<float>(temp[0]);
294 pos[1] = static_cast<float>(temp[1]);
295 pos[2] = static_cast<float>(temp[2]);
296 }
298 {
299 this->GetPosition(this->ReturnValue);
300 return this->ReturnValue;
301 }
302
303
305
311 void GetScale(double scale[3]);
312 void GetScale(float scale[3])
313 {
314 double temp[3];
315 this->GetScale(temp);
316 scale[0] = static_cast<float>(temp[0]);
317 scale[1] = static_cast<float>(temp[1]);
318 scale[2] = static_cast<float>(temp[2]);
319 }
321 {
322 this->GetScale(this->ReturnValue);
323 return this->ReturnValue;
324 }
325
326
331 void GetInverse(vtkMatrix4x4* inverse);
332
338 void GetTranspose(vtkMatrix4x4* transpose);
339
341
350 vtkLinearTransform* GetInput() { return this->Input; }
352
360 vtkTypeBool GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
361
363
366 void Push()
367 {
368 if (this->Stack == nullptr)
369 {
371 }
372 this->Stack->Push(&this->Concatenation);
373 this->Modified();
374 }
375
376
378
382 void Pop()
383 {
384 if (this->Stack == nullptr)
385 {
386 return;
387 }
388 this->Stack->Pop(&this->Concatenation);
389 this->Modified();
390 }
391
392
401 int CircuitCheck(vtkAbstractTransform* transform) override;
402
403 // Return an inverse transform which will always update itself
404 // to match this transform.
406
411
416
418
423 void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
424 void MultiplyPoint(const double in[4], double out[4])
425 {
426 this->GetMatrix()->MultiplyPoint(in, out);
427 }
428
429
430protected:
432 ~vtkTransform() override;
433
435
436 void InternalUpdate() override;
437
441
442 // this allows us to check whether people have been fooling
443 // around with our matrix
445
446 float Point[4];
447 double DoublePoint[4];
448 double ReturnValue[4];
449
450private:
451 vtkTransform(const vtkTransform&) = delete;
452 void operator=(const vtkTransform&) = delete;
453};
454
455VTK_ABI_NAMESPACE_END
456#endif
void Modified() override
Override Modified to avoid ModifiedEvent during update.
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
vtkLinearTransform()=default
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!
static vtkTransformConcatenationStack * New()
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...
double ReturnValue[4]
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 ...
float Point[4]
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 ...
double DoublePoint[4]
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:323
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO