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-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00008 All rights reserved.
00009 
00010 Redistribution and use in source and binary forms, with or without
00011 modification, are permitted provided that the following conditions are met:
00012 
00013  * Redistributions of source code must retain the above copyright notice,
00014    this list of conditions and the following disclaimer.
00015 
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019 
00020  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00021    of any contributors may be used to endorse or promote products derived
00022    from this software without specific prior written permission.
00023 
00024  * Modified source versions must be plainly marked as such, and must not be
00025    misrepresented as being the original software.
00026 
00027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00028 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00031 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00032 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00033 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00034 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00035 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 
00038 =========================================================================*/
00067 #ifndef __vtkAbstractTransform_h
00068 #define __vtkAbstractTransform_h
00069 
00070 #include "vtkObject.h"
00071 #include "vtkMatrix4x4.h"
00072 #include "vtkPoints.h"
00073 
00074 class vtkSimpleCriticalSection;
00075 
00076 
00077 class VTK_COMMON_EXPORT vtkAbstractTransform : public vtkObject
00078 {
00079 public:
00080 
00081   vtkTypeMacro(vtkAbstractTransform,vtkObject);
00082   void PrintSelf(ostream& os, vtkIndent indent);
00083 
00085 
00087   void TransformPoint(const float in[3], float out[3]) {
00088     this->Update(); this->InternalTransformPoint(in,out); };
00090 
00092 
00094   void TransformPoint(const double in[3], double out[3]) {
00095     this->Update(); this->InternalTransformPoint(in,out); };
00097 
00099 
00101   double *TransformPoint(double x, double y, double z) {
00102     return this->TransformDoublePoint(x,y,z); }
00103   double *TransformPoint(const double point[3]) {
00104     return this->TransformPoint(point[0],point[1],point[2]); };
00106 
00108 
00110   float *TransformFloatPoint(float x, float y, float z) {
00111       this->InternalFloatPoint[0] = x;
00112       this->InternalFloatPoint[1] = y;
00113       this->InternalFloatPoint[2] = z;
00114       this->TransformPoint(this->InternalFloatPoint,this->InternalFloatPoint);
00115       return this->InternalFloatPoint; };
00116   float *TransformFloatPoint(const float point[3]) {
00117     return this->TransformFloatPoint(point[0],point[1],point[2]); };
00119 
00121 
00123   double *TransformDoublePoint(double x, double y, double z) {
00124     this->InternalDoublePoint[0] = x;
00125     this->InternalDoublePoint[1] = y;
00126     this->InternalDoublePoint[2] = z;
00127     this->TransformPoint(this->InternalDoublePoint,this->InternalDoublePoint);
00128     return this->InternalDoublePoint; };
00129   double *TransformDoublePoint(const double point[3]) {
00130     return this->TransformDoublePoint(point[0],point[1],point[2]); };
00132 
00134 
00137   void TransformNormalAtPoint(const float point[3], const float in[3],
00138                               float out[3]);
00139   void TransformNormalAtPoint(const double point[3], const double in[3],
00140                               double out[3]);
00142 
00143   double *TransformNormalAtPoint(const double point[3], 
00144                                  const double normal[3]) {
00145     this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint);
00146     return this->InternalDoublePoint; };
00147 
00149 
00152   double *TransformDoubleNormalAtPoint(const double point[3],
00153                                        const double normal[3]) {
00154     this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint);
00155     return this->InternalDoublePoint; };
00157   
00159 
00162   float *TransformFloatNormalAtPoint(const float point[3],
00163                                      const float normal[3]) {
00164     this->TransformNormalAtPoint(point,normal,this->InternalFloatPoint);
00165     return this->InternalFloatPoint; };
00167 
00169 
00172   void TransformVectorAtPoint(const float point[3], const float in[3],
00173                               float out[3]);
00174   void TransformVectorAtPoint(const double point[3], const double in[3],
00175                               double out[3]);
00177 
00178   double *TransformVectorAtPoint(const double point[3], 
00179                                  const double vector[3]) {
00180     this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint);
00181     return this->InternalDoublePoint; };
00182 
00184 
00187   double *TransformDoubleVectorAtPoint(const double point[3],
00188                                        const double vector[3]) {
00189     this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint);
00190     return this->InternalDoublePoint; };
00192   
00194 
00197   float *TransformFloatVectorAtPoint(const float point[3],
00198                                      const float vector[3]) {
00199     this->TransformVectorAtPoint(point,vector,this->InternalFloatPoint);
00200     return this->InternalFloatPoint; };
00202 
00205   virtual void TransformPoints(vtkPoints *inPts, vtkPoints *outPts);
00206 
00208 
00210   virtual void TransformPointsNormalsVectors(vtkPoints *inPts, 
00211                                              vtkPoints *outPts, 
00212                                              vtkDataArray *inNms, 
00213                                              vtkDataArray *outNms,
00214                                              vtkDataArray *inVrs, 
00215                                              vtkDataArray *outVrs);
00217 
00223   vtkAbstractTransform *GetInverse();
00224 
00228   void SetInverse(vtkAbstractTransform *transform);
00229 
00231   virtual void Inverse() = 0;
00232 
00234   void DeepCopy(vtkAbstractTransform *);
00235 
00239   void Update();
00240 
00242 
00244   virtual void InternalTransformPoint(const float in[3], float out[3]) = 0;
00245   virtual void InternalTransformPoint(const double in[3], double out[3]) = 0;
00247 
00249 
00253   virtual void InternalTransformDerivative(const float in[3], float out[3],
00254                                            float derivative[3][3]) = 0;
00255   virtual void InternalTransformDerivative(const double in[3], double out[3],
00256                                            double derivative[3][3]) = 0;
00258 
00260   virtual vtkAbstractTransform *MakeTransform() = 0;
00261 
00268   virtual int CircuitCheck(vtkAbstractTransform *transform);
00269 
00271   unsigned long GetMTime();
00272 
00275   void UnRegister(vtkObject *O);
00276 
00278 
00280   void Identity() { 
00281     vtkWarningMacro("vtkAbstractTransform::Identity() is deprecated"); };
00283 
00284 protected:
00285   vtkAbstractTransform();
00286   ~vtkAbstractTransform();
00287 
00289   virtual void InternalUpdate() {};
00290 
00292   virtual void InternalDeepCopy(vtkAbstractTransform *) {};
00293 
00294   float InternalFloatPoint[3];
00295   double InternalDoublePoint[3];
00296 
00297 private:
00298   
00299 //BTX
00300   // We need to record the time of the last update, and we also need
00301   // to do mutex locking so updates don't collide.  These are private
00302   // because Update() is not virtual.
00303   // If DependsOnInverse is set, then this transform object will
00304   // check its inverse on every update, and update itself accordingly
00305   // if necessary.
00306 //ETX
00307   vtkTimeStamp UpdateTime;
00308   vtkSimpleCriticalSection *UpdateMutex;
00309   vtkSimpleCriticalSection *InverseMutex;
00310   int DependsOnInverse;
00311 
00312 //BTX
00313   // MyInverse is a transform which is the inverse of this one.
00314 //ETX
00315   vtkAbstractTransform *MyInverse;
00316 
00317   int InUnRegister;
00318   
00319 private:
00320   vtkAbstractTransform(const vtkAbstractTransform&);  // Not implemented.
00321   void operator=(const vtkAbstractTransform&);  // Not implemented.
00322 };
00323 
00324 //BTX
00325 //-------------------------------------------------------------------------
00326 // A simple data structure to hold both a transform and its inverse.
00327 // One of ForwardTransform or InverseTransform might be NULL,
00328 // and must be acquired by calling GetInverse() on the other.
00329 class vtkTransformPair
00330 {
00331 public:
00332   vtkAbstractTransform *ForwardTransform;
00333   vtkAbstractTransform *InverseTransform;
00334   
00335   void SwapForwardInverse() {
00336     vtkAbstractTransform *tmp = this->ForwardTransform;
00337     this->ForwardTransform = this->InverseTransform;
00338     this->InverseTransform = tmp; };
00339 };
00340 
00341 // A helper class (not derived from vtkObject) to store a series of
00342 // transformations in a pipelined concatenation.
00343 class VTK_COMMON_EXPORT vtkTransformConcatenation
00344 {
00345 public:
00346   static vtkTransformConcatenation *New() {
00347     return new vtkTransformConcatenation(); };
00348   void Delete() { delete this; };
00349 
00350   // add a transform to the list according to Pre/PostMultiply semantics
00351   void Concatenate(vtkAbstractTransform *transform); 
00352     
00353   // concatenate with a matrix according to Pre/PostMultiply semantics
00354   void Concatenate(const double elements[16]);
00355 
00356   // set the PreMultiply flag
00357   void SetPreMultiplyFlag(int flag) { this->PreMultiplyFlag = flag; };
00358   int GetPreMultiplyFlag() { return this->PreMultiplyFlag; };
00359   
00360   // the three basic linear transformations
00361   void Translate(double x, double y, double z);
00362   void Rotate(double angle, double x, double y, double z);
00363   void Scale(double x, double y, double z);
00364 
00365   // invert the concatenation
00366   void Inverse();
00367   
00368   // get the inverse flag
00369   int GetInverseFlag() { return this->InverseFlag; };
00370   
00371   // identity simply clears the transform list
00372   void Identity();
00373     
00374   // copy the list
00375   void DeepCopy(vtkTransformConcatenation *transform);
00376     
00377   // the number of stored transforms
00378   int GetNumberOfTransforms() { return this->NumberOfTransforms; };
00379     
00380   // the number of transforms that were pre-concatenated (note that
00381   // whenever Iverse() is called, the pre-concatenated and
00382   // post-concatenated transforms are switched)
00383   int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; };
00384 
00385   // the number of transforms that were post-concatenated.
00386   int GetNumberOfPostTransforms() { 
00387     return this->NumberOfTransforms-this->NumberOfPreTransforms; };
00388 
00389   // get one of the transforms
00390   vtkAbstractTransform *GetTransform(int i);
00391     
00392   // get maximum MTime of all transforms
00393   unsigned long GetMaxMTime();
00394     
00395   void PrintSelf(ostream& os, vtkIndent indent);
00396 
00397 protected:
00398   vtkTransformConcatenation();
00399   ~vtkTransformConcatenation();  
00400     
00401   int InverseFlag;
00402   int PreMultiplyFlag;
00403     
00404   vtkMatrix4x4 *PreMatrix;
00405   vtkMatrix4x4 *PostMatrix;
00406   vtkAbstractTransform *PreMatrixTransform;
00407   vtkAbstractTransform *PostMatrixTransform;
00408 
00409   int NumberOfTransforms;
00410   int NumberOfPreTransforms;
00411   int MaxNumberOfTransforms;
00412   vtkTransformPair *TransformList;
00413 };
00414 
00415 // A helper class (not derived from vtkObject) to store a stack of
00416 // concatenations.
00417 class VTK_COMMON_EXPORT vtkTransformConcatenationStack
00418 {
00419 public:
00420   static vtkTransformConcatenationStack *New() {
00421     return new vtkTransformConcatenationStack(); };
00422   void Delete() { delete this; };
00423 
00424   // pop will pop delete 'concat', then pop the
00425   // top item on the stack onto 'concat'.
00426   void Pop(vtkTransformConcatenation **concat);
00427 
00428   // push will move 'concat' onto the stack, and
00429   // make 'concat' a copy of its previous self
00430   void Push(vtkTransformConcatenation **concat);
00431 
00432   void DeepCopy(vtkTransformConcatenationStack *stack);
00433 
00434 protected:
00435   vtkTransformConcatenationStack();
00436   ~vtkTransformConcatenationStack();
00437 
00438   int StackSize;
00439   vtkTransformConcatenation **Stack;
00440   vtkTransformConcatenation **StackBottom;
00441 };
00442 
00443 //ETX
00444 
00445 #endif
00446 
00447 
00448 
00449 
00450 

Generated on Thu Mar 28 14:19:14 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001