/vol/vipdata/irtk/packages/transformation/include/irtkAffineTransformation.h

00001 /*=========================================================================
00002 
00003   Library   : Image Registration Toolkit (IRTK)
00004   Module    : $Id: irtkAffineTransformation.h 2 2008-12-23 12:40:14Z dr $
00005   Copyright : Imperial College, Department of Computing
00006               Visual Information Processing (VIP), 2008 onwards
00007   Date      : $Date: 2008-12-23 12:40:14 +0000 (Tue, 23 Dec 2008) $
00008   Version   : $Revision: 2 $
00009   Changes   : $Author: dr $
00010 
00011 =========================================================================*/
00012 
00013 #ifndef _IRTKAFFINETRANSFORMATION_H
00014 
00015 #define _IRTKAFFINETRANSFORMATION_H
00016 
00034 class irtkAffineTransformation : public irtkRigidTransformation
00035 {
00036 
00037 protected:
00038 
00040   double _sx;
00041 
00043   double _sy;
00044 
00046   double _sz;
00047 
00049   double _sxy;
00050 
00052   double _syz;
00053 
00055   double _sxz;
00056 
00058   virtual irtkMatrix Parameters2Matrix(double *) const;
00059 
00061   virtual irtkMatrix Parameters2Matrix_15DOFs(double *) const;
00062 
00065   virtual void SetParameters(double *);
00066 
00067 public:
00068 
00070   irtkAffineTransformation();
00071 
00073   irtkAffineTransformation(const irtkRigidTransformation &);
00074 
00076   irtkAffineTransformation(const irtkAffineTransformation &);
00077 
00079   virtual ~irtkAffineTransformation();
00080 
00082   virtual void   PutScaleX(double);
00083 
00085   virtual double GetScaleX();
00086 
00088   virtual void   PutScaleY(double);
00089 
00091   virtual double GetScaleY();
00092 
00094   virtual void   PutScaleZ(double);
00095 
00097   virtual double GetScaleZ();
00098 
00100   virtual void   PutShearXY(double);
00101 
00103   virtual double GetShearXY();
00104 
00106   virtual void   PutShearYZ(double);
00107 
00109   virtual double GetShearYZ();
00110 
00112   virtual void   PutShearXZ(double);
00113 
00115   virtual double GetShearXZ();
00116 
00118   virtual int NumberOfDOFs() const;
00119 
00121   virtual void   Put(int, double);
00122 
00124   virtual double Get(int) const;
00125 
00127   virtual Bool IsIdentity();
00128 
00130   virtual void Print();
00131 
00133   static int CheckHeader(char *);
00134 
00136   virtual const char *NameOfClass();
00137 
00139   virtual irtkCifstream& Read(irtkCifstream&);
00140 
00142   virtual irtkCofstream& Write(irtkCofstream&);
00143 
00145   virtual istream& Import(istream&);
00146 
00148   virtual ostream& Export(ostream&);
00149 
00151   virtual void PutMatrix(const irtkMatrix &);
00152 
00154   virtual void UpdateMatrix();
00155 
00157   virtual void UpdateParameter();
00158 
00159 };
00160 
00161 inline int irtkAffineTransformation::NumberOfDOFs() const
00162 {
00163   return 12;
00164 }
00165 
00166 inline irtkAffineTransformation::irtkAffineTransformation()
00167 {
00168   int i;
00169 
00170   // Initialize rotations and translations
00171   _tx = _ty = _tz = 0;
00172   _rx = _ry = _rz = 0;
00173 
00174   // Initialize scale and shears
00175   _sx  = _sy  = _sz  = 100;
00176   _sxy = _syz = _sxz = 0;
00177 
00178   // Free memory allocated for DOF status by base class
00179   delete []_status;
00180 
00181   // Allocate memory for DOF status
00182   _status = new _Status[this->NumberOfDOFs()];
00183 
00184   // Initialize memory for DOF status
00185   for (i = 0; i < this->NumberOfDOFs(); i++) {
00186     _status[i] = _Active;
00187   }
00188 
00189   // Update transformation matrix
00190   this->UpdateMatrix();
00191 }
00192 
00193 inline irtkAffineTransformation::irtkAffineTransformation(const irtkRigidTransformation &t)
00194 {
00195   int i;
00196 
00197   // Copy rotations and translations
00198   _tx = t.Get(0);
00199   _ty = t.Get(1);
00200   _tz = t.Get(2);
00201   _rx = t.Get(3);
00202   _ry = t.Get(4);
00203   _rz = t.Get(5);
00204 
00205   // Initialize scale and shears
00206   _sx  = 100;
00207   _sy  = 100;
00208   _sz  = 100;
00209   _sxy = 0;
00210   _syz = 0;
00211   _sxz = 0;
00212 
00213   // Free memory allocated for DOF status by base class
00214   delete []_status;
00215 
00216   // Allocate memory for DOF status
00217   _status = new _Status[this->NumberOfDOFs()];
00218 
00219   // Initialize DOF status
00220   for (i = 0; i < this->NumberOfDOFs(); i++) {
00221     if (i < 6) {
00222       _status[i] = t.GetStatus(i);
00223     } else {
00224       _status[i] = _Active;
00225     }
00226   }
00227 
00228   // Update transformation matrix
00229   this->UpdateMatrix();
00230 }
00231 
00232 inline irtkAffineTransformation::irtkAffineTransformation(const irtkAffineTransformation &t)
00233 {
00234   int i;
00235 
00236   // Copy rotations and translations
00237   _tx = t._tx;
00238   _ty = t._ty;
00239   _tz = t._tz;
00240   _rx = t._rx;
00241   _ry = t._ry;
00242   _rz = t._rz;
00243 
00244   // Copy scale and shears
00245   _sx  = t._sx;
00246   _sy  = t._sy;
00247   _sz  = t._sz;
00248   _sxy = t._sxy;
00249   _syz = t._syz;
00250   _sxz = t._sxz;
00251 
00252   // Free memory allocated for DOF status by base class
00253   delete []_status;
00254 
00255   // Allocate memory for DOF status
00256   _status = new _Status[this->NumberOfDOFs()];
00257 
00258   // Initialize memory for DOF status
00259   for (i = 0; i < this->NumberOfDOFs(); i++) {
00260     _status[i] = t._status[i];
00261   }
00262 
00263   // Update transformation matrix
00264   this->UpdateMatrix();
00265 }
00266 
00267 inline irtkAffineTransformation::~irtkAffineTransformation()
00268 {
00269 }
00270 
00271 inline void irtkAffineTransformation::PutScaleX(double sx)
00272 {
00273   _sx = sx;
00274   this->UpdateMatrix();
00275 }
00276 
00277 inline double irtkAffineTransformation::GetScaleX()
00278 {
00279   return _sx;
00280 }
00281 
00282 inline void irtkAffineTransformation::PutScaleY(double sy)
00283 {
00284   _sy = sy;
00285   this->UpdateMatrix();
00286 }
00287 
00288 inline double irtkAffineTransformation::GetScaleY()
00289 {
00290   return _sy;
00291 }
00292 
00293 inline void irtkAffineTransformation::PutScaleZ(double sz)
00294 {
00295   _sz = sz;
00296   this->UpdateMatrix();
00297 }
00298 
00299 inline double irtkAffineTransformation::GetScaleZ()
00300 {
00301   return _sz;
00302 }
00303 
00304 inline void irtkAffineTransformation::PutShearXY(double sxy)
00305 {
00306   _sxy = sxy;
00307   this->UpdateMatrix();
00308 }
00309 
00310 inline double irtkAffineTransformation::GetShearXY()
00311 {
00312   return _sxy;
00313 }
00314 
00315 inline void irtkAffineTransformation::PutShearYZ(double syz)
00316 {
00317   _syz = syz;
00318   this->UpdateMatrix();
00319 }
00320 
00321 inline double irtkAffineTransformation::GetShearYZ()
00322 {
00323   return _syz;
00324 }
00325 
00326 inline void irtkAffineTransformation::PutShearXZ(double sxz)
00327 {
00328   _sxz = sxz;
00329   this->UpdateMatrix();
00330 }
00331 
00332 inline double irtkAffineTransformation::GetShearXZ()
00333 {
00334   return _sxz;
00335 }
00336 
00337 inline const char *irtkAffineTransformation::NameOfClass()
00338 {
00339   return "irtkAffineTransformation";
00340 }
00341 
00342 inline void irtkAffineTransformation::PutMatrix(const irtkMatrix &matrix)
00343 {
00344   _matrix = matrix;
00345   this->UpdateParameter();
00346 }
00347 
00348 inline void irtkAffineTransformation::SetParameters(double *params)
00349 {
00350   this->irtkRigidTransformation::SetParameters(params);
00351 
00352   _sx  = params[SX];
00353   _sy  = params[SY];
00354   _sz  = params[SZ];
00355 
00356   _sxy = params[SXY];
00357   _syz = params[SYZ];
00358   _sxz = params[SXZ];
00359 
00360   this->UpdateMatrix();
00361 }
00362 
00363 #endif