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