00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _IRTKTRANSFORMATION_H
00014
00015 #define _IRTKTRANSFORMATION_H
00016
00017 #include <irtkImage.h>
00018
00020 typedef enum { _Active, _Passive, _Unknown } _Status;
00021
00022 #define IRTKTRANSFORMATION_MAGIC 815007
00023
00024 #define IRTKTRANSFORMATION_HOMOGENEOUS 1
00025 #define IRTKTRANSFORMATION_RIGID 2
00026 #define IRTKTRANSFORMATION_AFFINE 3
00027 #define IRTKTRANSFORMATION_BSPLINE_FFD 4
00028 #define IRTKTRANSFORMATION_LINEAR_FFD 5
00029 #define IRTKTRANSFORMATION_EIGEN_FFD 6
00030 #define IRTKTRANSFORMATION_MFFD 7
00031 #define IRTKTRANSFORMATION_FLUID 8
00032 #define IRTKTRANSFORMATION_LATTICE_FFD 9
00033 #define IRTKTRANSFORMATION_MULTI_FRAME_LATTICE_FFD 10
00034 #define IRTKTRANSFORMATION_QUATERNION 11
00035 #define IRTKTRANSFORMATION_BSPLINE_FFD_EXT1 12
00036 #define IRTKTRANSFORMATION_LINEAR_FFD_EXT1 13
00037 #define IRTKTRANSFORMATION_BSPLINE_FFD_4D 14
00038
00047 class irtkTransformation : public irtkObject
00048 {
00049
00050 protected:
00051
00053 _Status *_status;
00054
00056 irtkTransformation();
00057
00058 public:
00059
00064 static irtkTransformation *New(char *);
00065
00069 static irtkTransformation *New(irtkTransformation *);
00070
00072 virtual ~irtkTransformation();
00073
00075 virtual int NumberOfDOFs() const = 0;
00076
00078 virtual double Get(int) const = 0;
00079
00081 virtual void Put(int, double) = 0;
00082
00084 virtual void PutStatus(int, _Status);
00085
00087 virtual _Status GetStatus(int) const;
00088
00090 virtual void Transform(irtkPoint &);
00091
00093 virtual void Transform(irtkPointSet &);
00094
00096 virtual void Transform(double &, double &, double &, double = 0) = 0;
00097
00099 virtual void GlobalTransform(double &, double &, double &, double = 0) = 0;
00100
00102 virtual void LocalTransform (double &, double &, double &, double = 0) = 0;
00103
00105 virtual void GlobalDisplacement(double &, double &, double &, double = 0);
00106
00108 virtual void LocalDisplacement(double &, double &, double &, double = 0);
00109
00111 virtual double Inverse(double &, double &, double &, double = 0, double = 0.01) = 0;
00112
00114 virtual void Jacobian(irtkMatrix &, double, double, double, double = 0) = 0;
00115
00117 virtual void LocalJacobian(irtkMatrix &, double, double, double, double = 0) = 0;
00118
00120 virtual void GlobalJacobian(irtkMatrix &, double, double, double, double = 0) = 0;
00121
00123 virtual double Jacobian(double, double, double, double = 0);
00124
00126 virtual double LocalJacobian(double, double, double, double = 0);
00127
00129 virtual double GlobalJacobian(double, double, double, double = 0);
00130
00132 virtual Bool IsIdentity() = 0;
00133
00135 virtual void Read (char *);
00136
00138 virtual void Write(char *);
00139
00141 virtual void Import(char *);
00142
00144 virtual void Export(char *);
00145
00147 virtual irtkCifstream& Read(irtkCifstream&) = 0;
00148
00150 virtual irtkCofstream& Write( irtkCofstream&) = 0;
00151
00153 virtual istream& Import(istream&);
00154
00156 virtual ostream& Export(ostream&);
00157
00159 virtual void Draw ();
00160
00162 virtual void Print() = 0;
00163
00165 virtual const char *NameOfClass() = 0;
00166 };
00167
00168
00169 inline _Status irtkTransformation::GetStatus(int index) const
00170 {
00171 if (index >= this->NumberOfDOFs()) {
00172 cerr << "irtkTransformation::GetStatus: No such dof" << endl;
00173 exit(1);
00174 }
00175 return _status[index];
00176 }
00177
00178 inline void irtkTransformation::PutStatus(int index, _Status s)
00179 {
00180 if (index >= this->NumberOfDOFs()) {
00181 cerr << "irtkTransformation::PutStatus: No such dof" << endl;
00182 exit(1);
00183 }
00184 _status[index] = s;
00185 }
00186
00187 inline void irtkTransformation::Transform(irtkPoint &p)
00188 {
00189 this->Transform(p._x, p._y, p._z);
00190 }
00191
00192 inline void irtkTransformation::Transform(irtkPointSet &pset)
00193 {
00194 for (int i = 0; i < pset.Size(); i++) {
00195 irtkPoint p = pset(i);
00196 this->Transform(p._x, p._y, p._z);
00197 pset(i) = p;
00198 }
00199 }
00200
00201 inline void irtkTransformation::GlobalDisplacement(double &x, double &y, double &z, double t)
00202 {
00203 double a, b, c;
00204
00205 a = x;
00206 b = y;
00207 c = z;
00208 this->GlobalTransform(a, b, c, t);
00209 x = a - x;
00210 y = b - y;
00211 z = c - z;
00212 }
00213
00214 inline void irtkTransformation::LocalDisplacement(double &x, double &y, double &z, double t)
00215 {
00216 double a, b, c;
00217
00218 a = x;
00219 b = y;
00220 c = z;
00221 this->LocalTransform(a, b, c, t);
00222 x = a - x;
00223 y = b - y;
00224 z = c - z;
00225 }
00226
00227 inline double irtkTransformation::Jacobian(double x, double y, double z, double t)
00228 {
00229 irtkMatrix jac(3, 3);
00230
00231
00232 this->Jacobian(jac, x, y, z, t);
00233
00234
00235 return (jac(0, 0)*jac(1, 1)*jac(2, 2) + jac(0, 1)*jac(1, 2)*jac(2, 0) +
00236 jac(0, 2)*jac(1, 0)*jac(2, 1) - jac(0, 2)*jac(1, 1)*jac(2, 0) -
00237 jac(0, 0)*jac(1, 2)*jac(2, 1) - jac(0, 1)*jac(1, 0)*jac(2, 2));
00238 }
00239
00240
00241 inline double irtkTransformation::LocalJacobian(double x, double y, double z, double t)
00242 {
00243 irtkMatrix jac(3, 3);
00244
00245
00246 this->LocalJacobian(jac, x, y, z, t);
00247
00248
00249 return (jac(0, 0)*jac(1, 1)*jac(2, 2) + jac(0, 1)*jac(1, 2)*jac(2, 0) +
00250 jac(0, 2)*jac(1, 0)*jac(2, 1) - jac(0, 2)*jac(1, 1)*jac(2, 0) -
00251 jac(0, 0)*jac(1, 2)*jac(2, 1) - jac(0, 1)*jac(1, 0)*jac(2, 2));
00252 }
00253
00254 inline double irtkTransformation::GlobalJacobian(double x, double y, double z, double t)
00255 {
00256 irtkMatrix jac(3, 3);
00257
00258
00259 this->GlobalJacobian(jac, x, y, z, t);
00260
00261
00262 return (jac(0, 0)*jac(1, 1)*jac(2, 2) + jac(0, 1)*jac(1, 2)*jac(2, 0) +
00263 jac(0, 2)*jac(1, 0)*jac(2, 1) - jac(0, 2)*jac(1, 1)*jac(2, 0) -
00264 jac(0, 0)*jac(1, 2)*jac(2, 1) - jac(0, 1)*jac(1, 0)*jac(2, 2));
00265 }
00266
00267 inline void irtkTransformation::Import(char *name)
00268 {
00269 ifstream from(name);
00270
00271 if (!from) {
00272 cerr << "irtkTransformation::Import: Can't open file " << name << "\n";
00273 exit(1);
00274 }
00275
00276 this->Import(from);
00277 }
00278
00279 inline void irtkTransformation::Export(char *name)
00280 {
00281 ofstream to(name);
00282
00283 if (!to) {
00284 cerr << "irtkTransformation::Export: Can't open file " << name << "\n";
00285 exit(1);
00286 }
00287
00288 this->Export(to);
00289
00290
00291 to.close();
00292 }
00293
00294 inline istream& irtkTransformation::Import(istream &)
00295 {
00296 cerr << "irtkTransformation::Import: Cannot import transformation" << endl;
00297 exit(1);
00298 }
00299
00300 inline ostream& irtkTransformation::Export(ostream &)
00301 {
00302 cerr << "irtkTransformation::Export: Cannot export transformation" << endl;
00303 exit(1);
00304 }
00305
00306
00307 #include <irtkHomogeneousTransformation.h>
00308 #include <irtkRigidTransformation.h>
00309 #include <irtkAffineTransformation.h>
00310
00311 #include <irtkFreeFormTransformation.h>
00312 #include <irtkFreeFormTransformation3D.h>
00313 #include <irtkBSplineFreeFormTransformation3D.h>
00314 #include <irtkLinearFreeFormTransformation.h>
00315
00316 #include <irtkMultiLevelFreeFormTransformation.h>
00317
00318 #include <irtkFluidFreeFormTransformation.h>
00319 #include <irtkEigenFreeFormTransformation.h>
00320
00321 #include <irtkFreeFormTransformation4D.h>
00322 #include <irtkBSplineFreeFormTransformation4D.h>
00323
00324 #include <irtkImageTransformation.h>
00325 #include <irtkImageTransformation2.h>
00326 #include <irtkImageHomogeneousTransformation.h>
00327
00328
00329 typedef class irtkBSplineFreeFormTransformation3D irtkBSplineFreeFormTransformation;
00330
00331 #endif