VTK  9.3.20240328
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 
149 #ifndef vtkTransform_h
150 #define vtkTransform_h
151 
152 #include "vtkCommonTransformsModule.h" // For export macro
153 #include "vtkLinearTransform.h"
154 
155 #include "vtkMatrix4x4.h" // Needed for inline methods
156 
157 VTK_ABI_NAMESPACE_BEGIN
158 class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
159 {
160 public:
161  static vtkTransform* New();
163  void PrintSelf(ostream& os, vtkIndent indent) override;
164 
170  void Identity();
171 
177  void Inverse() override;
178 
180 
184  void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
185  void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
186  void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
188 
190 
196  void RotateWXYZ(double angle, double x, double y, double z)
197  {
198  this->Concatenation->Rotate(angle, x, y, z);
199  }
200  void RotateWXYZ(double angle, const double axis[3])
201  {
202  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
203  }
204  void RotateWXYZ(double angle, const float axis[3])
205  {
206  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
207  }
209 
211 
216  void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
217  void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
218  void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
220 
222 
227  void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
228  void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
229  void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
231 
233 
237  void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
238  void SetMatrix(const double elements[16])
239  {
240  this->Concatenation->Identity();
241  this->Concatenate(elements);
242  }
244 
246 
250  void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
251  void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
253 
261  void Concatenate(vtkLinearTransform* transform);
262 
270  void PreMultiply()
271  {
272  if (this->Concatenation->GetPreMultiplyFlag())
273  {
274  return;
275  }
276  this->Concatenation->SetPreMultiplyFlag(1);
277  this->Modified();
278  }
279 
288  {
289  if (!this->Concatenation->GetPreMultiplyFlag())
290  {
291  return;
292  }
293  this->Concatenation->SetPreMultiplyFlag(0);
294  this->Modified();
295  }
296 
302  {
303  return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
304  }
305 
307 
315  {
317  if (this->Input == nullptr)
318  {
319  t = this->Concatenation->GetTransform(i);
320  }
321  else if (i < this->Concatenation->GetNumberOfPreTransforms())
322  {
323  t = this->Concatenation->GetTransform(i);
324  }
325  else if (i > this->Concatenation->GetNumberOfPreTransforms())
326  {
327  t = this->Concatenation->GetTransform(i - 1);
328  }
329  else if (this->GetInverseFlag())
330  {
331  t = this->Input->GetInverse();
332  }
333  else
334  {
335  t = this->Input;
336  }
337  return static_cast<vtkLinearTransform*>(t);
338  }
340 
342 
346  void GetOrientation(double orient[3]);
347  void GetOrientation(float orient[3])
348  {
349  double temp[3];
350  this->GetOrientation(temp);
351  orient[0] = static_cast<float>(temp[0]);
352  orient[1] = static_cast<float>(temp[1]);
353  orient[2] = static_cast<float>(temp[2]);
354  }
356  {
357  this->GetOrientation(this->ReturnValue);
358  return this->ReturnValue;
359  }
361 
366  static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
367 
369 
373  void GetOrientationWXYZ(double wxyz[4]);
374  void GetOrientationWXYZ(float wxyz[4])
375  {
376  double temp[4];
377  this->GetOrientationWXYZ(temp);
378  wxyz[0] = static_cast<float>(temp[0]);
379  wxyz[1] = static_cast<float>(temp[1]);
380  wxyz[2] = static_cast<float>(temp[2]);
381  wxyz[3] = static_cast<float>(temp[3]);
382  }
384  {
385  this->GetOrientationWXYZ(this->ReturnValue);
386  return this->ReturnValue;
387  }
389 
391 
396  void GetPosition(double pos[3]);
397  void GetPosition(float pos[3])
398  {
399  double temp[3];
400  this->GetPosition(temp);
401  pos[0] = static_cast<float>(temp[0]);
402  pos[1] = static_cast<float>(temp[1]);
403  pos[2] = static_cast<float>(temp[2]);
404  }
406  {
407  this->GetPosition(this->ReturnValue);
408  return this->ReturnValue;
409  }
411 
413 
419  void GetScale(double scale[3]);
420  void GetScale(float scale[3])
421  {
422  double temp[3];
423  this->GetScale(temp);
424  scale[0] = static_cast<float>(temp[0]);
425  scale[1] = static_cast<float>(temp[1]);
426  scale[2] = static_cast<float>(temp[2]);
427  }
428  double* GetScale() VTK_SIZEHINT(3)
429  {
430  this->GetScale(this->ReturnValue);
431  return this->ReturnValue;
432  }
434 
439  void GetInverse(vtkMatrix4x4* inverse);
440 
446  void GetTranspose(vtkMatrix4x4* transpose);
447 
449 
458  vtkLinearTransform* GetInput() { return this->Input; }
460 
468  vtkTypeBool GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
469 
471 
474  void Push()
475  {
476  if (this->Stack == nullptr)
477  {
478  this->Stack = vtkTransformConcatenationStack::New();
479  }
480  this->Stack->Push(&this->Concatenation);
481  this->Modified();
482  }
484 
486 
490  void Pop()
491  {
492  if (this->Stack == nullptr)
493  {
494  return;
495  }
496  this->Stack->Pop(&this->Concatenation);
497  this->Modified();
498  }
500 
509  int CircuitCheck(vtkAbstractTransform* transform) override;
510 
511  // Return an inverse transform which will always update itself
512  // to match this transform.
514 
519 
523  vtkMTimeType GetMTime() override;
524 
526 
531  void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
532  void MultiplyPoint(const double in[4], double out[4])
533  {
534  this->GetMatrix()->MultiplyPoint(in, out);
535  }
537 
538 protected:
540  ~vtkTransform() override;
541 
543 
544  void InternalUpdate() override;
545 
549 
550  // this allows us to check whether people have been fooling
551  // around with our matrix
553 
554  float Point[4];
555  double DoublePoint[4];
556  double ReturnValue[4];
557 
558 private:
559  vtkTransform(const vtkTransform&) = delete;
560  void operator=(const vtkTransform&) = delete;
561 };
562 
563 VTK_ABI_NAMESPACE_END
564 #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:108
abstract superclass for linear transformations
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:140
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:256
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:143
virtual void Modified()
Update the modification time for this object.
static vtkTransformConcatenationStack * New()
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:159
void Push()
Pushes the current transformation onto the transformation stack.
Definition: vtkTransform.h:474
vtkTransformConcatenation * Concatenation
Definition: vtkTransform.h:547
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:218
vtkAbstractTransform * MakeTransform() override
Make a new transform of the same type.
vtkLinearTransform * Input
Definition: vtkTransform.h:546
void GetScale(float scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:420
~vtkTransform() override
double * GetScale()
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:428
vtkMTimeType MatrixUpdateMTime
Definition: vtkTransform.h:552
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:531
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:347
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:468
int GetNumberOfConcatenatedTransforms()
Get the total number of transformations that are linked into this one via Concatenate() operations or...
Definition: vtkTransform.h:301
void Concatenate(const double elements[16])
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
Definition: vtkTransform.h:251
void PreMultiply()
Sets the internal state of the transform to PreMultiply.
Definition: vtkTransform.h:270
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:204
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:217
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:228
vtkTransformConcatenationStack * Stack
Definition: vtkTransform.h:548
void GetPosition(float pos[3])
Return the position from the current transformation matrix as an array of three floating point number...
Definition: vtkTransform.h:397
vtkAbstractTransform * GetInverse()
Definition: vtkTransform.h:513
void Scale(const float s[3])
Create a scale matrix (i.e.
Definition: vtkTransform.h:229
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:405
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:250
static vtkTransform * New()
double * GetOrientationWXYZ()
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:383
void PostMultiply()
Sets the internal state of the transform to PostMultiply.
Definition: vtkTransform.h:287
void Pop()
Deletes the transformation on the top of the stack and sets the top to the next transformation on the...
Definition: vtkTransform.h:490
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:196
void Scale(double x, double y, double z)
Create a scale matrix (i.e.
Definition: vtkTransform.h:227
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:186
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:185
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:216
void SetMatrix(const double elements[16])
Set the current matrix directly.
Definition: vtkTransform.h:238
void GetOrientationWXYZ(float wxyz[4])
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:374
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:184
vtkLinearTransform * GetConcatenatedTransform(int i)
Get one of the concatenated transformations as a vtkAbstractTransform.
Definition: vtkTransform.h:314
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:200
double * GetOrientation()
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
Definition: vtkTransform.h:355
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:532
vtkLinearTransform * GetInput()
Set the input for this transformation.
Definition: vtkTransform.h:458
void InternalDeepCopy(vtkAbstractTransform *t) override
Perform any subclass-specific DeepCopy.
void SetMatrix(vtkMatrix4x4 *matrix)
Set the current matrix directly.
Definition: vtkTransform.h:237
@ scale
Definition: vtkX3D.h:229
int vtkTypeBool
Definition: vtkABI.h:64
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
#define VTK_SIZEHINT(...)