VTK
dox/Common/vtkTransform.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkTransform.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 =========================================================================*/
00015 
00051 #ifndef __vtkTransform_h
00052 #define __vtkTransform_h
00053 
00054 #include "vtkLinearTransform.h"
00055 
00056 #include "vtkMatrix4x4.h" // Needed for inline methods
00057 
00058 class VTK_COMMON_EXPORT vtkTransform : public vtkLinearTransform
00059 {
00060  public:
00061   static vtkTransform *New();
00062   vtkTypeMacro(vtkTransform,vtkLinearTransform);
00063   void PrintSelf(ostream& os, vtkIndent indent);
00064 
00068   void Identity();
00069 
00073   void Inverse();
00074 
00076 
00078   void Translate(double x, double y, double z) {
00079     this->Concatenation->Translate(x,y,z); };
00080   void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); };
00081   void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); };
00083 
00085 
00089   void RotateWXYZ(double angle, double x, double y, double z) {
00090     this->Concatenation->Rotate(angle,x,y,z); };
00091   void RotateWXYZ(double angle, const double axis[3]) {
00092     this->RotateWXYZ(angle, axis[0], axis[1], axis[2]); };
00093   void RotateWXYZ(double angle, const float axis[3]) {
00094     this->RotateWXYZ(angle, axis[0], axis[1], axis[2]); };
00096 
00098 
00101   void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); };
00102   void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); };
00103   void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); };
00105 
00107 
00110   void Scale(double x, double y, double z) {
00111     this->Concatenation->Scale(x,y,z); };
00112   void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); };
00113   void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); };
00115 
00117 
00119   void SetMatrix(vtkMatrix4x4 *matrix) { 
00120     this->SetMatrix(*matrix->Element); };
00121   void SetMatrix(const double elements[16]) { 
00122     this->Identity(); this->Concatenate(elements); };
00124 
00126 
00128   void Concatenate(vtkMatrix4x4 *matrix) { 
00129     this->Concatenate(*matrix->Element); };
00130   void Concatenate(const double elements[16]) {
00131     this->Concatenation->Concatenate(elements); };
00133 
00139   void Concatenate(vtkLinearTransform *transform);
00140 
00142 
00147   void PreMultiply() { 
00148     if (this->Concatenation->GetPreMultiplyFlag()) { return; }
00149     this->Concatenation->SetPreMultiplyFlag(1); this->Modified(); };
00151 
00153 
00158   void PostMultiply()  { 
00159     if (!this->Concatenation->GetPreMultiplyFlag()) { return; }
00160     this->Concatenation->SetPreMultiplyFlag(0); this->Modified(); };
00162 
00164 
00166   int GetNumberOfConcatenatedTransforms() {
00167     return this->Concatenation->GetNumberOfTransforms() + 
00168       (this->Input == NULL ? 0 : 1); };
00170 
00172 
00177   vtkLinearTransform *GetConcatenatedTransform(int i)
00178     {
00179       vtkAbstractTransform *t;
00180       if (this->Input == NULL)
00181         {
00182         t=this->Concatenation->GetTransform(i);
00183         }
00184       else if (i < this->Concatenation->GetNumberOfPreTransforms())
00185         {
00186         t=this->Concatenation->GetTransform(i);
00187         }
00188       else if (i > this->Concatenation->GetNumberOfPreTransforms())
00189         {
00190         t=this->Concatenation->GetTransform(i-1);
00191         }
00192       else if (this->GetInverseFlag())
00193         {
00194         t=this->Input->GetInverse();
00195         }
00196       else
00197         {
00198         t=this->Input;
00199         }
00200       return static_cast<vtkLinearTransform *>(t);
00201     }
00203 
00205 
00207   void GetOrientation(double orient[3]);
00208   void GetOrientation(float orient[3]) {
00209     double temp[3]; this->GetOrientation(temp); 
00210     orient[0] = static_cast<float>(temp[0]); 
00211     orient[1] = static_cast<float>(temp[1]); 
00212     orient[2] = static_cast<float>(temp[2]); };
00213   double *GetOrientation() { 
00214     this->GetOrientation(this->ReturnValue); return this->ReturnValue; };
00216 
00219   static void GetOrientation(double orient[3], vtkMatrix4x4 *matrix);
00220 
00222 
00224   void GetOrientationWXYZ(double wxyz[4]);
00225   void GetOrientationWXYZ(float wxyz[4]) {
00226     double temp[4]; this->GetOrientationWXYZ(temp); 
00227     wxyz[0]=static_cast<float>(temp[0]); 
00228     wxyz[1]=static_cast<float>(temp[1]); 
00229     wxyz[2]=static_cast<float>(temp[2]); 
00230     wxyz[3]=static_cast<float>(temp[3]);};
00231   double *GetOrientationWXYZ() { 
00232     this->GetOrientationWXYZ(this->ReturnValue); return this->ReturnValue; };
00234 
00236 
00239   void GetPosition(double pos[3]);
00240   void GetPosition(float pos[3]) {
00241     double temp[3]; this->GetPosition(temp); 
00242     pos[0] = static_cast<float>(temp[0]); 
00243     pos[1] = static_cast<float>(temp[1]); 
00244     pos[2] = static_cast<float>(temp[2]); };
00245   double *GetPosition() { 
00246     this->GetPosition(this->ReturnValue); return this->ReturnValue; };
00248 
00250 
00254   void GetScale(double scale[3]);
00255   void GetScale(float scale[3]) {
00256     double temp[3]; this->GetScale(temp); 
00257     scale[0] = static_cast<float>(temp[0]); 
00258     scale[1] = static_cast<float>(temp[1]); 
00259     scale[2] = static_cast<float>(temp[2]); };
00260   double *GetScale() { 
00261     this->GetScale(this->ReturnValue); return this->ReturnValue; };
00263 
00266   void GetInverse(vtkMatrix4x4 *inverse);
00267 
00271   void GetTranspose(vtkMatrix4x4 *transpose);
00272 
00274 
00280   void SetInput(vtkLinearTransform *input);
00281   vtkLinearTransform *GetInput() { return this->Input; };
00283 
00285 
00289   int GetInverseFlag() {
00290     return this->Concatenation->GetInverseFlag(); };
00292 
00294 
00295   void Push() { if (this->Stack == NULL) { 
00296                     this->Stack = vtkTransformConcatenationStack::New(); }
00297                 this->Stack->Push(&this->Concatenation); 
00298                 this->Modified(); };
00300 
00302 
00304   void Pop() { if (this->Stack == NULL) { return; }
00305                this->Stack->Pop(&this->Concatenation);
00306                this->Modified(); };
00308 
00315   int CircuitCheck(vtkAbstractTransform *transform);
00316 
00317   // Return an inverse transform which will always update itself
00318   // to match this transform.
00319   vtkAbstractTransform *GetInverse() { 
00320     return vtkLinearTransform::GetInverse(); }
00321 
00323   vtkAbstractTransform *MakeTransform();
00324 
00326   unsigned long GetMTime();
00327 
00329 
00332   void MultiplyPoint(const float in[4], float out[4]) {
00333     this->GetMatrix()->MultiplyPoint(in,out);};
00334   void MultiplyPoint(const double in[4], double out[4]) {      
00335     this->GetMatrix()->MultiplyPoint(in,out);};
00337 
00338 protected:
00339   vtkTransform ();
00340   ~vtkTransform ();
00341 
00342   void InternalDeepCopy(vtkAbstractTransform *t);
00343 
00344   void InternalUpdate();
00345 
00346   vtkLinearTransform *Input;
00347   vtkTransformConcatenation *Concatenation;
00348   vtkTransformConcatenationStack *Stack;
00349 
00350   // this allows us to check whether people have been fooling
00351   // around with our matrix
00352   unsigned long MatrixUpdateMTime;
00353 
00354   float Point[4];
00355   double DoublePoint[4];
00356   double ReturnValue[4];
00357 private:
00358   vtkTransform (const vtkTransform&);  // Not implemented
00359   void operator=(const vtkTransform&);  // Not implemented
00360 };
00361 
00362 #endif