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

mitkVis2Matrix4x4.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 #ifndef _mitkVis2Matrix4x4_h
00011 #define _mitkVis2Matrix4x4_h
00012 
00013 #include "mitkVis2Vector4.h"
00014 
00015 class MITK_VISUALIZATION2_API mitkVis2Matrix4x4
00016 {
00017 public:
00018     float ele[16];
00019 
00020     mitkVis2Matrix4x4();
00021     mitkVis2Matrix4x4(const mitkVis2Matrix4x4 &m);
00022     mitkVis2Matrix4x4(float e0, float e1, float e2, float e3,
00023                float e4, float e5, float e6, float e7,
00024                float e8, float e9, float e10, float e11,
00025                float e12, float e13, float e14, float e15);
00026     
00027     mitkVis2Matrix4x4& operator = (const mitkVis2Matrix4x4 &m) 
00028     {
00029         ele[0] =  m.ele[0]; 
00030         ele[1] =  m.ele[1]; 
00031         ele[2] =  m.ele[2]; 
00032         ele[3] =  m.ele[3]; 
00033         ele[4] =  m.ele[4]; 
00034         ele[5] =  m.ele[5]; 
00035         ele[6] =  m.ele[6]; 
00036         ele[7] =  m.ele[7]; 
00037         ele[8] =  m.ele[8]; 
00038         ele[9] =  m.ele[9]; 
00039         ele[10] = m.ele[10];
00040         ele[11] = m.ele[11];
00041         ele[12] = m.ele[12];
00042         ele[13] = m.ele[13];
00043         ele[14] = m.ele[14];
00044         ele[15] = m.ele[15];
00045         return *this;
00046     }
00047 
00048     mitkVis2Matrix4x4& operator *= (const mitkVis2Matrix4x4 &);
00049     mitkVis2Matrix4x4& operator *= (float);
00050     mitkVis2Matrix4x4& operator += (const mitkVis2Matrix4x4 &);
00051     mitkVis2Matrix4x4& operator -= (const mitkVis2Matrix4x4 &);
00052 
00053     operator const float* () const { return ele; }  
00054     operator float* () { return ele; }
00055 
00056     void IdentityMatrix();
00057 
00058     void Transpose();   
00059     float Inverse();    
00060 
00061     static mitkVis2Matrix4x4 TranslateMatrix(float tx,float ty,float tz);
00062     static mitkVis2Matrix4x4 ScaleMatrix(float sx,float sy,float sz);
00063     static mitkVis2Matrix4x4 RotateMatrix(float angle,float x,float y,float z);
00064 
00065 };
00066 
00067 inline void mitkVis2Matrix4x4::IdentityMatrix() 
00068 {
00069     ele[0] = ele[5] = ele[10] = ele[15] = 1.0f;
00070     ele[1] = ele[2] = ele[3] = ele[4] = 0.0f;
00071     ele[6] = ele[7] = ele[8] = ele[9] = 0.0f;
00072     ele[11] = ele[12] = ele[13] = ele[14] = 0.0f;
00073 }
00074 //----------------------------------------------------------------------------
00075 inline mitkVis2Matrix4x4 operator * (const mitkVis2Matrix4x4 &A, const mitkVis2Matrix4x4 &B) 
00076 {
00077     mitkVis2Matrix4x4 Res;
00078 
00079     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]; 
00080     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]; 
00081     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]; 
00082     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]; 
00083 
00084     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]; 
00085     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]; 
00086     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]; 
00087     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]; 
00088 
00089     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]; 
00090     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]; 
00091     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]; 
00092     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]; 
00093 
00094     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];     
00095     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];     
00096     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];    
00097     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];        
00098     return Res; 
00099 
00100 }
00101 //----------------------------------------------------------------------------
00102 inline mitkVis2Matrix4x4& mitkVis2Matrix4x4::operator *= (const mitkVis2Matrix4x4 &B) 
00103 {
00104     *this=(*this)*B;
00105     return *this;
00106 }
00107 //----------------------------------------------------------------------------
00108 inline mitkVis2Matrix4x4 operator * (const mitkVis2Matrix4x4 &A, float s) 
00109 {
00110     mitkVis2Matrix4x4 Res;
00111     Res.ele[0] = A.ele[0] * s;
00112     Res.ele[1] = A.ele[1] * s;
00113     Res.ele[2] = A.ele[2] * s;
00114     Res.ele[3] = A.ele[3] * s;
00115     Res.ele[4] = A.ele[4] * s;
00116     Res.ele[5] = A.ele[5] * s;
00117     Res.ele[6] = A.ele[6] * s;
00118     Res.ele[7] = A.ele[7] * s;
00119     Res.ele[8] = A.ele[8] * s;
00120     Res.ele[9] = A.ele[9] * s;
00121     Res.ele[10] = A.ele[10] * s;
00122     Res.ele[11] = A.ele[11] * s;
00123     Res.ele[12] = A.ele[12] * s;
00124     Res.ele[13] = A.ele[13] * s;
00125     Res.ele[14] = A.ele[14] * s;
00126     Res.ele[15] = A.ele[15] * s;
00127     return Res; 
00128 }
00129 //----------------------------------------------------------------------------
00130 inline mitkVis2Matrix4x4 operator * (float s, const mitkVis2Matrix4x4 &A) 
00131 {
00132     mitkVis2Matrix4x4 Res;
00133     Res.ele[0] = A.ele[0] * s;
00134     Res.ele[1] = A.ele[1] * s;
00135     Res.ele[2] = A.ele[2] * s;
00136     Res.ele[3] = A.ele[3] * s;
00137     Res.ele[4] = A.ele[4] * s;
00138     Res.ele[5] = A.ele[5] * s;
00139     Res.ele[6] = A.ele[6] * s;
00140     Res.ele[7] = A.ele[7] * s;
00141     Res.ele[8] = A.ele[8] * s;
00142     Res.ele[9] = A.ele[9] * s;
00143     Res.ele[10] = A.ele[10] * s;
00144     Res.ele[11] = A.ele[11] * s;
00145     Res.ele[12] = A.ele[12] * s;
00146     Res.ele[13] = A.ele[13] * s;
00147     Res.ele[14] = A.ele[14] * s;
00148     Res.ele[15] = A.ele[15] * s;
00149     return Res; 
00150 
00151 }
00152 //----------------------------------------------------------------------------
00153 inline mitkVis2Matrix4x4& mitkVis2Matrix4x4::operator *= (float s) 
00154 {
00155     ele[0] *= s;
00156     ele[1] *= s;
00157     ele[2] *= s;
00158     ele[3] *= s;
00159     ele[4] *= s;
00160     ele[5] *= s;
00161     ele[6] *= s;
00162     ele[7] *= s;
00163     ele[8] *= s;
00164     ele[9] *= s;
00165     ele[10] *= s;
00166     ele[11] *= s;
00167     ele[12] *= s;
00168     ele[13] *= s;
00169     ele[14] *= s;
00170     ele[15] *= s;
00171     return *this;
00172 }
00173 //----------------------------------------------------------------------------
00174 inline mitkVis2Matrix4x4 operator + (const mitkVis2Matrix4x4 &A, const mitkVis2Matrix4x4 &B) 
00175 {
00176     mitkVis2Matrix4x4 Res;
00177 
00178     Res.ele[0] = A.ele[0] + B.ele[0];
00179     Res.ele[1] = A.ele[1] + B.ele[1];
00180     Res.ele[2] = A.ele[2] + B.ele[2];
00181     Res.ele[3] = A.ele[3] + B.ele[3];
00182     Res.ele[4] = A.ele[4] + B.ele[4];
00183     Res.ele[5] = A.ele[5] + B.ele[5];
00184     Res.ele[6] = A.ele[6] + B.ele[6];
00185     Res.ele[7] = A.ele[7] + B.ele[7];   
00186     Res.ele[8] = A.ele[8] + B.ele[8];
00187     Res.ele[9] = A.ele[9] + B.ele[9];
00188     Res.ele[10] = A.ele[10] + B.ele[10];
00189     Res.ele[11] = A.ele[11] + B.ele[11];
00190     Res.ele[12] = A.ele[12] + B.ele[12];
00191     Res.ele[13] = A.ele[13] + B.ele[13];
00192     Res.ele[14] = A.ele[14] + B.ele[14];
00193     Res.ele[15] = A.ele[15] + B.ele[15];
00194     return Res;
00195 
00196 }
00197 //----------------------------------------------------------------------------
00198 inline mitkVis2Matrix4x4 & mitkVis2Matrix4x4::operator += (const mitkVis2Matrix4x4 &B) 
00199 {
00200     ele[0] += B.ele[0];
00201     ele[1] += B.ele[1];
00202     ele[2] += B.ele[2];
00203     ele[3] += B.ele[3];
00204     ele[4] += B.ele[4];
00205     ele[5] += B.ele[5];
00206     ele[6] += B.ele[6];
00207     ele[7] += B.ele[7];
00208     ele[8] += B.ele[8];
00209     ele[9] += B.ele[9];
00210     ele[10] += B.ele[10];
00211     ele[11] += B.ele[11];
00212     ele[12] += B.ele[12];
00213     ele[13] += B.ele[13];
00214     ele[14] += B.ele[14];
00215     ele[15] += B.ele[15];
00216     return *this;
00217 }
00218 //----------------------------------------------------------------------------
00219 inline mitkVis2Matrix4x4 operator - (const mitkVis2Matrix4x4 &A, const mitkVis2Matrix4x4 &B) 
00220 {
00221     mitkVis2Matrix4x4 Res;
00222     
00223     Res.ele[0] = A.ele[0] - B.ele[0];
00224     Res.ele[1] = A.ele[1] - B.ele[1];
00225     Res.ele[2] = A.ele[2] - B.ele[2];
00226     Res.ele[3] = A.ele[3] - B.ele[3];
00227     Res.ele[4] = A.ele[4] - B.ele[4];
00228     Res.ele[5] = A.ele[5] - B.ele[5];
00229     Res.ele[6] = A.ele[6] - B.ele[6];
00230     Res.ele[7] = A.ele[7] - B.ele[7];   
00231     Res.ele[8] = A.ele[8] - B.ele[8];
00232     Res.ele[9] = A.ele[9] - B.ele[9];
00233     Res.ele[10] = A.ele[10] - B.ele[10];
00234     Res.ele[11] = A.ele[11] - B.ele[11];
00235     Res.ele[12] = A.ele[12] - B.ele[12];
00236     Res.ele[13] = A.ele[13] - B.ele[13];
00237     Res.ele[14] = A.ele[14] - B.ele[14];
00238     Res.ele[15] = A.ele[15] - B.ele[15];
00239     return Res;
00240 
00241 }
00242 //----------------------------------------------------------------------------
00243 inline mitkVis2Matrix4x4 operator - (const mitkVis2Matrix4x4 &A)
00244 {
00245     mitkVis2Matrix4x4 Res;
00246 
00247     Res.ele[0] = - A.ele[0];
00248     Res.ele[1] = - A.ele[1];
00249     Res.ele[2] = - A.ele[2];
00250     Res.ele[3] = - A.ele[3];
00251     Res.ele[4] = - A.ele[4];
00252     Res.ele[5] = - A.ele[5];
00253     Res.ele[6] = - A.ele[6];
00254     Res.ele[7] = - A.ele[7];    
00255     Res.ele[8] = - A.ele[8];
00256     Res.ele[9] = - A.ele[9];
00257     Res.ele[10] = - A.ele[10];
00258     Res.ele[11] = - A.ele[11];
00259     Res.ele[12] = - A.ele[12];
00260     Res.ele[13] = - A.ele[13];
00261     Res.ele[14] = - A.ele[14];
00262     Res.ele[15] = - A.ele[15];
00263     return Res;
00264 
00265 }
00266 //----------------------------------------------------------------------------
00267 inline mitkVis2Matrix4x4 & mitkVis2Matrix4x4::operator -= (const mitkVis2Matrix4x4 &B) 
00268 {
00269 
00270     ele[0] -= B.ele[0];
00271     ele[1] -= B.ele[1];
00272     ele[2] -= B.ele[2];
00273     ele[3] -= B.ele[3];
00274     ele[4] -= B.ele[4];
00275     ele[5] -= B.ele[5];
00276     ele[6] -= B.ele[6];
00277     ele[7] -= B.ele[7];
00278     ele[8] -= B.ele[8];
00279     ele[9] -= B.ele[9];
00280     ele[10] -= B.ele[10];
00281     ele[11] -= B.ele[11];
00282     ele[12] -= B.ele[12];
00283     ele[13] -= B.ele[13];
00284     ele[14] -= B.ele[14];
00285     ele[15] -= B.ele[15];
00286     return *this;
00287 
00288 }
00289 //----------------------------------------------------------------------------
00290 inline mitkVis2Vector4 operator * (const mitkVis2Vector4& Vec, const mitkVis2Matrix4x4& Mat) 
00291 {
00292     mitkVis2Vector4 Res;
00293 
00294     
00295     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]; 
00296     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]; 
00297     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]; 
00298     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]; 
00299     return Res; 
00300 
00301 }
00302 //----------------------------------------------------------------------------
00303 inline mitkVis2Vector4 operator * (const mitkVis2Matrix4x4& Mat, const mitkVis2Vector4& Vec) 
00304 {
00305     mitkVis2Vector4 Res;
00306 
00307     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]; 
00308     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]; 
00309     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]; 
00310     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]; 
00311     return Res; 
00312     
00313 }
00314 
00315 #endif

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