VTK  9.3.20240329
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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
155 
156 #include "vtkMatrix4x4.h" // Needed for inline methods
157 
158 VTK_ABI_NAMESPACE_BEGIN
159 class VTKCOMMONTRANSFORMS_EXPORT VTK_MARSHALAUTO vtkTransform : public vtkLinearTransform
160 {
161 public:
162  static vtkTransform* New();
164  void PrintSelf(ostream& os, vtkIndent indent) override;
165 
171  void Identity();
172 
178  void Inverse() override;
179 
181 
185  void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
186  void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
187  void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
189 
191 
197  void RotateWXYZ(double angle, double x, double y, double z)
198  {
199  this->Concatenation->Rotate(angle, x, y, z);
200  }
201  void RotateWXYZ(double angle, const double axis[3])
202  {
203  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
204  }
205  void RotateWXYZ(double angle, const float axis[3])
206  {
207  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
208  }
210 
212 
217  void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
218  void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
219  void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
221 
223 
228  void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
229  void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
230  void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
232 
234 
238  void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
239  void SetMatrix(const double elements[16])
240  {
241  this->Concatenation->Identity();
242  this->Concatenate(elements);
243  }
245 
247 
251  void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
252  void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
254 
262  void Concatenate(vtkLinearTransform* transform);
263 
271  void PreMultiply()
272  {
273  if (this->Concatenation->GetPreMultiplyFlag())
274  {
275  return;
276  }
277  this->Concatenation->SetPreMultiplyFlag(1);
278  this->Modified();
279  }
280 
289  {
290  if (!this->Concatenation->GetPreMultiplyFlag())
291  {
292  return;
293  }
294  this->Concatenation->SetPreMultiplyFlag(0);
295  this->Modified();
296  }
297 
303  {
304  return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
305  }
306 
308 
316  {
318  if (this->Input == nullptr)
319  {
320  t = this->Concatenation->GetTransform(i);
321  }
322  else if (i < this->Concatenation->GetNumberOfPreTransforms())
323  {
324  t = this->Concatenation->GetTransform(i);
325  }
326  else if (i > this->Concatenation->GetNumberOfPreTransforms())
327  {
328  t = this->Concatenation->GetTransform(i - 1);
329  }
330  else if (this->GetInverseFlag())
331  {
332  t = this->Input->GetInverse();
333  }
334  else
335  {
336  t = this->Input;
337  }
338  return static_cast<vtkLinearTransform*>(t);
339  }
341 
343 
347  void GetOrientation(double orient[3]);
348  void GetOrientation(float orient[3])
349  {
350  double temp[3];
351  this->GetOrientation(temp);
352  orient[0] = static_cast<float>(temp[0]);
353  orient[1] = static_cast<float>(temp[1]);
354  orient[2] = static_cast<float>(temp[2]);
355  }
357  {
358  this->GetOrientation(this->ReturnValue);
359  return this->ReturnValue;
360  }
362 
367  static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
368 
370 
374  void GetOrientationWXYZ(double wxyz[4]);
375  void GetOrientationWXYZ(float wxyz[4])
376  {
377  double temp[4];
378  this->GetOrientationWXYZ(temp);
379  wxyz[0] = static_cast<float>(temp[0]);
380  wxyz[1] = static_cast<float>(temp[1]);
381  wxyz[2] = static_cast<float>(temp[2]);
382  wxyz[3] = static_cast<float>(temp[3]);
383  }
385  {
386  this->GetOrientationWXYZ(this->ReturnValue);
387  return this->ReturnValue;
388  }
390 
392 
397  void GetPosition(double pos[3]);
398  void GetPosition(float pos[3])
399  {
400  double temp[3];
401  this->GetPosition(temp);
402  pos[0] = static_cast<float>(temp[0]);
403  pos[1] = static_cast<float>(temp[1]);
404  pos[2] = static_cast<float>(temp[2]);
405  }
407  {
408  this->GetPosition(this->ReturnValue);
409  return this->ReturnValue;
410  }
412 
414 
420  void GetScale(double scale[3]);
421  void GetScale(float scale[3])
422  {
423  double temp[3];
424  this->GetScale(temp);
425  scale[0] = static_cast<float>(temp[0]);
426  scale[1] = static_cast<float>(temp[1]);
427  scale[2] = static_cast<float>(temp[2]);
428  }
429  double* GetScale() VTK_SIZEHINT(3)
430  {
431  this->GetScale(this->ReturnValue);
432  return this->ReturnValue;
433  }
435 
440  void GetInverse(vtkMatrix4x4* inverse);
441 
447  void GetTranspose(vtkMatrix4x4* transpose);
448 
450 
459  vtkLinearTransform* GetInput() { return this->Input; }
461 
469  vtkTypeBool GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
470 
472 
475  void Push()
476  {
477  if (this->Stack == nullptr)
478  {
479  this->Stack = vtkTransformConcatenationStack::New();
480  }
481  this->Stack->Push(&this->Concatenation);
482  this->Modified();
483  }
485 
487 
491  void Pop()
492  {
493  if (this->Stack == nullptr)
494  {
495  return;
496  }
497  this->Stack->Pop(&this->Concatenation);
498  this->Modified();
499  }
501 
510  int CircuitCheck(vtkAbstractTransform* transform) override;
511 
512  // Return an inverse transform which will always update itself
513  // to match this transform.
515 
520 
524  vtkMTimeType GetMTime() override;
525 
527 
532  void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
533  void MultiplyPoint(const double in[4], double out[4])
534  {
535  this->GetMatrix()->MultiplyPoint(in, out);
536  }
538 
539 protected:
541  ~vtkTransform() override;
542 
544 
545  void InternalUpdate() override;
546 
550 
551  // this allows us to check whether people have been fooling
552  // around with our matrix
554 
555  float Point[4];
556  double DoublePoint[4];
557  double ReturnValue[4];
558 
559 private:
560  vtkTransform(const vtkTransform&) = delete;
561  void operator=(const vtkTransform&) = delete;
562 };
563 
564 VTK_ABI_NAMESPACE_END
565 #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:141
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:257
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:144
virtual void Modified()
Update the modification time for this object.
static vtkTransformConcatenationStack * New()
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:160
void Push()
Pushes the current transformation onto the transformation stack.
Definition: vtkTransform.h:475
vtkTransformConcatenation * Concatenation
Definition: vtkTransform.h:548
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:219
vtkAbstractTransform * MakeTransform() override
Make a new transform of the same type.
vtkLinearTransform * Input
Definition: vtkTransform.h:547
void GetScale(float scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:421
~vtkTransform() override
double * GetScale()
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:429
vtkMTimeType MatrixUpdateMTime
Definition: vtkTransform.h:553
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:532
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:348
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:469
int GetNumberOfConcatenatedTransforms()
Get the total number of transformations that are linked into this one via Concatenate() operations or...
Definition: vtkTransform.h:302
void Concatenate(const double elements[16])
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
Definition: vtkTransform.h:252
void PreMultiply()
Sets the internal state of the transform to PreMultiply.
Definition: vtkTransform.h:271
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:205
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:218
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:229
vtkTransformConcatenationStack * Stack
Definition: vtkTransform.h:549
void GetPosition(float pos[3])
Return the position from the current transformation matrix as an array of three floating point number...
Definition: vtkTransform.h:398
vtkAbstractTransform * GetInverse()
Definition: vtkTransform.h:514
void Scale(const float s[3])
Create a scale matrix (i.e.
Definition: vtkTransform.h:230
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:406
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:251
static vtkTransform * New()
double * GetOrientationWXYZ()
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:384
void PostMultiply()
Sets the internal state of the transform to PostMultiply.
Definition: vtkTransform.h:288
void Pop()
Deletes the transformation on the top of the stack and sets the top to the next transformation on the...
Definition: vtkTransform.h:491
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:197
void Scale(double x, double y, double z)
Create a scale matrix (i.e.
Definition: vtkTransform.h:228
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:187
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:186
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:217
void SetMatrix(const double elements[16])
Set the current matrix directly.
Definition: vtkTransform.h:239
void GetOrientationWXYZ(float wxyz[4])
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:375
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:185
vtkLinearTransform * GetConcatenatedTransform(int i)
Get one of the concatenated transformations as a vtkAbstractTransform.
Definition: vtkTransform.h:315
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:201
double * GetOrientation()
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
Definition: vtkTransform.h:356
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:533
vtkLinearTransform * GetInput()
Set the input for this transformation.
Definition: vtkTransform.h:459
void InternalDeepCopy(vtkAbstractTransform *t) override
Perform any subclass-specific DeepCopy.
void SetMatrix(vtkMatrix4x4 *matrix)
Set the current matrix directly.
Definition: vtkTransform.h:238
@ scale
Definition: vtkX3D.h:229
int vtkTypeBool
Definition: vtkABI.h:64
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO