/vol/vipdata/irtk/contrib++/include/irtkPoint4D.h

00001 /*=========================================================================
00002 
00003   Library   : Image Registration Toolkit (IRTK)
00004   Module    : $Id: irtkPoint4D.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 _IRTKPOINT_4D
00014 
00015 #define _IRTKPOINT_4D
00016 
00023 class irtkPoint4D : public irtkObject
00024 {
00025 
00026 public:
00027 
00029   double _x;
00030 
00032   double _y;
00033 
00035   double _z;
00036 
00038   double _t;
00039 
00040   //
00041   // Constructors and destructor
00042   //
00043 
00045   irtkPoint4D();
00046 
00048   irtkPoint4D(double, double, double,double);
00049 
00051   irtkPoint4D(const irtkPoint4D &);
00052 
00054   irtkPoint4D(const irtkVector&);
00055 
00057   virtual ~irtkPoint4D(void);
00058 
00059   //
00060   // Operators for Point
00061   //
00062 
00064   irtkPoint4D& operator =(const irtkPoint4D&);
00065 
00067   irtkPoint4D& operator-=(const irtkPoint4D&);
00068 
00070   irtkPoint4D& operator+=(const irtkPoint4D&);
00071 
00073   irtkPoint4D& operator*=(const irtkPoint4D&);
00074 
00076   irtkPoint4D& operator/=(const irtkPoint4D&);
00077 
00079   irtkPoint4D  operator- (const irtkPoint4D&);
00080 
00082   irtkPoint4D  operator+ (const irtkPoint4D&);
00083 
00085   irtkPoint4D  operator* (const irtkPoint4D&);
00086 
00088   irtkPoint4D  operator/ (const irtkPoint4D&);
00089 
00090   //
00091   // Operators for comparison
00092   //
00093 
00095   int    operator==(const irtkPoint4D&);
00096 
00098   int    operator!=(const irtkPoint4D&);
00099 
00101   int    operator<(const irtkPoint4D&);
00102 
00103   //
00104   // Operators for double
00105   //
00106 
00108   irtkPoint4D& operator-=(double);
00109 
00111   irtkPoint4D& operator+=(double);
00112 
00114   irtkPoint4D& operator*=(double);
00115 
00117   irtkPoint4D& operator/=(double);
00118 
00119   // Return result of substraction of double
00120   irtkPoint4D  operator- (double);
00121 
00122   // Return result of addition of double
00123   irtkPoint4D  operator+ (double);
00124 
00125   // Return result of multiplication with double
00126   irtkPoint4D  operator* (double);
00127 
00128   // Return result of division by double
00129   irtkPoint4D  operator/ (double);
00130 
00131   //
00132   // Operators for Vector
00133   //
00134 
00136   irtkPoint4D& operator =(const irtkVector&);
00137 
00139   irtkPoint4D& operator-=(const irtkVector&);
00140 
00142   irtkPoint4D& operator+=(const irtkVector&);
00143 
00145   irtkPoint4D& operator*=(const irtkVector&);
00146 
00148   irtkPoint4D& operator/=(const irtkVector&);
00149 
00150   // Return result of vector substraction
00151   irtkPoint4D  operator- (const irtkVector&);
00152 
00153   // Return result of vector addition
00154   irtkPoint4D  operator+ (const irtkVector&);
00155 
00156   // Return result of vector multiplication
00157   irtkPoint4D  operator* (const irtkVector&);
00158 
00159   // Return result of vector division
00160   irtkPoint4D  operator/ (const irtkVector&);
00161 
00162   //
00163   // Operators for Matrix
00164   //
00165 
00167   irtkPoint4D& operator*=(const irtkMatrix&);
00168 
00170   irtkPoint4D  operator* (const irtkMatrix&);
00171 
00172   //
00173   // Distance methods
00174   //
00175 
00177   double  Distance(void) const;
00178 
00180   double  Distance(const irtkPoint4D&) const;
00181 
00182   //
00183   // I/O methods
00184   //
00185 
00186   // Interface to output stream
00187   friend ostream& operator<< (ostream&, const irtkPoint4D&);
00188 
00190   friend istream& operator>> (istream&, irtkPoint4D&);
00191 };
00192 
00193 inline irtkPoint4D::irtkPoint4D()
00194 {
00195   _x = 0;
00196   _y = 0;
00197   _z = 0;
00198   _t = 0;
00199 }
00200 
00201 inline irtkPoint4D::irtkPoint4D(double x, double y, double z,double t)
00202 {
00203   _x = x;
00204   _y = y;
00205   _z = z;
00206   _t = t;
00207 }
00208 
00209 inline irtkPoint4D::irtkPoint4D(const irtkPoint4D& p)
00210 {
00211   _x = p._x;
00212   _y = p._y;
00213   _z = p._z;
00214   _t = p._t;
00215 }
00216 
00217 inline irtkPoint4D::irtkPoint4D(const irtkVector& v)
00218 {
00219   if ((v.Rows() < 0) || (v.Rows() > 4)) {
00220     cerr << "irtkPoint4D::irtkPoint4D(const irtkVector&) Illegal dimension: " << v.Rows() << endl;
00221     exit(1);
00222   } else {
00223     if (v.Rows() == 1) {
00224       _x = v(0);
00225       _y = 0;
00226       _z = 0;
00227       _t = 0;
00228     }
00229     if (v.Rows() == 2) {
00230       _x = v(0);
00231       _y = v(1);
00232       _z = 0;
00233       _t = 0;
00234     }
00235     if (v.Rows() == 3) {
00236       _x = v(0);
00237       _y = v(1);
00238       _z = v(2);
00239       _t = 0;
00240     }
00241     if (v.Rows() == 4) {
00242       _x = v(0);
00243       _y = v(1);
00244       _z = v(2);
00245       _t = v(4);
00246     }
00247   }
00248 }
00249 
00250 inline irtkPoint4D::~irtkPoint4D()
00251 {
00252 }
00253 
00254 inline irtkPoint4D& irtkPoint4D::operator =(const irtkPoint4D& p)
00255 {
00256   _x = p._x;
00257   _y = p._y;
00258   _z = p._z;
00259   _t = p._t;
00260   return *this;
00261 }
00262 
00263 inline irtkPoint4D& irtkPoint4D::operator+=(const irtkPoint4D& p)
00264 {
00265   _x += p._x;
00266   _y += p._y;
00267   _z += p._z;
00268   _t += p._t;
00269   return *this;
00270 }
00271 
00272 inline irtkPoint4D& irtkPoint4D::operator-=(const irtkPoint4D& p)
00273 {
00274   _x -= p._x;
00275   _y -= p._y;
00276   _z -= p._z;
00277   _t -= p._t;
00278   return *this;
00279 }
00280 
00281 inline irtkPoint4D& irtkPoint4D::operator*=(const irtkPoint4D& p)
00282 {
00283   _x *= p._x;
00284   _y *= p._y;
00285   _z *= p._z;
00286   _t *= p._t;
00287   return *this;
00288 }
00289 
00290 inline irtkPoint4D& irtkPoint4D::operator/=(const irtkPoint4D& p)
00291 {
00292   _x /= p._x;
00293   _y /= p._y;
00294   _z /= p._z;
00295   _t /= p._t;
00296   return *this;
00297 }
00298 
00299 inline irtkPoint4D irtkPoint4D::operator+ (const irtkPoint4D& p)
00300 {
00301   irtkPoint4D tmp;
00302 
00303   tmp._x = _x + p._x;
00304   tmp._y = _y + p._y;
00305   tmp._z = _z + p._z;
00306   tmp._t = _t + p._t;
00307   return tmp;
00308 }
00309 
00310 inline irtkPoint4D irtkPoint4D::operator- (const irtkPoint4D& p)
00311 {
00312   irtkPoint4D tmp;
00313 
00314   tmp._x = _x - p._x;
00315   tmp._y = _y - p._y;
00316   tmp._z = _z - p._z;
00317   tmp._t = _t - p._t;
00318   return tmp;
00319 }
00320 
00321 inline irtkPoint4D irtkPoint4D::operator* (const irtkPoint4D& p)
00322 {
00323   irtkPoint4D tmp;
00324 
00325   tmp._x = _x * p._x;
00326   tmp._y = _y * p._y;
00327   tmp._z = _z * p._z;
00328   tmp._t = _t * p._t;
00329   return tmp;
00330 }
00331 
00332 inline irtkPoint4D irtkPoint4D::operator/ (const irtkPoint4D& p)
00333 {
00334   irtkPoint4D tmp;
00335 
00336   tmp._x = _x / p._x;
00337   tmp._y = _y / p._y;
00338   tmp._z = _z / p._z;
00339   tmp._t = _t / p._t;
00340   return tmp;
00341 }
00342 
00343 inline int irtkPoint4D::operator==(irtkPoint4D const &p)
00344 {
00345   return ((_x == p._x) && (_y == p._y) && (_z == p._z) && (_t==p._t) );
00346 }
00347 
00348 inline int irtkPoint4D::operator!=(irtkPoint4D const &p)
00349 {
00350   return ((_x != p._x) || (_y != p._y) || (_z != p._z) || (_t!=p._t) );
00351 }
00352 
00353 inline irtkPoint4D& irtkPoint4D::operator+=(double x)
00354 {
00355   _x += x;
00356   _y += x;
00357   _z += x;
00358   _t += x;
00359   return *this;
00360 }
00361 
00362 inline irtkPoint4D& irtkPoint4D::operator-=(double x)
00363 {
00364   _x -= x;
00365   _y -= x;
00366   _z -= x;
00367   _t -= x;
00368   return *this;
00369 }
00370 
00371 inline irtkPoint4D& irtkPoint4D::operator/=(double x)
00372 {
00373   _x /= x;
00374   _y /= x;
00375   _z /= x;
00376   _t /= x;
00377   return *this;
00378 }
00379 
00380 inline irtkPoint4D& irtkPoint4D::operator*=(double x)
00381 {
00382   _x *= x;
00383   _y *= x;
00384   _z *= x;
00385   _t *= x;
00386   return *this;
00387 }
00388 
00389 inline irtkPoint4D irtkPoint4D::operator+ (double x)
00390 {
00391   irtkPoint4D p;
00392 
00393   p._x = _x + x;
00394   p._y = _y + x;
00395   p._z = _z + x;
00396   p._t = _t + x;
00397   return p;
00398 }
00399 
00400 inline irtkPoint4D irtkPoint4D::operator- (double x)
00401 {
00402   irtkPoint4D p;
00403 
00404   p._x = _x - x;
00405   p._y = _y - x;
00406   p._z = _z - x;
00407   p._t = _t - x;
00408   return p;
00409 }
00410 
00411 inline irtkPoint4D irtkPoint4D::operator* (double x)
00412 {
00413   irtkPoint4D p;
00414 
00415   p._x = _x * x;
00416   p._y = _y * x;
00417   p._z = _z * x;
00418   p._t = _t * x;
00419   return p;
00420 }
00421 
00422 inline irtkPoint4D irtkPoint4D::operator/ (double x)
00423 {
00424   irtkPoint4D p;
00425 
00426   p._x = _x / x;
00427   p._y = _y / x;
00428   p._z = _z / x;
00429   p._t = _t / x;
00430   return p;
00431 }
00432 
00433 inline irtkPoint4D& irtkPoint4D::operator+=(const irtkVector& v)
00434 {
00435   if (v.Rows() != 4) {
00436     cerr << "irtkPoint4D::operator+=(const irtkVector& v): Size mismatch" << endl;
00437     exit(1);
00438   }
00439   _x += v(0);
00440   _y += v(1);
00441   _z += v(2);
00442   _t += v(3);
00443   return *this;
00444 }
00445 
00446 inline irtkPoint4D& irtkPoint4D::operator-=(const irtkVector& v)
00447 {
00448   if (v.Rows() != 4) {
00449     cerr << "irtkPoint4D::operator-=(const irtkVector& v): Size mismatch" << endl;
00450     exit(1);
00451   }
00452   _x -= v(0);
00453   _y -= v(1);
00454   _z -= v(2);
00455   _t -= v(3);
00456   return *this;
00457 }
00458 
00459 inline irtkPoint4D& irtkPoint4D::operator*=(const irtkVector& v)
00460 {
00461   if (v.Rows() != 4) {
00462     cerr << "irtkPoint4D::operator*=(const irtkVector& v): Size mismatch" << endl;
00463     exit(1);
00464   }
00465   _x *= v(0);
00466   _y *= v(1);
00467   _z *= v(2);
00468   _t *= v(3);
00469   return *this;
00470 }
00471 
00472 inline irtkPoint4D& irtkPoint4D::operator/=(const irtkVector& v)
00473 {
00474   if (v.Rows() != 4) {
00475     cerr << "irtkPoint4D::operator/=(const irtkVector& v): Size mismatch" << endl;
00476     exit(1);
00477   }
00478   _x /= v(0);
00479   _y /= v(1);
00480   _z /= v(2);
00481   _t /= v(3);
00482   return *this;
00483 }
00484 
00485 inline irtkPoint4D irtkPoint4D::operator+ (const irtkVector& v)
00486 {
00487   irtkPoint4D tmp;
00488 
00489   if (v.Rows() != 4) {
00490     cerr << "irtkPoint4D::operator+(const irtkVector& v): Size mismatch" << endl;
00491     exit(1);
00492   }
00493   tmp._x = _x + v(0);
00494   tmp._y = _y + v(1);
00495   tmp._z = _z + v(2);
00496   tmp._t = _t + v(3);
00497   return tmp;
00498 }
00499 
00500 inline irtkPoint4D irtkPoint4D::operator- (const irtkVector& v)
00501 {
00502   irtkPoint4D tmp;
00503 
00504   if (v.Rows() != 4) {
00505     cerr << "irtkPoint4D::operator-(const irtkVector& v): Size mismatch" << endl;
00506     exit(1);
00507   }
00508   tmp._x = _x - v(0);
00509   tmp._y = _y - v(1);
00510   tmp._z = _z - v(2);
00511   tmp._t = _t - v(3);
00512   return tmp;
00513 }
00514 
00515 inline irtkPoint4D irtkPoint4D::operator* (const irtkVector& v)
00516 {
00517   irtkPoint4D tmp;
00518 
00519   if (v.Rows() != 4) {
00520     cerr << "irtkPoint4D::operator*(const irtkVector& v): Size mismatch" << endl;
00521     exit(1);
00522   }
00523   tmp._x = _x * v(0);
00524   tmp._y = _y * v(1);
00525   tmp._z = _z * v(2);
00526   tmp._t = _t * v(3);
00527   return tmp;
00528 }
00529 
00530 inline irtkPoint4D irtkPoint4D::operator/ (const irtkVector& v)
00531 {
00532   irtkPoint4D tmp;
00533 
00534   if (v.Rows() != 4) {
00535     cerr << "irtkPoint4D::operator/(const irtkVector& v): Size mismatch" << endl;
00536     exit(1);
00537   }
00538   tmp._x = _x / v(0);
00539   tmp._y = _y / v(1);
00540   tmp._z = _z / v(2);
00541   tmp._t = _t / v(3);
00542   return tmp;
00543 }
00544 
00545 inline irtkPoint4D irtkPoint4D::operator* (const irtkMatrix& m)
00546 {
00547   irtkPoint4D tmp;
00548 
00549   if ((m.Rows() != 5) && (m.Cols() != 5)) {
00550     cerr << "irtkPoint4D::operator*(const irtkMatrix& m): Size mismatch" << endl;
00551     exit(1);
00552   }
00553   tmp._x = _x * m(0, 0) + _y * m(0, 1) + _z * m(0, 2) + _t * m(0, 3) + m(0,4);
00554   tmp._y = _x * m(1, 0) + _y * m(1, 1) + _z * m(1, 2) + _t * m(1, 3) + m(1,4);
00555   tmp._z = _x * m(2, 0) + _y * m(2, 1) + _z * m(2, 2) + _t * m(2, 3) + m(2,4);
00556   tmp._t = _x * m(3, 0) + _y * m(3, 1) + _z * m(3, 2) + _t * m(3, 3) + m(3,4);
00557 
00558   return tmp;
00559 }
00560 
00561 inline irtkPoint4D& irtkPoint4D::operator*=(const irtkMatrix& m)
00562 {
00563   irtkPoint4D tmp;
00564 
00565   if ((m.Rows() != 4) && (m.Cols() != 4)) {
00566     cerr << "irtkPoint4D::operator*(const irtkMatrix& m): Size mismatch" << endl;
00567     exit(1);
00568   }
00569   tmp._x = _x * m(0, 0) + _y * m(0, 1) + _z * m(0, 2) + _t * m(0, 3) + m(0,4);
00570   tmp._y = _x * m(1, 0) + _y * m(1, 1) + _z * m(1, 2) + _t * m(1, 3) + m(1,4);
00571   tmp._z = _x * m(2, 0) + _y * m(2, 1) + _z * m(2, 2) + _t * m(2, 3) + m(2,4);
00572   tmp._t = _x * m(3, 0) + _y * m(3, 1) + _z * m(3, 2) + _t * m(3, 3) + m(3,4);
00573   *this  = tmp;
00574 
00575   return *this;
00576 }
00577 
00578 inline double irtkPoint4D::Distance(void) const
00579 {
00580   return sqrt(_x*_x + _y*_y  + _z *_z + _t*_t);
00581 }
00582 
00583 inline double irtkPoint4D::Distance(const irtkPoint4D &p) const
00584 {
00585   return sqrt((_x - p._x)*(_x - p._x) + (_y - p._y)*(_y - p._y) +
00586               (_z - p._z)*(_z - p._z) + (_t - p._t)*(_t - p._t));
00587 }
00588 
00589 #endif