![]() |
CASToR
1.0
Tomographic Reconstruction (PET/SPECT)
|
00001 00002 /* 00003 Implementation of class oMatrix 00004 00005 - separators: X 00006 - doxygen: X 00007 - default initialization: X 00008 - CASTOR_DEBUG: none 00009 - CASTOR_VERBOSE: none 00010 */ 00011 00018 #include "oMatrix.hh" 00019 00020 00021 // ===================================================================== 00022 // --------------------------------------------------------------------- 00023 // --------------------------------------------------------------------- 00024 // ===================================================================== 00025 /* 00026 \brief oMatrix constructor. 00027 Initialize the member variables to their default values. 00028 */ 00029 oMatrix::oMatrix() 00030 { 00031 m_lin = 0; 00032 m_col = 0; 00033 00034 m2p_Mat = NULL; 00035 } 00036 00037 00038 00039 // ===================================================================== 00040 // --------------------------------------------------------------------- 00041 // --------------------------------------------------------------------- 00042 // ===================================================================== 00043 /* 00044 \param nl : a number of lines 00045 \param nc : a number of colons 00046 \brief oMatrix constructor. 00047 Instanciate a Matrix structure with the number of lines and colons provided in parameters 00048 */ 00049 oMatrix::oMatrix(uint16_t nl, uint16_t nc) 00050 { 00051 m_lin = nl; 00052 m_col = nc; 00053 m2p_Mat = new FLTNBLUT *[nl]; 00054 00055 for(uint16_t l=0 ; l<nl ; l++) 00056 m2p_Mat[l] = new FLTNBLUT[nc]; 00057 } 00058 00059 00060 00061 // ===================================================================== 00062 // --------------------------------------------------------------------- 00063 // --------------------------------------------------------------------- 00064 // ===================================================================== 00065 /* 00066 \brief oMatrix destructor. 00067 Free memory of the oMatrix object. 00068 */ 00069 oMatrix::~oMatrix() 00070 { 00071 for(uint16_t l=0 ; l<m_lin ; l++) 00072 if(m2p_Mat[l]) delete[] m2p_Mat[l]; 00073 00074 if(m2p_Mat) delete[] m2p_Mat; 00075 } 00076 00077 00078 00079 // ===================================================================== 00080 // --------------------------------------------------------------------- 00081 // --------------------------------------------------------------------- 00082 // ===================================================================== 00083 /* 00084 \fn Allocate 00085 \param nl : a number of lines 00086 \param nc : a number of colons 00087 \brief Instanciate a Matrix structure with the number of lines and colons provided in parameters 00088 */ 00089 void oMatrix::Allocate(uint16_t nl, uint16_t nc) 00090 { 00091 // No verbosity in oMatrix structure. Show this only if CASTOR_DEBUG is enabled (for bug tracking) 00092 #ifdef CASTOR_DEBUG 00093 Cout("oMatrix::Allocate() ..."); 00094 #endif 00095 00096 // Free memory in case the matrix had already been allocated 00097 if(m2p_Mat != NULL) 00098 { 00099 for(uint16_t l=0 ; l<m_lin ; l++) 00100 if(m2p_Mat[l]) delete[] m2p_Mat[l]; 00101 00102 delete[] m2p_Mat; 00103 } 00104 00105 m_lin = nl; 00106 m_col = nc; 00107 m2p_Mat = new FLTNBLUT *[nl]; 00108 00109 for(uint16_t l=0 ; l<nl ; l++) 00110 m2p_Mat[l] = new FLTNBLUT[nc]; 00111 } 00112 00113 00114 00115 // ===================================================================== 00116 // --------------------------------------------------------------------- 00117 // --------------------------------------------------------------------- 00118 // ===================================================================== 00119 /* 00120 \fn SetMatriceElt 00121 \param l : a line index 00122 \param c : a colon index 00123 \param a_val : a value to initialize the matrix element with 00124 \brief set the matrix element corresponding to the argument indices with the provided value. 00125 \return 0 if success, positive value otherwise 00126 */ 00127 int oMatrix::SetMatriceElt(uint16_t l, uint16_t c, FLTNBLUT a_val) 00128 { 00129 // No verbosity in oMatrix structure. Show this only if CASTOR_DEBUG is enabled (for bug tracking) 00130 #ifdef CASTOR_DEBUG 00131 Cout("oMatrix::SetMatriceElt() ..."); 00132 #endif 00133 00134 if(l>=m_lin || c>=m_col) 00135 { 00136 Cerr("***** oMatrix::SetMatriceElt()-> Nb of (lin,col) ("<<l+1<<","<<c+1<<") in parameters "); 00137 Cerr("> to the number of (lin,col) of this matrix ("<<m_lin<<","<<m_col<<") !" << endl); 00138 return 1; 00139 } 00140 00141 m2p_Mat[l][c] = a_val; 00142 00143 return 0; 00144 } 00145 00146 00147 00148 // ===================================================================== 00149 // --------------------------------------------------------------------- 00150 // --------------------------------------------------------------------- 00151 // ===================================================================== 00159 FLTNBLUT oMatrix::GetMatriceElt(uint16_t l,uint16_t c) 00160 { 00161 // No verbosity in oMatrix structure. Show this only if CASTOR_DEBUG is enabled (for bug tracking) 00162 #ifdef CASTOR_DEBUG 00163 Cout("oMatrix::GetMatriceElt() ..."); 00164 #endif 00165 00166 return m2p_Mat[l][c]; 00167 } 00168 00169 00170 00171 // ===================================================================== 00172 // --------------------------------------------------------------------- 00173 // --------------------------------------------------------------------- 00174 // ===================================================================== 00175 /* 00176 \fn Multiplication 00177 \param ap_Mtx : a line index 00178 \param ap_MtxResult : a colon index 00179 \brief Multiply the member matrix with the matrix provided in 1st parameter 00180 Return the result in the matric provided in 2nd parameter 00181 \return 0 if success, positive value otherwise 00182 */ 00183 int oMatrix::Multiplication(oMatrix *ap_Mtx, oMatrix *ap_MtxResult) 00184 { 00185 // No verbosity in oMatrix structure. Show this only if CASTOR_DEBUG is enabled (for bug tracking) 00186 #ifdef CASTOR_DEBUG 00187 Cout("oMatrix::Multiplication() ..."); 00188 #endif 00189 00190 double sum=0; 00191 00192 if ( m_col != ap_Mtx->m_lin ) 00193 { 00194 Cerr("***** oMatrix::Multiplication()-> Not matching number of colons and lines of the two matrices !"); 00195 return 1; 00196 } 00197 else if (ap_MtxResult == NULL) 00198 { 00199 Cerr("***** oMatrix::Multiplication()-> The resulting matrix has not been allocated !"); 00200 return 1; 00201 } 00202 else 00203 { 00204 for ( uint16_t tl = 0; tl < m_lin; tl++ ) 00205 for ( uint16_t c = 0; c < ap_Mtx->m_col; c++ ) 00206 { 00207 for ( uint16_t l = 0; l < ap_Mtx->m_lin; l++ ) 00208 { 00209 sum += GetMatriceElt(tl,l) * ap_Mtx->GetMatriceElt(l,c); 00210 } 00211 ap_MtxResult->SetMatriceElt(tl,c,sum); 00212 sum = 0; 00213 } 00214 } 00215 00216 return 0; 00217 }