CASToR  1.0
Tomographic Reconstruction (PET/SPECT)
iDynamicModelTemplate.cc
Go to the documentation of this file.
00001 
00002 /*
00003   Implementation of class iDynamicModelTemplate
00004 
00005   - separators: X
00006   - doxygen: X
00007   - default initialization: none 
00008   - CASTOR_DEBUG: X
00009   - CASTOR_VERBOSE: none
00010 */
00011 
00018 #include "iDynamicModelTemplate.hh"
00019 
00020 
00021 // =====================================================================
00022 // ---------------------------------------------------------------------
00023 // ---------------------------------------------------------------------
00024 // =====================================================================
00025 /*
00026   \fn iDynamicModelTemplate
00027   \brief Constructor of iDynamicModelTemplate. Simply set all data members to default values.
00028 */
00029 iDynamicModelTemplate::iDynamicModelTemplate() : vDynamicModel() 
00030 {
00031   m_nbTimeBF = 1; // Initialize the number of basis functions in the model
00032   m2p_parametricImages = NULL; // Should be allocated in Initialize() function
00033 }
00034 
00035 
00036 
00037 
00038 // =====================================================================
00039 // ---------------------------------------------------------------------
00040 // ---------------------------------------------------------------------
00041 // =====================================================================
00042 /*
00043   \fn ~iDynamicModelTemplate
00044   \brief Destructor of iDynamicModelTemplate
00045 */
00046 iDynamicModelTemplate::~iDynamicModelTemplate() 
00047 {
00048 }
00049 
00050 
00051 
00052 
00053 // =====================================================================
00054 // ---------------------------------------------------------------------
00055 // ---------------------------------------------------------------------
00056 // =====================================================================
00057 /*
00058   \fn ShowHelp
00059   \brief Print out specific help about the implementation of the Patlak
00060          model and its initialization
00061 */
00062 void iDynamicModelTemplate::ShowHelp()
00063 {
00064   // ===================================================================
00065   // Here, display some help and guidance to how to use this dynamic model and what it does
00066   // ===================================================================
00067   cout << "This class is a template class dedicated to add your own dynamic model." << endl;
00068 }
00069 
00070 
00071 
00072 
00073 // =====================================================================
00074 // ---------------------------------------------------------------------
00075 // ---------------------------------------------------------------------
00076 // =====================================================================
00077 /*
00078   \fn ReadAndCheckConfigurationFile
00079   \param const string& a_configurationFile : ASCII file containing informations about a dynamic model
00080   \brief This function is used to read options from a configuration file.
00081   \return 0 if success, other value otherwise.
00082 */
00083 int iDynamicModelTemplate::ReadAndCheckConfigurationFile(string a_fileOptions)
00084 {
00085   if(m_verbose >=2) Cout("iDynamicModelTemplate::ReadAndCheckConfigurationFile ..."<< endl); 
00086   
00087   // ===================================================================
00088   // Implement here the reading of any options specific to this dynamic model 
00089   // (i.e : parameters or path to deformation files), through a configuration file
00090   // The ReadDataASCIIFile() functions could be helpful to recover data from a file
00091   // ===================================================================
00092     
00093   return 0;
00094 }
00095 
00096 
00097 
00098 
00099 // =====================================================================
00100 // ---------------------------------------------------------------------
00101 // ---------------------------------------------------------------------
00102 // =====================================================================
00103 /*
00104   \fn ReadAndCheckOptionsList
00105   \param a_optionsList : a list of parameters separated by commas
00106   \brief This function is used to read parameters from a string.
00107   \return 0 if success, other value otherwise.
00108 */
00109 int iDynamicModelTemplate::ReadAndCheckOptionsList(string a_listOptions)
00110 {
00111   // ===================================================================
00112   // Implement here the reading of any options specific to this deformation model,
00113   // through a list of options separated by commas
00114   // The ReadStringOption() function could be helpful to parse the list of parameters in an array
00115   // ===================================================================
00116   
00117   // Normal end
00118   return 0;
00119 }
00120 
00121 
00122 
00123 
00124 // =====================================================================
00125 // ---------------------------------------------------------------------
00126 // ---------------------------------------------------------------------
00127 // =====================================================================
00128 /*
00129   \fn CheckSpecificParameters
00130   \brief This function is used to check whether all member variables
00131          have been correctly initialized or not.
00132   \return 0 if success, positive value otherwise.
00133 */
00134 int iDynamicModelTemplate::CheckSpecificParameters()
00135 {
00136   // ===================================================================
00137   // Implement here checks over parameters which should be read using either
00138   // ReadAndCheckConfigurationFile() and ReadAndCheckOptionsList() functions
00139   // ===================================================================
00140     
00141   if(m_verbose >=2) Cout("iDynamicModelTemplate::CheckSpecificParameters ..."<< endl); 
00142   
00143   // Normal end
00144   return 0;
00145 }
00146 
00147 
00148 
00149 
00150 // =====================================================================
00151 // ---------------------------------------------------------------------
00152 // ---------------------------------------------------------------------
00153 // =====================================================================
00154 /*
00155   \fn Initialize
00156   \brief This function is used to initialize Patlak parametric images and basis functions
00157   \return 0 if success, other value otherwise.
00158 */
00159 int iDynamicModelTemplate::Initialize()
00160 {
00161   if(m_verbose >=2) Cout("iDynamicModelTemplate::Initialize ..."<< endl); 
00162 
00163 
00164   // ===================================================================
00165   // Implement here the allocation/initialization of whatever member
00166   // variables specifically used by this deformation model
00167   // ===================================================================
00168   
00169   
00170   // Forbid initialization without check
00171   if (!m_checked)
00172   {
00173     Cerr("***** oDynamicModelManager::Initialize() -> Must call CheckParameters functions before Initialize() !" << endl);
00174     return 1;
00175   }
00176   
00177   // Normal end
00178   m_initialized = true;
00179   return 0;
00180 }
00181 
00182 
00183 
00184 
00185 // =====================================================================
00186 // ---------------------------------------------------------------------
00187 // ---------------------------------------------------------------------
00188 // =====================================================================
00189 /*
00190   \fn EstimateModelParameters
00191   \param ap_ImageS : pointer to the ImageSpace
00192   \param a_ite : index of the actual iteration (not used)
00193   \param a_sset : index of the actual subset (not used)
00194   \brief Estimate parametric images
00195   \return 0 if success, other value otherwise.
00196 */
00197 int iDynamicModelTemplate::EstimateModelParameters(oImageSpace* ap_ImageS, int a_ite, int a_sset) 
00198 {
00199   if(m_verbose >=2) Cout("iDynamicModelTemplate::EstimateModelParameters ..." <<endl);
00200 
00201   #ifdef CASTOR_DEBUG
00202   if (!m_initialized)
00203   {
00204     Cerr("***** iDynamicModelTemplate::EstimateModelParameters() -> Called while not initialized !" << endl);
00205     Exit(EXIT_DEBUG);
00206   }
00207   #endif
00208   
00209   // ===================================================================
00210   // Implement here the parametric images estimate after the image update
00211   // which occurs at the end of the iteration (or subset)
00212   //
00213   //
00214   // The main image matrices are stored in the ImageSpace object, passed
00215   // in argument.
00216   // The main image contains 4 dimensions :
00217   // ap_ImageS->m4p_image[fr][rg][cg][v]
00218   // fr = time frames
00219   // rg = respiratory gates
00220   // cg = cardiac gates
00221   //  v = actual voxel of the 3D volume
00222   
00223   /* IMAGE DIMENSIONS :
00224   * For code efficiency and readability, the spatial index of a voxel is a cumulative 1D index. That is to say, given a voxel [indexX,indexY,indexZ],
00225   * its cumulative 1D index is computed by 'index = indexZ*nbVoxXY + indexY*nbVoxX + indexX'.
00226   *
00227   * The image dimensions can be recovered from the mp_ID class
00228   * Total number of voxels         : mp_ID->GetNbVoxXYZ()
00229   * Number of voxels in a slice    : mp_ID->GetNbVoxXY()
00230   * Number of voxels on the X-axis : mp_ID->GetNbVoxX()
00231   */
00232   
00233   // Any error should return a value >0.
00234     
00235   // ===================================================================
00236   
00237   return 0;
00238 }
00239   
00240   
00241   
00242 // =====================================================================
00243 // ---------------------------------------------------------------------
00244 // ---------------------------------------------------------------------
00245 // =====================================================================
00246 /*
00247   \fn FitModel
00248   \param ap_ImageS : pointer to the ImageSpace
00249   \param a_ite : index of the actual iteration (not used)
00250   \param a_sset : index of the actual subset (not used)
00251   \brief Estimate image using Patlak parametric images and basis functions
00252   \return 0 if success, other value otherwise.
00253 */
00254 int iDynamicModelTemplate::FitModel(oImageSpace* ap_ImageS, int a_ite, int a_sset) 
00255 {
00256   if(m_verbose >= 2) Cout("iDynamicModelTemplate::FitModel ... " <<endl);
00257   
00258   #ifdef CASTOR_DEBUG
00259   if (!m_initialized)
00260   {
00261     Cerr("***** iDynamicModelTemplate::FitModel() -> Called while not initialized !" << endl);
00262     Exit(EXIT_DEBUG);
00263   }
00264   #endif
00265 
00266 
00267   // ===================================================================
00268   // Implement here the model fitting to the image which is called after
00269   // the EstimateModelParameters() function
00270   //
00271   //
00272   // The main image matrices are stored in the ImageSpace object, passed
00273   // in argument.
00274   // The main image contains 4 dimensions :
00275   // ap_ImageS->m4p_image[fr][rg][cg][v]
00276   // fr = time frames
00277   // rg = respiratory gates
00278   // cg = cardiac gates
00279   //  v = actual voxel of the 3D volume
00280   
00281   /* IMAGE DIMENSIONS :
00282   * For code efficiency and readability, the spatial index of a voxel is a cumulative 1D index. That is to say, given a voxel [indexX,indexY,indexZ],
00283   * its cumulative 1D index is computed by 'index = indexZ*nbVoxXY + indexY*nbVoxX + indexX'.
00284   *
00285   * The image dimensions can be recovered from the mp_ID class
00286   * Total number of voxels         : mp_ID->GetNbVoxXYZ()
00287   * Number of voxels in a slice    : mp_ID->GetNbVoxXY()
00288   * Number of voxels on the X-axis : mp_ID->GetNbVoxX()
00289   */
00290   
00291   // Any error should return a value >0.
00292     
00293   // ===================================================================
00294         
00295   return 0;
00296 }
00297 
00298 
00299 
00300 
00301 
00302 // =====================================================================
00303 // ---------------------------------------------------------------------
00304 // ---------------------------------------------------------------------
00305 // =====================================================================
00306 /*
00307   \fn SaveParametricImages
00308   \param ap_ImageS : pointer to the ImageSpace
00309   \param a_ite : index of the actual iteration
00310   \brief Write parametric images on disk if 'm_savePImgFlag' is enabled
00311   \return 0 if success, other value otherwise.
00312 */
00313 int iDynamicModelTemplate::SaveParametricImages(int a_ite)
00314 {
00315   if(m_verbose >=2) Cout("iDynamicModelTemplate::SaveParametricImages ..." <<endl);
00316   
00317 
00318   // ===================================================================
00319   // Implement here the parametric image output writting step, if needed
00320   // ===================================================================
00321 
00322   // Get the output manager which contains output directory
00323   sOutputManager* p_output_manager = sOutputManager::GetInstance();  
00324 
00325   // Interfile
00326   string path_to_image = p_output_manager->GetPathName() + p_output_manager->GetBaseName();
00327   
00328   // Add a suffix for iteration
00329   if (a_ite >= 0)
00330   {
00331     stringstream ss; ss << a_ite + 1;
00332     path_to_image.append("dynModel_it").append(ss.str());
00333   }
00334   
00335 
00336   
00337   // This function is dedicated to the output of parametric images
00338   if(IntfWriteImgDynCoeffFile(path_to_image, // path to the image (or metaheader) to write 
00339                               m2p_parametricImages, // parametric image to write.
00340                                                     // it must be a 2 dimensions array [nb of basis functions][nb of voxels]
00341                               mp_ID, // just the object containing image dimensions
00342                               m_nbTimeBF, // number of basis functions of the model
00343                               m_verbose) )
00344   {
00345     Cerr("***** iDynamicModelTemplate::SaveParametricImages()-> Error writing Interfile of output image !" << endl);  
00346     return 1;
00347   }
00348   
00349   return 0;
00350 }
00351 
00352 
 All Classes Files Functions Variables Typedefs Defines