VTK  9.0.20200605
vtkTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTransform.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
46 #ifndef vtkTransform_h
47 #define vtkTransform_h
48 
49 #include "vtkCommonTransformsModule.h" // For export macro
50 #include "vtkLinearTransform.h"
51 
52 #include "vtkMatrix4x4.h" // Needed for inline methods
53 
54 class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
55 {
56 public:
57  static vtkTransform* New();
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
66  void Identity();
67 
73  void Inverse() override;
74 
76 
80  void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
81  void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
82  void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
84 
86 
92  void RotateWXYZ(double angle, double x, double y, double z)
93  {
94  this->Concatenation->Rotate(angle, x, y, z);
95  }
96  void RotateWXYZ(double angle, const double axis[3])
97  {
98  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
99  }
100  void RotateWXYZ(double angle, const float axis[3])
101  {
102  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
103  }
105 
107 
112  void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
113  void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
114  void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
116 
118 
123  void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
124  void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
125  void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
127 
129 
133  void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
134  void SetMatrix(const double elements[16])
135  {
136  this->Concatenation->Identity();
137  this->Concatenate(elements);
138  }
140 
142 
146  void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
147  void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
149 
157  void Concatenate(vtkLinearTransform* transform);
158 
166  void PreMultiply()
167  {
168  if (this->Concatenation->GetPreMultiplyFlag())
169  {
170  return;
171  }
172  this->Concatenation->SetPreMultiplyFlag(1);
173  this->Modified();
174  }
175 
184  {
185  if (!this->Concatenation->GetPreMultiplyFlag())
186  {
187  return;
188  }
189  this->Concatenation->SetPreMultiplyFlag(0);
190  this->Modified();
191  }
192 
198  {
199  return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
200  }
201 
203 
211  {
213  if (this->Input == nullptr)
214  {
215  t = this->Concatenation->GetTransform(i);
216  }
217  else if (i < this->Concatenation->GetNumberOfPreTransforms())
218  {
219  t = this->Concatenation->GetTransform(i);
220  }
221  else if (i > this->Concatenation->GetNumberOfPreTransforms())
222  {
223  t = this->Concatenation->GetTransform(i - 1);
224  }
225  else if (this->GetInverseFlag())
226  {
227  t = this->Input->GetInverse();
228  }
229  else
230  {
231  t = this->Input;
232  }
233  return static_cast<vtkLinearTransform*>(t);
234  }
236 
238 
242  void GetOrientation(double orient[3]);
243  void GetOrientation(float orient[3])
244  {
245  double temp[3];
246  this->GetOrientation(temp);
247  orient[0] = static_cast<float>(temp[0]);
248  orient[1] = static_cast<float>(temp[1]);
249  orient[2] = static_cast<float>(temp[2]);
250  }
252  {
253  this->GetOrientation(this->ReturnValue);
254  return this->ReturnValue;
255  }
257 
262  static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
263 
265 
269  void GetOrientationWXYZ(double wxyz[4]);
270  void GetOrientationWXYZ(float wxyz[4])
271  {
272  double temp[4];
273  this->GetOrientationWXYZ(temp);
274  wxyz[0] = static_cast<float>(temp[0]);
275  wxyz[1] = static_cast<float>(temp[1]);
276  wxyz[2] = static_cast<float>(temp[2]);
277  wxyz[3] = static_cast<float>(temp[3]);
278  }
280  {
281  this->GetOrientationWXYZ(this->ReturnValue);
282  return this->ReturnValue;
283  }
285 
287 
292  void GetPosition(double pos[3]);
293  void GetPosition(float pos[3])
294  {
295  double temp[3];
296  this->GetPosition(temp);
297  pos[0] = static_cast<float>(temp[0]);
298  pos[1] = static_cast<float>(temp[1]);
299  pos[2] = static_cast<float>(temp[2]);
300  }
302  {
303  this->GetPosition(this->ReturnValue);
304  return this->ReturnValue;
305  }
307 
309 
315  void GetScale(double scale[3]);
316  void GetScale(float scale[3])
317  {
318  double temp[3];
319  this->GetScale(temp);
320  scale[0] = static_cast<float>(temp[0]);
321  scale[1] = static_cast<float>(temp[1]);
322  scale[2] = static_cast<float>(temp[2]);
323  }
324  double* GetScale() VTK_SIZEHINT(3)
325  {
326  this->GetScale(this->ReturnValue);
327  return this->ReturnValue;
328  }
330 
335  void GetInverse(vtkMatrix4x4* inverse);
336 
342  void GetTranspose(vtkMatrix4x4* transpose);
343 
345 
353  void SetInput(vtkLinearTransform* input);
354  vtkLinearTransform* GetInput() { return this->Input; }
356 
364  int GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
365 
367 
370  void Push()
371  {
372  if (this->Stack == nullptr)
373  {
374  this->Stack = vtkTransformConcatenationStack::New();
375  }
376  this->Stack->Push(&this->Concatenation);
377  this->Modified();
378  }
380 
382 
386  void Pop()
387  {
388  if (this->Stack == nullptr)
389  {
390  return;
391  }
392  this->Stack->Pop(&this->Concatenation);
393  this->Modified();
394  }
396 
405  int CircuitCheck(vtkAbstractTransform* transform) override;
406 
407  // Return an inverse transform which will always update itself
408  // to match this transform.
410 
415 
419  vtkMTimeType GetMTime() override;
420 
422 
427  void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
428  void MultiplyPoint(const double in[4], double out[4])
429  {
430  this->GetMatrix()->MultiplyPoint(in, out);
431  }
433 
434 protected:
435  vtkTransform();
436  ~vtkTransform() override;
437 
438  void InternalDeepCopy(vtkAbstractTransform* t) override;
439 
440  void InternalUpdate() override;
441 
445 
446  // this allows us to check whether people have been fooling
447  // around with our matrix
449 
450  float Point[4];
451  double DoublePoint[4];
452  double ReturnValue[4];
453 
454 private:
455  vtkTransform(const vtkTransform&) = delete;
456  void operator=(const vtkTransform&) = delete;
457 };
458 
459 #endif
vtkTransform::SetMatrix
void SetMatrix(vtkMatrix4x4 *matrix)
Set the current matrix directly.
Definition: vtkTransform.h:133
vtkLinearTransform.h
vtkTransform::GetOrientation
double * GetOrientation()
Definition: vtkTransform.h:251
vtkAbstractTransform::CircuitCheck
virtual int CircuitCheck(vtkAbstractTransform *transform)
Check for self-reference.
vtkHomogeneousTransform::InternalDeepCopy
void InternalDeepCopy(vtkAbstractTransform *transform) override
Perform any subclass-specific DeepCopy.
vtkAbstractTransform
superclass for all geometric transformations
Definition: vtkAbstractTransform.h:50
vtkX3D::scale
Definition: vtkX3D.h:235
vtkMatrix4x4::Element
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:39
vtkHomogeneousTransform::GetMatrix
vtkMatrix4x4 * GetMatrix()
Get a pointer to an internal vtkMatrix4x4 that represents the transformation.
Definition: vtkHomogeneousTransform.h:68
vtkAbstractTransform::Inverse
virtual void Inverse()=0
Invert the transformation.
vtkTransformConcatenationStack
Definition: vtkAbstractTransform.h:481
vtkTransform::GetScale
double * GetScale()
Definition: vtkTransform.h:324
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkAbstractTransform::InternalUpdate
virtual void InternalUpdate()
Perform any subclass-specific Update.
Definition: vtkAbstractTransform.h:317
vtkTransform::Pop
void Pop()
Deletes the transformation on the top of the stack and sets the top to the next transformation on the...
Definition: vtkTransform.h:386
vtkTransform::RotateWXYZ
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:92
vtkTransform::PreMultiply
void PreMultiply()
Sets the internal state of the transform to PreMultiply.
Definition: vtkTransform.h:166
vtkObject::Modified
virtual void Modified()
Update the modification time for this object.
vtkTransform::RotateY
void RotateY(double angle)
Definition: vtkTransform.h:113
vtkLinearTransform::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTransform::GetNumberOfConcatenatedTransforms
int GetNumberOfConcatenatedTransforms()
Get the total number of transformations that are linked into this one via Concatenate() operations or...
Definition: vtkTransform.h:197
vtkTransform::Push
void Push()
Pushes the current transformation onto the transformation stack.
Definition: vtkTransform.h:370
vtkTransform::PostMultiply
void PostMultiply()
Sets the internal state of the transform to PostMultiply.
Definition: vtkTransform.h:183
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:54
vtkTransform::GetPosition
double * GetPosition()
Definition: vtkTransform.h:301
vtkAbstractTransform::GetInverse
vtkAbstractTransform * GetInverse()
Get the inverse of this transform.
vtkLinearTransform
abstract superclass for linear transformations
Definition: vtkLinearTransform.h:31
vtkTransform::Scale
void Scale(const float s[3])
Definition: vtkTransform.h:125
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkTransform::MultiplyPoint
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:427
vtkTransform::RotateWXYZ
void RotateWXYZ(double angle, const float axis[3])
Definition: vtkTransform.h:100
vtkTransform::MatrixUpdateMTime
vtkMTimeType MatrixUpdateMTime
Definition: vtkTransform.h:448
vtkTransform::Translate
void Translate(const double x[3])
Definition: vtkTransform.h:81
vtkMatrix4x4.h
vtkMatrix4x4::MultiplyPoint
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:136
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
vtkTransform::SetMatrix
void SetMatrix(const double elements[16])
Definition: vtkTransform.h:134
vtkTransform::Scale
void Scale(double x, double y, double z)
Create a scale matrix (i.e.
Definition: vtkTransform.h:123
vtkAbstractTransform::GetMTime
vtkMTimeType GetMTime() override
Override GetMTime necessary because of inverse transforms.
vtkTransform::Concatenate
void Concatenate(vtkMatrix4x4 *matrix)
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
Definition: vtkTransform.h:146
vtkTransform::RotateX
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:112
vtkTransform::MultiplyPoint
void MultiplyPoint(const double in[4], double out[4])
Definition: vtkTransform.h:428
vtkTransform::Translate
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:80
vtkTransform::GetInput
vtkLinearTransform * GetInput()
Definition: vtkTransform.h:354
vtkTransform::Concatenation
vtkTransformConcatenation * Concatenation
Definition: vtkTransform.h:443
vtkTransform::RotateWXYZ
void RotateWXYZ(double angle, const double axis[3])
Definition: vtkTransform.h:96
vtkTransformConcatenationStack::New
static vtkTransformConcatenationStack * New()
Definition: vtkAbstractTransform.h:484
vtkTransform::GetScale
void GetScale(float scale[3])
Definition: vtkTransform.h:316
vtkTransform::GetPosition
void GetPosition(float pos[3])
Definition: vtkTransform.h:293
vtkTransform::GetOrientationWXYZ
void GetOrientationWXYZ(float wxyz[4])
Definition: vtkTransform.h:270
vtkTransform::GetInverse
vtkAbstractTransform * GetInverse()
Definition: vtkTransform.h:409
vtkTransform::Translate
void Translate(const float x[3])
Definition: vtkTransform.h:82
vtkTransform::RotateZ
void RotateZ(double angle)
Definition: vtkTransform.h:114
vtkTransform::Input
vtkLinearTransform * Input
Definition: vtkTransform.h:442
vtkTransform::Scale
void Scale(const double s[3])
Definition: vtkTransform.h:124
vtkTransform::GetOrientationWXYZ
double * GetOrientationWXYZ()
Definition: vtkTransform.h:279
vtkTransform::GetOrientation
void GetOrientation(float orient[3])
Definition: vtkTransform.h:243
vtkTransform::Concatenate
void Concatenate(const double elements[16])
Definition: vtkTransform.h:147
vtkTransformConcatenation
Definition: vtkAbstractTransform.h:375
vtkAbstractTransform::MakeTransform
virtual vtkAbstractTransform * MakeTransform()=0
Make another transform of the same type.
vtkTransform::GetConcatenatedTransform
vtkLinearTransform * GetConcatenatedTransform(int i)
Get one of the concatenated transformations as a vtkAbstractTransform.
Definition: vtkTransform.h:210
vtkTransform::Stack
vtkTransformConcatenationStack * Stack
Definition: vtkTransform.h:444
vtkTransform::GetInverseFlag
int GetInverseFlag()
Get the inverse flag of the transformation.
Definition: vtkTransform.h:364
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:285