VTK  9.2.6
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 
52 #ifndef vtkTransform_h
53 #define vtkTransform_h
54 
55 #include "vtkCommonTransformsModule.h" // For export macro
56 #include "vtkLinearTransform.h"
57 
58 #include "vtkMatrix4x4.h" // Needed for inline methods
59 
60 class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
61 {
62 public:
63  static vtkTransform* New();
65  void PrintSelf(ostream& os, vtkIndent indent) override;
66 
72  void Identity();
73 
79  void Inverse() override;
80 
82 
86  void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
87  void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
88  void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
90 
92 
98  void RotateWXYZ(double angle, double x, double y, double z)
99  {
100  this->Concatenation->Rotate(angle, x, y, z);
101  }
102  void RotateWXYZ(double angle, const double axis[3])
103  {
104  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
105  }
106  void RotateWXYZ(double angle, const float axis[3])
107  {
108  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
109  }
111 
113 
118  void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
119  void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
120  void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
122 
124 
129  void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
130  void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
131  void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
133 
135 
139  void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
140  void SetMatrix(const double elements[16])
141  {
142  this->Concatenation->Identity();
143  this->Concatenate(elements);
144  }
146 
148 
152  void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
153  void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
155 
163  void Concatenate(vtkLinearTransform* transform);
164 
172  void PreMultiply()
173  {
174  if (this->Concatenation->GetPreMultiplyFlag())
175  {
176  return;
177  }
178  this->Concatenation->SetPreMultiplyFlag(1);
179  this->Modified();
180  }
181 
190  {
191  if (!this->Concatenation->GetPreMultiplyFlag())
192  {
193  return;
194  }
195  this->Concatenation->SetPreMultiplyFlag(0);
196  this->Modified();
197  }
198 
204  {
205  return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
206  }
207 
209 
217  {
219  if (this->Input == nullptr)
220  {
221  t = this->Concatenation->GetTransform(i);
222  }
223  else if (i < this->Concatenation->GetNumberOfPreTransforms())
224  {
225  t = this->Concatenation->GetTransform(i);
226  }
227  else if (i > this->Concatenation->GetNumberOfPreTransforms())
228  {
229  t = this->Concatenation->GetTransform(i - 1);
230  }
231  else if (this->GetInverseFlag())
232  {
233  t = this->Input->GetInverse();
234  }
235  else
236  {
237  t = this->Input;
238  }
239  return static_cast<vtkLinearTransform*>(t);
240  }
242 
244 
248  void GetOrientation(double orient[3]);
249  void GetOrientation(float orient[3])
250  {
251  double temp[3];
252  this->GetOrientation(temp);
253  orient[0] = static_cast<float>(temp[0]);
254  orient[1] = static_cast<float>(temp[1]);
255  orient[2] = static_cast<float>(temp[2]);
256  }
258  {
259  this->GetOrientation(this->ReturnValue);
260  return this->ReturnValue;
261  }
263 
268  static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
269 
271 
275  void GetOrientationWXYZ(double wxyz[4]);
276  void GetOrientationWXYZ(float wxyz[4])
277  {
278  double temp[4];
279  this->GetOrientationWXYZ(temp);
280  wxyz[0] = static_cast<float>(temp[0]);
281  wxyz[1] = static_cast<float>(temp[1]);
282  wxyz[2] = static_cast<float>(temp[2]);
283  wxyz[3] = static_cast<float>(temp[3]);
284  }
286  {
287  this->GetOrientationWXYZ(this->ReturnValue);
288  return this->ReturnValue;
289  }
291 
293 
298  void GetPosition(double pos[3]);
299  void GetPosition(float pos[3])
300  {
301  double temp[3];
302  this->GetPosition(temp);
303  pos[0] = static_cast<float>(temp[0]);
304  pos[1] = static_cast<float>(temp[1]);
305  pos[2] = static_cast<float>(temp[2]);
306  }
308  {
309  this->GetPosition(this->ReturnValue);
310  return this->ReturnValue;
311  }
313 
315 
321  void GetScale(double scale[3]);
322  void GetScale(float scale[3])
323  {
324  double temp[3];
325  this->GetScale(temp);
326  scale[0] = static_cast<float>(temp[0]);
327  scale[1] = static_cast<float>(temp[1]);
328  scale[2] = static_cast<float>(temp[2]);
329  }
330  double* GetScale() VTK_SIZEHINT(3)
331  {
332  this->GetScale(this->ReturnValue);
333  return this->ReturnValue;
334  }
336 
341  void GetInverse(vtkMatrix4x4* inverse);
342 
348  void GetTranspose(vtkMatrix4x4* transpose);
349 
351 
359  void SetInput(vtkLinearTransform* input);
360  vtkLinearTransform* GetInput() { return this->Input; }
362 
370  int GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
371 
373 
376  void Push()
377  {
378  if (this->Stack == nullptr)
379  {
380  this->Stack = vtkTransformConcatenationStack::New();
381  }
382  this->Stack->Push(&this->Concatenation);
383  this->Modified();
384  }
386 
388 
392  void Pop()
393  {
394  if (this->Stack == nullptr)
395  {
396  return;
397  }
398  this->Stack->Pop(&this->Concatenation);
399  this->Modified();
400  }
402 
411  int CircuitCheck(vtkAbstractTransform* transform) override;
412 
413  // Return an inverse transform which will always update itself
414  // to match this transform.
416 
421 
425  vtkMTimeType GetMTime() override;
426 
428 
433  void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
434  void MultiplyPoint(const double in[4], double out[4])
435  {
436  this->GetMatrix()->MultiplyPoint(in, out);
437  }
439 
440 protected:
441  vtkTransform();
442  ~vtkTransform() override;
443 
444  void InternalDeepCopy(vtkAbstractTransform* t) override;
445 
446  void InternalUpdate() override;
447 
451 
452  // this allows us to check whether people have been fooling
453  // around with our matrix
455 
456  float Point[4];
457  double DoublePoint[4];
458  double ReturnValue[4];
459 
460 private:
461  vtkTransform(const vtkTransform&) = delete;
462  void operator=(const vtkTransform&) = delete;
463 };
464 
465 #endif
double * GetOrientationWXYZ()
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:285
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:98
void PreMultiply()
Sets the internal state of the transform to PreMultiply.
Definition: vtkTransform.h:172
double * GetScale()
Return the scale factors of the current transformation matrix as an array of three float numbers...
Definition: vtkTransform.h:330
void Concatenate(const double elements[16])
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
Definition: vtkTransform.h:153
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void PostMultiply()
Sets the internal state of the transform to PostMultiply.
Definition: vtkTransform.h:189
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
void Push()
Pushes the current transformation onto the transformation stack.
Definition: vtkTransform.h:376
vtkMTimeType GetMTime() override
Override GetMTime necessary because of inverse transforms.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
double * GetPosition()
Return the position from the current transformation matrix as an array of three floating point number...
Definition: vtkTransform.h:307
void SetMatrix(vtkMatrix4x4 *matrix)
Set the current matrix directly.
Definition: vtkTransform.h:139
virtual void InternalUpdate()
Perform any subclass-specific Update.
double * GetOrientation()
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
Definition: vtkTransform.h:257
void Scale(const float s[3])
Create a scale matrix (i.e.
Definition: vtkTransform.h:131
virtual vtkAbstractTransform * MakeTransform()=0
Make another transform of the same type.
vtkMTimeType MatrixUpdateMTime
Definition: vtkTransform.h:454
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
vtkAbstractTransform * GetInverse()
Get the inverse of this transform.
void Scale(double x, double y, double z)
Create a scale matrix (i.e.
Definition: vtkTransform.h:129
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:158
void Concatenate(vtkMatrix4x4 *matrix)
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
Definition: vtkTransform.h:152
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:102
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:119
void GetPosition(float pos[3])
Return the position from the current transformation matrix as an array of three floating point number...
Definition: vtkTransform.h:299
virtual int CircuitCheck(vtkAbstractTransform *transform)
Check for self-reference.
vtkLinearTransform * GetInput()
Set the input for this transformation.
Definition: vtkTransform.h:360
int GetNumberOfConcatenatedTransforms()
Get the total number of transformations that are linked into this one via Concatenate() operations or...
Definition: vtkTransform.h:203
a simple class to control print indentation
Definition: vtkIndent.h:39
void GetScale(float scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers...
Definition: vtkTransform.h:322
superclass for all geometric transformations
virtual void Modified()
Update the modification time for this object.
virtual void Inverse()=0
Invert the transformation.
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:106
#define VTK_SIZEHINT(...)
void Translate(const double x[3])
Create a translation matrix and concatenate it with the current transformation according to PreMultip...
Definition: vtkTransform.h:87
void MultiplyPoint(const float in[4], float out[4])
Use this method only if you wish to compute the transformation in homogeneous (x,y,z,w) coordinates, otherwise use TransformPoint().
Definition: vtkTransform.h:433
void Scale(const double s[3])
Create a scale matrix (i.e.
Definition: vtkTransform.h:130
void SetMatrix(const double elements[16])
Set the current matrix directly.
Definition: vtkTransform.h:140
void InternalDeepCopy(vtkAbstractTransform *transform) override
Perform any subclass-specific DeepCopy.
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:249
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:118
void MultiplyPoint(const double in[4], double out[4])
Use this method only if you wish to compute the transformation in homogeneous (x,y,z,w) coordinates, otherwise use TransformPoint().
Definition: vtkTransform.h:434
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:45
vtkLinearTransform * GetConcatenatedTransform(int i)
Get one of the concatenated transformations as a vtkAbstractTransform.
Definition: vtkTransform.h:216
vtkTransformConcatenationStack * Stack
Definition: vtkTransform.h:450
vtkTransformConcatenation * Concatenation
Definition: vtkTransform.h:449
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:86
int GetInverseFlag()
Get the inverse flag of the transformation.
Definition: vtkTransform.h:370
void GetOrientationWXYZ(float wxyz[4])
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:276
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
static vtkTransformConcatenationStack * New()
vtkMatrix4x4 * GetMatrix()
Get a pointer to an internal vtkMatrix4x4 that represents the transformation.
void Translate(const float x[3])
Create a translation matrix and concatenate it with the current transformation according to PreMultip...
Definition: vtkTransform.h:88
vtkAbstractTransform * GetInverse()
Definition: vtkTransform.h:415
abstract superclass for linear transformations
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:120
void Pop()
Deletes the transformation on the top of the stack and sets the top to the next transformation on the...
Definition: vtkTransform.h:392
vtkLinearTransform * Input
Definition: vtkTransform.h:448