9 #include "gVariables.hh" 10 #include "oAnalyticProjection.hh" 74 int oAnalyticProjection::LaunchGPU()
76 Cerr(
"***** oAnalyticProjection::LaunchGPU() -> The GPU specific function is not implemented !" << endl);
99 if (
m_verbose>=1)
Cout(
"oAnalyticProjection::LaunchCPU() -> Start analytic projection" << endl);
115 Cerr(
"***** oAnalyticProjection::LaunchCPU()-> Error during image initialization !" << endl);
121 Cerr(
"***** oAnalyticProjection::LaunchCPU()-> Error during attenuation image initialization !" << endl);
130 Cerr(
"***** oAnalyticProjection::LaunchCPU() -> A problem occurred while applying image convolver to forward image !" << endl);
136 clock_t clock_start = clock();
137 time_t time_start = time(NULL);
142 for(
int bed=0 ; bed<
m_nbBeds ; bed++)
145 unsigned int main_loop_start_index = 0 ;
146 unsigned int main_loop_stop_index = 0;
154 Cerr(
"***** oAnalyticProjection::LaunchCPU()-> An error occurred when trying to initialize main loop stop index !" << endl);
160 Cerr(
"***** oAnalyticProjection::LaunchCPU()-> An error occurred when trying to initialize inner loop start index !" << endl);
167 int64_t* elements_sum = (int64_t*)malloc(nb_total_elts*
sizeof(int64_t));
170 for (int64_t idx_elt=1 ; idx_elt<nb_total_elts ; idx_elt++)
171 elements_sum[idx_elt] = elements_sum[idx_elt-1] + (uint64_t)(nb_total_elts-idx_elt);
177 uint64_t printing_index = 0;
185 uint16_t nb_dyn_img_processed=0;
213 bool problem =
false;
218 #pragma omp parallel for private(idx_elt1) schedule(static, 1) 219 for (idx_elt1=main_loop_start_index ; idx_elt1<(int)main_loop_stop_index ; idx_elt1++)
224 th = omp_get_thread_num();
232 for (int64_t idx_elt2=inner_loop_start_index ; idx_elt2<inner_loop_stop_index ; idx_elt2++)
237 if (printing_index%10000==0)
243 int64_t progression_index_current = p_scannerManager->
PROJ_GetCurrentProgression(idx_elt1, idx_elt2, elements_sum, nb_dyn_img_processed);
245 FLTNB percent = ( (
FLTNB)progression_index_current /((
FLTNB)progression_index_total) ) * ((
FLTNB)100);
246 cout <<
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b " 263 Cerr(
"***** oAnalyticProjection::LaunchCPU() -> A problem occurred while computing the projection line !" << endl);
275 Cerr(
"***** oAnalyticProjection::LaunchCPU() -> An error occurred during the data update step !" << endl);
281 || event->GetEventValue(0)>0. )
285 total_events_in_cgate[th]++;
286 total_events_in_rgate[th]++;
287 total_events_in_frame[th]++;
288 HPFLTNB event_value =
event->GetEventValue(0);
289 total_prompts[th] += event_value;
290 total_prompts_in_cgate[th] += event_value;
291 total_prompts_in_rgate[th] += event_value;
292 total_prompts_in_frame[th] += event_value;
300 nb_dyn_img_processed++;
305 Cerr(
"***** oAnalyticProjection::LaunchCPU() -> A problem occurred inside the parallel loop over events !" << endl);
312 Cerr(
"***** oAnalyticProjection::LaunchCPU()-> An error occurred during the data writing step" << endl);
322 Cout(endl <<
"Total events in cgate #" << cg+1 <<
": " << total_events_in_cgate[0] << endl);
323 Cout(
"Total prompts in cgate #" << cg+1 <<
": " << total_prompts_in_cgate[0] << endl);
326 free(total_prompts_in_cgate);
327 free(total_events_in_cgate);
336 Cout(endl <<
"Total events in rgate #" << rg+1 <<
": " << total_events_in_rgate[0] << endl);
337 Cout(
"Total prompts in rgate #" << rg+1 <<
": " << total_prompts_in_rgate[0] << endl);
339 free(total_prompts_in_rgate);
340 free(total_events_in_rgate);
352 Cout(endl <<
"Total events in frame #" << fr+1 <<
": " << total_events_in_frame[0] << endl);
353 Cout(
"Total prompts in frame #" << fr+1 <<
": " << total_prompts_in_frame[0] << endl);
356 free(total_prompts_in_frame);
357 free(total_events_in_frame);
361 int acquisition_duration = 0;
366 if(acquisition_duration <= 0 ) acquisition_duration = 1;
369 cout <<
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b 100 % " << endl;
377 Cout(
"Total number of projected events:" << endl);
381 if (
m_verbose>=1)
Cout(
"Final total number of events projected: " << total_events[0] << endl);
383 if (
m_verbose>=1)
Cout(
"Final total number of prompts: " << total_prompts[0] << endl);
405 clock_t clock_stop = clock();
406 time_t time_stop = time(NULL);
407 Cout (endl << endl <<
" Total Time spent - Analytic Projection | User: " << time_stop-time_start <<
" sec | CPU: " << (clock_stop-clock_start)/((
FLTNB)CLOCKS_PER_SEC) <<
" sec" << endl);
uint32_t GetFrameTimeStartInMs(int a_bed, int a_frame)
void SetVerbose(int a_verboseLevel)
void LMS_InstantiateImage()
Allocate memory for the main image matrices (for list-mode sensitivity generation) ...
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
oAnalyticProjection()
oAnalyticProjection constructor. Initialize the member variables to their default values...
int64_t PROJ_GetModalityStartValueInnerLoop(int64_t a_elt1)
FLTNB GetFrameDurationInSec(int a_bed, int a_frame)
int PROJ_InitImage(const string &a_pathToInitialImage)
virtual int WriteHeader()=0
This function is implemented in child classes. Generate a header file according to the data output ...
void LMS_PrepareForwardImage()
Copy current image in forward-image buffer (for list-mode sensitivity generation) ...
oComputeProjection * mp_ComputeProjection
int ConvolveForward(oImageSpace *ap_ImageSpace)
int64_t PROJ_GetProgressionFinalValue()
Get numerator value according to the modality to compute percent progression during the projection pr...
oImageSpace * mp_ImageSpace
virtual uint16_t PROJ_GetSPECTNbProjections()
return the total number of projections for a SPECT acquisition
int PROJ_SaveProjectionImage()
Save an image of the projected data (for analytic projection)
void SetDuration(FLTNB a_value)
void LMS_InstantiateForwardImage()
Allocate memory for the forward image matrices (for list-mode sensitivity generation) ...
int InitAttenuationImage(const string &a_pathToAtnImage)
FLTNB GetFrameTimeStartInSec(int a_bed, int a_frame)
int DataUpdateStep(vDataFile *ap_DataFile, oProjectionLine *a2p_Line, oImageSpace *ap_Image, vEvent *ap_Event, int a_fr, int a_rg, int a_cg, int th, uint32_t a_timestamp, bool a_discardZeroEvent)
virtual uint16_t PROJ_GetSPECTNbPixels()
return the total number of pixels for a SPECT reconstruction
~oAnalyticProjection()
oAnalyticProjection destructor.
void PROJ_DeallocateProjectionImage(int a_nbProjs)
uint32_t GetFrameDurationInMs(int a_bed, int a_frame)
#define SCANNER_SPECT_CONVERGENT
oProjectorManager * mp_ProjectorManager
void SetStartTime(FLTNB a_value)
Singleton class that Instantiate and initialize the scanner object.
void LMS_DeallocateImage()
Free memory for the main image matrices (for list-mode sensitivity generation)
oImageDimensionsAndQuantification * mp_ID
int64_t PROJ_GetCurrentProgression(int64_t a_elt1, int64_t a_elt2, int64_t *ap_nbEltsArray, uint16_t a_nbDynImgProcessed)
oProjectionLine * ComputeProjectionLine(vEvent *ap_Event, int a_th)
int Launch()
Just call either the LaunchCPU or the LaunchGPU function as asked for.
vEvent * PROJ_GenerateEvent(int idx_elt1, int idx_elt2, int a_th)
bool NotEmptyLine()
This function is used to know if the line contains any voxel contribution.
void PROJ_InstantiateProjectionImage(int a_nbProjs, int a_nbPixels)
string m_pathToInitialImg
void SetNbEvents(int64_t a_value)
virtual int GetSystemNbElts()=0
This is a pure virtual method that must be implemented by children.
This class is designed to manage and store system matrix elements associated to a vEvent...
void LMS_DeallocateAttenuationImage()
Free memory for the Attenuation image matrices (for analytical projection or list-mode sensitivity ge...
int GetNbCardGates()
Get the number of cardiac gates.
vDataFile ** m2p_DataFile
Mother class for the Event objects.
int GetNbTimeFrames()
Get the number of time frames.
int GetNbThreadsForProjection()
Get the number of threads used for projections.
int GetNbRespGates()
Get the number of respiratory gates.
int64_t PROJ_GetModalityStopValueMainLoop()
Get the stop value for the main loop of analytic projection depending on the modality.
int PROJ_DeleteTmpDataFile()
Delete temporary datafile used for multithreaded output writing if needed.
virtual int IsAvailableLOR(int a_elt1, int a_elt2)
oImageConvolverManager * mp_ImageConvolverManager
void LMS_DeallocateForwardImage()
Free memory for the forward image matrices (for list-mode sensitivity generation) ...