ML Reference
MeVis/Foundation/Sources/MLLinearAlgebra/mlMatrix5.h
Go to the documentation of this file.
00001 // **InsertLicense** code 
00002 //=====================================================================================
00004 
00009 //=====================================================================================
00010 
00011 #ifndef __mlMatrix5_H
00012 #define __mlMatrix5_H
00013 
00014 // Include system independency file and project settings.
00015 #ifndef __mlLinearAlgebraSystem_H
00016 #include "mlLinearAlgebraSystem.h"
00017 #endif
00018 #ifndef __mlLinearAlgebraDefs_H
00019 #include "mlLinearAlgebraDefs.h"
00020 #endif
00021 
00022 
00023 #ifndef __mlFloatingPointMatrix_H
00024 #include "mlFloatingPointMatrix.h"
00025 #endif
00026 
00027 #ifndef __mlVector5_H
00028 #include "mlVector5.h"
00029 #endif
00030 
00031 #ifndef __mlMatrix4_H
00032 #include "mlMatrix4.h"
00033 #endif
00034 
00035 // All declarations of this header will be in the ML_LINEAR_ALGEBRA namespace.
00036 ML_LA_START_NAMESPACE
00037 //--------------------------------------------------------------------
00039 // This is necessary because we do not known whether vector or 
00040 // matrix header is included first and we cannot move template
00041 // code into C++ file.
00042 //--------------------------------------------------------------------
00043 template <class DT> class Tvec5;
00044 template <class DT> class Tmat4;
00046 
00047 //--------------------------------------------------------------------
00049 //--------------------------------------------------------------------
00050 template <class DT>
00051 class Tmat5 : public FloatingPointMatrix<Tvec5<DT>, 5>
00052 {
00053 public:
00054   
00056   typedef DT ComponentType;
00057   
00058   // Build 5x5 matrix from 25 zero elements.
00059   Tmat5();
00060   
00061   // Build matrix that has the argument at the diagonal values, zero otherwise
00062   Tmat5(const DT diagValue);
00063 
00064   // Build the matrix of the five row vectors row0, ..., row5.
00065   Tmat5(const Tvec5<DT> &row0, const Tvec5<DT> &row1, const Tvec5<DT> &row2,
00066         const Tvec5<DT> &row3, const Tvec5<DT> &row4);
00067   
00068   // Copy constructor from the Tmat5 mat.
00069   Tmat5(const Tmat5<DT> &mat);
00070   
00071   // Constructor from 25 floats given as array mat, row by row.
00072   Tmat5(const float mat[25]);
00073   
00074   // Constructor from 25 doubles given as array mat, row by row.
00075   Tmat5(const double mat[25]);
00076   
00077   // Initialize all matrix elements explicitly with scalars,
00078   // filling it row by row.
00079   Tmat5(const double in00, const double in01, const double in02, const double in03, const double in04, 
00080         const double in10, const double in11, const double in12, const double in13, const double in14, 
00081         const double in20, const double in21, const double in22, const double in23, const double in24,
00082         const double in30, const double in31, const double in32, const double in33, const double in34, 
00083         const double in40, const double in41, const double in42, const double in43, const double in44);
00084   
00085   // Copy contents from float array m into *this. m must point to an 
00086   // array with at least 25 valid entries, row by row.
00087   void setValues(const float m[25]);
00088   
00089   // Copy contents of *this into float array m. Note that range 
00090   // and precision of the float values may not be sufficient for 
00091   // higher precision matrix contents. m must point to an array with 
00092   // at least 25 accessible entries, row by row.
00093   void getValues(float m[25]) const;
00094   
00095   // Copy contents from double array m into *this. m must point to an 
00096   // array with at least 25 valid entries, row by row.
00097   void setValues(const double m[25]);
00098   
00099   // Copy contents of *this into double array m. m must point to an 
00100   // array with at least 25 accessible entries, row by row.
00101   void getValues(double m[25]) const;
00102   
00103   // Set diagonal matrix with scale on diagonal. 
00104   void setScaleMatrix(const DT scale);
00105   
00106   // Return a matrix filled with values val.
00107   static Tmat5<DT> getMat(const double val);
00108   
00109   // Set all values to val.
00110   void set(const DT val);
00111   
00114   bool operator<(const Tmat5<DT> &) const { return false; }
00115   
00116   // Assignment from a Tmat5.
00117   const Tmat5<DT>& operator=(const Tmat5<DT> &m);
00118   
00119   // Component wise addition with a Tmat5.
00120   const Tmat5<DT>& operator+=(const Tmat5<DT> &m);
00121   
00122   // Component wise subtraction by a Tmat5.
00123   const Tmat5<DT>& operator-=(const Tmat5<DT> &m);
00124   
00125   // Multiplication by a scalar constant
00126   const Tmat5<DT>& operator*=(const DT d);
00127   
00128   // Division by a scalar constant. 
00129   // Division by zero is not handled and must be avoided by caller.
00130   const Tmat5<DT>& operator/=(const DT d);
00131   
00132   //-------------------------------------------------
00133   // Special functions
00134   //-------------------------------------------------
00135   // Determine the (sub)determinant of columns given by col1, col2, col3 and col4.
00136   DT determinantLower4(const int col1, const int col2, const int col3, const int col4) const;
00137   
00138   // Determinant.
00139   DT det() const;
00140   
00141   // Returns the inverse. Gauss-Jordan elimination with partial pivoting.
00142   // If a non-NULL Boolean pointer is passed to isInvertible 
00143   // then true is returned in *isInvertible in the case of a 
00144   // successful inversion or false if the inversion is not possible
00145   // (function return is the identity then).
00146   // If a NULL pointer is passed as isInvertible the matrix must
00147   // be invertible, otherwise errors will occur.
00148   Tmat5<DT> inverse(bool* isInvertible=NULL) const;
00149   
00150   // Transpose. 
00151   Tmat5 transpose() const;
00152   
00153   // Return identity matrix. 
00154   static Tmat5 getIdentity();
00155   
00156   // Apply the function fct to each component. 
00157   const Tmat5<DT> & apply(MLDblFuncPtr fct);
00158   
00159 }; // end of class *Tmat5*
00160 
00161 
00162 
00163 
00164 //---------------------------------------------------------------------
00165 // Constructors
00166 //---------------------------------------------------------------------
00168 template <class DT>
00169 inline Tmat5<DT>::Tmat5()
00170 {
00171   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::Tmat5()");
00172   
00173   this->v[0] = this->v[1] = this->v[2] = this->v[3] = this->v[4] = Tvec5<DT>(0);
00174 }
00175 
00176 // Construct matrix that has the argument at the diagonal values, zero otherwise
00177 template <class DT>
00178 inline Tmat5<DT>::Tmat5(const DT diagValue)
00179 {
00180   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::Tmat5(diagValue)");
00181   
00182   this->v[0][0] = this->v[1][1] = this->v[2][2] = this->v[3][3] = this->v[4][4] = diagValue;
00183   this->v[1][0] = this->v[2][0] = this->v[3][0] = this->v[4][0] = this->v[2][1] = this->v[3][1] = this->v[4][1] = this->v[3][2] = this->v[4][2] = this->v[4][3] = 0;
00184   this->v[0][1] = this->v[0][2] = this->v[0][3] = this->v[0][4] = this->v[1][2] = this->v[1][3] = this->v[1][4] = this->v[2][3] = this->v[2][4] = this->v[3][4] = 0;
00185 }
00186 
00187 
00189 template <class DT>
00190 inline Tmat5<DT>::Tmat5(const Tvec5<DT>& row0, const Tvec5<DT>& row1, const Tvec5<DT>& row2,
00191                         const Tvec5<DT>& row3, const Tvec5<DT>& row4)
00192 {
00193   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::Tmat5(const Tvec5<DT>& row0, ..., const Tvec5<DT>& row4)");
00194   
00195   this->v[0] = row0; 
00196   this->v[1] = row1; 
00197   this->v[2] = row2;
00198   this->v[3] = row3; 
00199   this->v[4] = row4; 
00200 }
00201 
00203 template <class DT>
00204 inline Tmat5<DT>::Tmat5(const Tmat5<DT> &mat)
00205 {
00206   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::Tmat5(const Tmat5<DT> &mat)");
00207   
00208   this->v[0] = mat.v[0]; 
00209   this->v[1] = mat.v[1]; 
00210   this->v[2] = mat.v[2];
00211   this->v[3] = mat.v[3]; 
00212   this->v[4] = mat.v[4]; 
00213 }
00214 
00216 template <class DT>
00217 inline Tmat5<DT>::Tmat5(const float mat[25])
00218 {
00219   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::Tmat5(const float mat[25])");
00220   
00221   setValues(mat);
00222 }
00223 
00225 template <class DT>
00226 inline Tmat5<DT>::Tmat5(const double mat[25])
00227 {
00228   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::Tmat5(const double mat[25])");
00229   
00230   setValues(mat);
00231 }
00232 
00234 template <class DT>
00235 inline Tmat5<DT> Tmat5<DT>::getMat(const double val)
00236 {
00237   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::getMat(const double val)");
00238   
00239   return Tmat5<DT>(val, val, val, val, val,
00240                    val, val, val, val, val,
00241                    val, val, val, val, val,
00242                    val, val, val, val, val,
00243                    val, val, val, val, val);
00244 }
00245 
00247 template <class DT>
00248 inline void Tmat5<DT>::set(const DT val)
00249 {
00250   this->v[0] = this->v[1] = this->v[2] = this->v[3] = this->v[4] = Tvec5<DT>(val);
00251 }
00252 
00254 template <class DT>
00255 inline const Tmat5<DT> & Tmat5<DT>::operator=(const Tmat5<DT> &m)
00256 {
00257   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::operator=(const Tmat5<DT> &m)");
00258   
00259   if (&m != this){   
00260     this->v[0] = m.v[0]; 
00261     this->v[1] = m.v[1]; 
00262     this->v[2] = m.v[2];
00263     this->v[3] = m.v[3]; 
00264     this->v[4] = m.v[4]; 
00265   }
00266   
00267   return *this;
00268 }
00269 
00271 template <class DT>
00272 inline const Tmat5<DT> & Tmat5<DT>::operator+=(const Tmat5<DT> &m)
00273 {
00274   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::operator+=(const Tmat5<DT> &m)");
00275   
00276   this->v[0] += m.v[0]; 
00277   this->v[1] += m.v[1]; 
00278   this->v[2] += m.v[2];
00279   this->v[3] += m.v[3]; 
00280   this->v[4] += m.v[4]; 
00281   
00282   return *this;
00283 }
00284 
00286 template <class DT>
00287 inline const Tmat5<DT> & Tmat5<DT>::operator-=(const Tmat5<DT> &m)
00288 {
00289   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::operator-=(const Tmat5<DT> &m)");
00290   
00291   this->v[0] -= m.v[0]; 
00292   this->v[1] -= m.v[1]; 
00293   this->v[2] -= m.v[2];
00294   this->v[3] -= m.v[3]; 
00295   this->v[4] -= m.v[4]; 
00296   
00297   return *this;
00298 }
00299 
00301 template <class DT>
00302 inline const Tmat5<DT> & Tmat5<DT>::operator*=(const DT d)
00303 {
00304   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::operator*=(const DT d)");
00305   
00306   this->v[0] *= d; 
00307   this->v[1] *= d; 
00308   this->v[2] *= d;
00309   this->v[3] *= d; 
00310   this->v[4] *= d; 
00311   
00312   return *this;
00313 }
00314 
00316 template <class DT>
00317 inline const Tmat5<DT> & Tmat5<DT>::operator/=(const DT d)
00318 {
00319   ML_TRACE_IN("Tmat5<DT>::operator/=()");
00320   ML_TRY
00321   {
00322     ML_CHECK_FLOAT_THROW(d);
00323     this->v[0] /= d; 
00324     this->v[1] /= d; 
00325     this->v[2] /= d;
00326     this->v[3] /= d; 
00327     this->v[4] /= d; 
00328   }
00329   ML_CATCH_RETHROW;
00330   return *this;
00331 }
00332 
00333 
00334 //--------------------------------------------------------------------
00336 
00337 //--------------------------------------------------------------------
00339 template <class DT>
00340 inline Tmat5<DT> operator-(const Tmat5<DT> &a)
00341 {
00342   ML_TRACE_IN_TIME_CRITICAL("mlMatrix5.h: operator-(const Tmat5<DT> &a)");
00343   
00344   return Tmat5<DT>(a) *= static_cast<DT>(-1.0);
00345 }
00346 
00348 template <class DT>
00349 inline Tmat5<DT> operator+(const Tmat5<DT> &a, const Tmat5<DT> &b)
00350 {
00351   ML_TRACE_IN_TIME_CRITICAL("mlMatrix5.h: operator+(const Tmat5<DT> &a, const Tmat5<DT> &b)");
00352   
00353   return Tmat5<DT>(a) += b;
00354 }
00355 
00357 template <class DT>
00358 inline Tmat5<DT> operator-(const Tmat5<DT> &a, const Tmat5<DT> &b)
00359 {
00360   ML_TRACE_IN_TIME_CRITICAL("mlMatrix5.h: operator-(const Tmat5<DT> &a, const Tmat5<DT> &b)");
00361   
00362   return Tmat5<DT>(a) -= b;
00363 }
00364 
00366 template <class DT>
00367 inline Tmat5<DT> operator*(const Tmat5<DT> &a, const DT d)
00368 {
00369   ML_TRACE_IN_TIME_CRITICAL("mlMatrix5.h: operator*(const Tmat5<DT> &a, const DT d)");
00370   
00371   return Tmat5<DT>(a) *= d;
00372 }
00373 
00375 template <class DT>
00376 inline Tmat5<DT> operator*(const DT d, const Tmat5<DT> &a)
00377 {
00378   ML_TRACE_IN_TIME_CRITICAL("mlMatrix5.h: operator*(const DT d, const Tmat5<DT> &a)");
00379   
00380   return Tmat5<DT>(a) *= d;
00381 }
00382 
00385 template <class DT>
00386 inline Tmat5<DT> operator/(const Tmat5<DT> &a, const DT d)
00387 {
00388   ML_TRACE_IN("mlMatrix5.h: operator/(const Tmat5<DT> &a, const DT d)");
00389   
00390   Tmat5<DT> divided(a);
00391   ML_TRY
00392   {
00393     ML_CHECK_FLOAT_THROW(d);
00394     divided /= d;
00395   }
00396   ML_CATCH_RETHROW;
00397   return divided;
00398 }
00400 
00401 //-------------------------------------------------------------------
00402 //
00403 //      Tmat5 member functions
00404 //
00405 //-------------------------------------------------------------------
00406 
00407 //-------------------------------------------------------------------
00410 //-------------------------------------------------------------------
00411 template <class DT>
00412 Tmat5<DT>::Tmat5(const double in00, const double in01, const double in02, const double in03, const double in04, 
00413                  const double in10, const double in11, const double in12, const double in13, const double in14, 
00414                  const double in20, const double in21, const double in22, const double in23, const double in24,
00415                  const double in30, const double in31, const double in32, const double in33, const double in34, 
00416                  const double in40, const double in41, const double in42, const double in43, const double in44)
00417 {
00418   ML_TRACE_IN("Tmat5<DT>::Tmat5( )");
00419   
00420   this->v[0][0]=static_cast<DT>(in00); this->v[0][1]=static_cast<DT>(in01); this->v[0][2]=static_cast<DT>(in02);  this->v[0][3]=static_cast<DT>(in03); this->v[0][4]=static_cast<DT>(in04);
00421   this->v[1][0]=static_cast<DT>(in10); this->v[1][1]=static_cast<DT>(in11); this->v[1][2]=static_cast<DT>(in12);  this->v[1][3]=static_cast<DT>(in13); this->v[1][4]=static_cast<DT>(in14);
00422   this->v[2][0]=static_cast<DT>(in20); this->v[2][1]=static_cast<DT>(in21); this->v[2][2]=static_cast<DT>(in22);  this->v[2][3]=static_cast<DT>(in23); this->v[2][4]=static_cast<DT>(in24);
00423   this->v[3][0]=static_cast<DT>(in30); this->v[3][1]=static_cast<DT>(in31); this->v[3][2]=static_cast<DT>(in32);  this->v[3][3]=static_cast<DT>(in33); this->v[3][4]=static_cast<DT>(in34);
00424   this->v[4][0]=static_cast<DT>(in40); this->v[4][1]=static_cast<DT>(in41); this->v[4][2]=static_cast<DT>(in42);  this->v[4][3]=static_cast<DT>(in43); this->v[4][4]=static_cast<DT>(in44);
00425 }
00426 
00427 
00428 //--------------------------------------------------------------------
00431 //--------------------------------------------------------------------
00432 template <class DT>
00433 void Tmat5<DT>::setValues(const float m[25])
00434 {
00435   ML_TRACE_IN("Tmat5<DT>::setValues( )");
00436   ML_TRY
00437   {
00438     this->v[0][0] = static_cast<DT>(m[ 0]);
00439     this->v[0][1] = static_cast<DT>(m[ 1]);
00440     this->v[0][2] = static_cast<DT>(m[ 2]);
00441     this->v[0][3] = static_cast<DT>(m[ 3]);
00442     this->v[0][4] = static_cast<DT>(m[ 4]);
00443     
00444     this->v[1][0] = static_cast<DT>(m[ 5]);
00445     this->v[1][1] = static_cast<DT>(m[ 6]);
00446     this->v[1][2] = static_cast<DT>(m[ 7]);
00447     this->v[1][3] = static_cast<DT>(m[ 8]);
00448     this->v[1][4] = static_cast<DT>(m[ 9]);
00449     
00450     this->v[2][0] = static_cast<DT>(m[10]);
00451     this->v[2][1] = static_cast<DT>(m[11]);
00452     this->v[2][2] = static_cast<DT>(m[12]);
00453     this->v[2][3] = static_cast<DT>(m[13]);
00454     this->v[2][4] = static_cast<DT>(m[14]);
00455     
00456     this->v[3][0] = static_cast<DT>(m[15]);
00457     this->v[3][1] = static_cast<DT>(m[16]);
00458     this->v[3][2] = static_cast<DT>(m[17]);
00459     this->v[3][3] = static_cast<DT>(m[18]);
00460     this->v[3][4] = static_cast<DT>(m[19]);
00461     
00462     this->v[4][0] = static_cast<DT>(m[20]);
00463     this->v[4][1] = static_cast<DT>(m[21]);
00464     this->v[4][2] = static_cast<DT>(m[22]);
00465     this->v[4][3] = static_cast<DT>(m[23]);
00466     this->v[4][4] = static_cast<DT>(m[24]);
00467   }
00468   ML_CATCH_RETHROW;
00469 }
00470 
00471 //--------------------------------------------------------------------
00476 //--------------------------------------------------------------------
00477 template <class DT>
00478 void Tmat5<DT>::getValues(float m[25]) const
00479 {
00480   ML_TRACE_IN("Tmat5<DT>::setValues( )");
00481   ML_TRY
00482   {
00483     m[ 0] = static_cast<float>(this->v[0][0]);
00484     m[ 1] = static_cast<float>(this->v[0][1]);
00485     m[ 2] = static_cast<float>(this->v[0][2]);
00486     m[ 3] = static_cast<float>(this->v[0][3]);
00487     m[ 4] = static_cast<float>(this->v[0][4]);
00488     
00489     m[ 5] = static_cast<float>(this->v[1][0]);
00490     m[ 6] = static_cast<float>(this->v[1][1]);
00491     m[ 7] = static_cast<float>(this->v[1][2]);
00492     m[ 8] = static_cast<float>(this->v[1][3]);
00493     m[ 9] = static_cast<float>(this->v[1][4]);
00494     
00495     m[10] = static_cast<float>(this->v[2][0]);
00496     m[11] = static_cast<float>(this->v[2][1]);
00497     m[12] = static_cast<float>(this->v[2][2]);
00498     m[13] = static_cast<float>(this->v[2][3]);
00499     m[14] = static_cast<float>(this->v[2][4]);
00500     
00501     m[15] = static_cast<float>(this->v[3][0]);
00502     m[16] = static_cast<float>(this->v[3][1]);
00503     m[17] = static_cast<float>(this->v[3][2]);
00504     m[18] = static_cast<float>(this->v[3][3]);
00505     m[19] = static_cast<float>(this->v[3][4]);
00506     
00507     m[20] = static_cast<float>(this->v[4][0]);
00508     m[21] = static_cast<float>(this->v[4][1]);
00509     m[22] = static_cast<float>(this->v[4][2]);
00510     m[23] = static_cast<float>(this->v[4][3]);
00511     m[24] = static_cast<float>(this->v[4][4]);
00512   }
00513   ML_CATCH_RETHROW;
00514 }
00515 
00516 //--------------------------------------------------------------------
00519 //--------------------------------------------------------------------
00520 template <class DT>
00521 void Tmat5<DT>::setValues(const double m[25])
00522 {
00523   ML_TRACE_IN("Tmat5<DT>::setValues( )");
00524   ML_TRY
00525   {
00526     this->v[0][0] = static_cast<DT>(m[ 0]);
00527     this->v[0][1] = static_cast<DT>(m[ 1]);
00528     this->v[0][2] = static_cast<DT>(m[ 2]);
00529     this->v[0][3] = static_cast<DT>(m[ 3]);
00530     this->v[0][4] = static_cast<DT>(m[ 4]);
00531     
00532     this->v[1][0] = static_cast<DT>(m[ 5]);
00533     this->v[1][1] = static_cast<DT>(m[ 6]);
00534     this->v[1][2] = static_cast<DT>(m[ 7]);
00535     this->v[1][3] = static_cast<DT>(m[ 8]);
00536     this->v[1][4] = static_cast<DT>(m[ 9]);
00537     
00538     this->v[2][0] = static_cast<DT>(m[10]);
00539     this->v[2][1] = static_cast<DT>(m[11]);
00540     this->v[2][2] = static_cast<DT>(m[12]);
00541     this->v[2][3] = static_cast<DT>(m[13]);
00542     this->v[2][4] = static_cast<DT>(m[14]);
00543     
00544     this->v[3][0] = static_cast<DT>(m[15]);
00545     this->v[3][1] = static_cast<DT>(m[16]);
00546     this->v[3][2] = static_cast<DT>(m[17]);
00547     this->v[3][3] = static_cast<DT>(m[18]);
00548     this->v[3][4] = static_cast<DT>(m[19]);
00549     
00550     this->v[4][0] = static_cast<DT>(m[20]);
00551     this->v[4][1] = static_cast<DT>(m[21]);
00552     this->v[4][2] = static_cast<DT>(m[22]);
00553     this->v[4][3] = static_cast<DT>(m[23]);
00554     this->v[4][4] = static_cast<DT>(m[24]);
00555   }
00556   ML_CATCH_RETHROW;
00557 }
00558 
00559 //--------------------------------------------------------------------
00562 //--------------------------------------------------------------------
00563 template <class DT>
00564 void Tmat5<DT>::getValues(double m[25]) const
00565 {
00566   ML_TRACE_IN("Tmat5<DT>::setValues( )");
00567   ML_TRY
00568   {
00569     m[ 0] = static_cast<double>(this->v[0][0]);
00570     m[ 1] = static_cast<double>(this->v[0][1]);
00571     m[ 2] = static_cast<double>(this->v[0][2]);
00572     m[ 3] = static_cast<double>(this->v[0][3]);
00573     m[ 4] = static_cast<double>(this->v[0][4]);
00574     
00575     m[ 5] = static_cast<double>(this->v[1][0]);
00576     m[ 6] = static_cast<double>(this->v[1][1]);
00577     m[ 7] = static_cast<double>(this->v[1][2]);
00578     m[ 8] = static_cast<double>(this->v[1][3]);
00579     m[ 9] = static_cast<double>(this->v[1][4]);
00580     
00581     m[10] = static_cast<double>(this->v[2][0]);
00582     m[11] = static_cast<double>(this->v[2][1]);
00583     m[12] = static_cast<double>(this->v[2][2]);
00584     m[13] = static_cast<double>(this->v[2][3]);
00585     m[14] = static_cast<double>(this->v[2][4]);
00586     
00587     m[15] = static_cast<double>(this->v[3][0]);
00588     m[16] = static_cast<double>(this->v[3][1]);
00589     m[17] = static_cast<double>(this->v[3][2]);
00590     m[18] = static_cast<double>(this->v[3][3]);
00591     m[19] = static_cast<double>(this->v[3][4]);
00592     
00593     m[20] = static_cast<double>(this->v[4][0]);
00594     m[21] = static_cast<double>(this->v[4][1]);
00595     m[22] = static_cast<double>(this->v[4][2]);
00596     m[23] = static_cast<double>(this->v[4][3]);
00597     m[24] = static_cast<double>(this->v[4][4]);
00598   }
00599   ML_CATCH_RETHROW;
00600 }
00601 
00602 
00603 //-------------------------------------------------------------------
00605 //-------------------------------------------------------------------
00606 template <class DT>
00607 void Tmat5<DT>::setScaleMatrix(const DT scale)
00608 {
00609   ML_TRACE_IN("Tmat5<DT>::setScaleMatrix( )");
00610   
00611   this->v[0][0] = scale;   this->v[0][1] =     0;   this->v[0][2] =     0;  this->v[0][3] =     0;   this->v[0][4] =     0;
00612   this->v[1][0] =     0;   this->v[1][1] = scale;   this->v[1][2] =     0;  this->v[1][3] =     0;   this->v[1][4] =     0;
00613   this->v[2][0] =     0;   this->v[2][1] =     0;   this->v[2][2] = scale;  this->v[2][3] =     0;   this->v[2][4] =     0;
00614   this->v[3][0] =     0;   this->v[3][1] =     0;   this->v[3][2] =     0;  this->v[3][3] = scale;   this->v[3][4] =     0;
00615   this->v[4][0] =     0;   this->v[4][1] =     0;   this->v[4][2] =     0;  this->v[4][3] =     0;   this->v[4][4] = scale;
00616 }
00617 
00618 
00619 
00620 
00621 //-------------------------------------------------------------------
00623 
00624 //-------------------------------------------------------------------
00625 
00626 //--------------------------------------------------------------------
00628 //--------------------------------------------------------------------
00629 template <class DT>
00630 inline DT Tmat5<DT>::determinantLower4(const int col1, const int col2, const int col3, const int col4) const
00631 {
00632   ML_TRACE_IN("Tmat5<DT>::determinantLower4()");
00633   
00634   /* Determinant of 4x4 matrix with given entries */
00635   return Tmat4<DT>(this->v[1][col1], this->v[1][col2], this->v[1][col3], this->v[1][col4],
00636                    this->v[2][col1], this->v[2][col2], this->v[2][col3], this->v[2][col4],
00637                    this->v[3][col1], this->v[3][col2], this->v[3][col3], this->v[3][col4],
00638                    this->v[4][col1], this->v[4][col2], this->v[4][col3], this->v[4][col4]).det();
00639 }
00640 
00641 //--------------------------------------------------------------------
00643 //--------------------------------------------------------------------
00644 template <class DT>
00645 DT Tmat5<DT>::det() const
00646 {
00647   ML_TRACE_IN("Tmat5<DT>::determinantLower4()");
00648   
00649   DT determ = 0;
00650   ML_TRY
00651   {
00652     determ = (  this->v[0][0] * determinantLower4(1, 2, 3, 4)
00653               - this->v[0][1] * determinantLower4(0, 2, 3, 4)
00654               + this->v[0][2] * determinantLower4(0, 1, 3, 4)
00655               - this->v[0][3] * determinantLower4(0, 1, 2, 4)
00656               + this->v[0][4] * determinantLower4(0, 1, 2, 3));
00657   }
00658   ML_CATCH_RETHROW;
00659   return determ;
00660 }
00661 
00662 //--------------------------------------------------------------------
00670 //--------------------------------------------------------------------
00671 template <class DT>
00672 Tmat5<DT> Tmat5<DT>::inverse(bool* isInvertible) const
00673 {
00674   ML_TRACE_IN("Tmat5<DT>::inverse( )");
00675   
00676   Tmat5<DT> retVal;
00677   ML_TRY
00678   {
00679     // Epsilon for comparison with 0 in inversion process.
00680     static const DT Epsilon = static_cast<DT>(10e-13);
00681     
00682     // Use helper function from tools to invert the matrix.
00683     retVal = MLInverseMatHelper(*this,
00684                                 isInvertible, 
00685                                 Epsilon,
00686                                 "Tmat5<DT> Tmat5<DT>::inverse(bool* isInvertible) const, matrix not invertable",
00687                                 getIdentity(),
00688                                 5);
00689   }
00690   ML_CATCH_RETHROW;
00691   return retVal;
00692 }
00693 
00694 
00695 //-------------------------------------------------------------------
00697 //-------------------------------------------------------------------
00698 template <class DT>
00699 inline Tmat5<DT> Tmat5<DT>::transpose() const
00700 {
00701   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::transpose()");
00702   
00703   return Tmat5<DT>(Tvec5<DT>(this->v[0][0], this->v[1][0], this->v[2][0], this->v[3][0], this->v[4][0]),
00704                    Tvec5<DT>(this->v[0][1], this->v[1][1], this->v[2][1], this->v[3][1], this->v[4][1]),
00705                    Tvec5<DT>(this->v[0][2], this->v[1][2], this->v[2][2], this->v[3][2], this->v[4][2]),
00706                    Tvec5<DT>(this->v[0][3], this->v[1][3], this->v[2][3], this->v[3][3], this->v[4][3]),
00707                    Tvec5<DT>(this->v[0][4], this->v[1][4], this->v[2][4], this->v[3][4], this->v[4][4]));
00708 }
00709 
00710 //-------------------------------------------------------------------
00712 //-------------------------------------------------------------------
00713 template <class DT>
00714 inline Tmat5<DT> Tmat5<DT>::getIdentity()
00715 {
00716   ML_TRACE_IN_TIME_CRITICAL("Tmat5<DT>::getIdentity()");
00717   
00718   return Tmat5<DT>(Tvec5<DT>(1,0,0,0,0),
00719                    Tvec5<DT>(0,1,0,0,0),
00720                    Tvec5<DT>(0,0,1,0,0),
00721                    Tvec5<DT>(0,0,0,1,0),
00722                    Tvec5<DT>(0,0,0,0,1));
00723 }
00724 
00725 //-------------------------------------------------------------------
00727 //-------------------------------------------------------------------
00728 template <class DT>
00729 const Tmat5<DT> & Tmat5<DT>::apply(MLDblFuncPtr fct)
00730 {
00731   ML_TRACE_IN("Tmat5<DT>::apply(MLDblFuncPtr fct)");
00732   ML_TRY
00733   {
00734     this->v[0].apply(fct);
00735     this->v[1].apply(fct);
00736     this->v[2].apply(fct);
00737     this->v[3].apply(fct);
00738     this->v[4].apply(fct);
00739   }
00740   ML_CATCH_RETHROW;
00741   return *this;
00742 }
00743 
00744 
00746 #define _ML_MAT5_RC(i, j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + \
00747 a[i][3]*b[3][j] + a[i][4]*b[4][j]
00748 //-------------------------------------------------------------------
00750 //-------------------------------------------------------------------
00751 template <class DT>
00752 Tmat5<DT> operator*(const Tmat5<DT> &a, const Tmat5<DT> &b)
00753 {
00754   ML_TRACE_IN("mlMatrix5.h: operator*(const Tmat5<DT> &a, const Tmat5<DT> &b)");
00755   
00756   
00757   return Tmat5<DT>(Tvec5<DT>(_ML_MAT5_RC(0,0), _ML_MAT5_RC(0,1), _ML_MAT5_RC(0,2), _ML_MAT5_RC(0,3), _ML_MAT5_RC(0,4)),
00758                    Tvec5<DT>(_ML_MAT5_RC(1,0), _ML_MAT5_RC(1,1), _ML_MAT5_RC(1,2), _ML_MAT5_RC(1,3), _ML_MAT5_RC(1,4)),
00759                    Tvec5<DT>(_ML_MAT5_RC(2,0), _ML_MAT5_RC(2,1), _ML_MAT5_RC(2,2), _ML_MAT5_RC(2,3), _ML_MAT5_RC(2,4)),
00760                    Tvec5<DT>(_ML_MAT5_RC(3,0), _ML_MAT5_RC(3,1), _ML_MAT5_RC(3,2), _ML_MAT5_RC(3,3), _ML_MAT5_RC(3,4)),
00761                    Tvec5<DT>(_ML_MAT5_RC(4,0), _ML_MAT5_RC(4,1), _ML_MAT5_RC(4,2), _ML_MAT5_RC(4,3), _ML_MAT5_RC(4,4)));
00762 }
00763 #undef _ML_MAT5_RC
00764 
00765 
00766 // Note: Multiplications with Vector5 are implemented with/in class Tvec5.
00767 
00768 
00769 //-------------------------------------------------------------------
00771 //-------------------------------------------------------------------
00772 template <class DT>
00773 inline bool operator==(const Tmat5<DT> &a, const Tmat5<DT> &b)
00774 {
00775   ML_TRACE_IN_TIME_CRITICAL("mlMatrix5.h: operator==(const Tmat5<DT> &a, const Tmat5<DT> &b)");
00776   
00777   return (a[0] == b[0]) &&
00778   (a[1] == b[1]) &&
00779   (a[2] == b[2]) &&
00780   (a[3] == b[3]) &&
00781   (a[4] == b[4]);
00782 }
00783 
00784 //-------------------------------------------------------------------
00786 //-------------------------------------------------------------------
00787 template <class DT>
00788 inline bool operator!=(const Tmat5<DT> &a, const Tmat5<DT> &b)
00789 {
00790   ML_TRACE_IN_TIME_CRITICAL("mlMatrix5.h: operator!=(const Tmat5<DT> &a, const Tmat5<DT> &b)");
00791   
00792   return !(a == b);
00793 }
00795 
00796 
00797 //-----------------------------------------------------------------------------------
00799 
00800 //-----------------------------------------------------------------------------------
00801 
00803 typedef Tmat5<MLfloat>   Matrix5f;
00805 typedef Tmat5<MLdouble>  Matrix5d;
00807 typedef Tmat5<MLldouble> Matrix5ld;
00809 typedef Tmat5<MLdouble>  Matrix5;
00811 
00812 
00813 #ifdef ML_DEPRECATED
00814 
00816 
00817 
00821 ML_DEPRECATED typedef Tmat5<MLfloat>   matf5;
00825 ML_DEPRECATED typedef Tmat5<MLdouble>  matd5;
00829 ML_DEPRECATED typedef Tmat5<MLldouble> matld5;
00833 ML_DEPRECATED typedef Tmat5<MLdouble> mat5;
00835 
00836 
00837 #endif // ML_DEPRECATED
00838 
00839 
00840 
00841 ML_LA_END_NAMESPACE
00842 
00843 namespace std
00844 {
00845   //-------------------------------------------------------------------
00847   //-------------------------------------------------------------------
00848   template <class DT>
00849   inline std::ostream& operator<<(std::ostream& os, const ML_LA_NAMESPACE::Tmat5<DT> & m)
00850   {
00851     return os << m[0] << '\n' << m[1] << '\n' << m[2] << '\n' << m[3] << '\n' << m[4];
00852   }
00853   
00854   //-------------------------------------------------------------------
00856   //-------------------------------------------------------------------
00857   template <class DT>
00858   inline std::istream& operator>>(std::istream& is, ML_LA_NAMESPACE::Tmat5<DT> & m)
00859   {
00860     ML_LA_NAMESPACE::Tmat5<DT> m_tmp;
00861     
00862     is >> m_tmp[0] >> m_tmp[1] >> m_tmp[2] >> m_tmp[3] >> m_tmp[4];
00863     if (is){ m = m_tmp; }
00864     return is;
00865   }
00866 }
00867 
00868 
00869 #endif // __mlMatrix5_H
00870 
00871