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