VTK
dox/Common/vtkAbstractTransform.h
Go to the documentation of this file.
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 "vtkObject.h"
00042 
00043 class vtkDataArray;
00044 class vtkMatrix4x4;
00045 class vtkPoints;
00046 class vtkSimpleCriticalSection;
00047 
00048 class VTK_COMMON_EXPORT vtkAbstractTransform : public vtkObject
00049 {
00050 public:
00051 
00052   vtkTypeMacro(vtkAbstractTransform,vtkObject);
00053   void PrintSelf(ostream& os, vtkIndent indent);
00054 
00056 
00058   void TransformPoint(const float in[3], float out[3]) {
00059     this->Update(); this->InternalTransformPoint(in,out); };
00061 
00063 
00065   void TransformPoint(const double in[3], double out[3]) {
00066     this->Update(); this->InternalTransformPoint(in,out); };
00068 
00070 
00072   double *TransformPoint(double x, double y, double z) {
00073     return this->TransformDoublePoint(x,y,z); }
00074   double *TransformPoint(const double point[3]) {
00075     return this->TransformPoint(point[0],point[1],point[2]); };
00077 
00079 
00081   float *TransformFloatPoint(float x, float y, float z) {
00082       this->InternalFloatPoint[0] = x;
00083       this->InternalFloatPoint[1] = y;
00084       this->InternalFloatPoint[2] = z;
00085       this->TransformPoint(this->InternalFloatPoint,this->InternalFloatPoint);
00086       return this->InternalFloatPoint; };
00087   float *TransformFloatPoint(const float point[3]) {
00088     return this->TransformFloatPoint(point[0],point[1],point[2]); };
00090 
00092 
00094   double *TransformDoublePoint(double x, double y, double z) {
00095     this->InternalDoublePoint[0] = x;
00096     this->InternalDoublePoint[1] = y;
00097     this->InternalDoublePoint[2] = z;
00098     this->TransformPoint(this->InternalDoublePoint,this->InternalDoublePoint);
00099     return this->InternalDoublePoint; };
00100   double *TransformDoublePoint(const double point[3]) {
00101     return this->TransformDoublePoint(point[0],point[1],point[2]); };
00103 
00105 
00108   void TransformNormalAtPoint(const float point[3], const float in[3],
00109                               float out[3]);
00110   void TransformNormalAtPoint(const double point[3], const double in[3],
00111                               double out[3]);
00113 
00114   double *TransformNormalAtPoint(const double point[3], 
00115                                  const double normal[3]) {
00116     this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint);
00117     return this->InternalDoublePoint; };
00118 
00120 
00123   double *TransformDoubleNormalAtPoint(const double point[3],
00124                                        const double normal[3]) {
00125     this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint);
00126     return this->InternalDoublePoint; };
00128   
00130 
00133   float *TransformFloatNormalAtPoint(const float point[3],
00134                                      const float normal[3]) {
00135     this->TransformNormalAtPoint(point,normal,this->InternalFloatPoint);
00136     return this->InternalFloatPoint; };
00138 
00140 
00143   void TransformVectorAtPoint(const float point[3], const float in[3],
00144                               float out[3]);
00145   void TransformVectorAtPoint(const double point[3], const double in[3],
00146                               double out[3]);
00148 
00149   double *TransformVectorAtPoint(const double point[3], 
00150                                  const double vector[3]) {
00151     this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint);
00152     return this->InternalDoublePoint; };
00153 
00155 
00158   double *TransformDoubleVectorAtPoint(const double point[3],
00159                                        const double vector[3]) {
00160     this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint);
00161     return this->InternalDoublePoint; };
00163   
00165 
00168   float *TransformFloatVectorAtPoint(const float point[3],
00169                                      const float vector[3]) {
00170     this->TransformVectorAtPoint(point,vector,this->InternalFloatPoint);
00171     return this->InternalFloatPoint; };
00173 
00176   virtual void TransformPoints(vtkPoints *inPts, vtkPoints *outPts);
00177 
00179 
00181   virtual void TransformPointsNormalsVectors(vtkPoints *inPts, 
00182                                              vtkPoints *outPts, 
00183                                              vtkDataArray *inNms, 
00184                                              vtkDataArray *outNms,
00185                                              vtkDataArray *inVrs, 
00186                                              vtkDataArray *outVrs);
00188 
00194   vtkAbstractTransform *GetInverse();
00195 
00199   void SetInverse(vtkAbstractTransform *transform);
00200 
00202   virtual void Inverse() = 0;
00203 
00205   void DeepCopy(vtkAbstractTransform *);
00206 
00210   void Update();
00211 
00213 
00215   virtual void InternalTransformPoint(const float in[3], float out[3]) = 0;
00216   virtual void InternalTransformPoint(const double in[3], double out[3]) = 0;
00218 
00220 
00224   virtual void InternalTransformDerivative(const float in[3], float out[3],
00225                                            float derivative[3][3]) = 0;
00226   virtual void InternalTransformDerivative(const double in[3], double out[3],
00227                                            double derivative[3][3]) = 0;
00229 
00231   virtual vtkAbstractTransform *MakeTransform() = 0;
00232 
00239   virtual int CircuitCheck(vtkAbstractTransform *transform);
00240 
00242   unsigned long GetMTime();
00243 
00246   virtual void UnRegister(vtkObjectBase *O);
00247 
00250   VTK_LEGACY(void Identity());
00251 
00252 protected:
00253   vtkAbstractTransform();
00254   ~vtkAbstractTransform();
00255 
00257   virtual void InternalUpdate() {};
00258 
00260   virtual void InternalDeepCopy(vtkAbstractTransform *) {};
00261 
00262   float InternalFloatPoint[3];
00263   double InternalDoublePoint[3];
00264 
00265 private:
00266   
00267 //BTX
00268   // We need to record the time of the last update, and we also need
00269   // to do mutex locking so updates don't collide.  These are private
00270   // because Update() is not virtual.
00271   // If DependsOnInverse is set, then this transform object will
00272   // check its inverse on every update, and update itself accordingly
00273   // if necessary.
00274 //ETX
00275   vtkTimeStamp UpdateTime;
00276   vtkSimpleCriticalSection *UpdateMutex;
00277   vtkSimpleCriticalSection *InverseMutex;
00278   int DependsOnInverse;
00279 
00280 //BTX
00281   // MyInverse is a transform which is the inverse of this one.
00282 //ETX
00283   vtkAbstractTransform *MyInverse;
00284 
00285   int InUnRegister;
00286   
00287 private:
00288   vtkAbstractTransform(const vtkAbstractTransform&);  // Not implemented.
00289   void operator=(const vtkAbstractTransform&);  // Not implemented.
00290 };
00291 
00292 //BTX
00293 //-------------------------------------------------------------------------
00294 // A simple data structure to hold both a transform and its inverse.
00295 // One of ForwardTransform or InverseTransform might be NULL,
00296 // and must be acquired by calling GetInverse() on the other.
00297 class vtkTransformPair
00298 {
00299 public:
00300   vtkTransformPair() {};
00301 
00302   vtkAbstractTransform *ForwardTransform;
00303   vtkAbstractTransform *InverseTransform;
00304   
00305   void SwapForwardInverse() {
00306     vtkAbstractTransform *tmp = this->ForwardTransform;
00307     this->ForwardTransform = this->InverseTransform;
00308     this->InverseTransform = tmp; };
00309 };
00310 
00311 // .NAME vtkTransformConcatenation - store a series of transformations.
00312 // .SECTION Description
00313 // A helper class (not derived from vtkObject) to store a series of
00314 // transformations in a pipelined concatenation.
00315 class VTK_COMMON_EXPORT vtkTransformConcatenation
00316 {
00317 public:
00318   static vtkTransformConcatenation *New() {
00319     return new vtkTransformConcatenation(); };
00320   void Delete() { delete this; };
00321 
00323   void Concatenate(vtkAbstractTransform *transform); 
00324     
00326   void Concatenate(const double elements[16]);
00327 
00329 
00330   void SetPreMultiplyFlag(int flag) { this->PreMultiplyFlag = flag; };
00331   int GetPreMultiplyFlag() { return this->PreMultiplyFlag; };
00333   
00335 
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);
00340   
00342   void Inverse();
00343   
00345   int GetInverseFlag() { return this->InverseFlag; };
00346   
00348   void Identity();
00349     
00350   // copy the list
00351   void DeepCopy(vtkTransformConcatenation *transform);
00352     
00354   int GetNumberOfTransforms() { return this->NumberOfTransforms; };
00355   
00359   int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; };
00360   
00362 
00363   int GetNumberOfPostTransforms() { 
00364     return this->NumberOfTransforms-this->NumberOfPreTransforms; };
00366 
00368   vtkAbstractTransform *GetTransform(int i);
00369   
00371   unsigned long GetMaxMTime();
00372     
00373   void PrintSelf(ostream& os, vtkIndent indent);
00374 
00375 protected:
00376   vtkTransformConcatenation();
00377   ~vtkTransformConcatenation();  
00378     
00379   int InverseFlag;
00380   int PreMultiplyFlag;
00381     
00382   vtkMatrix4x4 *PreMatrix;
00383   vtkMatrix4x4 *PostMatrix;
00384   vtkAbstractTransform *PreMatrixTransform;
00385   vtkAbstractTransform *PostMatrixTransform;
00386 
00387   int NumberOfTransforms;
00388   int NumberOfPreTransforms;
00389   int MaxNumberOfTransforms;
00390   vtkTransformPair *TransformList;
00391 };
00392 
00393 // .NAME vtkTransformConcatenationStack - Store a stack of concatenations.
00394 // .SECTION Description
00395 // A helper class (not derived from vtkObject) to store a stack of
00396 // concatenations.
00397 class VTK_COMMON_EXPORT vtkTransformConcatenationStack
00398 {
00399 public:
00400   static vtkTransformConcatenationStack *New()
00401     {
00402       return new vtkTransformConcatenationStack();
00403     }
00404   void Delete()
00405     {
00406       delete this;
00407     }
00408 
00411   void Pop(vtkTransformConcatenation **concat);
00412 
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