VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkAbstractTransform.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00038 #ifndef __vtkAbstractTransform_h 00039 #define __vtkAbstractTransform_h 00040 00041 #include "vtkCommonTransformsModule.h" // For export macro 00042 #include "vtkObject.h" 00043 00044 class vtkDataArray; 00045 class vtkMatrix4x4; 00046 class vtkPoints; 00047 class vtkSimpleCriticalSection; 00048 00049 class VTKCOMMONTRANSFORMS_EXPORT vtkAbstractTransform : public vtkObject 00050 { 00051 public: 00052 00053 vtkTypeMacro(vtkAbstractTransform,vtkObject); 00054 void PrintSelf(ostream& os, vtkIndent indent); 00055 00057 00059 void TransformPoint(const float in[3], float out[3]) { 00060 this->Update(); this->InternalTransformPoint(in,out); }; 00062 00064 00066 void TransformPoint(const double in[3], double out[3]) { 00067 this->Update(); this->InternalTransformPoint(in,out); }; 00069 00071 00073 double *TransformPoint(double x, double y, double z) { 00074 return this->TransformDoublePoint(x,y,z); } 00075 double *TransformPoint(const double point[3]) { 00076 return this->TransformPoint(point[0],point[1],point[2]); }; 00078 00080 00082 float *TransformFloatPoint(float x, float y, float z) { 00083 this->InternalFloatPoint[0] = x; 00084 this->InternalFloatPoint[1] = y; 00085 this->InternalFloatPoint[2] = z; 00086 this->TransformPoint(this->InternalFloatPoint,this->InternalFloatPoint); 00087 return this->InternalFloatPoint; }; 00088 float *TransformFloatPoint(const float point[3]) { 00089 return this->TransformFloatPoint(point[0],point[1],point[2]); }; 00091 00093 00095 double *TransformDoublePoint(double x, double y, double z) { 00096 this->InternalDoublePoint[0] = x; 00097 this->InternalDoublePoint[1] = y; 00098 this->InternalDoublePoint[2] = z; 00099 this->TransformPoint(this->InternalDoublePoint,this->InternalDoublePoint); 00100 return this->InternalDoublePoint; }; 00101 double *TransformDoublePoint(const double point[3]) { 00102 return this->TransformDoublePoint(point[0],point[1],point[2]); }; 00104 00106 00109 void TransformNormalAtPoint(const float point[3], const float in[3], 00110 float out[3]); 00111 void TransformNormalAtPoint(const double point[3], const double in[3], 00112 double out[3]); 00114 00115 double *TransformNormalAtPoint(const double point[3], 00116 const double normal[3]) { 00117 this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint); 00118 return this->InternalDoublePoint; }; 00119 00121 00124 double *TransformDoubleNormalAtPoint(const double point[3], 00125 const double normal[3]) { 00126 this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint); 00127 return this->InternalDoublePoint; }; 00129 00131 00134 float *TransformFloatNormalAtPoint(const float point[3], 00135 const float normal[3]) { 00136 this->TransformNormalAtPoint(point,normal,this->InternalFloatPoint); 00137 return this->InternalFloatPoint; }; 00139 00141 00144 void TransformVectorAtPoint(const float point[3], const float in[3], 00145 float out[3]); 00146 void TransformVectorAtPoint(const double point[3], const double in[3], 00147 double out[3]); 00149 00150 double *TransformVectorAtPoint(const double point[3], 00151 const double vector[3]) { 00152 this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint); 00153 return this->InternalDoublePoint; }; 00154 00156 00159 double *TransformDoubleVectorAtPoint(const double point[3], 00160 const double vector[3]) { 00161 this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint); 00162 return this->InternalDoublePoint; }; 00164 00166 00169 float *TransformFloatVectorAtPoint(const float point[3], 00170 const float vector[3]) { 00171 this->TransformVectorAtPoint(point,vector,this->InternalFloatPoint); 00172 return this->InternalFloatPoint; }; 00174 00177 virtual void TransformPoints(vtkPoints *inPts, vtkPoints *outPts); 00178 00180 00182 virtual void TransformPointsNormalsVectors(vtkPoints *inPts, 00183 vtkPoints *outPts, 00184 vtkDataArray *inNms, 00185 vtkDataArray *outNms, 00186 vtkDataArray *inVrs, 00187 vtkDataArray *outVrs); 00189 00195 vtkAbstractTransform *GetInverse(); 00196 00200 void SetInverse(vtkAbstractTransform *transform); 00201 00203 virtual void Inverse() = 0; 00204 00206 void DeepCopy(vtkAbstractTransform *); 00207 00211 void Update(); 00212 00214 00216 virtual void InternalTransformPoint(const float in[3], float out[3]) = 0; 00217 virtual void InternalTransformPoint(const double in[3], double out[3]) = 0; 00219 00221 00225 virtual void InternalTransformDerivative(const float in[3], float out[3], 00226 float derivative[3][3]) = 0; 00227 virtual void InternalTransformDerivative(const double in[3], double out[3], 00228 double derivative[3][3]) = 0; 00230 00232 virtual vtkAbstractTransform *MakeTransform() = 0; 00233 00240 virtual int CircuitCheck(vtkAbstractTransform *transform); 00241 00243 unsigned long GetMTime(); 00244 00247 virtual void UnRegister(vtkObjectBase *O); 00248 00249 protected: 00250 vtkAbstractTransform(); 00251 ~vtkAbstractTransform(); 00252 00254 virtual void InternalUpdate() {}; 00255 00257 virtual void InternalDeepCopy(vtkAbstractTransform *) {}; 00258 00259 float InternalFloatPoint[3]; 00260 double InternalDoublePoint[3]; 00261 00262 private: 00263 00264 //BTX 00265 // We need to record the time of the last update, and we also need 00266 // to do mutex locking so updates don't collide. These are private 00267 // because Update() is not virtual. 00268 // If DependsOnInverse is set, then this transform object will 00269 // check its inverse on every update, and update itself accordingly 00270 // if necessary. 00271 //ETX 00272 vtkTimeStamp UpdateTime; 00273 vtkSimpleCriticalSection *UpdateMutex; 00274 vtkSimpleCriticalSection *InverseMutex; 00275 int DependsOnInverse; 00276 00277 //BTX 00278 // MyInverse is a transform which is the inverse of this one. 00279 //ETX 00280 vtkAbstractTransform *MyInverse; 00281 00282 int InUnRegister; 00283 00284 private: 00285 vtkAbstractTransform(const vtkAbstractTransform&); // Not implemented. 00286 void operator=(const vtkAbstractTransform&); // Not implemented. 00287 }; 00288 00289 //BTX 00290 //------------------------------------------------------------------------- 00291 // A simple data structure to hold both a transform and its inverse. 00292 // One of ForwardTransform or InverseTransform might be NULL, 00293 // and must be acquired by calling GetInverse() on the other. 00294 class vtkTransformPair 00295 { 00296 public: 00297 vtkTransformPair() {}; 00298 00299 vtkAbstractTransform *ForwardTransform; 00300 vtkAbstractTransform *InverseTransform; 00301 00302 void SwapForwardInverse() { 00303 vtkAbstractTransform *tmp = this->ForwardTransform; 00304 this->ForwardTransform = this->InverseTransform; 00305 this->InverseTransform = tmp; }; 00306 }; 00307 00308 // .NAME vtkTransformConcatenation - store a series of transformations. 00309 // .SECTION Description 00310 // A helper class (not derived from vtkObject) to store a series of 00311 // transformations in a pipelined concatenation. 00312 class VTKCOMMONTRANSFORMS_EXPORT vtkTransformConcatenation 00313 { 00314 public: 00315 static vtkTransformConcatenation *New() { 00316 return new vtkTransformConcatenation(); }; 00317 void Delete() { delete this; }; 00318 00320 void Concatenate(vtkAbstractTransform *transform); 00321 00323 void Concatenate(const double elements[16]); 00324 00326 00327 void SetPreMultiplyFlag(int flag) { this->PreMultiplyFlag = flag; }; 00328 int GetPreMultiplyFlag() { return this->PreMultiplyFlag; }; 00330 00332 00333 void Translate(double x, double y, double z); 00334 void Rotate(double angle, double x, double y, double z); 00335 void Scale(double x, double y, double z); 00337 00339 void Inverse(); 00340 00342 int GetInverseFlag() { return this->InverseFlag; }; 00343 00345 void Identity(); 00346 00347 // copy the list 00348 void DeepCopy(vtkTransformConcatenation *transform); 00349 00351 int GetNumberOfTransforms() { return this->NumberOfTransforms; }; 00352 00356 int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; }; 00357 00359 00360 int GetNumberOfPostTransforms() { 00361 return this->NumberOfTransforms-this->NumberOfPreTransforms; }; 00363 00365 vtkAbstractTransform *GetTransform(int i); 00366 00368 unsigned long GetMaxMTime(); 00369 00370 void PrintSelf(ostream& os, vtkIndent indent); 00371 00372 protected: 00373 vtkTransformConcatenation(); 00374 ~vtkTransformConcatenation(); 00375 00376 int InverseFlag; 00377 int PreMultiplyFlag; 00378 00379 vtkMatrix4x4 *PreMatrix; 00380 vtkMatrix4x4 *PostMatrix; 00381 vtkAbstractTransform *PreMatrixTransform; 00382 vtkAbstractTransform *PostMatrixTransform; 00383 00384 int NumberOfTransforms; 00385 int NumberOfPreTransforms; 00386 int MaxNumberOfTransforms; 00387 vtkTransformPair *TransformList; 00388 }; 00389 00390 // .NAME vtkTransformConcatenationStack - Store a stack of concatenations. 00391 // .SECTION Description 00392 // A helper class (not derived from vtkObject) to store a stack of 00393 // concatenations. 00394 class VTKCOMMONTRANSFORMS_EXPORT vtkTransformConcatenationStack 00395 { 00396 public: 00397 static vtkTransformConcatenationStack *New() 00398 { 00399 return new vtkTransformConcatenationStack(); 00400 } 00401 void Delete() 00402 { 00403 delete this; 00404 } 00405 00408 void Pop(vtkTransformConcatenation **concat); 00409 00412 void Push(vtkTransformConcatenation **concat); 00413 00414 void DeepCopy(vtkTransformConcatenationStack *stack); 00415 00416 protected: 00417 vtkTransformConcatenationStack(); 00418 ~vtkTransformConcatenationStack(); 00419 00420 int StackSize; 00421 vtkTransformConcatenation **Stack; 00422 vtkTransformConcatenation **StackBottom; 00423 }; 00424 00425 //ETX 00426 00427 #endif