VTK
dox/Common/Transforms/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 "vtkCommonTransformsModule.h" // For export macro
00055 #include "vtkLinearTransform.h"
00056 
00057 #include "vtkMatrix4x4.h" // Needed for inline methods
00058 
00059 class VTKCOMMONTRANSFORMS_EXPORT vtkTransform : public vtkLinearTransform
00060 {
00061  public:
00062   static vtkTransform *New();
00063   vtkTypeMacro(vtkTransform,vtkLinearTransform);
00064   void PrintSelf(ostream& os, vtkIndent indent);
00065 
00069   void Identity();
00070 
00074   void Inverse();
00075 
00077 
00079   void Translate(double x, double y, double z) {
00080     this->Concatenation->Translate(x,y,z); };
00081   void Translate(const double x[3]) { this->Translate(x[0], x[1], x[2]); };
00082   void Translate(const float x[3]) { this->Translate(x[0], x[1], x[2]); };
00084 
00086 
00090   void RotateWXYZ(double angle, double x, double y, double z) {
00091     this->Concatenation->Rotate(angle,x,y,z); };
00092   void RotateWXYZ(double angle, const double axis[3]) {
00093     this->RotateWXYZ(angle, axis[0], axis[1], axis[2]); };
00094   void RotateWXYZ(double angle, const float axis[3]) {
00095     this->RotateWXYZ(angle, axis[0], axis[1], axis[2]); };
00097 
00099 
00102   void RotateX(double angle) { this->RotateWXYZ(angle, 1, 0, 0); };
00103   void RotateY(double angle) { this->RotateWXYZ(angle, 0, 1, 0); };
00104   void RotateZ(double angle) { this->RotateWXYZ(angle, 0, 0, 1); };
00106 
00108 
00111   void Scale(double x, double y, double z) {
00112     this->Concatenation->Scale(x,y,z); };
00113   void Scale(const double s[3]) { this->Scale(s[0], s[1], s[2]); };
00114   void Scale(const float s[3]) { this->Scale(s[0], s[1], s[2]); };
00116 
00118 
00120   void SetMatrix(vtkMatrix4x4 *matrix) {
00121     this->SetMatrix(*matrix->Element); };
00122   void SetMatrix(const double elements[16]) {
00123     this->Identity(); this->Concatenate(elements); };
00125 
00127 
00129   void Concatenate(vtkMatrix4x4 *matrix) {
00130     this->Concatenate(*matrix->Element); };
00131   void Concatenate(const double elements[16]) {
00132     this->Concatenation->Concatenate(elements); };
00134 
00140   void Concatenate(vtkLinearTransform *transform);
00141 
00143 
00148   void PreMultiply() {
00149     if (this->Concatenation->GetPreMultiplyFlag()) { return; }
00150     this->Concatenation->SetPreMultiplyFlag(1); this->Modified(); };
00152 
00154 
00159   void PostMultiply()  {
00160     if (!this->Concatenation->GetPreMultiplyFlag()) { return; }
00161     this->Concatenation->SetPreMultiplyFlag(0); this->Modified(); };
00163 
00165 
00167   int GetNumberOfConcatenatedTransforms() {
00168     return this->Concatenation->GetNumberOfTransforms() +
00169       (this->Input == NULL ? 0 : 1); };
00171 
00173 
00178   vtkLinearTransform *GetConcatenatedTransform(int i)
00179     {
00180       vtkAbstractTransform *t;
00181       if (this->Input == NULL)
00182         {
00183         t=this->Concatenation->GetTransform(i);
00184         }
00185       else if (i < this->Concatenation->GetNumberOfPreTransforms())
00186         {
00187         t=this->Concatenation->GetTransform(i);
00188         }
00189       else if (i > this->Concatenation->GetNumberOfPreTransforms())
00190         {
00191         t=this->Concatenation->GetTransform(i-1);
00192         }
00193       else if (this->GetInverseFlag())
00194         {
00195         t=this->Input->GetInverse();
00196         }
00197       else
00198         {
00199         t=this->Input;
00200         }
00201       return static_cast<vtkLinearTransform *>(t);
00202     }
00204 
00206 
00208   void GetOrientation(double orient[3]);
00209   void GetOrientation(float orient[3]) {
00210     double temp[3]; this->GetOrientation(temp);
00211     orient[0] = static_cast<float>(temp[0]);
00212     orient[1] = static_cast<float>(temp[1]);
00213     orient[2] = static_cast<float>(temp[2]); };
00214   double *GetOrientation() {
00215     this->GetOrientation(this->ReturnValue); return this->ReturnValue; };
00217 
00220   static void GetOrientation(double orient[3], vtkMatrix4x4 *matrix);
00221 
00223 
00225   void GetOrientationWXYZ(double wxyz[4]);
00226   void GetOrientationWXYZ(float wxyz[4]) {
00227     double temp[4]; this->GetOrientationWXYZ(temp);
00228     wxyz[0]=static_cast<float>(temp[0]);
00229     wxyz[1]=static_cast<float>(temp[1]);
00230     wxyz[2]=static_cast<float>(temp[2]);
00231     wxyz[3]=static_cast<float>(temp[3]);};
00232   double *GetOrientationWXYZ() {
00233     this->GetOrientationWXYZ(this->ReturnValue); return this->ReturnValue; };
00235 
00237 
00240   void GetPosition(double pos[3]);
00241   void GetPosition(float pos[3]) {
00242     double temp[3]; this->GetPosition(temp);
00243     pos[0] = static_cast<float>(temp[0]);
00244     pos[1] = static_cast<float>(temp[1]);
00245     pos[2] = static_cast<float>(temp[2]); };
00246   double *GetPosition() {
00247     this->GetPosition(this->ReturnValue); return this->ReturnValue; };
00249 
00251 
00255   void GetScale(double scale[3]);
00256   void GetScale(float scale[3]) {
00257     double temp[3]; this->GetScale(temp);
00258     scale[0] = static_cast<float>(temp[0]);
00259     scale[1] = static_cast<float>(temp[1]);
00260     scale[2] = static_cast<float>(temp[2]); };
00261   double *GetScale() {
00262     this->GetScale(this->ReturnValue); return this->ReturnValue; };
00264 
00267   void GetInverse(vtkMatrix4x4 *inverse);
00268 
00272   void GetTranspose(vtkMatrix4x4 *transpose);
00273 
00275 
00281   void SetInput(vtkLinearTransform *input);
00282   vtkLinearTransform *GetInput() { return this->Input; };
00284 
00286 
00290   int GetInverseFlag() {
00291     return this->Concatenation->GetInverseFlag(); };
00293 
00295 
00296   void Push() { if (this->Stack == NULL) {
00297                     this->Stack = vtkTransformConcatenationStack::New(); }
00298                 this->Stack->Push(&this->Concatenation);
00299                 this->Modified(); };
00301 
00303 
00305   void Pop() { if (this->Stack == NULL) { return; }
00306                this->Stack->Pop(&this->Concatenation);
00307                this->Modified(); };
00309 
00316   int CircuitCheck(vtkAbstractTransform *transform);
00317 
00318   // Return an inverse transform which will always update itself
00319   // to match this transform.
00320   vtkAbstractTransform *GetInverse() {
00321     return vtkLinearTransform::GetInverse(); }
00322 
00324   vtkAbstractTransform *MakeTransform();
00325 
00327   unsigned long GetMTime();
00328 
00330 
00333   void MultiplyPoint(const float in[4], float out[4]) {
00334     this->GetMatrix()->MultiplyPoint(in,out);};
00335   void MultiplyPoint(const double in[4], double out[4]) {
00336     this->GetMatrix()->MultiplyPoint(in,out);};
00338 
00339 protected:
00340   vtkTransform ();
00341   ~vtkTransform ();
00342 
00343   void InternalDeepCopy(vtkAbstractTransform *t);
00344 
00345   void InternalUpdate();
00346 
00347   vtkLinearTransform *Input;
00348   vtkTransformConcatenation *Concatenation;
00349   vtkTransformConcatenationStack *Stack;
00350 
00351   // this allows us to check whether people have been fooling
00352   // around with our matrix
00353   unsigned long MatrixUpdateMTime;
00354 
00355   float Point[4];
00356   double DoublePoint[4];
00357   double ReturnValue[4];
00358 private:
00359   vtkTransform (const vtkTransform&);  // Not implemented
00360   void operator=(const vtkTransform&);  // Not implemented
00361 };
00362 
00363 #endif