8 #include "gVariables.hh" 9 #include "vAlgorithm.hh" 10 #include "iEventHistoCT.hh" 65 if (a_nbIterationsSubsets==
"")
return 0;
70 string buf = a_nbIterationsSubsets;
74 while ((pos_comma=buf.find_first_of(
","))!=string::npos)
77 string sub_buf = buf.substr(0,pos_comma);
79 size_t pos_column = sub_buf.find_first_of(
":");
80 if (pos_column==string::npos || pos_column==0)
82 Cerr(
"***** vAlgorithm::SetNbIterationsAndSubsets() -> Syntax problem in number of iterations and subsets !" << endl);
85 int iter = atoi( sub_buf.substr(0,pos_column).c_str() );
86 int subs = atoi( sub_buf.substr(pos_column+1).c_str() );
88 for (
int it=0; it<iter; it++) mp_nbSubsets[
m_nbIterations+it] = subs;
90 buf = buf.substr(pos_comma+1);
94 size_t pos_column = buf.find_first_of(
":");
95 if (pos_column==string::npos || pos_column==0)
97 Cerr(
"***** vAlgorithm::SetNbIterationsAndSubsets() -> Syntax problem in number of iterations and subsets !" << endl);
100 int iter = atoi( buf.substr(0,pos_column).c_str() );
101 int subs = atoi( buf.substr(pos_column+1).c_str() );
103 for (
int it=0; it<iter; it++) mp_nbSubsets[
m_nbIterations+it] = subs;
108 Cout(
"vAlgorithm::SetNbIterationsAndSubsets() -> Selected numbers of subsets for each iteration:" << endl);
109 Cout(
" Iteration / number of subsets "<< endl);
110 for (
int it=0 ; it<
m_nbIterations ; it++)
Cout(
" " << it+1 <<
" / " << mp_nbSubsets[it] << endl);
123 if (
m_verbose>=2)
Cout(
"vAlgorithm::SetOutputIterations ..." << endl);
130 if (a_outputIterations==
"")
137 string buf = a_outputIterations;
141 int current_iteration = -1;
142 while ((pos_comma=buf.find_first_of(
","))!=string::npos)
145 string sub_buf = buf.substr(0,pos_comma);
147 size_t pos_column = sub_buf.find_first_of(
":");
148 if (pos_column==string::npos || pos_column==0)
150 Cerr(
"***** vAlgorithm::SetOutputIterations() -> Syntax problem in output iteration numbers !" << endl);
153 int step_iteration = atoi( sub_buf.substr(0,pos_column).c_str() );
154 if (step_iteration<=0)
156 Cerr(
"***** vAlgorithm::SetOutputIterations() -> Iteration step must be strictly positive (here it is " << step_iteration <<
") !" << endl);
159 int stop_iteration = atoi( sub_buf.substr(pos_column+1).c_str() );
160 if (stop_iteration<=current_iteration)
162 Cerr(
"***** oIterationAlgorithm::SetOutputIterations() -> Output iteration number must be increasing through provided couples !" << endl);
165 for (
int it=current_iteration+step_iteration; it<stop_iteration; it+=step_iteration)
if (it<m_nbIterations)
mp_outputIterations[it] =
true;
166 current_iteration = stop_iteration-1;
167 buf = buf.substr(pos_comma+1);
171 size_t pos_column = buf.find_first_of(
":");
172 if (pos_column==string::npos || pos_column==0)
183 Cerr(
"***** vAlgorithm::SetOutputIterations() -> Syntax problem in output iteration numbers !" << endl);
187 int step_iteration = atoi( buf.substr(0,pos_column).c_str() );
188 if (step_iteration<=0)
190 Cerr(
"***** vAlgorithm::SetOutputIterations() -> Iteration step must be strictly positive (here it is " << step_iteration <<
") !" << endl);
193 int stop_iteration = atoi( buf.substr(pos_column+1).c_str() );
194 if (stop_iteration<=current_iteration)
196 Cerr(
"***** oIterationAlgorithm::SetOutputIterations() -> Output iteration number must be increasing through provided couples !" << endl);
199 for (
int it=current_iteration+step_iteration; it<stop_iteration; it+=step_iteration)
if (it<m_nbIterations)
mp_outputIterations[it] =
true;
245 MPI_Barrier(MPI_COMM_WORLD);
252 clock_t clock_start_whole = clock();
253 time_t time_start_whole = time(NULL);
259 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepBeforeIterationLoop() function !" << endl);
270 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepBeforeSubsetLoop() function !" << endl);
275 for (
int subset=0 ; subset<
mp_nbSubsets[iteration] ; subset++)
280 Cout(
"vAlgorithm::IterateCPU() -> Start iteration " << iteration+1 <<
"/" << m_nbIterations
281 <<
" subset " << subset+1 <<
"/" << mp_nbSubsets[iteration] << endl);
285 clock_t clock_start_subset = clock();
286 time_t time_start_subset = time(NULL);
291 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepPreProcessInsideSubsetLoop() function !" << endl);
297 MPI_Barrier(MPI_COMM_WORLD);
301 for (
int bed=0 ; bed<
m_nbBeds ; bed++)
306 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepInnerLoopInsideSubsetLoop() function !" << endl);
313 MPI_Barrier(MPI_COMM_WORLD);
319 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepPostProcessInsideSubsetLoop() function !" << endl);
324 clock_t clock_stop_subset = clock();
325 time_t time_stop_subset = time(NULL);
326 if (
m_verbose>=2)
Cout (
"vAlgorithm::IterateCPU() -> Time spent for subset " << subset+1 <<
" | User: " << time_stop_subset-time_start_subset
327 <<
" sec | CPU: " << (clock_stop_subset-clock_start_subset)/((
FLTNB)CLOCKS_PER_SEC) <<
" sec" << endl);
336 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepAfterSubsetLoop() function !" << endl);
346 Cerr(
"***** vAlgorithm::IterateCPU() -> A problem occurred while calling StepAfterIterationLoop() function !" << endl);
351 clock_t clock_stop_whole = clock();
352 time_t time_stop_whole = time(NULL);
353 if (
m_verbose>=1)
Cout(
"vAlgorithm::IterateCPU() -> Total time spent | User: " << time_stop_whole-time_start_whole
354 <<
" sec | CPU: " << (clock_stop_whole-clock_start_whole)/((
FLTNB)CLOCKS_PER_SEC) <<
" sec" << endl);
367 if (
m_verbose>=2)
Cout(
"vAlgorithm::StepBeforeIterationLoop ... " << endl);
372 Cerr(
"***** vAlgorithm::StepBeforeIterationLoop() -> Image space has not been created or was not checked !" << endl);
385 Cerr(
"***** vAlgorithm::StepBeforeIterationLoop()-> Error during attenuation image initialization !" << endl);
391 Cerr(
"***** vAlgorithm::StepBeforeIterationLoop() -> An error occurred while initializing the sensitivity image !" << endl);
397 Cerr(
"***** vAlgorithm::StepBeforeIterationLoop()-> Error during multimodal image initialization !" << endl);
456 if (
m_verbose>=2)
Cout(
"vAlgorithm::StepAfterIterationLoop ... " << endl);
488 (void)a_specificOptions;
virtual int InitSpecificOptions(string a_specificOptions)
int SetNbIterationsAndSubsets(const string &a_nbIterationsSubsets)
oImageDimensionsAndQuantification * mp_ID
vector< string > m_pathToMultiModalImg
void DeallocateImage()
Free memory for the main image matrices.
oImageSpace * mp_ImageSpace
int InitMultiModalImage(const vector< string > &a_pathToMultiModalImage)
int RunCPU()
Perform the iterative loop of the algorithm. Function designed to be executed on the CPU only...
void DeallocateMultiModalImage()
Free memory for the multimodal image.
virtual int StepBeforeSubsetLoop(int a_iteration)
int Run()
Just call either the RunCPU or the RunGPU function as asked for.
bool m_saveSensitivityHistoFlag
void DeallocateSensitivityImage()
Free memory for the sensitivity image matrices.
oOptimizerManager * mp_OptimizerManager
void InstantiateImage()
Allocate memory for the main image matrices.
void InstantiateSensitivityImage(const string &a_pathToSensitivityImage)
int InitAttenuationImage(const string &a_pathToAtnImage)
virtual int StepImageOutput(int a_iteration, int a_subset=-1)=0
void DeallocateVisitedVoxelsImage()
Free memory for the image matrix containing binary information regarding which 3D voxels have been vi...
virtual int StepInnerLoopInsideSubsetLoop(int a_iteration, int a_subset, int a_bed)=0
oImageProcessingManager * mp_ImageProcessingManager
virtual int StepPostProcessInsideSubsetLoop(int a_iteration, int a_subset)
vAlgorithm()
vAlgorithm constructor. Initialize the member variables to their default values.
bool m_saveDynamicBasisCoefficients
string m_pathToSensitivityImg
void InstantiateVisitedVoxelsImage()
Memory allocation and initialization for the image matrix containing binary information regarding whi...
string m_pathToInitialImg
virtual int StepPreProcessInsideSubsetLoop(int a_iteration, int a_subset)
virtual int StepBeforeIterationLoop()
This function is called at the beginning of the RunCPU function.
bool m_saveImageAfterSubsets
virtual ~vAlgorithm()
vAlgorithm destructor.
oImageConvolverManager * mp_ImageConvolverManager
void InstantiateForwardImage()
Allocate memory for the forward image matrices.
oProjectorManager * mp_ProjectorManager
virtual int StepAfterSubsetLoop(int a_iteration)
oDeformationManager * mp_DeformationManager
virtual int StepAfterIterationLoop()
This function is called at the end of the RunCPU function.
void DeallocateOutputImage()
Free memory for the Image matrices dedicated to output writing on disk.
int SetOutputIterations(const string &a_outputIterations)
bool * mp_outputIterations
vDataFile ** m2p_DataFile
bool Checked()
Simply check that the image dimensions and verbosity has been set.
int InitSensitivityImage(const string &a_pathToSensitivityImage)
void DeallocateForwardImage()
Free memory for the forward image matrices.
oDynamicModelManager * mp_DynamicModelManager
void InstantiateOutputImage()
Instanciate Image matrices dedicated to output writing on disk.