VTK  9.2.5
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 
161 #ifndef vtkTransform_h
162 #define vtkTransform_h
163 
164 #include "vtkCommonTransformsModule.h" // For export macro
165 #include "vtkLinearTransform.h"
166 
167 #include "vtkMatrix4x4.h" // Needed for inline methods
168 
169 class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
170 {
171 public:
172  static vtkTransform* New();
174  void PrintSelf(ostream& os, vtkIndent indent) override;
175 
181  void Identity();
182 
188  void Inverse() override;
189 
191 
195  void Translate(double x, double y, double z) { this->Concatenation->Translate(x, y, z); }
196  void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); }
197  void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); }
199 
201 
207  void RotateWXYZ(double angle, double x, double y, double z)
208  {
209  this->Concatenation->Rotate(angle, x, y, z);
210  }
211  void RotateWXYZ(double angle, const double axis[3])
212  {
213  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
214  }
215  void RotateWXYZ(double angle, const float axis[3])
216  {
217  this->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
218  }
220 
222 
227  void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); }
228  void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); }
229  void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); }
231 
233 
238  void Scale(double x, double y, double z) { this->Concatenation->Scale(x, y, z); }
239  void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); }
240  void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); }
242 
244 
248  void SetMatrix(vtkMatrix4x4* matrix) { this->SetMatrix(*matrix->Element); }
249  void SetMatrix(const double elements[16])
250  {
251  this->Concatenation->Identity();
252  this->Concatenate(elements);
253  }
255 
257 
261  void Concatenate(vtkMatrix4x4* matrix) { this->Concatenate(*matrix->Element); }
262  void Concatenate(const double elements[16]) { this->Concatenation->Concatenate(elements); }
264 
272  void Concatenate(vtkLinearTransform* transform);
273 
281  void PreMultiply()
282  {
283  if (this->Concatenation->GetPreMultiplyFlag())
284  {
285  return;
286  }
287  this->Concatenation->SetPreMultiplyFlag(1);
288  this->Modified();
289  }
290 
299  {
300  if (!this->Concatenation->GetPreMultiplyFlag())
301  {
302  return;
303  }
304  this->Concatenation->SetPreMultiplyFlag(0);
305  this->Modified();
306  }
307 
313  {
314  return this->Concatenation->GetNumberOfTransforms() + (this->Input == nullptr ? 0 : 1);
315  }
316 
318 
326  {
328  if (this->Input == nullptr)
329  {
330  t = this->Concatenation->GetTransform(i);
331  }
332  else if (i < this->Concatenation->GetNumberOfPreTransforms())
333  {
334  t = this->Concatenation->GetTransform(i);
335  }
336  else if (i > this->Concatenation->GetNumberOfPreTransforms())
337  {
338  t = this->Concatenation->GetTransform(i - 1);
339  }
340  else if (this->GetInverseFlag())
341  {
342  t = this->Input->GetInverse();
343  }
344  else
345  {
346  t = this->Input;
347  }
348  return static_cast<vtkLinearTransform*>(t);
349  }
351 
353 
357  void GetOrientation(double orient[3]);
358  void GetOrientation(float orient[3])
359  {
360  double temp[3];
361  this->GetOrientation(temp);
362  orient[0] = static_cast<float>(temp[0]);
363  orient[1] = static_cast<float>(temp[1]);
364  orient[2] = static_cast<float>(temp[2]);
365  }
367  {
368  this->GetOrientation(this->ReturnValue);
369  return this->ReturnValue;
370  }
372 
377  static void GetOrientation(double orient[3], vtkMatrix4x4* matrix);
378 
380 
384  void GetOrientationWXYZ(double wxyz[4]);
385  void GetOrientationWXYZ(float wxyz[4])
386  {
387  double temp[4];
388  this->GetOrientationWXYZ(temp);
389  wxyz[0] = static_cast<float>(temp[0]);
390  wxyz[1] = static_cast<float>(temp[1]);
391  wxyz[2] = static_cast<float>(temp[2]);
392  wxyz[3] = static_cast<float>(temp[3]);
393  }
395  {
396  this->GetOrientationWXYZ(this->ReturnValue);
397  return this->ReturnValue;
398  }
400 
402 
407  void GetPosition(double pos[3]);
408  void GetPosition(float pos[3])
409  {
410  double temp[3];
411  this->GetPosition(temp);
412  pos[0] = static_cast<float>(temp[0]);
413  pos[1] = static_cast<float>(temp[1]);
414  pos[2] = static_cast<float>(temp[2]);
415  }
417  {
418  this->GetPosition(this->ReturnValue);
419  return this->ReturnValue;
420  }
422 
424 
430  void GetScale(double scale[3]);
431  void GetScale(float scale[3])
432  {
433  double temp[3];
434  this->GetScale(temp);
435  scale[0] = static_cast<float>(temp[0]);
436  scale[1] = static_cast<float>(temp[1]);
437  scale[2] = static_cast<float>(temp[2]);
438  }
439  double* GetScale() VTK_SIZEHINT(3)
440  {
441  this->GetScale(this->ReturnValue);
442  return this->ReturnValue;
443  }
445 
450  void GetInverse(vtkMatrix4x4* inverse);
451 
457  void GetTranspose(vtkMatrix4x4* transpose);
458 
460 
469  vtkLinearTransform* GetInput() { return this->Input; }
471 
479  int GetInverseFlag() { return this->Concatenation->GetInverseFlag(); }
480 
482 
485  void Push()
486  {
487  if (this->Stack == nullptr)
488  {
489  this->Stack = vtkTransformConcatenationStack::New();
490  }
491  this->Stack->Push(&this->Concatenation);
492  this->Modified();
493  }
495 
497 
501  void Pop()
502  {
503  if (this->Stack == nullptr)
504  {
505  return;
506  }
507  this->Stack->Pop(&this->Concatenation);
508  this->Modified();
509  }
511 
520  int CircuitCheck(vtkAbstractTransform* transform) override;
521 
522  // Return an inverse transform which will always update itself
523  // to match this transform.
525 
530 
534  vtkMTimeType GetMTime() override;
535 
537 
542  void MultiplyPoint(const float in[4], float out[4]) { this->GetMatrix()->MultiplyPoint(in, out); }
543  void MultiplyPoint(const double in[4], double out[4])
544  {
545  this->GetMatrix()->MultiplyPoint(in, out);
546  }
548 
549 protected:
551  ~vtkTransform() override;
552 
554 
555  void InternalUpdate() override;
556 
560 
561  // this allows us to check whether people have been fooling
562  // around with our matrix
564 
565  float Point[4];
566  double DoublePoint[4];
567  double ReturnValue[4];
568 
569 private:
570  vtkTransform(const vtkTransform&) = delete;
571  void operator=(const vtkTransform&) = delete;
572 };
573 
574 #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:119
abstract superclass for linear transformations
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:151
void MultiplyPoint(const float in[4], float out[4])
Multiply a homogeneous coordinate by this matrix, i.e.
Definition: vtkMatrix4x4.h:267
double Element[4][4]
The internal data is public for historical reasons. Do not use!
Definition: vtkMatrix4x4.h:154
virtual void Modified()
Update the modification time for this object.
static vtkTransformConcatenationStack * New()
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:170
void Push()
Pushes the current transformation onto the transformation stack.
Definition: vtkTransform.h:485
vtkTransformConcatenation * Concatenation
Definition: vtkTransform.h:558
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:229
vtkAbstractTransform * MakeTransform() override
Make a new transform of the same type.
vtkLinearTransform * Input
Definition: vtkTransform.h:557
void GetScale(float scale[3])
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:431
~vtkTransform() override
double * GetScale()
Return the scale factors of the current transformation matrix as an array of three float numbers.
Definition: vtkTransform.h:439
vtkMTimeType MatrixUpdateMTime
Definition: vtkTransform.h:563
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:542
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:358
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:312
void Concatenate(const double elements[16])
Concatenates the matrix with the current transformation according to PreMultiply or PostMultiply sema...
Definition: vtkTransform.h:262
void PreMultiply()
Sets the internal state of the transform to PreMultiply.
Definition: vtkTransform.h:281
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:215
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:228
int GetInverseFlag()
Get the inverse flag of the transformation.
Definition: vtkTransform.h:479
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:239
vtkTransformConcatenationStack * Stack
Definition: vtkTransform.h:559
void GetPosition(float pos[3])
Return the position from the current transformation matrix as an array of three floating point number...
Definition: vtkTransform.h:408
vtkAbstractTransform * GetInverse()
Definition: vtkTransform.h:524
void Scale(const float s[3])
Create a scale matrix (i.e.
Definition: vtkTransform.h:240
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:416
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:261
static vtkTransform * New()
double * GetOrientationWXYZ()
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:394
void PostMultiply()
Sets the internal state of the transform to PostMultiply.
Definition: vtkTransform.h:298
void Pop()
Deletes the transformation on the top of the stack and sets the top to the next transformation on the...
Definition: vtkTransform.h:501
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:207
void Scale(double x, double y, double z)
Create a scale matrix (i.e.
Definition: vtkTransform.h:238
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:197
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:196
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:227
void SetMatrix(const double elements[16])
Set the current matrix directly.
Definition: vtkTransform.h:249
void GetOrientationWXYZ(float wxyz[4])
Return the wxyz angle+axis representing the current orientation.
Definition: vtkTransform.h:385
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:195
vtkLinearTransform * GetConcatenatedTransform(int i)
Get one of the concatenated transformations as a vtkAbstractTransform.
Definition: vtkTransform.h:325
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:211
double * GetOrientation()
Get the x, y, z orientation angles from the transformation matrix as an array of three floating point...
Definition: vtkTransform.h:366
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:543
vtkLinearTransform * GetInput()
Set the input for this transformation.
Definition: vtkTransform.h:469
void InternalDeepCopy(vtkAbstractTransform *t) override
Perform any subclass-specific DeepCopy.
void SetMatrix(vtkMatrix4x4 *matrix)
Set the current matrix directly.
Definition: vtkTransform.h:248
@ scale
Definition: vtkX3D.h:235
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
#define VTK_SIZEHINT(...)