Common/vtkAbstractTransform.h Source File

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

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