CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-2018 all CASToR contributors listed below:
18 
19  --> current contributors: Thibaut MERLIN, Simon STUTE, Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Mael MILLARDET
20  --> past contributors: Valentin VIELZEUF
21 
22 This is CASToR version 2.0.
23 */
24 
31 #include "iOptimizerTemplate.hh"
32 #include "sOutputManager.hh"
33 
34 // =====================================================================
35 // ---------------------------------------------------------------------
36 // ---------------------------------------------------------------------
37 // =====================================================================
38 
40 {
41  // ---------------------------
42  // Mandatory member parameters
43  // (inherited from vOptimizer)
44  // ---------------------------
45 
46  // Initial value of the image voxels before iterating
47  m_initialValue = 1.;
48  // The number of backward images used by the optimizer (most of the time it is 1, but it can be more for special cases)
50  // Specify here if the optimizer is compatible with list-mode and/or histogram data
53  // Specify here if the optimizer is compatible with emission and/or transmission data
56 
57  // --------------------------
58  // Specific member parameters
59  // --------------------------
60 
61  // Set here the default values of the parameters specific to this optimizer
62 
63 }
64 
65 // =====================================================================
66 // ---------------------------------------------------------------------
67 // ---------------------------------------------------------------------
68 // =====================================================================
69 
71 {
72  // Delete or free ONLY things that were built into this class
73 }
74 
75 // =====================================================================
76 // ---------------------------------------------------------------------
77 // ---------------------------------------------------------------------
78 // =====================================================================
79 
81 {
82  cout << "This optimizer is only a squeleton template to explain how to add an optimizer into CASToR." << endl;
83  cout << "If you want to implement your own optimizer, start from here." << endl;
84  cout << "The following options can be used (in this particular order when provided as a list):" << endl;
85  cout << " my parameter: blablabla" << endl;
86 }
87 
88 // =====================================================================
89 // ---------------------------------------------------------------------
90 // ---------------------------------------------------------------------
91 // =====================================================================
92 
93 int iOptimizerTemplate::ReadConfigurationFile(const string& a_configurationFile)
94 {
95  // This function is designed to read parameters specific to the optimizer through a configuration file.
96  // To do that, use the ReadDataASCIIFile() function, and take a look at other optimizers to see how it is done.
97  // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
98  // Return 1 if any problem.
99 
100  // Normal end
101  return 0;
102 }
103 
104 // =====================================================================
105 // ---------------------------------------------------------------------
106 // ---------------------------------------------------------------------
107 // =====================================================================
108 
109 int iOptimizerTemplate::ReadOptionsList(const string& a_optionsList)
110 {
111  // This function is designed to read parameters specific to the optimizer through a list of options in a string.
112  // To do that, use the ReadStringOption() function, and take a look at other optimizers to see how it is done.
113  // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
114  // Return 1 if any problem.
115 
116  // Normal end
117  return 0;
118 }
119 
120 // =====================================================================
121 // ---------------------------------------------------------------------
122 // ---------------------------------------------------------------------
123 // =====================================================================
124 
126 {
127  // This function is designed to check that all parameters specific to the optimizer have been set properly.
128  // Return 1 if any problem.
129 
130  // Normal end
131  return 0;
132 }
133 
134 // =====================================================================
135 // ---------------------------------------------------------------------
136 // ---------------------------------------------------------------------
137 // =====================================================================
138 
140 {
141  // Verbose
142  if (m_verbose>=2) Cout("iOptimizerTemplate::InitializeSpecific() -> Use the template optimizer" << endl);
143 
144  // This function is designed to initialize everything that should be initialized before being able to launch the iteration.
145  // Return 1 if any problem.
146 
147  // Normal end
148  return 0;
149 }
150 
151 // =====================================================================
152 // ---------------------------------------------------------------------
153 // ---------------------------------------------------------------------
154 // =====================================================================
155 
156 int iOptimizerTemplate::SensitivitySpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_weight,
157  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
158  FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
159 {
160  // The purpose of this function is to assign the weight of the event. In most cases, it is simply 1 (note that all multiplicative
161  // terms belonging to the system matrix are automatically taken into account during the back-projection, explaining why the weight
162  // is simply 1 in most cases). The weight should be put into *ap_weight.
163  // About the parameters:
164  // a_data: is the data of the event (in number of counts; 1 if list-mode data, and any value for histogram data)
165  // a_forwardModel: is the forward model (also in number of counts); this the forward projection of the image including all system matrix
166  // related multiplicative terms as well as the additive terms; so it is directly comparable to the data
167  // ap_weight: is where the result should be put in
168  // a_multiplicativeCorrections: is the multiplicative corrections specific to the event; in other words, it does not contain the
169  // multiplicative factors global to the image, which are given in a separate parameter as a_quantificationFactor
170  // a_additiveCorrections: is the additive terms (in number of counts); e.g. scatters and randoms for PET
171  // a_blankValue: is the blank measurement in transmission tomography
172  // a_quantificationFactor: is the quantification factor associated to the image where the event belongs to
173  // ap_Line: is the projection line associated to the event; in case a forward projection should be perform, it must be passed to the
174  // ForwardProject() function as an argument
175  // Finally, note that this function is only called for histogram data. For list-mode data, the sensitivity is computed before launching the
176  // the iterations, assuming weights of 1. So if the weights here for the specific optimizer are different than 1, then the optimizer cannot
177  // handle list-mode data, so remember to set the m_listmodeCompatibility flag to false in the constructor, in such a case.
178 
179  *ap_weight = 1.;
180 
181  // That's all
182  return 0;
183 }
184 
185 // =====================================================================
186 // ---------------------------------------------------------------------
187 // ---------------------------------------------------------------------
188 // =====================================================================
189 
190 int iOptimizerTemplate::DataSpaceSpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_backwardValues,
191  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
192  FLTNB a_quantificationFactor, oProjectionLine* ap_Line )
193 {
194  // The purpose of this function is to perform the data space operations specific to the optimizer (this function is called for each event)
195  // in order to compute the correction terms that need to be back-projected. This value should be put into *ap_backwardValues. In case the
196  // optimization requires multiple backward images, one must simply set the number of backward images into the constructor as m_nbBackwardImages.
197  // Then, the multiple values to be back-projected can be put in ap_backwardValues[0], ap_backwardValues[1], etc.
198  // About the parameters:
199  // a_data: is the data of the event (in number of counts; 1 if list-mode data, and any value for histogram data)
200  // a_forwardModel: is the forward model (also in number of counts); this the forward projection of the image including all system matrix
201  // related multiplicative terms as well as the additive terms; so it is directly comparable to the data
202  // ap_backwardValues: is where the result should be put in (multiple values is accepted if m_nbBackwardImages>1)
203  // a_multiplicativeCorrections: is the multiplicative corrections specific to the event; in other words, it does not contain the
204  // multiplicative factors global to the image, which are given in a separate parameter as a_quantificationFactor
205  // a_additiveCorrections: is the additive terms (in number of counts); e.g. scatters and randoms for PET
206  // a_blankValue: is the blank measurement in transmission tomography
207  // a_quantificationFactor: is the quantification factor associated to the image where the event belongs to
208  // ap_Line: is the projection line associated to the event; in case a forward projection should be perform, it must be passed to the
209  // ForwardProject() function as an argument
210  // Look at the optimizers already implemented in order to get an idea of how to do it.
211 
212  *ap_backwardValues = 1.;
213 
214  // That's all
215  return 0;
216 }
217 
218 // =====================================================================
219 // ---------------------------------------------------------------------
220 // ---------------------------------------------------------------------
221 // =====================================================================
222 
223 int iOptimizerTemplate::ImageSpaceSpecificOperations( FLTNB a_currentImageValue, FLTNB* ap_newImageValue,
224  FLTNB a_sensitivity, FLTNB* ap_correctionValues, INTNB a_voxel )
225 {
226  // The purpose of this function is to perform the image space operations specific to the optimizer (this function is called for each voxel).
227  // 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
228  // back-projected correction terms computed in the DataSpaceSpecificOperations() function (there can be multiple correction values if
229  // m_nbBackwardImages>1). Note that being here means that the sensitivity value is not 0, so no need to check it.
230 
231  *ap_newImageValue = a_currentImageValue;
232 
233  // End
234  return 0;
235 }
236 
237 // =====================================================================
238 // ---------------------------------------------------------------------
239 // ---------------------------------------------------------------------
240 // =====================================================================
#define FLTNB
Definition: gVariables.hh:81
FLTNB m_initialValue
Definition: vOptimizer.hh:619
bool m_listmodeCompatibility
Definition: vOptimizer.hh:620
~iOptimizerTemplate()
The destructor of iOptimizerTemplate.
int ImageSpaceSpecificOperations(FLTNB a_currentImageValue, FLTNB *ap_newImageValue, FLTNB a_sensitivity, FLTNB *ap_correctionValues, INTNB a_voxel)
This function perform the image update step specific to the optimizer.
bool m_emissionCompatibility
Definition: vOptimizer.hh:622
Declaration of class iOptimizerTemplate.
int m_nbBackwardImages
Definition: vOptimizer.hh:615
iOptimizerTemplate()
The constructor of iOptimizerTemplate.
int CheckSpecificParameters()
A private function used to check the parameters settings specific to the child optimizer.
bool m_histogramCompatibility
Definition: vOptimizer.hh:621
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.
#define INTNB
Definition: gVariables.hh:92
bool m_transmissionCompatibility
Definition: vOptimizer.hh:623
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...