Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

dox/Common/vtkAbstractTransform.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkAbstractTransform.h,v $ 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 "vtkObject.h" 00042 00043 00044 //#include "vtkMatrix4x4.h" 00045 //#include "vtkPoints.h" 00046 class vtkDataArray; 00047 class vtkMatrix4x4; 00048 class vtkPoints; 00049 class vtkSimpleCriticalSection; 00050 00051 00052 class VTK_COMMON_EXPORT vtkAbstractTransform : public vtkObject 00053 { 00054 public: 00055 00056 vtkTypeRevisionMacro(vtkAbstractTransform,vtkObject); 00057 void PrintSelf(ostream& os, vtkIndent indent); 00058 00060 00062 void TransformPoint(const float in[3], float out[3]) { 00063 this->Update(); this->InternalTransformPoint(in,out); }; 00065 00067 00069 void TransformPoint(const double in[3], double out[3]) { 00070 this->Update(); this->InternalTransformPoint(in,out); }; 00072 00074 00076 double *TransformPoint(double x, double y, double z) { 00077 return this->TransformDoublePoint(x,y,z); } 00078 double *TransformPoint(const double point[3]) { 00079 return this->TransformPoint(point[0],point[1],point[2]); }; 00081 00083 00085 float *TransformFloatPoint(float x, float y, float z) { 00086 this->InternalFloatPoint[0] = x; 00087 this->InternalFloatPoint[1] = y; 00088 this->InternalFloatPoint[2] = z; 00089 this->TransformPoint(this->InternalFloatPoint,this->InternalFloatPoint); 00090 return this->InternalFloatPoint; }; 00091 float *TransformFloatPoint(const float point[3]) { 00092 return this->TransformFloatPoint(point[0],point[1],point[2]); }; 00094 00096 00098 double *TransformDoublePoint(double x, double y, double z) { 00099 this->InternalDoublePoint[0] = x; 00100 this->InternalDoublePoint[1] = y; 00101 this->InternalDoublePoint[2] = z; 00102 this->TransformPoint(this->InternalDoublePoint,this->InternalDoublePoint); 00103 return this->InternalDoublePoint; }; 00104 double *TransformDoublePoint(const double point[3]) { 00105 return this->TransformDoublePoint(point[0],point[1],point[2]); }; 00107 00109 00112 void TransformNormalAtPoint(const float point[3], const float in[3], 00113 float out[3]); 00114 void TransformNormalAtPoint(const double point[3], const double in[3], 00115 double out[3]); 00117 00118 double *TransformNormalAtPoint(const double point[3], 00119 const double normal[3]) { 00120 this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint); 00121 return this->InternalDoublePoint; }; 00122 00124 00127 double *TransformDoubleNormalAtPoint(const double point[3], 00128 const double normal[3]) { 00129 this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint); 00130 return this->InternalDoublePoint; }; 00132 00134 00137 float *TransformFloatNormalAtPoint(const float point[3], 00138 const float normal[3]) { 00139 this->TransformNormalAtPoint(point,normal,this->InternalFloatPoint); 00140 return this->InternalFloatPoint; }; 00142 00144 00147 void TransformVectorAtPoint(const float point[3], const float in[3], 00148 float out[3]); 00149 void TransformVectorAtPoint(const double point[3], const double in[3], 00150 double out[3]); 00152 00153 double *TransformVectorAtPoint(const double point[3], 00154 const double vector[3]) { 00155 this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint); 00156 return this->InternalDoublePoint; }; 00157 00159 00162 double *TransformDoubleVectorAtPoint(const double point[3], 00163 const double vector[3]) { 00164 this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint); 00165 return this->InternalDoublePoint; }; 00167 00169 00172 float *TransformFloatVectorAtPoint(const float point[3], 00173 const float vector[3]) { 00174 this->TransformVectorAtPoint(point,vector,this->InternalFloatPoint); 00175 return this->InternalFloatPoint; }; 00177 00180 virtual void TransformPoints(vtkPoints *inPts, vtkPoints *outPts); 00181 00183 00185 virtual void TransformPointsNormalsVectors(vtkPoints *inPts, 00186 vtkPoints *outPts, 00187 vtkDataArray *inNms, 00188 vtkDataArray *outNms, 00189 vtkDataArray *inVrs, 00190 vtkDataArray *outVrs); 00192 00198 vtkAbstractTransform *GetInverse(); 00199 00203 void SetInverse(vtkAbstractTransform *transform); 00204 00206 virtual void Inverse() = 0; 00207 00209 void DeepCopy(vtkAbstractTransform *); 00210 00214 void Update(); 00215 00217 00219 virtual void InternalTransformPoint(const float in[3], float out[3]) = 0; 00220 virtual void InternalTransformPoint(const double in[3], double out[3]) = 0; 00222 00224 00228 virtual void InternalTransformDerivative(const float in[3], float out[3], 00229 float derivative[3][3]) = 0; 00230 virtual void InternalTransformDerivative(const double in[3], double out[3], 00231 double derivative[3][3]) = 0; 00233 00235 virtual vtkAbstractTransform *MakeTransform() = 0; 00236 00243 virtual int CircuitCheck(vtkAbstractTransform *transform); 00244 00246 unsigned long GetMTime(); 00247 00250 virtual void UnRegister(vtkObjectBase *O); 00251 00253 00255 void Identity() { 00256 vtkWarningMacro("vtkAbstractTransform::Identity() is deprecated"); }; 00258 00259 protected: 00260 vtkAbstractTransform(); 00261 ~vtkAbstractTransform(); 00262 00264 virtual void InternalUpdate() {}; 00265 00267 virtual void InternalDeepCopy(vtkAbstractTransform *) {}; 00268 00269 float InternalFloatPoint[3]; 00270 double InternalDoublePoint[3]; 00271 00272 private: 00273 00274 //BTX 00275 // We need to record the time of the last update, and we also need 00276 // to do mutex locking so updates don't collide. These are private 00277 // because Update() is not virtual. 00278 // If DependsOnInverse is set, then this transform object will 00279 // check its inverse on every update, and update itself accordingly 00280 // if necessary. 00281 //ETX 00282 vtkTimeStamp UpdateTime; 00283 vtkSimpleCriticalSection *UpdateMutex; 00284 vtkSimpleCriticalSection *InverseMutex; 00285 int DependsOnInverse; 00286 00287 //BTX 00288 // MyInverse is a transform which is the inverse of this one. 00289 //ETX 00290 vtkAbstractTransform *MyInverse; 00291 00292 int InUnRegister; 00293 00294 private: 00295 vtkAbstractTransform(const vtkAbstractTransform&); // Not implemented. 00296 void operator=(const vtkAbstractTransform&); // Not implemented. 00297 }; 00298 00299 //BTX 00300 //------------------------------------------------------------------------- 00301 // A simple data structure to hold both a transform and its inverse. 00302 // One of ForwardTransform or InverseTransform might be NULL, 00303 // and must be acquired by calling GetInverse() on the other. 00304 class vtkTransformPair 00305 { 00306 public: 00307 vtkAbstractTransform *ForwardTransform; 00308 vtkAbstractTransform *InverseTransform; 00309 00310 void SwapForwardInverse() { 00311 vtkAbstractTransform *tmp = this->ForwardTransform; 00312 this->ForwardTransform = this->InverseTransform; 00313 this->InverseTransform = tmp; }; 00314 }; 00315 00316 // A helper class (not derived from vtkObject) to store a series of 00317 // transformations in a pipelined concatenation. 00318 class VTK_COMMON_EXPORT vtkTransformConcatenation 00319 { 00320 public: 00321 static vtkTransformConcatenation *New() { 00322 return new vtkTransformConcatenation(); }; 00323 void Delete() { delete this; }; 00324 00325 // add a transform to the list according to Pre/PostMultiply semantics 00326 void Concatenate(vtkAbstractTransform *transform); 00327 00328 // concatenate with a matrix according to Pre/PostMultiply semantics 00329 void Concatenate(const double elements[16]); 00330 00331 // set the PreMultiply flag 00332 void SetPreMultiplyFlag(int flag) { this->PreMultiplyFlag = flag; }; 00333 int GetPreMultiplyFlag() { return this->PreMultiplyFlag; }; 00334 00335 // the three basic linear transformations 00336 void Translate(double x, double y, double z); 00337 void Rotate(double angle, double x, double y, double z); 00338 void Scale(double x, double y, double z); 00339 00340 // invert the concatenation 00341 void Inverse(); 00342 00343 // get the inverse flag 00344 int GetInverseFlag() { return this->InverseFlag; }; 00345 00346 // identity simply clears the transform list 00347 void Identity(); 00348 00349 // copy the list 00350 void DeepCopy(vtkTransformConcatenation *transform); 00351 00352 // the number of stored transforms 00353 int GetNumberOfTransforms() { return this->NumberOfTransforms; }; 00354 00355 // the number of transforms that were pre-concatenated (note that 00356 // whenever Iverse() is called, the pre-concatenated and 00357 // post-concatenated transforms are switched) 00358 int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; }; 00359 00360 // the number of transforms that were post-concatenated. 00361 int GetNumberOfPostTransforms() { 00362 return this->NumberOfTransforms-this->NumberOfPreTransforms; }; 00363 00364 // get one of the transforms 00365 vtkAbstractTransform *GetTransform(int i); 00366 00367 // get maximum MTime of all transforms 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 // A helper class (not derived from vtkObject) to store a stack of 00391 // concatenations. 00392 class VTK_COMMON_EXPORT vtkTransformConcatenationStack 00393 { 00394 public: 00395 static vtkTransformConcatenationStack *New() { 00396 return new vtkTransformConcatenationStack(); }; 00397 void Delete() { delete this; }; 00398 00399 // pop will pop delete 'concat', then pop the 00400 // top item on the stack onto 'concat'. 00401 void Pop(vtkTransformConcatenation **concat); 00402 00403 // push will move 'concat' onto the stack, and 00404 // make 'concat' a copy of its previous self 00405 void Push(vtkTransformConcatenation **concat); 00406 00407 void DeepCopy(vtkTransformConcatenationStack *stack); 00408 00409 protected: 00410 vtkTransformConcatenationStack(); 00411 ~vtkTransformConcatenationStack(); 00412 00413 int StackSize; 00414 vtkTransformConcatenation **Stack; 00415 vtkTransformConcatenation **StackBottom; 00416 }; 00417 00418 //ETX 00419 00420 #endif 00421 00422 00423 00424 00425