CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-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 "iDynamicModelTemplate.hh"
32 
33 // =====================================================================
34 // ---------------------------------------------------------------------
35 // ---------------------------------------------------------------------
36 // =====================================================================
37 /*
38  \fn iDynamicModelTemplate
39  \brief Constructor of iDynamicModelTemplate. Simply set all data members to default values.
40 */
42 {
43  m_nbTimeBF = 1; // Initialize the number of basis functions in the model
44  m2p_parametricImages = NULL; // Should be allocated in Initialize() function
45 }
46 
47 
48 
49 
50 // =====================================================================
51 // ---------------------------------------------------------------------
52 // ---------------------------------------------------------------------
53 // =====================================================================
54 /*
55  \fn ~iDynamicModelTemplate
56  \brief Destructor of iDynamicModelTemplate
57 */
59 {
60 }
61 
62 
63 
64 
65 // =====================================================================
66 // ---------------------------------------------------------------------
67 // ---------------------------------------------------------------------
68 // =====================================================================
69 /*
70  \fn ShowHelp
71  \brief Print out specific help about the implementation of the model
72  and its initialization
73 */
75 {
76  // ===================================================================
77  // Here, display some help and guidance to how to use this dynamic model and what it does
78  // ===================================================================
79  cout << "This class is a template class dedicated to add your own dynamic model." << endl;
80 }
81 
82 
83 
84 
85 // =====================================================================
86 // ---------------------------------------------------------------------
87 // ---------------------------------------------------------------------
88 // =====================================================================
89 /*
90  \fn ReadAndCheckConfigurationFile
91  \param const string& a_configurationFile : ASCII file containing informations about a dynamic model
92  \brief This function is used to read options from a configuration file.
93  \return 0 if success, other value otherwise.
94 */
96 {
97  if(m_verbose >=2) Cout("iDynamicModelTemplate::ReadAndCheckConfigurationFile ..."<< endl);
98 
99  // ===================================================================
100  // Implement here the reading of any options specific to this dynamic model
101  // (i.e : parameters or path to deformation files), through a configuration file
102  // The ReadDataASCIIFile() functions could be helpful to recover data from a file
103  // ===================================================================
104 
105  return 0;
106 }
107 
108 
109 
110 
111 // =====================================================================
112 // ---------------------------------------------------------------------
113 // ---------------------------------------------------------------------
114 // =====================================================================
115 /*
116  \fn ReadAndCheckOptionsList
117  \param a_optionsList : a list of parameters separated by commas
118  \brief This function is used to read parameters from a string.
119  \return 0 if success, other value otherwise.
120 */
122 {
123  // ===================================================================
124  // Implement here the reading of any options specific to this deformation model,
125  // through a list of options separated by commas
126  // The ReadStringOption() function could be helpful to parse the list of parameters in an array
127  // ===================================================================
128 
129  // Normal end
130  return 0;
131 }
132 
133 
134 
135 
136 // =====================================================================
137 // ---------------------------------------------------------------------
138 // ---------------------------------------------------------------------
139 // =====================================================================
140 /*
141  \fn CheckSpecificParameters
142  \brief This function is used to check whether all member variables
143  have been correctly initialized or not.
144  \return 0 if success, positive value otherwise.
145 */
147 {
148  // ===================================================================
149  // Implement here checks over parameters which should be read using either
150  // ReadAndCheckConfigurationFile() and ReadAndCheckOptionsList() functions
151  // ===================================================================
152 
153  if(m_verbose >=2) Cout("iDynamicModelTemplate::CheckSpecificParameters ..."<< endl);
154 
155  // Normal end
156  return 0;
157 }
158 
159 
160 
161 
162 // =====================================================================
163 // ---------------------------------------------------------------------
164 // ---------------------------------------------------------------------
165 // =====================================================================
166 /*
167  \fn Initialize
168  \brief This function is used to initialize the model parametric images and basis functions
169  \return 0 if success, other value otherwise.
170 */
172 {
173  if(m_verbose >=2) Cout("iDynamicModelTemplate::Initialize ..."<< endl);
174 
175 
176  // ===================================================================
177  // Implement here the allocation/initialization of whatever member
178  // variables specifically used by this deformation model
179  // ===================================================================
180 
181 
182  // Forbid initialization without check
183  if (!m_checked)
184  {
185  Cerr("***** oDynamicModelManager::Initialize() -> Must call CheckParameters functions before Initialize() !" << endl);
186  return 1;
187  }
188 
189  // Normal end
190  m_initialized = true;
191  return 0;
192 }
193 
194 
195 
196 
197 // =====================================================================
198 // ---------------------------------------------------------------------
199 // ---------------------------------------------------------------------
200 // =====================================================================
201 /*
202  \fn EstimateModelParameters
203  \param ap_ImageS : pointer to the ImageSpace
204  \param a_ite : index of the actual iteration (not used)
205  \param a_sset : index of the actual subset (not used)
206  \brief Estimate parametric images
207  \return 0 if success, other value otherwise.
208 */
209 int iDynamicModelTemplate::EstimateModelParameters(oImageSpace* ap_ImageS, int a_ite, int a_sset)
210 {
211  if(m_verbose >=2) Cout("iDynamicModelTemplate::EstimateModelParameters ..." <<endl);
212 
213  #ifdef CASTOR_DEBUG
214  if (!m_initialized)
215  {
216  Cerr("***** iDynamicModelTemplate::EstimateModelParameters() -> Called while not initialized !" << endl);
217  Exit(EXIT_DEBUG);
218  }
219  #endif
220 
221  // ===================================================================
222  // Implement here the parametric images estimate after the image update
223  // which occurs at the end of the iteration (or subset)
224  //
225  //
226  // The main image matrices are stored in the ImageSpace object, passed
227  // in argument.
228  // The main image contains 4 dimensions :
229  // ap_ImageS->m4p_image[fr][rg][cg][v]
230  // fr = time frames
231  // rg = respiratory gates
232  // cg = cardiac gates
233  // v = actual voxel of the 3D volume
234 
235  /* IMAGE DIMENSIONS :
236  * 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],
237  * its cumulative 1D index is computed by 'index = indexZ*nbVoxXY + indexY*nbVoxX + indexX'.
238  *
239  * The image dimensions can be recovered from the mp_ID class
240  * Total number of voxels : mp_ID->GetNbVoxXYZ()
241  * Number of voxels in a slice : mp_ID->GetNbVoxXY()
242  * Number of voxels on the X-axis : mp_ID->GetNbVoxX()
243  */
244 
245  // Any error should return a value >0.
246 
247  // ===================================================================
248 
249  return 0;
250 }
251 
252 
253 
254 // =====================================================================
255 // ---------------------------------------------------------------------
256 // ---------------------------------------------------------------------
257 // =====================================================================
258 /*
259  \fn EstimateImageWithModel
260  \param ap_ImageS : pointer to the ImageSpace
261  \param a_ite : index of the actual iteration (not used)
262  \param a_sset : index of the actual subset (not used)
263  \brief Estimate image using the model parametric images and basis functions
264  \return 0 if success, other value otherwise.
265 */
266 int iDynamicModelTemplate::EstimateImageWithModel(oImageSpace* ap_ImageS, int a_ite, int a_sset)
267 {
268  if(m_verbose >= 2) Cout("iDynamicModelTemplate::EstimateImageWithModel ... " <<endl);
269 
270  #ifdef CASTOR_DEBUG
271  if (!m_initialized)
272  {
273  Cerr("***** iDynamicModelTemplate::EstimateImageWithModel() -> Called while not initialized !" << endl);
274  Exit(EXIT_DEBUG);
275  }
276  #endif
277 
278 
279  // ===================================================================
280  // This function can be used to generate the serie of dynamic images
281  // from the model, after estimation of the model parameters in EstimateModelParameters()
282  // It is called right after EstimateModelParameters()
283  //
284  // The main image matrices are stored in the ImageSpace object, passed
285  // in argument.
286  // The main image contains 4 dimensions :
287  // ap_ImageS->m4p_image[fr][rg][cg][v]
288  // fr = time frames
289  // rg = respiratory gates
290  // cg = cardiac gates
291  // v = actual voxel of the 3D volume
292 
293  /* IMAGE DIMENSIONS :
294  * 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],
295  * its cumulative 1D index is computed by 'index = indexZ*nbVoxXY + indexY*nbVoxX + indexX'.
296  *
297  * The image dimensions can be recovered from the mp_ID class
298  * Total number of voxels : mp_ID->GetNbVoxXYZ()
299  * Number of voxels in a slice : mp_ID->GetNbVoxXY()
300  * Number of voxels on the X-axis : mp_ID->GetNbVoxX()
301  */
302 
303  // Any error should return a value >0.
304 
305  // ===================================================================
306 
307  return 0;
308 }
309 
310 
311 
312 
313 
314 // =====================================================================
315 // ---------------------------------------------------------------------
316 // ---------------------------------------------------------------------
317 // =====================================================================
318 /*
319  \fn SaveParametricImages
320  \param ap_ImageS : pointer to the ImageSpace
321  \param a_ite : index of the actual iteration
322  \brief Write parametric images on disk if 'm_savePImgFlag' is enabled
323  \return 0 if success, other value otherwise.
324 */
326 {
327  if(m_verbose >=2) Cout("iDynamicModelTemplate::SaveParametricImages ..." <<endl);
328 
329 
330  // ===================================================================
331  // Implement here the parametric image output writting step, if needed
332  // ===================================================================
333 
334  // Get the output manager which contains output directory
335  sOutputManager* p_output_manager = sOutputManager::GetInstance();
336 
337  // Interfile
338  string path_to_image = p_output_manager->GetPathName() + p_output_manager->GetBaseName();
339 
340  // Add a suffix for iteration
341  if (a_ite >= 0)
342  {
343  stringstream ss; ss << a_ite + 1;
344  path_to_image.append("dynModel_it").append(ss.str());
345  }
346 
347 
348 
349  // This function is dedicated to the output of parametric images
350  if(IntfWriteImgDynCoeffFile(path_to_image, // path to the image (or metaheader) to write
351  m2p_parametricImages, // parametric image to write.
352  // it must be a 2 dimensions array [nb of basis functions][nb of voxels]
353  mp_ID, // just the object containing image dimensions
354  m_nbTimeBF, // number of basis functions of the model
355  m_verbose) )
356  {
357  Cerr("***** iDynamicModelTemplate::SaveParametricImages()-> Error writing Interfile of output image !" << endl);
358  return 1;
359  }
360 
361  return 0;
362 }
363 
364 
int Initialize()
This function is used to initialize the model parametric images and basis functions.
oImageDimensionsAndQuantification * mp_ID
This is the mother class of dynamic model classes.
int SaveParametricImages(int a_iteration)
Write parametric images on disk.
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
void Exit(int code)
iDynamicModelTemplate()
Constructor of iDynamicModelTemplate. Simply set all data members to default values.
#define Cerr(MESSAGE)
const string & GetPathName()
int ReadAndCheckConfigurationFile(string a_fileOptions)
This function is used to read options from a configuration file.
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
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)
Estimate the model parametric images.
void ShowHelp()
This function is used to print out specific help about the deformation model and its options...
int EstimateImageWithModel(oImageSpace *ap_Image, int a_ite, int a_sset)
Estimate image using model parametric images and basis functions.
const string & GetBaseName()
int IntfWriteImgDynCoeffFile(const string &a_pathToImg, FLTNB **a2p_ImgMatrix, oImageDimensionsAndQuantification *ap_ID, int a_nbParImgs, int vb)
Function dedicated to Interfile image writing for dynamic coefficients images.
This class holds all the matrices in the image domain that can be used in the algorithm: image...
Definition: oImageSpace.hh:61
#define EXIT_DEBUG
Definition: gVariables.hh:97
int ReadAndCheckOptionsList(string a_listOptions)
This function is used to read parameters from a string.
#define Cout(MESSAGE)
Declaration of class iDynamicModelTemplate.
~iDynamicModelTemplate()
Destructor of iDynamicModelTemplate.