CASToR  3.2
Tomographic Reconstruction (PET/SPECT/CT)
src/optimizer/iOptimizerTemplate.cc
Go to the documentation of this file.
1 
8 #include "iOptimizerTemplate.hh"
9 #include "sOutputManager.hh"
10 
11 // =====================================================================
12 // ---------------------------------------------------------------------
13 // ---------------------------------------------------------------------
14 // =====================================================================
15 
17 {
18  // ---------------------------
19  // Mandatory member parameters
20  // (inherited from vOptimizer)
21  // ---------------------------
22 
23  // Initial value of the image voxels before iterating
24  m_initialValue = 1.;
25  // The number of backward images used by the optimizer (most of the time it is 1, but it can be more for special cases)
27  // Specify here if the optimizer is compatible with list-mode and/or histogram data
30  // Specify here if the optimizer is compatible with emission and/or transmission data
33  // If the optimizer admits a penalty term, then specify the required minimum derivative order of the penalty.
34  // Otherwise, set it negative or just do nothing as it is already set to a negative value in vOptimizer.
36  // Some optimizers may require a global sensitivity with histogram data, as opposed to a sensitivity specific to each
37  // subset (i.e. computed only from LORs in the subset). In this case, just set the following flag to true.
39 
40  // --------------------------
41  // Specific member parameters
42  // --------------------------
43 
44  // Set here the default values of the parameters specific to this optimizer
45 
46 }
47 
48 // =====================================================================
49 // ---------------------------------------------------------------------
50 // ---------------------------------------------------------------------
51 // =====================================================================
52 
54 {
55  // Delete or free ONLY things that were built into this class
56 }
57 
58 // =====================================================================
59 // ---------------------------------------------------------------------
60 // ---------------------------------------------------------------------
61 // =====================================================================
62 
64 {
65  cout << "This optimizer is only a squeleton template to explain how to add an optimizer into CASToR. If you" << endl;
66  cout << "want to implement your own optimizer, start from here and look at the specific documentation." << endl;
67 }
68 
69 // =====================================================================
70 // ---------------------------------------------------------------------
71 // ---------------------------------------------------------------------
72 // =====================================================================
73 
74 int iOptimizerTemplate::ReadConfigurationFile(const string& a_configurationFile)
75 {
76  // This function is designed to read parameters specific to the optimizer through a configuration file.
77  // To do that, use the ReadDataASCIIFile() function, and take a look at other optimizers to see how it is done.
78  // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
79  // Return 1 if any problem. See other optimizers' implementation to get guidance.
80 
81  // Normal end
82  return 0;
83 }
84 
85 // =====================================================================
86 // ---------------------------------------------------------------------
87 // ---------------------------------------------------------------------
88 // =====================================================================
89 
90 int iOptimizerTemplate::ReadOptionsList(const string& a_optionsList)
91 {
92  // This function is designed to read parameters specific to the optimizer through a list of options in a string.
93  // To do that, use the ReadStringOption() function, and take a look at other optimizers to see how it is done.
94  // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
95  // Return 1 if any problem. See other optimizers' implementation to get guidance.
96 
97  // Normal end
98  return 0;
99 }
100 
101 // =====================================================================
102 // ---------------------------------------------------------------------
103 // ---------------------------------------------------------------------
104 // =====================================================================
105 
107 {
108  // This function is designed to check that all parameters specific to the optimizer have been set properly.
109  // Return 1 if any problem.
110 
111  // Normal end
112  return 0;
113 }
114 
115 // =====================================================================
116 // ---------------------------------------------------------------------
117 // ---------------------------------------------------------------------
118 // =====================================================================
119 
121 {
122  // Verbose
123  if (m_verbose>=2) Cout("iOptimizerTemplate::InitializeSpecific() -> Use the template optimizer" << endl);
124 
125  // This function is designed to initialize everything that should be initialized before being able to launch the iteration.
126  // Return 1 if any problem.
127 
128  // If additional miscellaneous images are needed, you may use the AllocateMiscellaneousImage() function from the oImageSpace
129  // to create some. Look at the iOptimizerOneStepLate for example.
130 
131  // Normal end
132  return 0;
133 }
134 
135 // =====================================================================
136 // ---------------------------------------------------------------------
137 // ---------------------------------------------------------------------
138 // =====================================================================
139 
141 {
142  // This function from the vOptimizer does nothing by default and is virtual. So it can be overloaded
143  // here in order to perform some operations, especially related to the computation of a penalty term
144  // if the optimizer is designed to include such a term. See other algorithms that admits a penalty
145  // term, like the iOptimizerOneStepLate for example.
146  // If you do not need it, it is recommended to remove this implementation and its declaration in the associated header file
147  // so that the default empty one from the mother class is used.
148 
149  // Normal end
150  return 0;
151 }
152 
153 // =====================================================================
154 // ---------------------------------------------------------------------
155 // ---------------------------------------------------------------------
156 // =====================================================================
157 
158 int iOptimizerTemplate::SensitivitySpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_weight,
159  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
160  FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
161 {
162  // The purpose of this function is to assign the weight of the event. In most cases, it is simply 1 (note that all multiplicative
163  // terms belonging to the system matrix are automatically taken into account during the back-projection, explaining why the weight
164  // is simply 1 in most cases). The weight should be put into *ap_weight.
165  // About the parameters:
166  // a_data: is the data of the event (in number of counts; 1 if list-mode data, and any value for histogram data)
167  // a_forwardModel: is the forward model (also in number of counts); this the forward projection of the image including all system matrix
168  // related multiplicative terms as well as the additive terms; so it is directly comparable to the data
169  // ap_weight: is where the result should be put in
170  // a_multiplicativeCorrections: is the multiplicative corrections specific to the event; in other words, it does not contain the
171  // multiplicative factors global to the image, which are given in a separate parameter as a_quantificationFactor
172  // a_additiveCorrections: is the additive terms (in number of counts); e.g. scatters and randoms for PET
173  // a_blankValue: is the blank measurement in transmission tomography
174  // a_quantificationFactor: is the quantification factor associated to the image where the event belongs to
175  // ap_Line: is the projection line associated to the event; in case a forward projection should be perform, it must be passed to the
176  // ForwardProject() function as an argument
177  // Finally, note that this function is only called for histogram data. For list-mode data, the sensitivity is computed before launching the
178  // the iterations, assuming weights of 1. So if the weights here for the specific optimizer are different than 1, then the optimizer cannot
179  // handle list-mode data, so remember to set the m_listmodeCompatibility flag to false in the constructor, in such a case.
180 
181  *ap_weight = 1.;
182 
183  // That's all
184  return 0;
185 }
186 
187 // =====================================================================
188 // ---------------------------------------------------------------------
189 // ---------------------------------------------------------------------
190 // =====================================================================
191 
192 int iOptimizerTemplate::DataSpaceSpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_backwardValues,
193  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
194  FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
195 {
196  // The purpose of this function is to perform the data space operations specific to the optimizer (this function is called for each event)
197  // in order to compute the correction terms that need to be back-projected. This value should be put into *ap_backwardValues. In case the
198  // optimization requires multiple backward images, one must simply set the number of backward images into the constructor as m_nbBackwardImages.
199  // Then, the multiple values to be back-projected can be put in ap_backwardValues[0], ap_backwardValues[1], etc.
200  // About the parameters:
201  // a_data: is the data of the event (in number of counts; 1 if list-mode data, and any value for histogram data)
202  // a_forwardModel: is the forward model (also in number of counts); this the forward projection of the image including all system matrix
203  // related multiplicative terms as well as the additive terms; so it is directly comparable to the data
204  // ap_backwardValues: is where the result should be put in (multiple values is accepted if m_nbBackwardImages>1)
205  // a_multiplicativeCorrections: is the multiplicative corrections specific to the event; in other words, it does not contain the
206  // multiplicative factors global to the image, which are given in a separate parameter as a_quantificationFactor
207  // a_additiveCorrections: is the additive terms (in number of counts); e.g. scatters and randoms for PET
208  // a_blankValue: is the blank measurement in transmission tomography
209  // a_quantificationFactor: is the quantification factor associated to the image where the event belongs to
210  // ap_Line: is the projection line associated to the event; in case a forward projection should be perform, it must be passed to the
211  // ForwardProject() function as an argument
212  // Look at the optimizers already implemented in order to get an idea of how to do it.
213 
214  *ap_backwardValues = 1.;
215 
216  // That's all
217  return 0;
218 }
219 
220 // =====================================================================
221 // ---------------------------------------------------------------------
222 // ---------------------------------------------------------------------
223 // =====================================================================
224 
225 int iOptimizerTemplate::ImageSpaceSpecificOperations( FLTNB a_currentImageValue, FLTNB* ap_newImageValue,
226  FLTNB a_sensitivity, FLTNB* ap_correctionValues,
227  INTNB a_voxel, int a_tbf, int a_rbf, int a_cbf )
228 {
229  // The purpose of this function is to perform the image space operations specific to the optimizer (this function is called for each voxel).
230  // 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
231  // back-projected correction terms computed in the DataSpaceSpecificOperations() function (there can be multiple correction values if
232  // m_nbBackwardImages>1). Note that being here means that the sensitivity value is not 0, so no need to check it.
233 
234  *ap_newImageValue = a_currentImageValue;
235 
236  // End
237  return 0;
238 }
239 
240 // =====================================================================
241 // ---------------------------------------------------------------------
242 // ---------------------------------------------------------------------
243 // =====================================================================
~iOptimizerTemplate()
The destructor of iOptimizerTemplate.
iOptimizerTemplate()
The constructor of iOptimizerTemplate.
int CheckSpecificParameters()
A private function used to check the parameters settings specific to the child optimizer.
int ImageSpaceSpecificOperations(FLTNB a_currentImageValue, FLTNB *ap_newImageValue, FLTNB a_sensitivity, FLTNB *ap_correctionValues, INTNB a_voxel, int a_tbf=-1, int a_rbf=-1, int a_cbf=-1)
int ReadOptionsList(const string &a_optionsList)
int InitializeSpecific()
This function is used to initialize specific stuff to the child optimizer.
int PreImageUpdateSpecificStep()
A private function used to compute the penalty term of the OneStepLate algorithm. ...
This class is designed to generically described any iterative optimizer.
This class is designed to manage and store system matrix elements associated to a vEvent...
int SensitivitySpecificOperations(FLTNB a_data, FLTNB a_forwardModel, FLTNB *ap_weight, FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue, FLTNB a_quantificationFactor, oProjectionLine *ap_Line)
int ReadConfigurationFile(const string &a_configurationFile)
#define Cout(MESSAGE)
void ShowHelpSpecific()
A function used to show help about the child optimizer.
int DataSpaceSpecificOperations(FLTNB a_data, FLTNB a_forwardModel, FLTNB *ap_backwardValues, FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue, FLTNB a_quantificationFactor, oProjectionLine *ap_Line)