Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkMatrixD.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkMatrixD_h
00012 #define __mitkMatrixD_h
00013 
00014 #include <math.h>
00015 #include "mitkGlobal.h"
00016 
00022 class MITK_COMMON_API mitkMatrixD
00023 {
00024 public:
00025     double ele[16];
00026 
00027     mitkMatrixD() {}
00028     mitkMatrixD(const mitkMatrixD &m)
00029     {
00030         ele[0] =  m.ele[0]; 
00031         ele[1] =  m.ele[1]; 
00032         ele[2] =  m.ele[2]; 
00033         ele[3] =  m.ele[3]; 
00034         ele[4] =  m.ele[4]; 
00035         ele[5] =  m.ele[5]; 
00036         ele[6] =  m.ele[6]; 
00037         ele[7] =  m.ele[7]; 
00038         ele[8] =  m.ele[8]; 
00039         ele[9] =  m.ele[9]; 
00040         ele[10] = m.ele[10];
00041         ele[11] = m.ele[11];
00042         ele[12] = m.ele[12];
00043         ele[13] = m.ele[13];
00044         ele[14] = m.ele[14];
00045         ele[15] = m.ele[15];        
00046     }
00047 
00048     mitkMatrixD(double e0, double e1, double e2, double e3,
00049                double e4, double e5, double e6, double e7,
00050                double e8, double e9, double e10, double e11,
00051                double e12, double e13, double e14, double e15)
00052     {
00053         ele[0] = e0;
00054         ele[1] = e1;
00055         ele[2] = e2;
00056         ele[3] = e3;
00057         ele[4] = e4;
00058         ele[5] = e5;
00059         ele[6] = e6;
00060         ele[7] = e7;
00061         ele[8] = e8;
00062         ele[9] = e9;
00063         ele[10] = e10;
00064         ele[11] = e11;
00065         ele[12] = e12;
00066         ele[13] = e13;
00067         ele[14] = e14;
00068         ele[15] = e15;      
00069     }   
00070 
00071     mitkMatrixD& operator = (const mitkMatrixD &m) 
00072     {
00073         ele[0] =  m.ele[0]; 
00074         ele[1] =  m.ele[1]; 
00075         ele[2] =  m.ele[2]; 
00076         ele[3] =  m.ele[3]; 
00077         ele[4] =  m.ele[4]; 
00078         ele[5] =  m.ele[5]; 
00079         ele[6] =  m.ele[6]; 
00080         ele[7] =  m.ele[7]; 
00081         ele[8] =  m.ele[8]; 
00082         ele[9] =  m.ele[9]; 
00083         ele[10] = m.ele[10];
00084         ele[11] = m.ele[11];
00085         ele[12] = m.ele[12];
00086         ele[13] = m.ele[13];
00087         ele[14] = m.ele[14];
00088         ele[15] = m.ele[15];        
00089         return *this;
00090     }
00091 
00092     friend mitkMatrixD operator * (const mitkMatrixD&, const mitkMatrixD&);
00093     friend mitkMatrixD operator + (const mitkMatrixD&, const mitkMatrixD&);
00094     friend mitkMatrixD operator - (const mitkMatrixD&, const mitkMatrixD&);
00095     friend mitkMatrixD operator + (const mitkMatrixD&);
00096     friend mitkMatrixD operator - (const mitkMatrixD&);
00097     friend mitkMatrixD operator * (const mitkMatrixD&, const double);
00098     friend mitkMatrixD operator * (const double, const mitkMatrixD&);
00099 
00100     mitkMatrixD& operator *= (const mitkMatrixD &);
00101     mitkMatrixD& operator *= (const double);
00102     mitkMatrixD& operator += (const mitkMatrixD &);
00103     mitkMatrixD& operator -= (const mitkMatrixD &);
00104 
00105     operator const double* () const { return ele; }
00106     operator double* () { return ele; }
00107 
00111     void    Transpose();    
00112     
00116     double  Inverse();      
00117 
00121     double  Determinant();  
00122 
00126     void    Adjoint();
00127 
00131     double  MinValue();     
00132 
00136     double  MaxValue();     
00137 
00141     void ZeroMatrix();
00142 
00146     void IdentityMatrix();
00147 
00151     void TranslateMatrix(const double dx, const double dy, const double dz);
00152 
00156     void ScaleMatrix(const double a, const double b, const double c);
00157 
00161     void ScaleMatrix(const double a);
00162 
00166     void RotateXMatrix(const double angle);
00167 
00171     void RotateYMatrix(const double angle);
00172 
00176     void RotateZMatrix(const double angle);
00177 
00181     void Translate(const double dx, const double dy, const double dz);
00182 
00186     void Scale(const double a, const double b, const double c);
00187 
00191     void Rotate(const double angle, const double x, const double y, const double z);
00192 
00196     void RotateX(const double angle);
00197 
00201     void RotateY(const double angle);
00202 
00206     void RotateZ(const double angle);
00207 };
00208 
00209 
00210 class MITK_COMMON_API mitkVectorD
00211 {
00212 public:
00213     double  ele[4];
00214     
00215     mitkVectorD()
00216     {
00217         ele[0] = 0.0;
00218         ele[1] = 0.0;
00219         ele[2] = 0.0;
00220         ele[3] = 1.0;
00221     }
00222     mitkVectorD(const mitkVectorD &v)
00223     {
00224         ele[0] = v.ele[0];
00225         ele[1] = v.ele[1];
00226         ele[2] = v.ele[2];
00227         ele[3] = v.ele[3];      
00228     }
00229 
00230     mitkVectorD(const double x, const double y, const double z, const double w = 1.0f)
00231     {
00232         ele[0] = x;
00233         ele[1] = y;
00234         ele[2] = z;
00235         ele[3] = w;
00236     }
00237 
00238     mitkVectorD(const double srcVector[4])
00239     {
00240         ele[0] = srcVector[0];
00241         ele[1] = srcVector[1];
00242         ele[2] = srcVector[2];
00243         ele[3] = srcVector[3];
00244     }   
00245     
00246 
00247     operator double* () { return ele; } 
00248     operator const double* () const { return ele; }
00249 
00250     mitkVectorD& operator = (const mitkVectorD &a)
00251     {
00252         ele[0] = a.ele[0];
00253         ele[1] = a.ele[1];
00254         ele[2] = a.ele[2];
00255         ele[3] = a.ele[3];
00256         return *this; 
00257     }
00258     
00259     friend mitkVectorD operator * (const mitkVectorD&, const mitkMatrixD&);
00260     friend double operator * (const mitkVectorD &, const mitkVectorD &);            // Dot Product
00261     friend mitkVectorD operator % (const mitkVectorD &, const mitkVectorD &);       // Cross Product
00262     friend mitkVectorD operator * (const mitkVectorD &, const double);
00263     friend mitkVectorD operator * (const double, const mitkVectorD &);
00264     friend mitkVectorD operator + (const mitkVectorD&);
00265     friend mitkVectorD operator + (const mitkVectorD&, const mitkVectorD&);
00266     friend mitkVectorD operator - (const mitkVectorD&);
00267     friend mitkVectorD operator - (const mitkVectorD&, const mitkVectorD&);
00268     friend mitkVectorD operator ~ (const mitkVectorD&);                         // Normalize
00269 
00270     mitkVectorD& operator *= (const mitkMatrixD &);
00271     mitkVectorD& operator *= (const double);
00272     mitkVectorD& operator += (const mitkVectorD &);
00273     mitkVectorD& operator -= (const mitkVectorD &);
00274 
00275     double Length();
00276     double Length2();
00277     void Normalize();
00278 };
00279 //----------------------------------------------------------------------------
00280 inline void mitkMatrixD::ZeroMatrix() 
00281 {
00282     ele[0] = ele[1] = ele[2] = ele[3] = 0.0f;
00283     ele[4] = ele[5] = ele[6] = ele[7] = 0.0f;
00284     ele[8] = ele[9] = ele[10] = ele[11] = 0.0f;
00285     ele[12] = ele[13] = ele[14] = ele[15] = 0.0f;
00286 }
00287 //----------------------------------------------------------------------------
00288 inline void mitkMatrixD::IdentityMatrix() 
00289 {
00290     ele[0] = ele[5] = ele[10] = ele[15] = 1.0;
00291     ele[1] = ele[2] = ele[3] = ele[4] = 0.0;
00292     ele[6] = ele[7] = ele[8] = ele[9] = 0.0;
00293     ele[11] = ele[12] = ele[13] = ele[14] = 0.0;        
00294 }
00295 //----------------------------------------------------------------------------
00296 inline mitkMatrixD operator * (const mitkMatrixD &A, const mitkMatrixD &B) 
00297 {
00298     mitkMatrixD Res;
00299     
00300     Res.ele[0]   = A.ele[0]*B.ele[0] + A.ele[4]*B.ele[1] + A.ele[8]*B.ele[2] + A.ele[12]*B.ele[3]; 
00301     Res.ele[1]   = A.ele[1]*B.ele[0] + A.ele[5]*B.ele[1] + A.ele[9]*B.ele[2] + A.ele[13]*B.ele[3]; 
00302     Res.ele[2]   = A.ele[2]*B.ele[0] + A.ele[6]*B.ele[1] + A.ele[10]*B.ele[2] + A.ele[14]*B.ele[3]; 
00303     Res.ele[3]   = A.ele[3]*B.ele[0] + A.ele[7]*B.ele[1] + A.ele[11]*B.ele[2] + A.ele[15]*B.ele[3]; 
00304 
00305     Res.ele[4]   = A.ele[0]*B.ele[4] + A.ele[4]*B.ele[5] + A.ele[8]*B.ele[6] + A.ele[12]*B.ele[7]; 
00306     Res.ele[5]   = A.ele[1]*B.ele[4] + A.ele[5]*B.ele[5] + A.ele[9]*B.ele[6] + A.ele[13]*B.ele[7]; 
00307     Res.ele[6]   = A.ele[2]*B.ele[4] + A.ele[6]*B.ele[5] + A.ele[10]*B.ele[6] + A.ele[14]*B.ele[7]; 
00308     Res.ele[7]   = A.ele[3]*B.ele[4] + A.ele[7]*B.ele[5] + A.ele[11]*B.ele[6] + A.ele[15]*B.ele[7]; 
00309 
00310     Res.ele[8]   = A.ele[0]*B.ele[8] + A.ele[4]*B.ele[9] + A.ele[8]*B.ele[10] + A.ele[12]*B.ele[11]; 
00311     Res.ele[9]   = A.ele[1]*B.ele[8] + A.ele[5]*B.ele[9] + A.ele[9]*B.ele[10] + A.ele[13]*B.ele[11]; 
00312     Res.ele[10]   = A.ele[2]*B.ele[8] + A.ele[6]*B.ele[9] + A.ele[10]*B.ele[10] + A.ele[14]*B.ele[11]; 
00313     Res.ele[11]   = A.ele[3]*B.ele[8] + A.ele[7]*B.ele[9] + A.ele[11]*B.ele[10] + A.ele[15]*B.ele[11]; 
00314 
00315     Res.ele[12]   = A.ele[0]*B.ele[12] + A.ele[4]*B.ele[13] + A.ele[8]*B.ele[14] + A.ele[12]*B.ele[15];     
00316     Res.ele[13]   = A.ele[1]*B.ele[12] + A.ele[5]*B.ele[13] + A.ele[9]*B.ele[14] + A.ele[13]*B.ele[15];     
00317     Res.ele[14]   = A.ele[2]*B.ele[12] + A.ele[6]*B.ele[13] + A.ele[10]*B.ele[14] + A.ele[14]*B.ele[15];    
00318     Res.ele[15]   = A.ele[3]*B.ele[12] + A.ele[7]*B.ele[13] + A.ele[11]*B.ele[14] + A.ele[15]*B.ele[15];        
00319     return Res;         
00320 }
00321 //----------------------------------------------------------------------------
00322 inline mitkMatrixD& mitkMatrixD::operator *= (const mitkMatrixD &B) 
00323 {
00324     mitkMatrixD Res;
00325     Res.ele[0]   = ele[0]*B.ele[0] + ele[4]*B.ele[1] + ele[8]*B.ele[2] + ele[12]*B.ele[3]; 
00326     Res.ele[1]   = ele[1]*B.ele[0] + ele[5]*B.ele[1] + ele[9]*B.ele[2] + ele[13]*B.ele[3]; 
00327     Res.ele[2]   = ele[2]*B.ele[0] + ele[6]*B.ele[1] + ele[10]*B.ele[2] + ele[14]*B.ele[3]; 
00328     Res.ele[3]   = ele[3]*B.ele[0] + ele[7]*B.ele[1] + ele[11]*B.ele[2] + ele[15]*B.ele[3]; 
00329 
00330     Res.ele[4]   = ele[0]*B.ele[4] + ele[4]*B.ele[5] + ele[8]*B.ele[6] + ele[12]*B.ele[7]; 
00331     Res.ele[5]   = ele[1]*B.ele[4] + ele[5]*B.ele[5] + ele[9]*B.ele[6] + ele[13]*B.ele[7]; 
00332     Res.ele[6]   = ele[2]*B.ele[4] + ele[6]*B.ele[5] + ele[10]*B.ele[6] + ele[14]*B.ele[7]; 
00333     Res.ele[7]   = ele[3]*B.ele[4] + ele[7]*B.ele[5] + ele[11]*B.ele[6] + ele[15]*B.ele[7]; 
00334 
00335     Res.ele[8]   = ele[0]*B.ele[8] + ele[4]*B.ele[9] + ele[8]*B.ele[10] + ele[12]*B.ele[11]; 
00336     Res.ele[9]   = ele[1]*B.ele[8] + ele[5]*B.ele[9] + ele[9]*B.ele[10] + ele[13]*B.ele[11]; 
00337     Res.ele[10]   = ele[2]*B.ele[8] + ele[6]*B.ele[9] + ele[10]*B.ele[10] + ele[14]*B.ele[11]; 
00338     Res.ele[11]   = ele[3]*B.ele[8] + ele[7]*B.ele[9] + ele[11]*B.ele[10] + ele[15]*B.ele[11]; 
00339 
00340     Res.ele[12]   = ele[0]*B.ele[12] + ele[4]*B.ele[13] + ele[8]*B.ele[14] + ele[12]*B.ele[15];     
00341     Res.ele[13]   = ele[1]*B.ele[12] + ele[5]*B.ele[13] + ele[9]*B.ele[14] + ele[13]*B.ele[15];     
00342     Res.ele[14]   = ele[2]*B.ele[12] + ele[6]*B.ele[13] + ele[10]*B.ele[14] + ele[14]*B.ele[15];    
00343     Res.ele[15]   = ele[3]*B.ele[12] + ele[7]*B.ele[13] + ele[11]*B.ele[14] + ele[15]*B.ele[15];        
00344     *this = Res;
00345     return *this;
00346 }
00347 //----------------------------------------------------------------------------
00348 inline mitkMatrixD operator * (const mitkMatrixD &A, const double s) 
00349 {
00350     mitkMatrixD Res;
00351     
00352     Res.ele[0] = A.ele[0] * s;
00353     Res.ele[1] = A.ele[1] * s;
00354     Res.ele[2] = A.ele[2] * s;
00355     Res.ele[3] = A.ele[3] * s;
00356     Res.ele[4] = A.ele[4] * s;
00357     Res.ele[5] = A.ele[5] * s;
00358     Res.ele[6] = A.ele[6] * s;
00359     Res.ele[7] = A.ele[7] * s;
00360     Res.ele[8] = A.ele[8] * s;
00361     Res.ele[9] = A.ele[9] * s;
00362     Res.ele[10] = A.ele[10] * s;
00363     Res.ele[11] = A.ele[11] * s;
00364     Res.ele[12] = A.ele[12] * s;
00365     Res.ele[13] = A.ele[13] * s;
00366     Res.ele[14] = A.ele[14] * s;
00367     Res.ele[15] = A.ele[15] * s;
00368     return Res; 
00369 }
00370 //----------------------------------------------------------------------------
00371 inline mitkMatrixD operator * (const double s, const mitkMatrixD &A) 
00372 {
00373     mitkMatrixD Res;
00374     
00375     Res.ele[0] = A.ele[0] * s;
00376     Res.ele[1] = A.ele[1] * s;
00377     Res.ele[2] = A.ele[2] * s;
00378     Res.ele[3] = A.ele[3] * s;
00379     Res.ele[4] = A.ele[4] * s;
00380     Res.ele[5] = A.ele[5] * s;
00381     Res.ele[6] = A.ele[6] * s;
00382     Res.ele[7] = A.ele[7] * s;
00383     Res.ele[8] = A.ele[8] * s;
00384     Res.ele[9] = A.ele[9] * s;
00385     Res.ele[10] = A.ele[10] * s;
00386     Res.ele[11] = A.ele[11] * s;
00387     Res.ele[12] = A.ele[12] * s;
00388     Res.ele[13] = A.ele[13] * s;
00389     Res.ele[14] = A.ele[14] * s;
00390     Res.ele[15] = A.ele[15] * s;
00391     return Res; 
00392 }
00393 //----------------------------------------------------------------------------
00394 inline mitkMatrixD& mitkMatrixD::operator *= (const double s) 
00395 {
00396     ele[0] *= s;
00397     ele[1] *= s;
00398     ele[2] *= s;
00399     ele[3] *= s;
00400     ele[4] *= s;
00401     ele[5] *= s;
00402     ele[6] *= s;
00403     ele[7] *= s;
00404     ele[8] *= s;
00405     ele[9] *= s;
00406     ele[10] *= s;
00407     ele[11] *= s;
00408     ele[12] *= s;
00409     ele[13] *= s;
00410     ele[14] *= s;
00411     ele[15] *= s;
00412     return *this;
00413 }
00414 //----------------------------------------------------------------------------
00415 inline mitkMatrixD operator + (const mitkMatrixD &A, const mitkMatrixD &B) 
00416 {
00417     mitkMatrixD Res;
00418 
00419     Res.ele[0] = A.ele[0] + B.ele[0];
00420     Res.ele[1] = A.ele[1] + B.ele[1];
00421     Res.ele[2] = A.ele[2] + B.ele[2];
00422     Res.ele[3] = A.ele[3] + B.ele[3];
00423     Res.ele[4] = A.ele[4] + B.ele[4];
00424     Res.ele[5] = A.ele[5] + B.ele[5];
00425     Res.ele[6] = A.ele[6] + B.ele[6];
00426     Res.ele[7] = A.ele[7] + B.ele[7];   
00427     Res.ele[8] = A.ele[8] + B.ele[8];
00428     Res.ele[9] = A.ele[9] + B.ele[9];
00429     Res.ele[10] = A.ele[10] + B.ele[10];
00430     Res.ele[11] = A.ele[11] + B.ele[11];
00431     Res.ele[12] = A.ele[12] + B.ele[12];
00432     Res.ele[13] = A.ele[13] + B.ele[13];
00433     Res.ele[14] = A.ele[14] + B.ele[14];
00434     Res.ele[15] = A.ele[15] + B.ele[15];
00435     return Res;
00436 }
00437 //----------------------------------------------------------------------------
00438 inline mitkMatrixD & mitkMatrixD::operator += (const mitkMatrixD &B) 
00439 {
00440     ele[0] += B.ele[0];
00441     ele[1] += B.ele[1];
00442     ele[2] += B.ele[2];
00443     ele[3] += B.ele[3];
00444     ele[4] += B.ele[4];
00445     ele[5] += B.ele[5];
00446     ele[6] += B.ele[6];
00447     ele[7] += B.ele[7];
00448     ele[8] += B.ele[8];
00449     ele[9] += B.ele[9];
00450     ele[10] += B.ele[10];
00451     ele[11] += B.ele[11];
00452     ele[12] += B.ele[12];
00453     ele[13] += B.ele[13];
00454     ele[14] += B.ele[14];
00455     ele[15] += B.ele[15];
00456     return *this;
00457 }
00458 //----------------------------------------------------------------------------
00459 inline mitkMatrixD operator - (const mitkMatrixD &A, const mitkMatrixD &B) 
00460 {
00461     mitkMatrixD Res;
00462 
00463     Res.ele[0] = A.ele[0] - B.ele[0];
00464     Res.ele[1] = A.ele[1] - B.ele[1];
00465     Res.ele[2] = A.ele[2] - B.ele[2];
00466     Res.ele[3] = A.ele[3] - B.ele[3];
00467     Res.ele[4] = A.ele[4] - B.ele[4];
00468     Res.ele[5] = A.ele[5] - B.ele[5];
00469     Res.ele[6] = A.ele[6] - B.ele[6];
00470     Res.ele[7] = A.ele[7] - B.ele[7];   
00471     Res.ele[8] = A.ele[8] - B.ele[8];
00472     Res.ele[9] = A.ele[9] - B.ele[9];
00473     Res.ele[10] = A.ele[10] - B.ele[10];
00474     Res.ele[11] = A.ele[11] - B.ele[11];
00475     Res.ele[12] = A.ele[12] - B.ele[12];
00476     Res.ele[13] = A.ele[13] - B.ele[13];
00477     Res.ele[14] = A.ele[14] - B.ele[14];
00478     Res.ele[15] = A.ele[15] - B.ele[15];
00479     return Res;
00480 }
00481 //----------------------------------------------------------------------------
00482 inline mitkMatrixD operator - (const mitkMatrixD &A)
00483 {
00484     mitkMatrixD Res;
00485 
00486     Res.ele[0] = - A.ele[0];
00487     Res.ele[1] = - A.ele[1];
00488     Res.ele[2] = - A.ele[2];
00489     Res.ele[3] = - A.ele[3];
00490     Res.ele[4] = - A.ele[4];
00491     Res.ele[5] = - A.ele[5];
00492     Res.ele[6] = - A.ele[6];
00493     Res.ele[7] = - A.ele[7];    
00494     Res.ele[8] = - A.ele[8];
00495     Res.ele[9] = - A.ele[9];
00496     Res.ele[10] = - A.ele[10];
00497     Res.ele[11] = - A.ele[11];
00498     Res.ele[12] = - A.ele[12];
00499     Res.ele[13] = - A.ele[13];
00500     Res.ele[14] = - A.ele[14];
00501     Res.ele[15] = - A.ele[15];
00502     return Res;
00503 }
00504 //----------------------------------------------------------------------------
00505 inline mitkMatrixD & mitkMatrixD::operator -= (const mitkMatrixD &B) 
00506 {
00507     ele[0] -= B.ele[0];
00508     ele[1] -= B.ele[1];
00509     ele[2] -= B.ele[2];
00510     ele[3] -= B.ele[3];
00511     ele[4] -= B.ele[4];
00512     ele[5] -= B.ele[5];
00513     ele[6] -= B.ele[6];
00514     ele[7] -= B.ele[7];
00515     ele[8] -= B.ele[8];
00516     ele[9] -= B.ele[9];
00517     ele[10] -= B.ele[10];
00518     ele[11] -= B.ele[11];
00519     ele[12] -= B.ele[12];
00520     ele[13] -= B.ele[13];
00521     ele[14] -= B.ele[14];
00522     ele[15] -= B.ele[15];
00523     return *this;
00524 }
00525 //----------------------------------------------------------------------------
00526 inline mitkVectorD operator * (const mitkVectorD& Vec, const mitkMatrixD& Mat) 
00527 {
00528     mitkVectorD Res;
00529     Res.ele[0] = Mat.ele[0]*Vec.ele[0] + Mat.ele[1]*Vec.ele[1] + Mat.ele[2]*Vec.ele[2] + Mat.ele[3]*Vec.ele[3]; 
00530     Res.ele[1] = Mat.ele[4]*Vec.ele[0] + Mat.ele[5]*Vec.ele[1] + Mat.ele[6]*Vec.ele[2] + Mat.ele[7]*Vec.ele[3]; 
00531     Res.ele[2] = Mat.ele[8]*Vec.ele[0] + Mat.ele[9]*Vec.ele[1] + Mat.ele[10]*Vec.ele[2] + Mat.ele[11]*Vec.ele[3]; 
00532     Res.ele[3] = Mat.ele[12]*Vec.ele[0] + Mat.ele[13]*Vec.ele[1] + Mat.ele[14]*Vec.ele[2] + Mat.ele[15]*Vec.ele[3]; 
00533     return Res;     
00534 }
00535 //----------------------------------------------------------------------------
00536 inline mitkVectorD operator * (const mitkMatrixD& Mat, mitkVectorD& Vec) 
00537 {
00538     mitkVectorD Res;
00539     Res.ele[0] = Mat.ele[0]*Vec.ele[0] + Mat.ele[4]*Vec.ele[1] + Mat.ele[8]*Vec.ele[2] + Mat.ele[12]*Vec.ele[3]; 
00540     Res.ele[1] = Mat.ele[1]*Vec.ele[0] + Mat.ele[5]*Vec.ele[1] + Mat.ele[9]*Vec.ele[2] + Mat.ele[13]*Vec.ele[3]; 
00541     Res.ele[2] = Mat.ele[2]*Vec.ele[0] + Mat.ele[6]*Vec.ele[1] + Mat.ele[10]*Vec.ele[2] + Mat.ele[14]*Vec.ele[3]; 
00542     Res.ele[3] = Mat.ele[3]*Vec.ele[0] + Mat.ele[7]*Vec.ele[1] + Mat.ele[11]*Vec.ele[2] + Mat.ele[15]*Vec.ele[3]; 
00543     return Res;     
00544 }
00545 //----------------------------------------------------------------------------
00546 inline mitkVectorD& mitkVectorD::operator *= (const mitkMatrixD& Mat) 
00547 {
00548     double temp[4];
00549     temp[0] = Mat.ele[0]*ele[0] + Mat.ele[4]*ele[1] + Mat.ele[8]*ele[2] + Mat.ele[12]*ele[3]; 
00550     temp[1] = Mat.ele[1]*ele[0] + Mat.ele[5]*ele[1] + Mat.ele[9]*ele[2] + Mat.ele[13]*ele[3]; 
00551     temp[2] = Mat.ele[2]*ele[0] + Mat.ele[6]*ele[1] + Mat.ele[10]*ele[2] + Mat.ele[14]*ele[3]; 
00552     temp[3] = Mat.ele[3]*ele[0] + Mat.ele[7]*ele[1] + Mat.ele[11]*ele[2] + Mat.ele[15]*ele[3]; 
00553     ele[0] = temp[0];
00554     ele[1] = temp[1];
00555     ele[2] = temp[2];
00556     ele[3] = temp[3];   
00557     return *this;
00558 }
00559 //----------------------------------------------------------------------------
00560 inline double operator * (const mitkVectorD& A, const mitkVectorD& B) 
00561 {
00562     return A.ele[0]*B.ele[0] + A.ele[1]*B.ele[1] + A.ele[2]*B.ele[2];   
00563 }
00564 //----------------------------------------------------------------------------
00565 inline mitkVectorD operator % (const mitkVectorD& A, const mitkVectorD& B) 
00566 {
00567     mitkVectorD Res;
00568     Res.ele[0] = A.ele[1] * B.ele[2] - A.ele[2] * B.ele[1]; 
00569     Res.ele[1] = A.ele[2] * B.ele[0] - A.ele[0] * B.ele[2]; 
00570     Res.ele[2] = A.ele[0] * B.ele[1] - A.ele[1] * B.ele[0]; 
00571     Res.ele[3] = 0.0f;
00572     return Res;
00573 }
00574 //----------------------------------------------------------------------------
00575 inline mitkVectorD operator * (const mitkVectorD &V, const double s) 
00576 {
00577     mitkVectorD Res;
00578     Res.ele[0] = V.ele[0] * s;
00579     Res.ele[1] = V.ele[1] * s;
00580     Res.ele[2] = V.ele[2] * s;
00581     Res.ele[3] = V.ele[3] * s;  
00582     return Res;
00583 }
00584 //----------------------------------------------------------------------------
00585 inline mitkVectorD operator * (const double s, const mitkVectorD &V) 
00586 {
00587     mitkVectorD Res;
00588     Res.ele[0] = V.ele[0] * s;
00589     Res.ele[1] = V.ele[1] * s;
00590     Res.ele[2] = V.ele[2] * s;
00591     Res.ele[3] = V.ele[3] * s;  
00592     return Res;
00593 }
00594 //----------------------------------------------------------------------------
00595 inline mitkVectorD& mitkVectorD::operator *= (const double s) 
00596 {
00597     ele[0] *= s;
00598     ele[1] *= s;
00599     ele[2] *= s;
00600     ele[3] *= s;    
00601     return *this;
00602 }
00603 //----------------------------------------------------------------------------
00604 inline mitkVectorD operator + (const mitkVectorD& A, const mitkVectorD& B) 
00605 {
00606     mitkVectorD Res;
00607     Res.ele[0] = A.ele[0] + B.ele[0];
00608     Res.ele[1] = A.ele[1] + B.ele[1];
00609     Res.ele[2] = A.ele[2] + B.ele[2];
00610     Res.ele[3] = A.ele[3] + B.ele[3];
00611     return Res;
00612 }
00613 //----------------------------------------------------------------------------
00614 inline mitkVectorD operator - (const mitkVectorD& A, const mitkVectorD& B) 
00615 {
00616     mitkVectorD Res;
00617     Res.ele[0] = A.ele[0] - B.ele[0];
00618     Res.ele[1] = A.ele[1] - B.ele[1];
00619     Res.ele[2] = A.ele[2] - B.ele[2];
00620     Res.ele[3] = A.ele[3] - B.ele[3];
00621     return Res;
00622 }
00623 //----------------------------------------------------------------------------
00624 inline mitkVectorD operator - (const mitkVectorD& A)
00625 {
00626     mitkVectorD Res;
00627     Res.ele[0] = - A.ele[0];
00628     Res.ele[1] = - A.ele[1];
00629     Res.ele[2] = - A.ele[2];
00630     Res.ele[3] = - A.ele[3];
00631     return Res;
00632 }
00633 //----------------------------------------------------------------------------
00634 inline mitkVectorD & mitkVectorD::operator += (const mitkVectorD &B) 
00635 {
00636     ele[0] += B.ele[0];
00637     ele[1] += B.ele[1];
00638     ele[2] += B.ele[2];
00639     ele[3] += B.ele[3];
00640     return *this;
00641 }
00642 //----------------------------------------------------------------------------
00643 inline mitkVectorD & mitkVectorD::operator -= (const mitkVectorD &B) 
00644 {
00645     ele[0] -= B.ele[0];
00646     ele[1] -= B.ele[1];
00647     ele[2] -= B.ele[2];
00648     ele[3] -= B.ele[3];
00649     return *this;
00650 }
00651 //----------------------------------------------------------------------------
00652 inline double mitkVectorD::Length()
00653 {
00654     return sqrt(ele[0]*ele[0] + ele[1]*ele[1] + ele[2]*ele[2]);
00655 }
00656 //----------------------------------------------------------------------------
00657 inline double mitkVectorD::Length2()
00658 {
00659     return (ele[0]*ele[0] + ele[1]*ele[1] + ele[2]*ele[2]);
00660 }
00661 //----------------------------------------------------------------------------
00662 inline void mitkVectorD::Normalize() 
00663 {
00664     double vecLenInv = 1.0 / sqrt(ele[0]*ele[0] + ele[1]*ele[1] + ele[2]*ele[2]);
00665     ele[0] *= vecLenInv;
00666     ele[1] *= vecLenInv;
00667     ele[2] *= vecLenInv;
00668 }
00669 
00670    
00671 #endif
00672 

Generated on Tue Feb 25 15:00:37 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3