VTK  9.1.0
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 
155 #ifndef vtkTransform_h
156 #define vtkTransform_h
157 
158 #include "vtkCommonTransformsModule.h" // For export macro
159 #include "vtkLinearTransform.h"
160 
161 #include "vtkMatrix4x4.h" // Needed for inline methods
162 
163 class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
164 {
165 public:
166  static vtkTransform* New();
168  void PrintSelf(ostream& os, vtkIndent indent) override;
169 
175  void Identity();
176 
182  void Inverse() override;
183 
185 
189  void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
190  void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
191  void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
193 
195 
201  void RotateWXYZ(double angle, double x, double y, double z)
202  {
203  this->Concatenation->Rotate(angle, x, y, z);
204  }
205  void RotateWXYZ(double angle, const double axis[3])
206  {
207  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
208  }
209  void RotateWXYZ(double angle, const float axis[3])
210  {
211  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
212  }
214 
216 
221  void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
222  void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
223  void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
225 
227 
232  void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
233  void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
234  void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
236 
238 
242  void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
243  void SetMatrix(const double elements[16])
244  {
245  this->Concatenation->Identity();
246  this->Concatenate(elements);
247  }
249 
251 
255  void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
256  void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
258 
266  void Concatenate(vtkLinearTransform* transform);
267 
275  void PreMultiply()
276  {
277  if (this->Concatenation->GetPreMultiplyFlag())
278  {
279  return;
280  }
281  this->Concatenation->SetPreMultiplyFlag(1);
282  this->Modified();
283  }
284 
293  {
294  if (!this->Concatenation->GetPreMultiplyFlag())
295  {
296  return;
297  }
298  this->Concatenation->SetPreMultiplyFlag(0);
299  this->Modified();
300  }
301 
307  {
308  return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
309  }
310 
312 
320  {
322  if (this->Input == nullptr)
323  {
324  t = this->Concatenation->GetTransform(i);
325  }
326  else if (i < this->Concatenation->GetNumberOfPreTransforms())
327  {
328  t = this->Concatenation->GetTransform(i);
329  }
330  else if (i > this->Concatenation->GetNumberOfPreTransforms())
331  {
332  t = this->Concatenation->GetTransform(i - 1);
333  }
334  else if (this->GetInverseFlag())
335  {
336  t = this->Input->GetInverse();
337  }
338  else
339  {
340  t = this->Input;
341  }
342  return static_cast<vtkLinearTransform*>(t);
343  }
345 
347 
351  void GetOrientation(double orient[3]);
352  void GetOrientation(float orient[3])
353  {
354  double temp[3];
355  this->GetOrientation(temp);
356  orient[0] = static_cast<float>(temp[0]);
357  orient[1] = static_cast<float>(temp[1]);
358  orient[2] = static_cast<float>(temp[2]);
359  }
361  {
362  this->GetOrientation(this->ReturnValue);
363  return this->ReturnValue;
364  }
366 
371  static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
372 
374 
378  void GetOrientationWXYZ(double wxyz[4]);
379  void GetOrientationWXYZ(float wxyz[4])
380  {
381  double temp[4];
382  this->GetOrientationWXYZ(temp);
383  wxyz[0] = static_cast<float>(temp[0]);
384  wxyz[1] = static_cast<float>(temp[1]);
385  wxyz[2] = static_cast<float>(temp[2]);
386  wxyz[3] = static_cast<float>(temp[3]);
387  }
389  {
390  this->GetOrientationWXYZ(this->ReturnValue);
391  return this->ReturnValue;
392  }
394 
396 
401  void GetPosition(double pos[3]);
402  void GetPosition(float pos[3])
403  {
404  double temp[3];
405  this->GetPosition(temp);
406  pos[0] = static_cast<float>(temp[0]);
407  pos[1] = static_cast<float>(temp[1]);
408  pos[2] = static_cast<float>(temp[2]);
409  }
411  {
412  this->GetPosition(this->ReturnValue);
413  return this->ReturnValue;
414  }
416 
418 
424  void GetScale(double scale[3]);
425  void GetScale(float scale[3])
426  {
427  double temp[3];
428  this->GetScale(temp);
429  scale[0] = static_cast<float>(temp[0]);
430  scale[1] = static_cast<float>(temp[1]);
431  scale[2] = static_cast<float>(temp[2]);
432  }
433  double* GetScale() VTK_SIZEHINT(3)
434  {
435  this->GetScale(this->ReturnValue);
436  return this->ReturnValue;
437  }
439 
444  void GetInverse(vtkMatrix4x4* inverse);
445 
451  void GetTranspose(vtkMatrix4x4* transpose);
452 
454 
463  vtkLinearTransform* GetInput() { return this->Input; }
465 
473  int GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
474 
476 
479  void Push()
480  {
481  if (this->Stack == nullptr)
482  {
483  this->Stack = vtkTransformConcatenationStack::New();
484  }
485  this->Stack->Push(&this->Concatenation);
486  this->Modified();
487  }
489 
491 
495  void Pop()
496  {
497  if (this->Stack == nullptr)
498  {
499  return;
500  }
501  this->Stack->Pop(&this->Concatenation);
502  this->Modified();
503  }
505 
514  int CircuitCheck(vtkAbstractTransform* transform) override;
515 
516  // Return an inverse transform which will always update itself
517  // to match this transform.
519 
524 
528  vtkMTimeType GetMTime() override;
529 
531 
536  void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
537  void MultiplyPoint(const double in[4], double out[4])
538  {
539  this->GetMatrix()->MultiplyPoint(in, out);
540  }
542 
543 protected:
545  ~vtkTransform() override;
546 
548 
549  void InternalUpdate() override;
550 
554 
555  // this allows us to check whether people have been fooling
556  // around with our matrix
558 
559  float Point[4];
560  double DoublePoint[4];
561  double ReturnValue[4];
562 
563 private:
564  vtkTransform(const vtkTransform&) = delete;
565  void operator=(const vtkTransform&) = delete;
566 };
567 
568 #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:113
abstract superclass for linear transformations
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:245
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:148
virtual void Modified()
Update the modification time for this object.
static vtkTransformConcatenationStack * New()
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:164
void Push()
Pushes the current transformation onto the transformation stack.
Definition: vtkTransform.h:479
vtkTransformConcatenation * Concatenation
Definition: vtkTransform.h:552
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:223
vtkAbstractTransform * MakeTransform() override
Make a new transform of the same type.
vtkLinearTransform * Input
Definition: vtkTransform.h:551
void GetScale(float scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:425
~vtkTransform() override
double * GetScale()
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:433
vtkMTimeType MatrixUpdateMTime
Definition: vtkTransform.h:557
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:536
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:352
void GetTranspose(vtkMatrix4x4 *transpose)
Return a matrix which is the transpose of the current transformation matrix.
int GetNumberOfConcatenatedTransforms()
Get the total number of transformations that are linked into this one via Concatenate() operations or...
Definition: vtkTransform.h:306
void Concatenate(const double elements[16])
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
Definition: vtkTransform.h:256
void PreMultiply()
Sets the internal state of the transform to PreMultiply.
Definition: vtkTransform.h:275
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:209
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:222
int GetInverseFlag()
Get the inverse flag of the transformation.
Definition: vtkTransform.h:473
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:233
vtkTransformConcatenationStack * Stack
Definition: vtkTransform.h:553
void GetPosition(float pos[3])
Return the position from the current transformation matrix as an array of three floating point number...
Definition: vtkTransform.h:402
vtkAbstractTransform * GetInverse()
Definition: vtkTransform.h:518
void Scale(const float s[3])
Create a scale matrix (i.e.
Definition: vtkTransform.h:234
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:410
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:255
static vtkTransform * New()
double * GetOrientationWXYZ()
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:388
void PostMultiply()
Sets the internal state of the transform to PostMultiply.
Definition: vtkTransform.h:292
void Pop()
Deletes the transformation on the top of the stack and sets the top to the next transformation on the...
Definition: vtkTransform.h:495
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:201
void Scale(double x, double y, double z)
Create a scale matrix (i.e.
Definition: vtkTransform.h:232
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:191
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:190
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:221
void SetMatrix(const double elements[16])
Set the current matrix directly.
Definition: vtkTransform.h:243
void GetOrientationWXYZ(float wxyz[4])
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:379
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:189
vtkLinearTransform * GetConcatenatedTransform(int i)
Get one of the concatenated transformations as a vtkAbstractTransform.
Definition: vtkTransform.h:319
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:205
double * GetOrientation()
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
Definition: vtkTransform.h:360
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:537
vtkLinearTransform * GetInput()
Set the input for this transformation.
Definition: vtkTransform.h:463
void InternalDeepCopy(vtkAbstractTransform *t) override
Perform any subclass-specific DeepCopy.
void SetMatrix(vtkMatrix4x4 *matrix)
Set the current matrix directly.
Definition: vtkTransform.h:242
@ scale
Definition: vtkX3D.h:235
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
#define VTK_SIZEHINT(...)