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

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 =========================================================================*/
00048 #ifndef __vtkAbstractTransform_h
00049 #define __vtkAbstractTransform_h
00050 
00051 #include "vtkObject.h"
00052 
00053 
00054 //#include "vtkMatrix4x4.h"
00055 //#include "vtkPoints.h"
00056 class vtkDataArray;
00057 class vtkMatrix4x4;
00058 class vtkPoints;
00059 class vtkSimpleCriticalSection;
00060 
00061 
00062 class VTK_COMMON_EXPORT vtkAbstractTransform : public vtkObject
00063 {
00064 public:
00065 
00066   vtkTypeRevisionMacro(vtkAbstractTransform,vtkObject);
00067   void PrintSelf(ostream& os, vtkIndent indent);
00068 
00070 
00072   void TransformPoint(const float in[3], float out[3]) {
00073     this->Update(); this->InternalTransformPoint(in,out); };
00075 
00077 
00079   void TransformPoint(const double in[3], double out[3]) {
00080     this->Update(); this->InternalTransformPoint(in,out); };
00082 
00084 
00086   double *TransformPoint(double x, double y, double z) {
00087     return this->TransformDoublePoint(x,y,z); }
00088   double *TransformPoint(const double point[3]) {
00089     return this->TransformPoint(point[0],point[1],point[2]); };
00091 
00093 
00095   float *TransformFloatPoint(float x, float y, float z) {
00096       this->InternalFloatPoint[0] = x;
00097       this->InternalFloatPoint[1] = y;
00098       this->InternalFloatPoint[2] = z;
00099       this->TransformPoint(this->InternalFloatPoint,this->InternalFloatPoint);
00100       return this->InternalFloatPoint; };
00101   float *TransformFloatPoint(const float point[3]) {
00102     return this->TransformFloatPoint(point[0],point[1],point[2]); };
00104 
00106 
00108   double *TransformDoublePoint(double x, double y, double z) {
00109     this->InternalDoublePoint[0] = x;
00110     this->InternalDoublePoint[1] = y;
00111     this->InternalDoublePoint[2] = z;
00112     this->TransformPoint(this->InternalDoublePoint,this->InternalDoublePoint);
00113     return this->InternalDoublePoint; };
00114   double *TransformDoublePoint(const double point[3]) {
00115     return this->TransformDoublePoint(point[0],point[1],point[2]); };
00117 
00119 
00122   void TransformNormalAtPoint(const float point[3], const float in[3],
00123                               float out[3]);
00124   void TransformNormalAtPoint(const double point[3], const double in[3],
00125                               double out[3]);
00127 
00128   double *TransformNormalAtPoint(const double point[3], 
00129                                  const double normal[3]) {
00130     this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint);
00131     return this->InternalDoublePoint; };
00132 
00134 
00137   double *TransformDoubleNormalAtPoint(const double point[3],
00138                                        const double normal[3]) {
00139     this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint);
00140     return this->InternalDoublePoint; };
00142   
00144 
00147   float *TransformFloatNormalAtPoint(const float point[3],
00148                                      const float normal[3]) {
00149     this->TransformNormalAtPoint(point,normal,this->InternalFloatPoint);
00150     return this->InternalFloatPoint; };
00152 
00154 
00157   void TransformVectorAtPoint(const float point[3], const float in[3],
00158                               float out[3]);
00159   void TransformVectorAtPoint(const double point[3], const double in[3],
00160                               double out[3]);
00162 
00163   double *TransformVectorAtPoint(const double point[3], 
00164                                  const double vector[3]) {
00165     this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint);
00166     return this->InternalDoublePoint; };
00167 
00169 
00172   double *TransformDoubleVectorAtPoint(const double point[3],
00173                                        const double vector[3]) {
00174     this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint);
00175     return this->InternalDoublePoint; };
00177   
00179 
00182   float *TransformFloatVectorAtPoint(const float point[3],
00183                                      const float vector[3]) {
00184     this->TransformVectorAtPoint(point,vector,this->InternalFloatPoint);
00185     return this->InternalFloatPoint; };
00187 
00190   virtual void TransformPoints(vtkPoints *inPts, vtkPoints *outPts);
00191 
00193 
00195   virtual void TransformPointsNormalsVectors(vtkPoints *inPts, 
00196                                              vtkPoints *outPts, 
00197                                              vtkDataArray *inNms, 
00198                                              vtkDataArray *outNms,
00199                                              vtkDataArray *inVrs, 
00200                                              vtkDataArray *outVrs);
00202 
00208   vtkAbstractTransform *GetInverse();
00209 
00213   void SetInverse(vtkAbstractTransform *transform);
00214 
00216   virtual void Inverse() = 0;
00217 
00219   void DeepCopy(vtkAbstractTransform *);
00220 
00224   void Update();
00225 
00227 
00229   virtual void InternalTransformPoint(const float in[3], float out[3]) = 0;
00230   virtual void InternalTransformPoint(const double in[3], double out[3]) = 0;
00232 
00234 
00238   virtual void InternalTransformDerivative(const float in[3], float out[3],
00239                                            float derivative[3][3]) = 0;
00240   virtual void InternalTransformDerivative(const double in[3], double out[3],
00241                                            double derivative[3][3]) = 0;
00243 
00245   virtual vtkAbstractTransform *MakeTransform() = 0;
00246 
00253   virtual int CircuitCheck(vtkAbstractTransform *transform);
00254 
00256   unsigned long GetMTime();
00257 
00260   virtual void UnRegister(vtkObjectBase *O);
00261 
00263 
00265   void Identity() { 
00266     vtkWarningMacro("vtkAbstractTransform::Identity() is deprecated"); };
00268 
00269 protected:
00270   vtkAbstractTransform();
00271   ~vtkAbstractTransform();
00272 
00274   virtual void InternalUpdate() {};
00275 
00277   virtual void InternalDeepCopy(vtkAbstractTransform *) {};
00278 
00279   float InternalFloatPoint[3];
00280   double InternalDoublePoint[3];
00281 
00282 private:
00283   
00284 //BTX
00285   // We need to record the time of the last update, and we also need
00286   // to do mutex locking so updates don't collide.  These are private
00287   // because Update() is not virtual.
00288   // If DependsOnInverse is set, then this transform object will
00289   // check its inverse on every update, and update itself accordingly
00290   // if necessary.
00291 //ETX
00292   vtkTimeStamp UpdateTime;
00293   vtkSimpleCriticalSection *UpdateMutex;
00294   vtkSimpleCriticalSection *InverseMutex;
00295   int DependsOnInverse;
00296 
00297 //BTX
00298   // MyInverse is a transform which is the inverse of this one.
00299 //ETX
00300   vtkAbstractTransform *MyInverse;
00301 
00302   int InUnRegister;
00303   
00304 private:
00305   vtkAbstractTransform(const vtkAbstractTransform&);  // Not implemented.
00306   void operator=(const vtkAbstractTransform&);  // Not implemented.
00307 };
00308 
00309 //BTX
00310 //-------------------------------------------------------------------------
00311 // A simple data structure to hold both a transform and its inverse.
00312 // One of ForwardTransform or InverseTransform might be NULL,
00313 // and must be acquired by calling GetInverse() on the other.
00314 class vtkTransformPair
00315 {
00316 public:
00317   vtkAbstractTransform *ForwardTransform;
00318   vtkAbstractTransform *InverseTransform;
00319   
00320   void SwapForwardInverse() {
00321     vtkAbstractTransform *tmp = this->ForwardTransform;
00322     this->ForwardTransform = this->InverseTransform;
00323     this->InverseTransform = tmp; };
00324 };
00325 
00326 // A helper class (not derived from vtkObject) to store a series of
00327 // transformations in a pipelined concatenation.
00328 class VTK_COMMON_EXPORT vtkTransformConcatenation
00329 {
00330 public:
00331   static vtkTransformConcatenation *New() {
00332     return new vtkTransformConcatenation(); };
00333   void Delete() { delete this; };
00334 
00335   // add a transform to the list according to Pre/PostMultiply semantics
00336   void Concatenate(vtkAbstractTransform *transform); 
00337     
00338   // concatenate with a matrix according to Pre/PostMultiply semantics
00339   void Concatenate(const double elements[16]);
00340 
00341   // set the PreMultiply flag
00342   void SetPreMultiplyFlag(int flag) { this->PreMultiplyFlag = flag; };
00343   int GetPreMultiplyFlag() { return this->PreMultiplyFlag; };
00344   
00345   // the three basic linear transformations
00346   void Translate(double x, double y, double z);
00347   void Rotate(double angle, double x, double y, double z);
00348   void Scale(double x, double y, double z);
00349 
00350   // invert the concatenation
00351   void Inverse();
00352   
00353   // get the inverse flag
00354   int GetInverseFlag() { return this->InverseFlag; };
00355   
00356   // identity simply clears the transform list
00357   void Identity();
00358     
00359   // copy the list
00360   void DeepCopy(vtkTransformConcatenation *transform);
00361     
00362   // the number of stored transforms
00363   int GetNumberOfTransforms() { return this->NumberOfTransforms; };
00364     
00365   // the number of transforms that were pre-concatenated (note that
00366   // whenever Iverse() is called, the pre-concatenated and
00367   // post-concatenated transforms are switched)
00368   int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; };
00369 
00370   // the number of transforms that were post-concatenated.
00371   int GetNumberOfPostTransforms() { 
00372     return this->NumberOfTransforms-this->NumberOfPreTransforms; };
00373 
00374   // get one of the transforms
00375   vtkAbstractTransform *GetTransform(int i);
00376     
00377   // get maximum MTime of all transforms
00378   unsigned long GetMaxMTime();
00379     
00380   void PrintSelf(ostream& os, vtkIndent indent);
00381 
00382 protected:
00383   vtkTransformConcatenation();
00384   ~vtkTransformConcatenation();  
00385     
00386   int InverseFlag;
00387   int PreMultiplyFlag;
00388     
00389   vtkMatrix4x4 *PreMatrix;
00390   vtkMatrix4x4 *PostMatrix;
00391   vtkAbstractTransform *PreMatrixTransform;
00392   vtkAbstractTransform *PostMatrixTransform;
00393 
00394   int NumberOfTransforms;
00395   int NumberOfPreTransforms;
00396   int MaxNumberOfTransforms;
00397   vtkTransformPair *TransformList;
00398 };
00399 
00400 // A helper class (not derived from vtkObject) to store a stack of
00401 // concatenations.
00402 class VTK_COMMON_EXPORT vtkTransformConcatenationStack
00403 {
00404 public:
00405   static vtkTransformConcatenationStack *New() {
00406     return new vtkTransformConcatenationStack(); };
00407   void Delete() { delete this; };
00408 
00409   // pop will pop delete 'concat', then pop the
00410   // top item on the stack onto 'concat'.
00411   void Pop(vtkTransformConcatenation **concat);
00412 
00413   // push will move 'concat' onto the stack, and
00414   // make 'concat' a copy of its previous self
00415   void Push(vtkTransformConcatenation **concat);
00416 
00417   void DeepCopy(vtkTransformConcatenationStack *stack);
00418 
00419 protected:
00420   vtkTransformConcatenationStack();
00421   ~vtkTransformConcatenationStack();
00422 
00423   int StackSize;
00424   vtkTransformConcatenation **Stack;
00425   vtkTransformConcatenation **StackBottom;
00426 };
00427 
00428 //ETX
00429 
00430 #endif
00431 
00432 
00433 
00434 
00435