CASToR  1.0
Tomographic Reconstruction (PET/SPECT)
iOptimizerTemplate.cc
Go to the documentation of this file.
00001 
00002 /*
00003   Implementation of the class iOptimizerMLEM
00004 
00005   - separators: X
00006   - doxygen: X
00007   - default initialization: X
00008   - CASTOR_DEBUG: 
00009   - CASTOR_VERBOSE: 
00010 */
00011 
00018 #include "iOptimizerTemplate.hh"
00019 #include "sOutputManager.hh"
00020 
00021 // =====================================================================
00022 // ---------------------------------------------------------------------
00023 // ---------------------------------------------------------------------
00024 // =====================================================================
00025 
00026 iOptimizerTemplate::iOptimizerTemplate() : vOptimizer()
00027 {
00028   // ---------------------------
00029   // Mandatory member parameters
00030   // (inherited from vOptimizer)
00031   // ---------------------------
00032 
00033   // Initial value of the image voxels before iterating
00034   m_initialValue = 1.;
00035   // The number of backward images used by the optimizer (most of the time it is 1, but it can be more for special cases)
00036   m_nbBackwardImages = 1;
00037   // Specify here is the optimizer is compatible with list-mode and/or histogram data
00038   m_listmodeCompatibility = true;
00039   m_histogramCompatibility = true;
00040 
00041   // --------------------------
00042   // Specific member parameters
00043   // --------------------------
00044 
00045   // Set here the default values of the parameters specific to this optimizer
00046 
00047 }
00048 
00049 // =====================================================================
00050 // ---------------------------------------------------------------------
00051 // ---------------------------------------------------------------------
00052 // =====================================================================
00053 
00054 iOptimizerTemplate::~iOptimizerTemplate()
00055 {
00056   // Delete or free ONLY things that were built into this class
00057 }
00058 
00059 // =====================================================================
00060 // ---------------------------------------------------------------------
00061 // ---------------------------------------------------------------------
00062 // =====================================================================
00063 
00064 void iOptimizerTemplate::ShowHelpSpecific()
00065 {
00066   cout << "This optimizer is only a squeleton template to explain how to add an optimizer into CASToR." << endl;
00067   cout << "If you want to implement your own optimizer, start from here." << endl;
00068   cout << "The following options can be used (in this particular order when provided as a list):" << endl;
00069   cout << "  my parameter: blablabla" << endl;
00070 }
00071 
00072 // =====================================================================
00073 // ---------------------------------------------------------------------
00074 // ---------------------------------------------------------------------
00075 // =====================================================================
00076 
00077 int iOptimizerTemplate::ReadConfigurationFile(const string& a_configurationFile)
00078 {
00079   // This function is designed to read parameters specific to the optimizer through a configuration file.
00080   // To do that, use the ReadDataASCIIFile() function, and take a look at other optimizers to see how it is done.
00081   // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
00082   // Return 1 if any problem.
00083 
00084   // Normal end
00085   return 0;
00086 }
00087 
00088 // =====================================================================
00089 // ---------------------------------------------------------------------
00090 // ---------------------------------------------------------------------
00091 // =====================================================================
00092 
00093 int iOptimizerTemplate::ReadOptionsList(const string& a_optionsList)
00094 {
00095   // This function is designed to read parameters specific to the optimizer through a list of options in a string.
00096   // To do that, use the ReadStringOption() function, and take a look at other optimizers to see how it is done.
00097   // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
00098   // Return 1 if any problem.
00099 
00100   // Normal end
00101   return 0;
00102 }
00103 
00104 // =====================================================================
00105 // ---------------------------------------------------------------------
00106 // ---------------------------------------------------------------------
00107 // =====================================================================
00108 
00109 int iOptimizerTemplate::CheckSpecificParameters()
00110 {
00111   // This function is designed to check that all parameters specific to the optimizer have been set properly.
00112   // Return 1 if any problem.
00113 
00114   // Normal end
00115   return 0;
00116 }
00117 
00118 // =====================================================================
00119 // ---------------------------------------------------------------------
00120 // ---------------------------------------------------------------------
00121 // =====================================================================
00122 
00123 int iOptimizerTemplate::InitializeSpecific()
00124 {
00125   // Verbose
00126   if (m_verbose>=1) Cout("iOptimizerTemplate::Initialize() -> Use the template optimizer" << endl);
00127 
00128   // This function is designed to initialize everything that should be initialized before being able to launch the iteration.
00129   // Return 1 if any problem.
00130 
00131   // Normal end
00132   return 0;
00133 }
00134 
00135 // =====================================================================
00136 // ---------------------------------------------------------------------
00137 // ---------------------------------------------------------------------
00138 // =====================================================================
00139 
00140 int iOptimizerTemplate::SensitivitySpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_weight,
00141                                                        FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections,
00142                                                        FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
00143 {
00144   // The purpose of this function is to assign the weight of the event. In most cases, it is simply 1 (note that all multiplicative
00145   // terms belonging to the system matrix are automatically taken into account during the back-projection, explaining why the weight
00146   // is simply 1 in most cases). The weight should be put into *ap_weight.
00147   // About the parameters:
00148   //   a_data: is the data of the event (in number of counts; 1 if list-mode data, and any value for histogram data)
00149   //   a_forwardModel: is the forward model (also in number of counts); this the forward projection of the image including all system matrix
00150   //                   related multiplicative terms as well as the additive terms; so it is directly comparable to the data
00151   //   ap_weight: is where the result should be put in
00152   //   a_multiplicativeCorrections: is the multiplicative corrections specific to the event; in other words, it does not contain the
00153   //                                multiplicative factors global to the image, which are given in a separate parameter as a_quantificationFactor
00154   //   a_additiveCorrections: is the additive terms (in number of counts); e.g. scatters and randoms for PET
00155   //   a_quantificationFactor: is the quantification factor associated to the image where the event belongs to
00156   //   ap_Line: is the projection line associated to the event; in case a forward projection should be perform, it must be passed to the
00157   //            ForwardProject() function as an argument
00158   // Finally, note that this function is only called for histogram data. For list-mode data, the sensitivity is computed before launching the
00159   // the iterations, assuming weights of 1. So if the weights here for the specific optimizer are different than 1, then the optimizer cannot
00160   // handle list-mode data, so remember to set the m_listmodeCompatibility flag to false in the constructor, in such a case.
00161 
00162   *ap_weight = 1.;
00163 
00164   // That's all
00165   return 0;
00166 }
00167 
00168 // =====================================================================
00169 // ---------------------------------------------------------------------
00170 // ---------------------------------------------------------------------
00171 // =====================================================================
00172 
00173 int iOptimizerTemplate::DataSpaceSpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_backwardValues,
00174                                                      FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections,
00175                                                      FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
00176 {
00177   // The purpose of this function is to perform the data space operations specific to the optimizer (this function is called for each event)
00178   // in order to compute the correction terms that need to be back-projected. This value should be put into *ap_backwardValues. In case the
00179   // optimization requires multiple backward images, one must simply set the number of backward images into the constructor as m_nbBackwardImages.
00180   // Then, the multiple values to be back-projected can be put in ap_backwardValues[0], ap_backwardValues[1], etc.
00181   // About the parameters:
00182   //   a_data: is the data of the event (in number of counts; 1 if list-mode data, and any value for histogram data)
00183   //   a_forwardModel: is the forward model (also in number of counts); this the forward projection of the image including all system matrix
00184   //                   related multiplicative terms as well as the additive terms; so it is directly comparable to the data
00185   //   ap_backwardValues: is where the result should be put in (multiple values is accepted if m_nbBackwardImages>1)
00186   //   a_multiplicativeCorrections: is the multiplicative corrections specific to the event; in other words, it does not contain the
00187   //                                multiplicative factors global to the image, which are given in a separate parameter as a_quantificationFactor
00188   //   a_additiveCorrections: is the additive terms (in number of counts); e.g. scatters and randoms for PET
00189   //   a_quantificationFactor: is the quantification factor associated to the image where the event belongs to
00190   //   ap_Line: is the projection line associated to the event; in case a forward projection should be perform, it must be passed to the
00191   //            ForwardProject() function as an argument
00192   // Look at the optimizers already implemented in order to get an idea of how to do it.
00193 
00194   *ap_backwardValues = 1.;
00195 
00196   // That's all
00197   return 0;
00198 }
00199 
00200 // =====================================================================
00201 // ---------------------------------------------------------------------
00202 // ---------------------------------------------------------------------
00203 // =====================================================================
00204 
00205 int iOptimizerTemplate::ImageSpaceSpecificOperations( FLTNB a_currentImageValue, FLTNB* ap_newImageValue,
00206                                                       FLTNB a_sensitivity, FLTNB* ap_correctionValues )
00207 {
00208   // The purpose of this function is to perform the image space operations specific to the optimizer (this function is called for each voxel).
00209   // In other words, the new voxel value has to be computed based on the previous one, the sensitivity and the correction values which are the
00210   // back-projected correction terms computed in the DataSpaceSpecificOperations() function (there can be multiple correction values if
00211   // m_nbBackwardImages>1). Note that being here means that the sensitivity value is not 0, so no need to check it.
00212 
00213   *ap_newImageValue = a_currentImageValue;
00214 
00215   // End
00216   return 0;
00217 }
00218 
00219 // =====================================================================
00220 // ---------------------------------------------------------------------
00221 // ---------------------------------------------------------------------
00222 // =====================================================================
 All Classes Files Functions Variables Typedefs Defines