CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
iOptimizerTemplate.cc
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2019 all CASToR contributors listed below:
18 
19  --> Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Thibaut MERLIN, Mael MILLARDET, Simon STUTE, Valentin VIELZEUF
20 
21 This is CASToR version 3.0.
22 */
23 
30 #include "iOptimizerTemplate.hh"
31 #include "sOutputManager.hh"
32 
33 // =====================================================================
34 // ---------------------------------------------------------------------
35 // ---------------------------------------------------------------------
36 // =====================================================================
37 
39 {
40  // ---------------------------
41  // Mandatory member parameters
42  // (inherited from vOptimizer)
43  // ---------------------------
44 
45  // Initial value of the image voxels before iterating
46  m_initialValue = 1.;
47  // The number of backward images used by the optimizer (most of the time it is 1, but it can be more for special cases)
49  // Specify here if the optimizer is compatible with list-mode and/or histogram data
52  // Specify here if the optimizer is compatible with emission and/or transmission data
55  // If the optimizer admits a penalty term, then specify the required minimum derivative order of the penalty.
56  // Otherwise, set it negative or just do nothing as it is already set to a negative value in vOptimizer.
58  // Some optimizers may require a global sensitivity with histogram data, as opposed to a sensitivity specific to each
59  // subset (i.e. computed only from LORs in the subset). In this case, just set the following flag to true.
61 
62  // --------------------------
63  // Specific member parameters
64  // --------------------------
65 
66  // Set here the default values of the parameters specific to this optimizer
67 
68 }
69 
70 // =====================================================================
71 // ---------------------------------------------------------------------
72 // ---------------------------------------------------------------------
73 // =====================================================================
74 
76 {
77  // Delete or free ONLY things that were built into this class
78 }
79 
80 // =====================================================================
81 // ---------------------------------------------------------------------
82 // ---------------------------------------------------------------------
83 // =====================================================================
84 
86 {
87  cout << "This optimizer is only a squeleton template to explain how to add an optimizer into CASToR. If you" << endl;
88  cout << "want to implement your own optimizer, start from here and look at the specific documentation." << endl;
89 }
90 
91 // =====================================================================
92 // ---------------------------------------------------------------------
93 // ---------------------------------------------------------------------
94 // =====================================================================
95 
96 int iOptimizerTemplate::ReadConfigurationFile(const string& a_configurationFile)
97 {
98  // This function is designed to read parameters specific to the optimizer through a configuration file.
99  // To do that, use the ReadDataASCIIFile() function, and take a look at other optimizers to see how it is done.
100  // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
101  // Return 1 if any problem. See other optimizers' implementation to get guidance.
102 
103  // Normal end
104  return 0;
105 }
106 
107 // =====================================================================
108 // ---------------------------------------------------------------------
109 // ---------------------------------------------------------------------
110 // =====================================================================
111 
112 int iOptimizerTemplate::ReadOptionsList(const string& a_optionsList)
113 {
114  // This function is designed to read parameters specific to the optimizer through a list of options in a string.
115  // To do that, use the ReadStringOption() function, and take a look at other optimizers to see how it is done.
116  // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
117  // Return 1 if any problem. See other optimizers' implementation to get guidance.
118 
119  // Normal end
120  return 0;
121 }
122 
123 // =====================================================================
124 // ---------------------------------------------------------------------
125 // ---------------------------------------------------------------------
126 // =====================================================================
127 
129 {
130  // This function is designed to check that all parameters specific to the optimizer have been set properly.
131  // Return 1 if any problem.
132 
133  // Normal end
134  return 0;
135 }
136 
137 // =====================================================================
138 // ---------------------------------------------------------------------
139 // ---------------------------------------------------------------------
140 // =====================================================================
141 
143 {
144  // Verbose
145  if (m_verbose>=2) Cout("iOptimizerTemplate::InitializeSpecific() -> Use the template optimizer" << endl);
146 
147  // This function is designed to initialize everything that should be initialized before being able to launch the iteration.
148  // Return 1 if any problem.
149 
150  // If additional miscellaneous images are needed, you may use the AllocateMiscellaneousImage() function from the oImageSpace
151  // to create some. Look at the iOptimizerOneStepLate for example.
152 
153  // Normal end
154  return 0;
155 }
156 
157 // =====================================================================
158 // ---------------------------------------------------------------------
159 // ---------------------------------------------------------------------
160 // =====================================================================
161 
163 {
164  // This function from the vOptimizer does nothing by default and is virtual. So it can be overloaded
165  // here in order to perform some operations, especially related to the computation of a penalty term
166  // if the optimizer is designed to include such a term. See other algorithms that admits a penalty
167  // term, like the iOptimizerOneStepLate for example.
168  // If you do not need it, it is recommended to remove this implementation and its declaration in the associated header file
169  // so that the default empty one from the mother class is used.
170 
171  // Normal end
172  return 0;
173 }
174 
175 // =====================================================================
176 // ---------------------------------------------------------------------
177 // ---------------------------------------------------------------------
178 // =====================================================================
179 
180 int iOptimizerTemplate::SensitivitySpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_weight,
181  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
182  FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
183 {
184  // The purpose of this function is to assign the weight of the event. In most cases, it is simply 1 (note that all multiplicative
185  // terms belonging to the system matrix are automatically taken into account during the back-projection, explaining why the weight
186  // is simply 1 in most cases). The weight should be put into *ap_weight.
187  // About the parameters:
188  // a_data: is the data of the event (in number of counts; 1 if list-mode data, and any value for histogram data)
189  // a_forwardModel: is the forward model (also in number of counts); this the forward projection of the image including all system matrix
190  // related multiplicative terms as well as the additive terms; so it is directly comparable to the data
191  // ap_weight: is where the result should be put in
192  // a_multiplicativeCorrections: is the multiplicative corrections specific to the event; in other words, it does not contain the
193  // multiplicative factors global to the image, which are given in a separate parameter as a_quantificationFactor
194  // a_additiveCorrections: is the additive terms (in number of counts); e.g. scatters and randoms for PET
195  // a_blankValue: is the blank measurement in transmission tomography
196  // a_quantificationFactor: is the quantification factor associated to the image where the event belongs to
197  // ap_Line: is the projection line associated to the event; in case a forward projection should be perform, it must be passed to the
198  // ForwardProject() function as an argument
199  // Finally, note that this function is only called for histogram data. For list-mode data, the sensitivity is computed before launching the
200  // the iterations, assuming weights of 1. So if the weights here for the specific optimizer are different than 1, then the optimizer cannot
201  // handle list-mode data, so remember to set the m_listmodeCompatibility flag to false in the constructor, in such a case.
202 
203  *ap_weight = 1.;
204 
205  // That's all
206  return 0;
207 }
208 
209 // =====================================================================
210 // ---------------------------------------------------------------------
211 // ---------------------------------------------------------------------
212 // =====================================================================
213 
214 int iOptimizerTemplate::DataSpaceSpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_backwardValues,
215  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
216  FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
217 {
218  // The purpose of this function is to perform the data space operations specific to the optimizer (this function is called for each event)
219  // in order to compute the correction terms that need to be back-projected. This value should be put into *ap_backwardValues. In case the
220  // optimization requires multiple backward images, one must simply set the number of backward images into the constructor as m_nbBackwardImages.
221  // Then, the multiple values to be back-projected can be put in ap_backwardValues[0], ap_backwardValues[1], etc.
222  // About the parameters:
223  // a_data: is the data of the event (in number of counts; 1 if list-mode data, and any value for histogram data)
224  // a_forwardModel: is the forward model (also in number of counts); this the forward projection of the image including all system matrix
225  // related multiplicative terms as well as the additive terms; so it is directly comparable to the data
226  // ap_backwardValues: is where the result should be put in (multiple values is accepted if m_nbBackwardImages>1)
227  // a_multiplicativeCorrections: is the multiplicative corrections specific to the event; in other words, it does not contain the
228  // multiplicative factors global to the image, which are given in a separate parameter as a_quantificationFactor
229  // a_additiveCorrections: is the additive terms (in number of counts); e.g. scatters and randoms for PET
230  // a_blankValue: is the blank measurement in transmission tomography
231  // a_quantificationFactor: is the quantification factor associated to the image where the event belongs to
232  // ap_Line: is the projection line associated to the event; in case a forward projection should be perform, it must be passed to the
233  // ForwardProject() function as an argument
234  // Look at the optimizers already implemented in order to get an idea of how to do it.
235 
236  *ap_backwardValues = 1.;
237 
238  // That's all
239  return 0;
240 }
241 
242 // =====================================================================
243 // ---------------------------------------------------------------------
244 // ---------------------------------------------------------------------
245 // =====================================================================
246 
247 int iOptimizerTemplate::ImageSpaceSpecificOperations( FLTNB a_currentImageValue, FLTNB* ap_newImageValue,
248  FLTNB a_sensitivity, FLTNB* ap_correctionValues,
249  INTNB a_voxel, int a_tbf, int a_rbf, int a_cbf )
250 {
251  // The purpose of this function is to perform the image space operations specific to the optimizer (this function is called for each voxel).
252  // 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
253  // back-projected correction terms computed in the DataSpaceSpecificOperations() function (there can be multiple correction values if
254  // m_nbBackwardImages>1). Note that being here means that the sensitivity value is not 0, so no need to check it.
255 
256  *ap_newImageValue = a_currentImageValue;
257 
258  // End
259  return 0;
260 }
261 
262 // =====================================================================
263 // ---------------------------------------------------------------------
264 // ---------------------------------------------------------------------
265 // =====================================================================
int m_requiredPenaltyDerivativesOrder
Definition: vOptimizer.hh:697
#define FLTNB
Definition: gVariables.hh:81
FLTNB m_initialValue
Definition: vOptimizer.hh:663
bool m_listmodeCompatibility
Definition: vOptimizer.hh:664
~iOptimizerTemplate()
The destructor of iOptimizerTemplate.
bool m_needGlobalSensitivity
Definition: vOptimizer.hh:699
bool m_emissionCompatibility
Definition: vOptimizer.hh:666
Declaration of class iOptimizerTemplate.
int m_nbBackwardImages
Definition: vOptimizer.hh:659
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)
This function perform the image update step specific to the optimizer.
bool m_histogramCompatibility
Definition: vOptimizer.hh:665
int ReadOptionsList(const string &a_optionsList)
A function used to read options from a list of options.
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. ...
#define INTNB
Definition: gVariables.hh:92
bool m_transmissionCompatibility
Definition: vOptimizer.hh:667
This class is designed to generically described any iterative optimizer.
Definition: vOptimizer.hh:59
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)
This function compute the weight associated to the provided event (for sensitivity computation) ...
Declaration of class sOutputManager.
#define Cout(MESSAGE)
int ReadConfigurationFile(const string &a_configurationFile)
A function used to read options from a configuration file.
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)
This function performs the data space operations specific to the optimizer (computes the values to be...