VTK  9.2.6
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 
236  vtkAbstractTransform* GetInverse();
237 
243  void SetInverse(vtkAbstractTransform* transform);
244 
248  virtual void Inverse() = 0;
249 
253  void DeepCopy(vtkAbstractTransform*);
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 
279  virtual void InternalTransformDerivative(
280  const float in[3], float out[3], float derivative[3][3]) = 0;
281  virtual void InternalTransformDerivative(
282  const double in[3], double out[3], double derivative[3][3]) = 0;
284 
288  virtual VTK_NEWINSTANCE vtkAbstractTransform* MakeTransform() = 0;
289 
298  virtual int CircuitCheck(vtkAbstractTransform* transform);
299 
303  vtkMTimeType GetMTime() override;
304 
309  void UnRegister(vtkObjectBase* O) override;
310 
311 protected:
313  ~vtkAbstractTransform() override;
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 
385  void Concatenate(vtkAbstractTransform* transform);
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
425  void DeepCopy(vtkTransformConcatenation* transform);
426 
430  int GetNumberOfTransforms() { return this->NumberOfTransforms; }
431 
437  int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; }
438 
442  int GetNumberOfPostTransforms() { return this->NumberOfTransforms - this->NumberOfPreTransforms; }
443 
447  vtkAbstractTransform* GetTransform(int i);
448 
452  vtkMTimeType GetMaxMTime();
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 
492  void Pop(vtkTransformConcatenation** concat);
493 
498  void Push(vtkTransformConcatenation** concat);
499 
500  void DeepCopy(vtkTransformConcatenationStack* stack);
501 
502 protected:
505 
509 
510 private:
512  void operator=(const vtkTransformConcatenationStack&) = delete;
513 };
514 
515 #endif
void SetPreMultiplyFlag(int flag)
set/get the PreMultiply flag
static vtkTransformConcatenation * New()
void TransformPoint(const float in[3], float out[3])
Apply the transformation to a coordinate.
vtkAbstractTransform * PostMatrixTransform
double * TransformVectorAtPoint(const double point[3], const double vector[3])
abstract base class for most VTK objects
Definition: vtkObject.h:62
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
vtkAbstractTransform * InverseTransform
int GetNumberOfPreTransforms()
the number of transforms that were pre-concatenated (note that whenever Inverse() is called...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTransformConcatenation ** StackBottom
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
int GetNumberOfPostTransforms()
the number of transforms that were post-concatenated.
record modification and/or execution time
Definition: vtkTimeStamp.h:35
virtual void InternalUpdate()
Perform any subclass-specific Update.
float * TransformFloatNormalAtPoint(const float point[3], const float normal[3])
Apply the transformation to a single-precision normal at the specified vertex.
double * TransformPoint(double x, double y, double z)
Apply the transformation to a double-precision coordinate.
float * TransformFloatPoint(const float point[3])
Apply the transformation to an (x,y,z) coordinate.
double * TransformPoint(const double point[3])
vtkAbstractTransform * ForwardTransform
virtual void InternalDeepCopy(vtkAbstractTransform *)
Perform any subclass-specific DeepCopy.
int GetInverseFlag()
get the inverse flag
vtkAbstractTransform * PreMatrixTransform
int GetPreMultiplyFlag()
set/get the PreMultiply flag
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkTransformPair()=default
double * TransformDoublePoint(double x, double y, double z)
Apply the transformation to a double-precision (x,y,z) coordinate.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
superclass for all geometric transformations
virtual vtkMTimeType GetMTime()
Return this object's modified time.
double * TransformDoublePoint(const double point[3])
Apply the transformation to a double-precision (x,y,z) coordinate.
float * TransformFloatVectorAtPoint(const float point[3], const float vector[3])
Apply the transformation to a single-precision vector at the specified vertex.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:73
#define VTK_SIZEHINT(...)
#define VTK_NEWINSTANCE
vtkTransformPair * TransformList
double * TransformDoubleVectorAtPoint(const double point[3], const double vector[3])
Apply the transformation to a double-precision vector at the specified vertex.
int GetNumberOfTransforms()
the number of stored transforms
double * TransformDoubleNormalAtPoint(const double point[3], const double normal[3])
Apply the transformation to a double-precision normal at the specified vertex.
double * TransformNormalAtPoint(const double point[3], const double normal[3])
vtkTransformConcatenation ** Stack
float * TransformFloatPoint(float x, float y, float z)
Apply the transformation to an (x,y,z) coordinate.
static vtkTransformConcatenationStack * New()
represent and manipulate 3D points
Definition: vtkPoints.h:39
void TransformPoint(const double in[3], double out[3])
Apply the transformation to a double-precision coordinate.