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 
48 VTK_ABI_NAMESPACE_BEGIN
49 class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
50 {
51 public:
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 
152  void Concatenate(vtkLinearTransform* transform);
153 
161  void PreMultiply()
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  }
319  double* GetScale() VTK_SIZEHINT(3)
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  {
369  this->Stack = vtkTransformConcatenationStack::New();
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 
414  vtkMTimeType GetMTime() override;
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 
429 protected:
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 
449 private:
450  vtkTransform(const vtkTransform&) = delete;
451  void operator=(const vtkTransform&) = delete;
452 };
453 
454 VTK_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
Definition: vtkMatrix4x4.h:31
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:147
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:34
virtual void Modified()
Update the modification time for this object.
static vtkTransformConcatenationStack * New()
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:50
void Push()
Pushes the current transformation onto the transformation stack.
Definition: vtkTransform.h:365
vtkTransformConcatenation * Concatenation
Definition: vtkTransform.h:438
void RotateZ(double angle)
Create a rotation matrix about the X, Y, or Z axis and concatenate it with the current transformation...
Definition: vtkTransform.h:109
vtkAbstractTransform * MakeTransform() override
Make a new transform of the same type.
vtkLinearTransform * Input
Definition: vtkTransform.h:437
void GetScale(float scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:311
~vtkTransform() override
double * GetScale()
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:319
vtkMTimeType MatrixUpdateMTime
Definition: vtkTransform.h:443
void MultiplyPoint(const float in[4], float out[4])
Use this method only if you wish to compute the transformation in homogeneous (x,y,...
Definition: vtkTransform.h:422
void GetOrientation(float orient[3])
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
Definition: vtkTransform.h:238
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.
Definition: vtkTransform.h:359
int GetNumberOfConcatenatedTransforms()
Get the total number of transformations that are linked into this one via Concatenate() operations or...
Definition: vtkTransform.h:192
void Concatenate(const double elements[16])
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
Definition: vtkTransform.h:142
void PreMultiply()
Sets the internal state of the transform to PreMultiply.
Definition: vtkTransform.h:161
void RotateWXYZ(double angle, const float axis[3])
Create a rotation matrix and concatenate it with the current transformation according to PreMultiply ...
Definition: vtkTransform.h:95
void RotateY(double angle)
Create a rotation matrix about the X, Y, or Z axis and concatenate it with the current transformation...
Definition: vtkTransform.h:108
void GetInverse(vtkMatrix4x4 *inverse)
Return a matrix which is the inverse of the current transformation matrix.
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.
Definition: vtkTransform.h:119
vtkTransformConcatenationStack * Stack
Definition: vtkTransform.h:439
void GetPosition(float pos[3])
Return the position from the current transformation matrix as an array of three floating point number...
Definition: vtkTransform.h:288
vtkAbstractTransform * GetInverse()
Definition: vtkTransform.h:404
void Scale(const float s[3])
Create a scale matrix (i.e.
Definition: vtkTransform.h:120
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...
double * GetPosition()
Return the position from the current transformation matrix as an array of three floating point number...
Definition: vtkTransform.h:296
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...
Definition: vtkTransform.h:141
static vtkTransform * New()
double * GetOrientationWXYZ()
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:274
void PostMultiply()
Sets the internal state of the transform to PostMultiply.
Definition: vtkTransform.h:178
void Pop()
Deletes the transformation on the top of the stack and sets the top to the next transformation on the...
Definition: vtkTransform.h:381
void RotateWXYZ(double angle, double x, double y, double z)
Create a rotation matrix and concatenate it with the current transformation according to PreMultiply ...
Definition: vtkTransform.h:87
void Scale(double x, double y, double z)
Create a scale matrix (i.e.
Definition: vtkTransform.h:118
void GetOrientationWXYZ(double wxyz[4])
Return the wxyz angle+axis representing the current orientation.
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...
Definition: vtkTransform.h:77
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...
Definition: vtkTransform.h:76
void RotateX(double angle)
Create a rotation matrix about the X, Y, or Z axis and concatenate it with the current transformation...
Definition: vtkTransform.h:107
void SetMatrix(const double elements[16])
Set the current matrix directly.
Definition: vtkTransform.h:129
void GetOrientationWXYZ(float wxyz[4])
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:265
void Translate(double x, double y, double z)
Create a translation matrix and concatenate it with the current transformation according to PreMultip...
Definition: vtkTransform.h:75
vtkLinearTransform * GetConcatenatedTransform(int i)
Get one of the concatenated transformations as a vtkAbstractTransform.
Definition: vtkTransform.h:205
void RotateWXYZ(double angle, const double axis[3])
Create a rotation matrix and concatenate it with the current transformation according to PreMultiply ...
Definition: vtkTransform.h:91
double * GetOrientation()
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
Definition: vtkTransform.h:246
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.
void MultiplyPoint(const double in[4], double out[4])
Use this method only if you wish to compute the transformation in homogeneous (x,y,...
Definition: vtkTransform.h:423
vtkLinearTransform * GetInput()
Set the input for this transformation.
Definition: vtkTransform.h:349
void InternalDeepCopy(vtkAbstractTransform *t) override
Perform any subclass-specific DeepCopy.
void SetMatrix(vtkMatrix4x4 *matrix)
Set the current matrix directly.
Definition: vtkTransform.h:128
@ scale
Definition: vtkX3D.h:229
int vtkTypeBool
Definition: vtkABI.h:64
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
#define VTK_SIZEHINT(...)