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 =========================================================================*/
00066 #ifndef __vtkAbstractTransform_h
00067 #define __vtkAbstractTransform_h
00068 
00069 #include "vtkObject.h"
00070 #include "vtkMatrix4x4.h"
00071 #include "vtkPoints.h"
00072 #include "vtkNormals.h"
00073 #include "vtkVectors.h"
00074 #include "vtkMutexLock.h"
00075 
00076 class VTK_EXPORT vtkAbstractTransform : public vtkObject
00077 {
00078 public:
00079 
00080   vtkTypeMacro(vtkAbstractTransform,vtkObject);
00081   void PrintSelf(ostream& os, vtkIndent indent);
00082 
00085   void TransformPoint(const float in[3], float out[3]) {
00086     this->Update(); this->InternalTransformPoint(in,out); };
00087 
00090   void TransformPoint(const double in[3], double out[3]) {
00091     this->Update(); this->InternalTransformPoint(in,out); };
00092 
00095   double *TransformPoint(double x, double y, double z) {
00096     return this->TransformDoublePoint(x,y,z); }
00097   double *TransformPoint(const double point[3]) {
00098     return this->TransformPoint(point[0],point[1],point[2]); };
00099 
00102   float *TransformFloatPoint(float x, float y, float z) {
00103       this->InternalFloatPoint[0] = x;
00104       this->InternalFloatPoint[1] = y;
00105       this->InternalFloatPoint[2] = z;
00106       this->TransformPoint(this->InternalFloatPoint,this->InternalFloatPoint);
00107       return this->InternalFloatPoint; };
00108   float *TransformFloatPoint(const float point[3]) {
00109     return this->TransformFloatPoint(point[0],point[1],point[2]); };
00110 
00113   double *TransformDoublePoint(double x, double y, double z) {
00114     this->InternalDoublePoint[0] = x;
00115     this->InternalDoublePoint[1] = y;
00116     this->InternalDoublePoint[2] = z;
00117     this->TransformPoint(this->InternalDoublePoint,this->InternalDoublePoint);
00118     return this->InternalDoublePoint; };
00119   double *TransformDoublePoint(const double point[3]) {
00120     return this->TransformDoublePoint(point[0],point[1],point[2]); };
00121 
00125   void TransformNormalAtPoint(const float point[3], const float in[3],
00126                float out[3]);
00127   void TransformNormalAtPoint(const double point[3], const double in[3],
00128                double out[3]);
00129 
00130   double *TransformNormalAtPoint(const double point[3], 
00131              const double normal[3]) {
00132     this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint);
00133     return this->InternalDoublePoint; };
00134 
00138   double *TransformDoubleNormalAtPoint(const double point[3],
00139                    const double normal[3]) {
00140     this->TransformNormalAtPoint(point,normal,this->InternalDoublePoint);
00141     return this->InternalDoublePoint; };
00142   
00146   float *TransformFloatNormalAtPoint(const float point[3],
00147                  const float normal[3]) {
00148     this->TransformNormalAtPoint(point,normal,this->InternalFloatPoint);
00149     return this->InternalFloatPoint; };
00150 
00154   void TransformVectorAtPoint(const float point[3], const float in[3],
00155                float out[3]);
00156   void TransformVectorAtPoint(const double point[3], const double in[3],
00157                double out[3]);
00158 
00159   double *TransformVectorAtPoint(const double point[3], 
00160              const double vector[3]) {
00161     this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint);
00162     return this->InternalDoublePoint; };
00163 
00167   double *TransformDoubleVectorAtPoint(const double point[3],
00168                    const double vector[3]) {
00169     this->TransformVectorAtPoint(point,vector,this->InternalDoublePoint);
00170     return this->InternalDoublePoint; };
00171   
00175   float *TransformFloatVectorAtPoint(const float point[3],
00176                  const float vector[3]) {
00177     this->TransformVectorAtPoint(point,vector,this->InternalFloatPoint);
00178     return this->InternalFloatPoint; };
00179 
00182   virtual void TransformPoints(vtkPoints *inPts, vtkPoints *outPts);
00183 
00186   virtual void TransformPointsNormalsVectors(vtkPoints *inPts, 
00187                     vtkPoints *outPts, 
00188                     vtkNormals *inNms, 
00189                     vtkNormals *outNms,
00190                     vtkVectors *inVrs, 
00191                     vtkVectors *outVrs);
00192 
00198   vtkAbstractTransform *GetInverse();
00199 
00203   void SetInverse(vtkAbstractTransform *transform);
00204 
00206   virtual void Inverse() = 0;
00207 
00209   void DeepCopy(vtkAbstractTransform *);
00210 
00214   void Update();
00215 
00218   virtual void InternalTransformPoint(const float in[3], float out[3]) = 0;
00219   virtual void InternalTransformPoint(const double in[3], double out[3]) = 0;
00220 
00225   virtual void InternalTransformDerivative(const float in[3], float out[3],
00226                   float derivative[3][3]) = 0;
00227   virtual void InternalTransformDerivative(const double in[3], double out[3],
00228                   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   void UnRegister(vtkObject *O);
00247 
00250   void Identity() { 
00251     vtkWarningMacro("vtkAbstractTransform::Identity() is deprecated"); };
00252 
00253 protected:
00254   vtkAbstractTransform();
00255   ~vtkAbstractTransform();
00256   vtkAbstractTransform(const vtkAbstractTransform&) {};
00257   void operator=(const vtkAbstractTransform&) {};
00258 
00260   virtual void InternalUpdate() {};
00261 
00263   virtual void InternalDeepCopy(vtkAbstractTransform *) {};
00264 
00265   float InternalFloatPoint[3];
00266   double InternalDoublePoint[3];
00267 
00268 private:
00269   
00270 //BTX
00271   // We need to record the time of the last update, and we also need
00272   // to do mutex locking so updates don't collide.  These are private
00273   // because Update() is not virtual.
00274   // If DependsOnInverse is set, then this transform object will
00275   // check its inverse on every update, and update itself accordingly
00276   // if necessary.
00277 //ETX
00278   vtkTimeStamp UpdateTime;
00279   vtkSimpleMutexLock *UpdateMutex;
00280   vtkSimpleMutexLock *InverseMutex;
00281   int DependsOnInverse;
00282 
00283 //BTX
00284   // MyInverse is a transform which is the inverse of this one.
00285 //ETX
00286   vtkAbstractTransform *MyInverse;
00287 
00288   int InUnRegister;
00289 };
00290 
00291 //BTX
00292 //-------------------------------------------------------------------------
00293 // A simple data structure to hold both a transform and its inverse.
00294 // One of ForwardTransform or InverseTransform might be NULL,
00295 // and must be acquired by calling GetInverse() on the other.
00296 class vtkTransformPair
00297 {
00298 public:
00299   vtkAbstractTransform *ForwardTransform;
00300   vtkAbstractTransform *InverseTransform;
00301   
00302   void SwapForwardInverse() {
00303     vtkAbstractTransform *tmp = this->ForwardTransform;
00304     this->ForwardTransform = this->InverseTransform;
00305     this->InverseTransform = tmp; };
00306 };
00307 
00308 // A helper class (not derived from vtkObject) to store a series of
00309 // transformations in a pipelined concatenation.
00310 class VTK_EXPORT vtkTransformConcatenation
00311 {
00312 public:
00313   static vtkTransformConcatenation *New() {
00314     return new vtkTransformConcatenation(); };
00315   void Delete() { delete this; };
00316 
00317   // add a transform to the list according to Pre/PostMultiply semantics
00318   void Concatenate(vtkAbstractTransform *transform); 
00319     
00320   // concatenate with a matrix according to Pre/PostMultiply semantics
00321   void Concatenate(const double elements[16]);
00322 
00323   // set the PreMultiply flag
00324   void SetPreMultiplyFlag(int flag) { this->PreMultiplyFlag = flag; };
00325   int GetPreMultiplyFlag() { return this->PreMultiplyFlag; };
00326   
00327   // the three basic linear transformations
00328   void Translate(double x, double y, double z);
00329   void Rotate(double angle, double x, double y, double z);
00330   void Scale(double x, double y, double z);
00331 
00332   // invert the concatenation
00333   void Inverse();
00334   
00335   // get the inverse flag
00336   int GetInverseFlag() { return this->InverseFlag; };
00337   
00338   // identity simply clears the transform list
00339   void Identity();
00340     
00341   // copy the list
00342   void DeepCopy(vtkTransformConcatenation *transform);
00343     
00344   // the number of stored transforms
00345   int GetNumberOfTransforms() { return this->NumberOfTransforms; };
00346     
00347   // the number of transforms that were pre-concatenated (note that
00348   // whenever Iverse() is called, the pre-concatenated and
00349   // post-concatenated transforms are switched)
00350   int GetNumberOfPreTransforms() { return this->NumberOfPreTransforms; };
00351 
00352   // the number of transforms that were post-concatenated.
00353   int GetNumberOfPostTransforms() { 
00354     return this->NumberOfTransforms-this->NumberOfPreTransforms; };
00355 
00356   // get one of the transforms
00357   vtkAbstractTransform *GetTransform(int i);
00358     
00359   // get maximum MTime of all transforms
00360   unsigned long GetMaxMTime();
00361     
00362   void PrintSelf(ostream& os, vtkIndent indent);
00363 
00364 protected:
00365   vtkTransformConcatenation();
00366   ~vtkTransformConcatenation();  
00367     
00368   int InverseFlag;
00369   int PreMultiplyFlag;
00370     
00371   vtkMatrix4x4 *PreMatrix;
00372   vtkMatrix4x4 *PostMatrix;
00373   vtkAbstractTransform *PreMatrixTransform;
00374   vtkAbstractTransform *PostMatrixTransform;
00375 
00376   int NumberOfTransforms;
00377   int NumberOfPreTransforms;
00378   int MaxNumberOfTransforms;
00379   vtkTransformPair *TransformList;
00380 };
00381 
00382 // A helper class (not derived from vtkObject) to store a stack of
00383 // concatenations.
00384 class VTK_EXPORT vtkTransformConcatenationStack
00385 {
00386 public:
00387   static vtkTransformConcatenationStack *New() {
00388     return new vtkTransformConcatenationStack(); };
00389   void Delete() { delete this; };
00390 
00391   // pop will pop delete 'concat', then pop the
00392   // top item on the stack onto 'concat'.
00393   void Pop(vtkTransformConcatenation **concat);
00394 
00395   // push will move 'concat' onto the stack, and
00396   // make 'concat' a copy of its previous self
00397   void Push(vtkTransformConcatenation **concat);
00398 
00399   void DeepCopy(vtkTransformConcatenationStack *stack);
00400 
00401 protected:
00402   vtkTransformConcatenationStack();
00403   ~vtkTransformConcatenationStack();
00404 
00405   int StackSize;
00406   vtkTransformConcatenation **Stack;
00407   vtkTransformConcatenation **StackBottom;
00408 };
00409 
00410 //ETX
00411 
00412 #endif
00413 
00414 
00415 
00416 
00417 

Generated on Wed Nov 21 12:26:50 2001 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001