VTK  9.0.20210508
vtkAbstractTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAbstractTransform.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 =========================================================================*/
39 #ifndef vtkAbstractTransform_h
40 #define vtkAbstractTransform_h
41 
42 #include "vtkCommonTransformsModule.h" // For export macro
43 #include "vtkObject.h"
44 
45 #include <mutex> // for std::mutex
46 
47 class vtkDataArray;
48 class vtkMatrix4x4;
49 class vtkPoints;
50 
51 class VTKCOMMONTRANSFORMS_EXPORT vtkAbstractTransform : public vtkObject
52 {
53 public:
55  void PrintSelf(ostream& os, vtkIndent indent) override;
56 
61  void TransformPoint(const float in[3], float out[3])
62  {
63  this->Update();
64  this->InternalTransformPoint(in, out);
65  }
66 
71  void TransformPoint(const double in[3], double out[3])
72  {
73  this->Update();
74  this->InternalTransformPoint(in, out);
75  }
76 
81  double* TransformPoint(double x, double y, double z) VTK_SIZEHINT(3)
82  {
83  return this->TransformDoublePoint(x, y, z);
84  }
85  double* TransformPoint(const double point[3]) VTK_SIZEHINT(3)
86  {
87  return this->TransformPoint(point[0], point[1], point[2]);
88  }
89 
91 
95  float* TransformFloatPoint(float x, float y, float z) VTK_SIZEHINT(3)
96  {
97  this->InternalFloatPoint[0] = x;
98  this->InternalFloatPoint[1] = y;
99  this->InternalFloatPoint[2] = z;
100  this->TransformPoint(this->InternalFloatPoint, this->InternalFloatPoint);
101  return this->InternalFloatPoint;
102  }
103  float* TransformFloatPoint(const float point[3]) VTK_SIZEHINT(3)
104  {
105  return this->TransformFloatPoint(point[0], point[1], point[2]);
106  }
108 
110 
114  double* TransformDoublePoint(double x, double y, double z) VTK_SIZEHINT(3)
115  {
116  this->InternalDoublePoint[0] = x;
117  this->InternalDoublePoint[1] = y;
118  this->InternalDoublePoint[2] = z;
119  this->TransformPoint(this->InternalDoublePoint, this->InternalDoublePoint);
120  return this->InternalDoublePoint;
121  }
122  double* TransformDoublePoint(const double point[3]) VTK_SIZEHINT(3)
123  {
124  return this->TransformDoublePoint(point[0], point[1], point[2]);
125  }
127 
129 
134  void TransformNormalAtPoint(const float point[3], const float in[3], float out[3]);
135  void TransformNormalAtPoint(const double point[3], const double in[3], double out[3]);
137 
138  double* TransformNormalAtPoint(const double point[3], const double normal[3]) VTK_SIZEHINT(3)
139  {
140  this->TransformNormalAtPoint(point, normal, this->InternalDoublePoint);
141  return this->InternalDoublePoint;
142  }
143 
145 
150  double* TransformDoubleNormalAtPoint(const double point[3], const double normal[3])
151  VTK_SIZEHINT(3)
152  {
153  this->TransformNormalAtPoint(point, normal, this->InternalDoublePoint);
154  return this->InternalDoublePoint;
155  }
157 
159 
164  float* TransformFloatNormalAtPoint(const float point[3], const float normal[3]) VTK_SIZEHINT(3)
165  {
166  this->TransformNormalAtPoint(point, normal, this->InternalFloatPoint);
167  return this->InternalFloatPoint;
168  }
170 
172 
177  void TransformVectorAtPoint(const float point[3], const float in[3], float out[3]);
178  void TransformVectorAtPoint(const double point[3], const double in[3], double out[3]);
180 
181  double* TransformVectorAtPoint(const double point[3], const double vector[3]) VTK_SIZEHINT(3)
182  {
183  this->TransformVectorAtPoint(point, vector, this->InternalDoublePoint);
184  return this->InternalDoublePoint;
185  }
186 
188 
193  double* TransformDoubleVectorAtPoint(const double point[3], const double vector[3])
194  VTK_SIZEHINT(3)
195  {
196  this->TransformVectorAtPoint(point, vector, this->InternalDoublePoint);
197  return this->InternalDoublePoint;
198  }
200 
202 
207  float* TransformFloatVectorAtPoint(const float point[3], const float vector[3]) VTK_SIZEHINT(3)
208  {
209  this->TransformVectorAtPoint(point, vector, this->InternalFloatPoint);
210  return this->InternalFloatPoint;
211  }
213 
218  virtual void TransformPoints(vtkPoints* inPts, vtkPoints* outPts);
219 
224  virtual void TransformPointsNormalsVectors(vtkPoints* inPts, vtkPoints* outPts,
225  vtkDataArray* inNms, vtkDataArray* outNms, vtkDataArray* inVrs, vtkDataArray* outVrs,
226  int nOptionalVectors = 0, vtkDataArray** inVrsArr = nullptr,
227  vtkDataArray** outVrsArr = nullptr);
228 
237 
244 
248  virtual void Inverse() = 0;
249 
254 
261  void Update();
262 
264 
268  virtual void InternalTransformPoint(const float in[3], float out[3]) = 0;
269  virtual void InternalTransformPoint(const double in[3], double out[3]) = 0;
271 
273 
280  const float in[3], float out[3], float derivative[3][3]) = 0;
282  const double in[3], double out[3], double derivative[3][3]) = 0;
284 
289 
298  virtual int CircuitCheck(vtkAbstractTransform* transform);
299 
303  vtkMTimeType GetMTime() override;
304 
309  void UnRegister(vtkObjectBase* O) override;
310 
311 protected:
314 
318  virtual void InternalUpdate() {}
319 
324 
325  float InternalFloatPoint[3];
326  double InternalDoublePoint[3];
327 
328 private:
329  // We need to record the time of the last update, and we also need
330  // to do mutex locking so updates don't collide. These are private
331  // because Update() is not virtual.
332  // If DependsOnInverse is set, then this transform object will
333  // check its inverse on every update, and update itself accordingly
334  // if necessary.
335 
336  vtkTimeStamp UpdateTime;
337  std::mutex UpdateMutex;
338  std::mutex InverseMutex;
339  int DependsOnInverse;
340 
341  // MyInverse is a transform which is the inverse of this one.
342 
343  vtkAbstractTransform* MyInverse;
344 
345  int InUnRegister;
346 
347 private:
349  void operator=(const vtkAbstractTransform&) = delete;
350 };
351 
352 //-------------------------------------------------------------------------
353 // A simple data structure to hold both a transform and its inverse.
354 // One of ForwardTransform or InverseTransform might be nullptr,
355 // and must be acquired by calling GetInverse() on the other.
357 {
358 public:
359  vtkTransformPair() = default;
360 
363 
365  {
367  this->ForwardTransform = this->InverseTransform;
368  this->InverseTransform = tmp;
369  }
370 };
371 
372 // .NAME vtkTransformConcatenation - store a series of transformations.
373 // .SECTION Description
374 // A helper class (not derived from vtkObject) to store a series of
375 // transformations in a pipelined concatenation.
376 class VTKCOMMONTRANSFORMS_EXPORT vtkTransformConcatenation
377 {
378 public:
380  void Delete() { delete this; }
381 
386 
390  void Concatenate(const double elements[16]);
391 
393 
396  void SetPreMultiplyFlag(int flag) { this->PreMultiplyFlag = flag; }
397  int GetPreMultiplyFlag() { return this->PreMultiplyFlag; }
399 
401 
404  void Translate(double x, double y, double z);
405  void Rotate(double angle, double x, double y, double z);
406  void Scale(double x, double y, double z);
408 
412  void Inverse();
413 
417  int GetInverseFlag() { return this->InverseFlag; }
418 
422  void Identity();
423 
424  // copy the list
426 
430  int GetNumberOfTransforms() { return this->NumberOfTransforms; }
431 
437  int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; }
438 
442  int GetNumberOfPostTransforms() { return this->NumberOfTransforms - this->NumberOfPreTransforms; }
443 
448 
453 
454  void PrintSelf(ostream& os, vtkIndent indent);
455 
456 protected:
459 
462 
467 
472 
473 private:
475  void operator=(const vtkTransformConcatenation&) = delete;
476 };
477 
478 // .NAME vtkTransformConcatenationStack - Store a stack of concatenations.
479 // .SECTION Description
480 // A helper class (not derived from vtkObject) to store a stack of
481 // concatenations.
482 class VTKCOMMONTRANSFORMS_EXPORT vtkTransformConcatenationStack
483 {
484 public:
486  void Delete() { delete this; }
487 
493 
499 
501 
502 protected:
505 
509 
510 private:
512  void operator=(const vtkTransformConcatenationStack&) = delete;
513 };
514 
515 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:34
vtkTransformConcatenation::GetNumberOfPostTransforms
int GetNumberOfPostTransforms()
the number of transforms that were post-concatenated.
Definition: vtkAbstractTransform.h:442
vtkX3D::vector
@ vector
Definition: vtkX3D.h:243
vtkTransformConcatenation::Concatenate
void Concatenate(const double elements[16])
concatenate with a matrix according to Pre/PostMultiply semantics
vtkTransformConcatenation::Scale
void Scale(double x, double y, double z)
the three basic linear transformations
vtkTransformConcatenationStack::vtkTransformConcatenationStack
vtkTransformConcatenationStack()
vtkAbstractTransform::CircuitCheck
virtual int CircuitCheck(vtkAbstractTransform *transform)
Check for self-reference.
vtkTransformConcatenation::GetNumberOfTransforms
int GetNumberOfTransforms()
the number of stored transforms
Definition: vtkAbstractTransform.h:430
vtkAbstractTransform
superclass for all geometric transformations
Definition: vtkAbstractTransform.h:52
vtkAbstractTransform::InternalTransformPoint
virtual void InternalTransformPoint(const float in[3], float out[3])=0
This will calculate the transformation without calling Update.
vtkTransformConcatenationStack::StackSize
int StackSize
Definition: vtkAbstractTransform.h:506
vtkTransformConcatenationStack::DeepCopy
void DeepCopy(vtkTransformConcatenationStack *stack)
vtkTransformConcatenation::PreMatrixTransform
vtkAbstractTransform * PreMatrixTransform
Definition: vtkAbstractTransform.h:465
vtkTransformConcatenation::GetPreMultiplyFlag
int GetPreMultiplyFlag()
set/get the PreMultiply flag
Definition: vtkAbstractTransform.h:397
vtkAbstractTransform::TransformNormalAtPoint
double * TransformNormalAtPoint(const double point[3], const double normal[3])
Definition: vtkAbstractTransform.h:138
vtkAbstractTransform::TransformNormalAtPoint
void TransformNormalAtPoint(const double point[3], const double in[3], double out[3])
Apply the transformation to a normal at the specified vertex.
vtkTransformConcatenation::SetPreMultiplyFlag
void SetPreMultiplyFlag(int flag)
set/get the PreMultiply flag
Definition: vtkAbstractTransform.h:396
vtkAbstractTransform::TransformVectorAtPoint
double * TransformVectorAtPoint(const double point[3], const double vector[3])
Definition: vtkAbstractTransform.h:181
vtkAbstractTransform::Inverse
virtual void Inverse()=0
Invert the transformation.
vtkTransformConcatenationStack
Definition: vtkAbstractTransform.h:483
vtkAbstractTransform::TransformPointsNormalsVectors
virtual void TransformPointsNormalsVectors(vtkPoints *inPts, vtkPoints *outPts, vtkDataArray *inNms, vtkDataArray *outNms, vtkDataArray *inVrs, vtkDataArray *outVrs, int nOptionalVectors=0, vtkDataArray **inVrsArr=nullptr, vtkDataArray **outVrsArr=nullptr)
Apply the transformation to a combination of points, normals and vectors.
vtkTransformConcatenation::PostMatrix
vtkMatrix4x4 * PostMatrix
Definition: vtkAbstractTransform.h:464
vtkAbstractTransform::InternalUpdate
virtual void InternalUpdate()
Perform any subclass-specific Update.
Definition: vtkAbstractTransform.h:318
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:33
vtkTransformConcatenation::Delete
void Delete()
Definition: vtkAbstractTransform.h:380
vtkAbstractTransform::InternalTransformDerivative
virtual void InternalTransformDerivative(const double in[3], double out[3], double derivative[3][3])=0
This will transform a point and, at the same time, calculate a 3x3 Jacobian matrix that provides the ...
vtkTransformPair::SwapForwardInverse
void SwapForwardInverse()
Definition: vtkAbstractTransform.h:364
vtkAbstractTransform::TransformFloatPoint
float * TransformFloatPoint(const float point[3])
Apply the transformation to an (x,y,z) coordinate.
Definition: vtkAbstractTransform.h:103
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:63
vtkTransformConcatenation::GetTransform
vtkAbstractTransform * GetTransform(int i)
get one of the transforms
vtkTransformConcatenation::GetMaxMTime
vtkMTimeType GetMaxMTime()
get maximum MTime of all transforms
vtkTransformConcatenation::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkTransformPair::vtkTransformPair
vtkTransformPair()=default
vtkAbstractTransform::TransformFloatPoint
float * TransformFloatPoint(float x, float y, float z)
Apply the transformation to an (x,y,z) coordinate.
Definition: vtkAbstractTransform.h:95
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
vtkTransformConcatenation::PreMatrix
vtkMatrix4x4 * PreMatrix
Definition: vtkAbstractTransform.h:463
vtkAbstractTransform::SetInverse
void SetInverse(vtkAbstractTransform *transform)
Set a transformation that this transform will be the inverse of.
vtkAbstractTransform::TransformPoint
void TransformPoint(const double in[3], double out[3])
Apply the transformation to a double-precision coordinate.
Definition: vtkAbstractTransform.h:71
vtkAbstractTransform::Update
void Update()
Update the transform to account for any changes which have been made.
vtkAbstractTransform::GetInverse
vtkAbstractTransform * GetInverse()
Get the inverse of this transform.
vtkTransformConcatenationStack::Delete
void Delete()
Definition: vtkAbstractTransform.h:486
vtkAbstractTransform::TransformVectorAtPoint
void TransformVectorAtPoint(const float point[3], const float in[3], float out[3])
Apply the transformation to a vector at the specified vertex.
vtkAbstractTransform::InternalTransformPoint
virtual void InternalTransformPoint(const double in[3], double out[3])=0
This will calculate the transformation without calling Update.
vtkAbstractTransform::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkAbstractTransform::TransformDoubleVectorAtPoint
double * TransformDoubleVectorAtPoint(const double point[3], const double vector[3])
Apply the transformation to a double-precision vector at the specified vertex.
Definition: vtkAbstractTransform.h:193
vtkTransformConcatenationStack::Pop
void Pop(vtkTransformConcatenation **concat)
pop will pop delete 'concat', then pop the top item on the stack onto 'concat'.
vtkTransformConcatenation::PostMatrixTransform
vtkAbstractTransform * PostMatrixTransform
Definition: vtkAbstractTransform.h:466
vtkTransformConcatenation::NumberOfPreTransforms
int NumberOfPreTransforms
Definition: vtkAbstractTransform.h:469
vtkAbstractTransform::TransformPoint
double * TransformPoint(const double point[3])
Definition: vtkAbstractTransform.h:85
vtkX3D::point
@ point
Definition: vtkX3D.h:242
vtkTransformConcatenation::~vtkTransformConcatenation
~vtkTransformConcatenation()
vtkAbstractTransform::~vtkAbstractTransform
~vtkAbstractTransform() override
vtkTransformConcatenation::GetNumberOfPreTransforms
int GetNumberOfPreTransforms()
the number of transforms that were pre-concatenated (note that whenever Inverse() is called,...
Definition: vtkAbstractTransform.h:437
vtkTransformConcatenationStack::Stack
vtkTransformConcatenation ** Stack
Definition: vtkAbstractTransform.h:507
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:48
vtkTransformPair::InverseTransform
vtkAbstractTransform * InverseTransform
Definition: vtkAbstractTransform.h:362
vtkAbstractTransform::TransformFloatNormalAtPoint
float * TransformFloatNormalAtPoint(const float point[3], const float normal[3])
Apply the transformation to a single-precision normal at the specified vertex.
Definition: vtkAbstractTransform.h:164
vtkTransformConcatenation::GetInverseFlag
int GetInverseFlag()
get the inverse flag
Definition: vtkAbstractTransform.h:417
vtkAbstractTransform::UnRegister
void UnRegister(vtkObjectBase *O) override
Needs a special UnRegister() implementation to avoid circular references.
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
vtkAbstractTransform::TransformVectorAtPoint
void TransformVectorAtPoint(const double point[3], const double in[3], double out[3])
Apply the transformation to a vector at the specified vertex.
vtkAbstractTransform::InternalTransformDerivative
virtual void InternalTransformDerivative(const float in[3], float out[3], float derivative[3][3])=0
This will transform a point and, at the same time, calculate a 3x3 Jacobian matrix that provides the ...
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkAbstractTransform::TransformPoint
double * TransformPoint(double x, double y, double z)
Apply the transformation to a double-precision coordinate.
Definition: vtkAbstractTransform.h:81
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
vtkTransformConcatenation::InverseFlag
int InverseFlag
Definition: vtkAbstractTransform.h:460
vtkAbstractTransform::GetMTime
vtkMTimeType GetMTime() override
Override GetMTime necessary because of inverse transforms.
vtkTransformConcatenation::Translate
void Translate(double x, double y, double z)
the three basic linear transformations
vtkTransformConcatenation::TransformList
vtkTransformPair * TransformList
Definition: vtkAbstractTransform.h:471
vtkTransformConcatenation::Concatenate
void Concatenate(vtkAbstractTransform *transform)
add a transform to the list according to Pre/PostMultiply semantics
vtkTransformConcatenation::Identity
void Identity()
identity simply clears the transform list
vtkTransformConcatenationStack::New
static vtkTransformConcatenationStack * New()
Definition: vtkAbstractTransform.h:485
vtkTransformPair::ForwardTransform
vtkAbstractTransform * ForwardTransform
Definition: vtkAbstractTransform.h:361
vtkObject.h
vtkAbstractTransform::TransformFloatVectorAtPoint
float * TransformFloatVectorAtPoint(const float point[3], const float vector[3])
Apply the transformation to a single-precision vector at the specified vertex.
Definition: vtkAbstractTransform.h:207
vtkTransformPair
Definition: vtkAbstractTransform.h:357
vtkAbstractTransform::TransformDoubleNormalAtPoint
double * TransformDoubleNormalAtPoint(const double point[3], const double normal[3])
Apply the transformation to a double-precision normal at the specified vertex.
Definition: vtkAbstractTransform.h:150
vtkAbstractTransform::TransformNormalAtPoint
void TransformNormalAtPoint(const float point[3], const float in[3], float out[3])
Apply the transformation to a normal at the specified vertex.
vtkTransformConcatenation::Inverse
void Inverse()
invert the concatenation
vtkTransformConcatenation::vtkTransformConcatenation
vtkTransformConcatenation()
vtkTransformConcatenationStack::StackBottom
vtkTransformConcatenation ** StackBottom
Definition: vtkAbstractTransform.h:508
vtkAbstractTransform::DeepCopy
void DeepCopy(vtkAbstractTransform *)
Copy this transform from another of the same type.
vtkTransformConcatenation::NumberOfTransforms
int NumberOfTransforms
Definition: vtkAbstractTransform.h:468
vtkAbstractTransform::TransformPoint
void TransformPoint(const float in[3], float out[3])
Apply the transformation to a coordinate.
Definition: vtkAbstractTransform.h:61
vtkAbstractTransform::TransformPoints
virtual void TransformPoints(vtkPoints *inPts, vtkPoints *outPts)
Apply the transformation to a series of points, and append the results to outPts.
vtkTransformConcatenation::DeepCopy
void DeepCopy(vtkTransformConcatenation *transform)
vtkTransformConcatenation::Rotate
void Rotate(double angle, double x, double y, double z)
the three basic linear transformations
vtkAbstractTransform::TransformDoublePoint
double * TransformDoublePoint(const double point[3])
Apply the transformation to a double-precision (x,y,z) coordinate.
Definition: vtkAbstractTransform.h:122
vtkAbstractTransform::vtkAbstractTransform
vtkAbstractTransform()
vtkTransformConcatenation::PreMultiplyFlag
int PreMultiplyFlag
Definition: vtkAbstractTransform.h:461
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:44
vtkTransformConcatenation::MaxNumberOfTransforms
int MaxNumberOfTransforms
Definition: vtkAbstractTransform.h:470
vtkTransformConcatenationStack::Push
void Push(vtkTransformConcatenation **concat)
push will move 'concat' onto the stack, and make 'concat' a copy of its previous self
vtkTransformConcatenation::New
static vtkTransformConcatenation * New()
Definition: vtkAbstractTransform.h:379
vtkTransformConcatenation
Definition: vtkAbstractTransform.h:377
vtkAbstractTransform::MakeTransform
virtual vtkAbstractTransform * MakeTransform()=0
Make another transform of the same type.
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293
vtkAbstractTransform::InternalDeepCopy
virtual void InternalDeepCopy(vtkAbstractTransform *)
Perform any subclass-specific DeepCopy.
Definition: vtkAbstractTransform.h:323
vtkTransformConcatenationStack::~vtkTransformConcatenationStack
~vtkTransformConcatenationStack()
vtkAbstractTransform::TransformDoublePoint
double * TransformDoublePoint(double x, double y, double z)
Apply the transformation to a double-precision (x,y,z) coordinate.
Definition: vtkAbstractTransform.h:114