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 Language: C++ 00006 00007 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 00008 All rights reserved. 00009 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notice for more information. 00014 00015 =========================================================================*/ 00042 #ifndef __vtkAbstractTransform_h 00043 #define __vtkAbstractTransform_h 00044 00045 #include "vtkObject.h" 00046 00047 00048 //#include "vtkMatrix4x4.h" 00049 //#include "vtkPoints.h" 00050 class vtkDataArray; 00051 class vtkMatrix4x4; 00052 class vtkPoints; 00053 class vtkSimpleCriticalSection; 00054 00055 00056 class VTK_COMMON_EXPORT vtkAbstractTransform : public vtkObject 00057 { 00058 public: 00059 00060 vtkTypeRevisionMacro(vtkAbstractTransform,vtkObject); 00061 void PrintSelf(ostream& os, vtkIndent indent); 00062 00064 00066 void TransformPoint(const float in[3], float out[3]) { 00067 this->Update(); this->InternalTransformPoint(in,out); }; 00069 00071 00073 void TransformPoint(const double in[3], double out[3]) { 00074 this->Update(); this->InternalTransformPoint(in,out); }; 00076 00078 00080 double *TransformPoint(double x, double y, double z) { 00081 return this->TransformDoublePoint(x,y,z); } 00082 double *TransformPoint(const double point[3]) { 00083 return this->TransformPoint(point[0],point[1],point[2]); }; 00085 00087 00089 float *TransformFloatPoint(float x, float y, float z) { 00090 this->InternalFloatPoint[0] = x; 00091 this->InternalFloatPoint[1] = y; 00092 this->InternalFloatPoint[2] = z; 00093 this->TransformPoint(this->InternalFloatPoint,this->InternalFloatPoint); 00094 return this->InternalFloatPoint; }; 00095 float *TransformFloatPoint(const float point[3]) { 00096 return this->TransformFloatPoint(point[0],point[1],point[2]); }; 00098 00100 00102 double *TransformDoublePoint(double x, double y, double z) { 00103 this->InternalDoublePoint[0] = x; 00104 this->InternalDoublePoint[1] = y; 00105 this->InternalDoublePoint[2] = z; 00106 this->TransformPoint(this->InternalDoublePoint,this->InternalDoublePoint); 00107 return this->InternalDoublePoint; }; 00108 double *TransformDoublePoint(const double point[3]) { 00109 return this->TransformDoublePoint(point[0],point[1],point[2]); }; 00111 00113 00116 void TransformNormalAtPoint(const float point[3], const float in[3], 00117 float out[3]); 00118 void TransformNormalAtPoint(const double point[3], const double in[3], 00119 double out[3]); 00121 00122 double *TransformNormalAtPoint(const double point[3], 00123 const double normal[3]) { 00124 this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint); 00125 return this->InternalDoublePoint; }; 00126 00128 00131 double *TransformDoubleNormalAtPoint(const double point[3], 00132 const double normal[3]) { 00133 this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint); 00134 return this->InternalDoublePoint; }; 00136 00138 00141 float *TransformFloatNormalAtPoint(const float point[3], 00142 const float normal[3]) { 00143 this->TransformNormalAtPoint(point,normal,this->InternalFloatPoint); 00144 return this->InternalFloatPoint; }; 00146 00148 00151 void TransformVectorAtPoint(const float point[3], const float in[3], 00152 float out[3]); 00153 void TransformVectorAtPoint(const double point[3], const double in[3], 00154 double out[3]); 00156 00157 double *TransformVectorAtPoint(const double point[3], 00158 const double vector[3]) { 00159 this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint); 00160 return this->InternalDoublePoint; }; 00161 00163 00166 double *TransformDoubleVectorAtPoint(const double point[3], 00167 const double vector[3]) { 00168 this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint); 00169 return this->InternalDoublePoint; }; 00171 00173 00176 float *TransformFloatVectorAtPoint(const float point[3], 00177 const float vector[3]) { 00178 this->TransformVectorAtPoint(point,vector,this->InternalFloatPoint); 00179 return this->InternalFloatPoint; }; 00181 00184 virtual void TransformPoints(vtkPoints *inPts, vtkPoints *outPts); 00185 00187 00189 virtual void TransformPointsNormalsVectors(vtkPoints *inPts, 00190 vtkPoints *outPts, 00191 vtkDataArray *inNms, 00192 vtkDataArray *outNms, 00193 vtkDataArray *inVrs, 00194 vtkDataArray *outVrs); 00196 00202 vtkAbstractTransform *GetInverse(); 00203 00207 void SetInverse(vtkAbstractTransform *transform); 00208 00210 virtual void Inverse() = 0; 00211 00213 void DeepCopy(vtkAbstractTransform *); 00214 00218 void Update(); 00219 00221 00223 virtual void InternalTransformPoint(const float in[3], float out[3]) = 0; 00224 virtual void InternalTransformPoint(const double in[3], double out[3]) = 0; 00226 00228 00232 virtual void InternalTransformDerivative(const float in[3], float out[3], 00233 float derivative[3][3]) = 0; 00234 virtual void InternalTransformDerivative(const double in[3], double out[3], 00235 double derivative[3][3]) = 0; 00237 00239 virtual vtkAbstractTransform *MakeTransform() = 0; 00240 00247 virtual int CircuitCheck(vtkAbstractTransform *transform); 00248 00250 unsigned long GetMTime(); 00251 00254 virtual void UnRegister(vtkObjectBase *O); 00255 00257 00259 void Identity() { 00260 vtkWarningMacro("vtkAbstractTransform::Identity() is deprecated"); }; 00262 00263 protected: 00264 vtkAbstractTransform(); 00265 ~vtkAbstractTransform(); 00266 00268 virtual void InternalUpdate() {}; 00269 00271 virtual void InternalDeepCopy(vtkAbstractTransform *) {}; 00272 00273 float InternalFloatPoint[3]; 00274 double InternalDoublePoint[3]; 00275 00276 private: 00277 00278 //BTX 00279 // We need to record the time of the last update, and we also need 00280 // to do mutex locking so updates don't collide. These are private 00281 // because Update() is not virtual. 00282 // If DependsOnInverse is set, then this transform object will 00283 // check its inverse on every update, and update itself accordingly 00284 // if necessary. 00285 //ETX 00286 vtkTimeStamp UpdateTime; 00287 vtkSimpleCriticalSection *UpdateMutex; 00288 vtkSimpleCriticalSection *InverseMutex; 00289 int DependsOnInverse; 00290 00291 //BTX 00292 // MyInverse is a transform which is the inverse of this one. 00293 //ETX 00294 vtkAbstractTransform *MyInverse; 00295 00296 int InUnRegister; 00297 00298 private: 00299 vtkAbstractTransform(const vtkAbstractTransform&); // Not implemented. 00300 void operator=(const vtkAbstractTransform&); // Not implemented. 00301 }; 00302 00303 //BTX 00304 //------------------------------------------------------------------------- 00305 // A simple data structure to hold both a transform and its inverse. 00306 // One of ForwardTransform or InverseTransform might be NULL, 00307 // and must be acquired by calling GetInverse() on the other. 00308 class vtkTransformPair 00309 { 00310 public: 00311 vtkAbstractTransform *ForwardTransform; 00312 vtkAbstractTransform *InverseTransform; 00313 00314 void SwapForwardInverse() { 00315 vtkAbstractTransform *tmp = this->ForwardTransform; 00316 this->ForwardTransform = this->InverseTransform; 00317 this->InverseTransform = tmp; }; 00318 }; 00319 00320 // A helper class (not derived from vtkObject) to store a series of 00321 // transformations in a pipelined concatenation. 00322 class VTK_COMMON_EXPORT vtkTransformConcatenation 00323 { 00324 public: 00325 static vtkTransformConcatenation *New() { 00326 return new vtkTransformConcatenation(); }; 00327 void Delete() { delete this; }; 00328 00329 // add a transform to the list according to Pre/PostMultiply semantics 00330 void Concatenate(vtkAbstractTransform *transform); 00331 00332 // concatenate with a matrix according to Pre/PostMultiply semantics 00333 void Concatenate(const double elements[16]); 00334 00335 // set the PreMultiply flag 00336 void SetPreMultiplyFlag(int flag) { this->PreMultiplyFlag = flag; }; 00337 int GetPreMultiplyFlag() { return this->PreMultiplyFlag; }; 00338 00339 // the three basic linear transformations 00340 void Translate(double x, double y, double z); 00341 void Rotate(double angle, double x, double y, double z); 00342 void Scale(double x, double y, double z); 00343 00344 // invert the concatenation 00345 void Inverse(); 00346 00347 // get the inverse flag 00348 int GetInverseFlag() { return this->InverseFlag; }; 00349 00350 // identity simply clears the transform list 00351 void Identity(); 00352 00353 // copy the list 00354 void DeepCopy(vtkTransformConcatenation *transform); 00355 00356 // the number of stored transforms 00357 int GetNumberOfTransforms() { return this->NumberOfTransforms; }; 00358 00359 // the number of transforms that were pre-concatenated (note that 00360 // whenever Iverse() is called, the pre-concatenated and 00361 // post-concatenated transforms are switched) 00362 int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; }; 00363 00364 // the number of transforms that were post-concatenated. 00365 int GetNumberOfPostTransforms() { 00366 return this->NumberOfTransforms-this->NumberOfPreTransforms; }; 00367 00368 // get one of the transforms 00369 vtkAbstractTransform *GetTransform(int i); 00370 00371 // get maximum MTime of all transforms 00372 unsigned long GetMaxMTime(); 00373 00374 void PrintSelf(ostream& os, vtkIndent indent); 00375 00376 protected: 00377 vtkTransformConcatenation(); 00378 ~vtkTransformConcatenation(); 00379 00380 int InverseFlag; 00381 int PreMultiplyFlag; 00382 00383 vtkMatrix4x4 *PreMatrix; 00384 vtkMatrix4x4 *PostMatrix; 00385 vtkAbstractTransform *PreMatrixTransform; 00386 vtkAbstractTransform *PostMatrixTransform; 00387 00388 int NumberOfTransforms; 00389 int NumberOfPreTransforms; 00390 int MaxNumberOfTransforms; 00391 vtkTransformPair *TransformList; 00392 }; 00393 00394 // A helper class (not derived from vtkObject) to store a stack of 00395 // concatenations. 00396 class VTK_COMMON_EXPORT vtkTransformConcatenationStack 00397 { 00398 public: 00399 static vtkTransformConcatenationStack *New() { 00400 return new vtkTransformConcatenationStack(); }; 00401 void Delete() { delete this; }; 00402 00403 // pop will pop delete 'concat', then pop the 00404 // top item on the stack onto 'concat'. 00405 void Pop(vtkTransformConcatenation **concat); 00406 00407 // push will move 'concat' onto the stack, and 00408 // make 'concat' a copy of its previous self 00409 void Push(vtkTransformConcatenation **concat); 00410 00411 void DeepCopy(vtkTransformConcatenationStack *stack); 00412 00413 protected: 00414 vtkTransformConcatenationStack(); 00415 ~vtkTransformConcatenationStack(); 00416 00417 int StackSize; 00418 vtkTransformConcatenation **Stack; 00419 vtkTransformConcatenation **StackBottom; 00420 }; 00421 00422 //ETX 00423 00424 #endif 00425 00426 00427 00428 00429