CASToR  3.1
Tomographic Reconstruction (PET/SPECT/CT)
iDynamicModelTemplate.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-2020 all CASToR contributors listed below:
18 
19  --> Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Thibaut MERLIN, Mael MILLARDET, Simon STUTE, Valentin VIELZEUF, Zacharias CHALAMPALAKIS
20 
21 This is CASToR version 3.1.
22 */
23 
30 #include "iDynamicModelTemplate.hh"
31 
32 // =====================================================================
33 // ---------------------------------------------------------------------
34 // ---------------------------------------------------------------------
35 // =====================================================================
36 /*
37  \fn iDynamicModelTemplate
38  \brief Constructor of iDynamicModelTemplate. Simply set all data members to default values.
39 */
41 {
42  // --- Parameters inherited from vDynamicModel class --- //
43 
44  m_nbTimeBF = 1; // Number of basis functions in the model
45  m_nbModelParam = 1; // Number of model parameters
46 
47  // Image matrix containing the parametric images.
48  // 2 pointers:
49  // 1: Parametric image related to the dynamic model basis functions.
50  // 2: 3D voxels
51  // Should be allocated in InitializeSpecific() function
52  m2p_parametricImages = NULL;
53 
54  // Vector containing the Model temporal basis functions
55  // 2 pointers:
56  // 1: index of the temporal function
57  // 2: coefficient of the functions for each time points (frame) of the dynamic acquisition
58  // Dimensions : [m_nbModelParam][voxels]
59  // Should be allocated in InitializeSpecific() function
61 
62  // Image matrix to gather the parametric image before writing on disk
63  // By default it will point directly to the parametric m2p_parametricImages.
64  // They are allocated if post-processing are enabled before writing the image (i.e FOV masking)
65  // 2 pointers: \n
66  // 1: Parametric image related to the dynamic model basis functions.
67  // 2: 3D voxels
68  m2p_outputParImages = NULL;
69 
70  // Image matrix containing the voxels which the model cannot fit
71  // 1 pointer: 3D voxels
73 
74  // Flag indicating if the blacklisted voxels mask image should be written on disk
76 
77  // Input image containing a mask defining in which voxels the model must be applied (1) or not (0). Default: all voxels to 1
78  // 1 pointer: 3D voxels
79  mp_maskModel = NULL;
80 
81  // Number of voxels in mask
82  m_nbVoxelsMask = -1;
83 
84  // Path to a configuration file. To be used for initialization in ReadAndCheckConfigurationFileSpecific() and InitializeSpecific() functions
85  m_fileOptions = "";
86 
87  // String containing a list of options. To be used for initialization in ReadAndCheckOptionsList() and InitializeSpecific() functions
88  m_listOptions = "";
89 
90  // Boolean indicating whether the parameters were checked or not
91  m_checked = false;
92 
93  // Boolean indicating whether the manager was initialized or not
94  m_initialized = false;
95 
96  // Flag indicating if parametric images should be written on disk (default=true)
97  // Could be disabled with the keyword 'Save_parametric_images: 0' in a configuration file (managed by vDynamicModel)
98  m_saveParImageFlag = true;
99 
100  // If true, the EstimateImageWithModel() functions is not called, so the reconstructed images are not estimated from the parametric images,
101  // The class will only estimate parametric images from each current estimation of the images (default=false)
102  // Could be disabled with the keyword 'No_image_update: 1' in a configuration file (managed by vDynamicModel)
103  m_noImageUpdateFlag = false;
104 
105  // If true, the EstimateModelParameters() functions is not called, so the parameters are not estimated from the serie of dynamic images (default=false)
106  // Could be disabled with the keyword 'No_parameters_update: 1' in a configuration file (managed by vDynamicModel)
107  m_noParametersUpdateFlag = false;
110  // Number of iterations after which the reconstructed images are estimated from the parametric images. (default or negative value =0)
111  // Could be modified with the keyword 'Number of iterations before image update: xxx' in a configuration file (managed by vDynamicModel)
113 
114  //Verbosity
115  m_verbose = -1;
116 }
117 
118 
119 
120 
121 // =====================================================================
122 // ---------------------------------------------------------------------
123 // ---------------------------------------------------------------------
124 // =====================================================================
125 /*
126  \fn ~iDynamicModelTemplate
127  \brief Destructor of iDynamicModelTemplate
128 */
130 {
131  if(m_initialized)
132  {
133  // Free variables
134  }
135 }
136 
137 
138 
139 
140 // =====================================================================
141 // ---------------------------------------------------------------------
142 // ---------------------------------------------------------------------
143 // =====================================================================
144 /*
145  \fn ShowHelpModelSpecific
146  \brief Print out specific help about the implementation of the model
147  and its initialization
148 */
150 {
151  // ===================================================================
152  // Here, display some help and guidance to how to use this dynamic model and what it does
153  // ===================================================================
154  cout << "This class is a template class dedicated to add your own dynamic model." << endl;
155 }
156 
157 
158 
159 
160 // =====================================================================
161 // ---------------------------------------------------------------------
162 // ---------------------------------------------------------------------
163 // =====================================================================
164 /*
165  \fn ReadAndCheckConfigurationFileSpecific
166  \brief This function is used to read options from a configuration file.
167  \return 0 if success, other value otherwise.
168 */
170 {
171  if(m_verbose >=3) Cout("iDynamicModelTemplate::ReadAndCheckConfigurationFileSpecific ..."<< endl);
172 
173  // ===================================================================
174  // Implement here the reading of any options specific to this dynamic model
175  // (i.e : parameters or path to deformation files), through a configuration file
176  // The ReadDataASCIIFile() functions could be helpful to recover data from a file
177  // (check other dynamicModels for examples)
178  // ===================================================================
179 
180  return 0;
181 }
182 
183 
184 
185 
186 // =====================================================================
187 // ---------------------------------------------------------------------
188 // ---------------------------------------------------------------------
189 // =====================================================================
190 /*
191  \fn ReadAndCheckOptionsList
192  \param a_optionsList : a list of parameters separated by commas
193  \brief This function is used to read parameters from a string.
194  \return 0 if success, other value otherwise.
195 */
197 {
198  // ===================================================================
199  // Implement here the reading of any options specific to this dynamic model,
200  // through a list of options separated by commas
201  // The ReadStringOption() function could be helpful to parse the list of parameters in an array
202  // ===================================================================
203 
204  // Normal end
205  return 0;
206 }
207 
208 
209 
210 
211 // =====================================================================
212 // ---------------------------------------------------------------------
213 // ---------------------------------------------------------------------
214 // =====================================================================
215 /*
216  \fn CheckSpecificParameters
217  \brief This function is used to check whether all member variables
218  have been correctly initialized or not.
219  \return 0 if success, positive value otherwise.
220 */
222 {
223  // ===================================================================
224  // Implement here checks over parameters which should be read using either
225  // ReadAndCheckConfigurationFile() and ReadAndCheckOptionsList() functions
226  // ===================================================================
227 
228  if(m_verbose >=3) Cout("iDynamicModelTemplate::CheckSpecificParameters ..."<< endl);
229 
230  // Normal end
231  return 0;
232 }
233 
234 
235 
236 
237 // =====================================================================
238 // ---------------------------------------------------------------------
239 // ---------------------------------------------------------------------
240 // =====================================================================
241 /*
242  \fn InitializeSpecific
243  \brief This function is used to initialize the model parametric images and basis functions
244  \return 0 if success, other value otherwise.
245 */
247 {
248  if(m_verbose >=3) Cout("iDynamicModelTemplate::InitializeSpecific ..."<< endl);
249 
250 
251  // ===================================================================
252  // Implement here the allocation/initialization of whatever member
253  // variables specifically used by this dynamic model
254  // ===================================================================
255 
256 
257  // Forbid initialization without check
258  if (!m_checked)
259  {
260  Cerr("***** oDynamicModelManager::InitializeSpecific() -> Must call CheckParameters functions before Initialize() !" << endl);
261  return 1;
262  }
263 
264  // Normal end
265  m_initialized = true;
266  return 0;
267 }
268 
269 
270 
271 
272 // =====================================================================
273 // ---------------------------------------------------------------------
274 // ---------------------------------------------------------------------
275 // =====================================================================
276 /*
277  \fn EstimateModelParameters
278  \param ap_ImageS : pointer to the ImageSpace
279  \param a_ite : index of the actual iteration (not used)
280  \param a_sset : index of the actual subset (not used)
281  \brief Estimate parametric images
282  \return 0 if success, other value otherwise.
283 */
284 int iDynamicModelTemplate::EstimateModelParameters(oImageSpace* ap_ImageS, int a_ite, int a_sset)
285 {
286  if(m_verbose >=3) Cout("iDynamicModelTemplate::EstimateModelParameters ..." <<endl);
287 
288  #ifdef CASTOR_DEBUG
289  if (!m_initialized)
290  {
291  Cerr("***** iDynamicModelTemplate::EstimateModelParameters() -> Called while not initialized !" << endl);
292  Exit(EXIT_DEBUG);
293  }
294  #endif
295 
296  // ===================================================================
297  // This function can be used to implement the estimation any parameters of the model
298  // and parametric images
299  // This function is called dring the iterative image reconstruction
300  // during the image update which occurs at the end of the iteration/subset
301  //
302  //
303  // The main image matrices are stored in the ImageSpace object, passed
304  // in argument.
305  // The main image contains 4 dimensions :
306  // ap_ImageS->m4p_image[fr][rg][cg][v]
307  // fr = time frames
308  // rg = respiratory gates
309  // cg = cardiac gates
310  // v = actual voxel of the 3D volume
311 
312  /* IMAGE DIMENSIONS :
313  * 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],
314  * its cumulative 1D index is computed by 'index = indexZ*nbVoxXY + indexY*nbVoxX + indexX'.
315  *
316  * The image dimensions can be recovered from the mp_ID class
317  * Total number of voxels : mp_ID->GetNbVoxXYZ()
318  * Number of voxels in a slice : mp_ID->GetNbVoxXY()
319  * Number of voxels on the X-axis : mp_ID->GetNbVoxX()
320  */
321 
322  // Any error should return a value >0.
323 
324  // ===================================================================
325 
326  return 0;
327 }
328 
329 
330 
331 // =====================================================================
332 // ---------------------------------------------------------------------
333 // ---------------------------------------------------------------------
334 // =====================================================================
335 /*
336  \fn EstimateImageWithModel
337  \param ap_ImageS : pointer to the ImageSpace
338  \param a_ite : index of the actual iteration (not used)
339  \param a_sset : index of the actual subset (not used)
340  \brief Estimate image using the model parametric images and basis functions
341  \return 0 if success, other value otherwise.
342 */
343 int iDynamicModelTemplate::EstimateImageWithModel(oImageSpace* ap_ImageS, int a_ite, int a_sset)
344 {
345  if(m_verbose >= 3) Cout("iDynamicModelTemplate::EstimateImageWithModel ... " <<endl);
346 
347  #ifdef CASTOR_DEBUG
348  if (!m_initialized)
349  {
350  Cerr("***** iDynamicModelTemplate::EstimateImageWithModel() -> Called while not initialized !" << endl);
351  Exit(EXIT_DEBUG);
352  }
353  #endif
354 
355 
356  // ===================================================================
357  // This function can be used to generate the serie of dynamic images
358  // from the model, after estimation of the model parameters in EstimateModelParameters()
359  // It is called right after EstimateModelParameters()
360  //
361  // The main image matrices are stored in the ImageSpace object, passed
362  // in argument.
363  // The main image contains 4 dimensions :
364  // ap_ImageS->m4p_image[fr][rg][cg][v]
365  // fr = time frames
366  // rg = respiratory gates
367  // cg = cardiac gates
368  // v = actual voxel of the 3D volume
369 
370  /* IMAGE DIMENSIONS :
371  * 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],
372  * its cumulative 1D index is computed by 'index = indexZ*nbVoxXY + indexY*nbVoxX + indexX'.
373  *
374  * The image dimensions can be recovered from the mp_ID class
375  * Total number of voxels : mp_ID->GetNbVoxXYZ()
376  * Number of voxels in a slice : mp_ID->GetNbVoxXY()
377  * Number of voxels on the X-axis : mp_ID->GetNbVoxX()
378  */
379 
380  // Any error should return a value >0.
381 
382  // ===================================================================
383 
384  return 0;
385 }
string m_listOptions
int InitializeSpecific()
This function is used to initialize the model parametric images and basis functions.
This is the mother class of dynamic model classes.
bool m_saveBlacklistedImageMaskFlag
void Exit(int code)
iDynamicModelTemplate()
Constructor of iDynamicModelTemplate. Simply set all data members to default values.
int ReadAndCheckConfigurationFileSpecific()
This function is used to read options from a configuration file.
string m_fileOptions
#define Cerr(MESSAGE)
FLTNB ** m2p_outputParImages
int CheckSpecificParameters()
This function is used to check whether all member variables have been correctly initialized or not...
FLTNB * mp_maskModel
int EstimateModelParameters(oImageSpace *ap_Image, int a_ite, int a_sset)
Estimate the model parametric images.
FLTNB ** m2p_nestedModelTimeBasisFunctions
bool m_noParametersUpdateFlag
int EstimateImageWithModel(oImageSpace *ap_Image, int a_ite, int a_sset)
Estimate image using model parametric images and basis functions.
This class holds all the matrices in the image domain that can be used in the algorithm: image...
Definition: oImageSpace.hh:60
#define EXIT_DEBUG
Definition: gVariables.hh:97
int ReadAndCheckOptionsList(string a_listOptions)
This function is used to read parameters from a string.
bool m_noImageUpdateFlag
#define Cout(MESSAGE)
void ShowHelpModelSpecific()
This function is used to print out specific help about the dynamic model and its options. It is pure virtual so must be implemented by children.
Declaration of class iDynamicModelTemplate.
~iDynamicModelTemplate()
Destructor of iDynamicModelTemplate.
FLTNB * mp_blackListedvoxelsImage