8 #include "gVariables.hh" 9 #include "iIterativeAlgorithm.hh" 10 #include "iEventHistoCT.hh" 39 Cerr(
"***** iIterativeAlgorithm::StepBeforeIterationLoop() -> A problem occurred while calling StepBeforeIterationLoop() function !" << endl);
42 if (
m_verbose>=2)
Cout(
"iIterativeAlgorithm::StepBeforeIterationLoop ... " << endl);
50 Cerr(
"***** iIterativeAlgorithm::StepBeforeIterationLoop() -> An error occurred while reading the initialization image !" << endl);
68 if (
m_verbose>=3)
Cout(
"iIterativeAlgorithm::StepBeforeSubsetLoop ... " << endl);
84 if (
m_verbose>=3)
Cout(
"iIterativeAlgorithm::StepPreProcessInsideSubsetLoop ... " << endl);
101 Cerr(
"***** iIterativeAlgorithm::StepPreProcessInsideSubsetLoop() -> A problem occurred while applyin image processing to forward image !" << endl);
109 Cerr(
"***** iIterativeAlgorithm::StepPreProcessInsideSubsetLoop() -> A problem occurred while applying image convolver to forward image !" << endl);
137 if (
m_nbBeds>1)
Cout(
"iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> Start loop over events for bed " << a_bed+1 << endl << flush);
138 else Cout(
"iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> Start loop over events" << endl << flush);
150 cout <<
"0 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%" << endl;
151 cout <<
"|----|----|----|----|----|----|----|----|----|----|" << endl;
152 cout <<
"|" << flush;
154 int progression_percentage_old = 0;
155 int progression_nb_bars = 0;
156 uint64_t progression_printing_index = 0;
159 int64_t index_start = 0;
160 int64_t index_stop = 0;
165 MPI_Barrier(MPI_COMM_WORLD);
174 bool problem =
false;
186 #pragma omp parallel for private(index) schedule(static, 1) 187 for ( index = index_start ; index < index_stop ; index +=
mp_nbSubsets[a_iteration] )
192 th = omp_get_thread_num();
197 if (progression_printing_index%1000==0)
199 int progression_percentage_new = ((int)( (((
float)(index-index_start+1))/((float)(index_stop-index_start)) ) * 100.));
200 if (progression_percentage_new>=progression_percentage_old+2)
202 int nb_steps = (progression_percentage_new-progression_percentage_old)/2;
203 for (
int i=0; i<nb_steps; i++)
205 cout <<
"-" << flush;
206 progression_nb_bars++;
208 progression_percentage_old += nb_steps*2;
211 progression_printing_index++;
214 if (p_end_loop_flags[th])
continue;
219 if (
m_verbose>=4)
Cout(
"iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> Step1: Get current event for that thread index " << endl);
224 Cerr(
"***** iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> An error occurred while getting the event from index " 225 << index <<
" (thread " << th <<
") !" << endl);
238 Cout(
"iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> Step2: Check for Dynamic event (frame/gate switch, image-based deformation " << endl);
241 int dynamic_switch_value =
mp_ID->
DynamicSwitch(index, event->GetTimeInMs(), a_bed, th);
254 #pragma omp critical (deformation_requirements_first) 259 bool wait_for_deformation =
true;
260 while (wait_for_deformation)
266 bool all_threads_ready =
false;
268 #pragma omp critical (deformation_requirements_first) 272 if (all_threads_ready)
277 #pragma omp critical (deformation_requirements_second) 284 #pragma omp critical (deformation_requirements_second) 297 cout <<
"0 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%" << endl;
298 cout <<
"|----|----|----|----|----|----|----|----|----|----|" << endl;
299 int progression_percentage_new = ((int)( (((
float)(index-index_start+1))/((float)(index_stop-index_start)) ) * 100.));
302 for (
int i=0; i< progression_percentage_new / 2 ; i++) cout <<
"-";
309 p_end_loop_flags[th] =
true;
317 if (
m_verbose>=4)
Cout(
"iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> Step3: Compute the projection line " << endl);
322 Cerr(
"***** iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> A problem occurred while computing the projection line !" << endl);
333 if (
m_verbose>=4)
Cout(
"iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> Step4: Optimize in the data space " << endl);
347 MPI_Barrier(MPI_COMM_WORLD);
358 int progression_total_bars = 49;
359 for (
int i=0; i<progression_total_bars-progression_nb_bars; i++) cout <<
"-";
366 Cerr(
"***** iIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() -> A problem occurred inside the parallel loop over events !" << endl);
381 if (
m_verbose>=3)
Cout(
"iIterativeAlgorithm::StepPostProcessInsideSubsetLoop ... " << endl);
396 Cerr(
"***** iIterativeAlgorithm::StepPostProcessInsideSubsetLoop() -> A problem occurred while applying convolver to backward images !" << endl);
404 Cerr(
"***** iIterativeAlgorithm::StepPostProcessInsideSubsetLoop() -> A problem occurred while performing the pre-image-update step !" << endl);
411 Cerr(
"***** iIterativeAlgorithm::StepPostProcessInsideSubsetLoop() -> A problem occurred while performing the image update step !" << endl);
419 Cerr(
"***** iIterativeAlgorithm::StepPostProcessInsideSubsetLoop() -> A problem occurred while applying convolver to current estimate images !" << endl);
427 Cerr(
"***** iIterativeAlgorithm::StepPostProcessInsideSubsetLoop() -> A problem occurred while applying dynamic model to current estimate images !" << endl);
434 Cerr(
"***** iIterativeAlgorithm::StepPostProcessInsideSubsetLoop() -> A problem occurred while applying image processing to current estimate images !" << endl);
445 stringstream temp_it; temp_it << a_iteration + 1;
446 stringstream temp_ss; temp_ss << a_subset + 1;
447 temp_sens.append(
"_it").append(temp_it.str()).append(
"_ss").append(temp_ss.str()).append(
"_sensitivity");
456 if (
m_verbose>=1)
Cout(
"iIterativeAlgorithm::StepPostProcessInsideSubsetLoop() -> Save image at iteration " << a_iteration+1 <<
" for subset " << a_subset+1 << endl);
460 Cerr(
"***** iIterativeAlgorithm::StepPostProcessInsideSubsetLoop() -> A problem occurred while saving images at iteration " << a_iteration+1 <<
" !" << endl);
476 if (
m_verbose>=3)
Cout(
"iIterativeAlgorithm::StepAfterSubsetLoop() -> Clean never visited voxels and save images if needed" << endl);
483 if (
m_verbose>=1)
Cout(
"iIterativeAlgorithm::StepAfterSubsetLoop() -> Save image at iteration " << a_iteration+1 << endl);
487 Cerr(
"***** iIterativeAlgorithm::StepAfterSubsetLoop() -> A problem occurred while saving images at iteration " << a_iteration+1 <<
" !" << endl);
504 Cerr(
"***** iIterativeAlgorithm::StepAfterIterationLoop() -> A problem occurred while calling StepAfterIterationLoop() function !" << endl);
507 if (
m_verbose>=2)
Cout(
"iIterativeAlgorithm::StepAfterIterationLoop ... " << endl);
531 Cerr(
"***** iIterativeAlgorithm::StepImageOutput() -> A problem occurred while saving parametric images related to the dynamic model !" << endl);
543 Cerr(
"***** iIterativeAlgorithm::StepImageOutput() -> A problem occurred while convolving the output image !" << endl);
550 Cerr(
"***** iIterativeAlgorithm::StepImageOutput() -> A problem occurred while applying image processing the output image !" << endl);
556 Cerr(
"***** iIterativeAlgorithm::StepImageOutput() -> A problem occurred while applying output FOV masking !" << endl);
562 Cerr(
"***** iIterativeAlgorithm::StepImageOutput() -> A problem occurred while applying output flip !" << endl);
575 Cerr(
"***** iIterativeAlgorithm::StepImageOutput() -> A problem occurred while saving output image !" << endl);
589 Cerr(
"***** iIterativeAlgorithm::StepImageOutput() -> A problem occurred while saving output image !" << endl);
603 (void)a_specificOptions;
604 if (
m_verbose>=2)
Cout(
"iIterativeAlgorithm::InitSpecificOptions ... " << endl);
int ApplyProcessingForward(oImageSpace *ap_ImageSpace)
void GetEventIndexStartAndStop(int64_t *ap_indexStart, int64_t *ap_indexStop, int a_subsetNum=0, int a_NbSubsets=1)
void DeallocateBackwardImageFromDynamicBasis()
Free memory for the backward image matrices.
FLTNB GetInitialValue()
Return the initial image value used by the optimizer, explaining why the eponym function of vOptimize...
oImageDimensionsAndQuantification * mp_ID
void SetCurrentSubset(int a_currentSubset)
int PreImageUpdateStep()
A function that simply calls the eponym function from the vOptimizer.
void Reduce()
Merge parallel results into the matrix of the backward image matrix of the first thread. Also for MPI.
oImageSpace * mp_ImageSpace
#define DYNAMIC_SWITCH_DEFORMATION
void StartIterativeDataUpdateStep4(int a_thread)
int ConvolveForward(oImageSpace *ap_ImageSpace)
int InitSpecificOptions(string a_specificOptions)
int ApplyOutputFOVMasking()
Mask the outside of the transaxial FOV based on the m_fovOutPercent.
int StepInnerLoopInsideSubsetLoop(int a_iteration, int a_subset, int a_bed)
bool m_saveSensitivityHistoFlag
oOptimizerManager * mp_OptimizerManager
int GetCurrentCardImage(int a_th)
void InstantiateBackwardImageFromDynamicBasis(int a_nbBackwardImages)
void StartIterativeDataUpdateStep3(int a_thread)
void StartIterativeDataUpdateStep2(int a_thread)
void StartIterativeDataUpdateStep1(int a_thread)
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
int ConvolvePost(oImageSpace *ap_ImageSpace)
int ConvolveIntra(oImageSpace *ap_ImageSpace)
int ApplyProcessingPost(oImageSpace *ap_ImageSpace)
int InitImage(const string &a_pathToInitialImage, FLTNB a_value)
int DynamicSwitch(int64_t a_currentEventIndex, uint32_t a_currentTime, int a_bed, int a_th)
int StepAfterIterationLoop()
This function is called at the end of the RunCPU function.
int DataUpdateStep(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
void StopIterativeDataUpdateStep2(int a_thread)
oImageProcessingManager * mp_ImageProcessingManager
bool GetRespStaticFlag()
Get the respiratory static flag that says if the reconstruction has only one respiratory gate or not...
int StepPostProcessInsideSubsetLoop(int a_iteration, int a_subset)
vEvent * GetEvent(int64_t a_eventIndex, int a_th=0)
void PrepareForwardImage()
Copy current image matrix in the forward-image buffer matrix.
int GetCurrentRespImage(int a_th)
int SaveOutputBasisCoefficientImage(int a_iteration, int a_subset=-1)
bool m_saveDynamicBasisCoefficients
void StopIterativeDataUpdateStep1(int a_thread)
const string & GetPathName()
bool GetCardStaticFlag()
Get the cardiac static flag that says if the reconstruction has only one cardiac gate or not...
int StepBeforeSubsetLoop(int a_iteration)
void CleanNeverVisitedVoxels()
Based on the visitedVoxelsImage, clean the never visited voxels in the image. This function must be c...
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
int StepPreProcessInsideSubsetLoop(int a_iteration, int a_subset)
string m_pathToInitialImg
int GetNbBackwardImages()
Return the number of backward images used by the optimizer, explaining why the eponym function of vOp...
int SaveOutputImage(int a_iteration, int a_subset=-1)
int PreDataUpdateStep()
A function that simply calls the eponym function from the vOptimizer.
void StopIterativeDataUpdateStep3(int a_thread)
void ResetCurrentDynamicIndices()
Call the eponym function from the oDynamicDataManager class using the member object.
virtual int StepBeforeIterationLoop()
This function is called at the beginning of the RunCPU function.
bool m_saveImageAfterSubsets
void ComputeOutputImage()
oProjectionLine * ComputeProjectionLine(vEvent *ap_Event, int a_th)
int ConvolveBackward(oImageSpace *ap_ImageSpace)
void StopIterativeDataUpdateStep4(int a_thread)
oImageConvolverManager * mp_ImageConvolverManager
int SaveParametricImages(int a_iteration, int a_subset=-1)
void ApplyBedOffset(int a_bed)
void SetCurrentIteration(int a_currentIteration)
void StartConvolution()
Start the timer for duration of convolution.
bool GetTimeStaticFlag()
Get the time static flag that says if the reconstruction has only one frame or not.
bool NotEmptyLine()
This function is used to know if the line contains any voxel contribution.
#define DYNAMIC_SWITCH_CONTINUE
int ApplyProcessingIntra(oImageSpace *ap_ImageSpace)
oProjectorManager * mp_ProjectorManager
int StepBeforeIterationLoop()
This function is called at the beginning of the RunCPU function.
oDeformationManager * mp_DeformationManager
This class is designed to manage and store system matrix elements associated to a vEvent...
const string & GetBaseName()
int ApplyOutputFlip()
Just flip the output image.
virtual int StepAfterIterationLoop()
This function is called at the end of the RunCPU function.
int StepImageOutput(int a_iteration, int a_subset=-1)
This is the base class for reconstructions, containing a framework with iteration and data subset loo...
void StopConvolution()
Stop the timer for duration of convolution.
void SetNumbersOfIterationsAndSubsets(int a_nbIterations, int *ap_nbSubsets)
Mother class for the Event objects.
int GetNbThreadsForImageComputation()
Get the number of threads used for image operations.
int ImageUpdateStep()
A function dedicated to the update step in the image space (performed after the loop on events) ...
int GetNbThreadsForProjection()
Get the number of threads used for projections.
int StepAfterSubsetLoop(int a_iteration)
bool * mp_outputIterations
vDataFile ** m2p_DataFile
This class is designed to manage some profiling of the code.
int GetCurrentTimeFrame(int a_th)
int SaveSensitivityImage(const string &a_pathToSensitivityImage)
#define DYNAMIC_SWITCH_END_LOOP
void InitBackwardImage()
Initialize each voxel of the backward images to 0, also for sensitivity if not loaded (estimated on t...
static sChronoManager * GetInstance()
Instantiate the singleton if not already done, then return the pointer to its instance.
int GetMPIRank()
Get the MPI instance number (the rank)
int ApplyDynamicModel(oImageSpace *ap_ImageS, int a_iteration, int a_subset)
oDynamicModelManager * mp_DynamicModelManager