9 #include "oDynamicDataManager.hh" 10 #include "oImageDimensionsAndQuantification.hh" 93 int a_rmCorrFlag,
int a_cmCorrFlag,
int a_pmCorrFlag)
158 Cerr(
"***** oDynamicDataManager::InitDynamicData() -> Respiratory motion correction is enabled for cardiac-gated data. This is not supported in the current implementation !" << endl);
165 Cerr(
"***** oDynamicDataManager::InitDynamicData() -> Involuntary patient image-based motion correction cannot be used along with respiratory or cardiac motion correction !" << endl);
175 if(
m_verbose>=
VERBOSE_DETAIL)
Cout(
"oDynamicDataManager::InitDynamicData() -> Initializing data for gated reconstruction... " << endl);
179 Cerr(
"***** oDynamicDataManager::InitDynamicData() -> A problem occurred during the dynamic gating initialization !" << endl);
187 Cerr(
"***** oDynamicDataManager::InitDynamicData() -> A problem occurred during the patient involuntary motion correction initialization !" << endl);
194 if (
m_respGatingFlag)
Cout(
"oDynamicDataManager::InitDynamicData() -> Respiratory gating enabled" << endl);
195 if (
m_rMotionCorrFlag)
Cout(
"oDynamicDataManager::InitDynamicData() -> Respiratory image-based motion correction enabled" << endl);
196 if (
m_cardGatingFlag)
Cout(
"oDynamicDataManager::InitDynamicData() -> Cardiac gating enabled" << endl);
197 if (
m_cMotionCorrFlag)
Cout(
"oDynamicDataManager::InitDynamicData() -> Cardiac image-based motion correction enabled" << endl);
198 if (
m_pMotionCorrFlag)
Cout(
"oDynamicDataManager::InitDynamicData() -> Involuntary image-based patient motion correction enabled" << endl);
221 "nb_events_respiratory_gates",
227 Cerr(
"***** oDynamicDataManager::InitDynamicDataGating() -> Error while trying to read 'nb_events_respiratory_gates' in file '" << a_pathToFile <<
"' !" << endl);
232 uint64_t event_number_sum = 0;
249 "nb_events_cardiac_gates",
255 Cerr(
"***** oDynamicDataManager::InitDynamicDataGating() -> Error while trying to read 'nb_events_cardiac_gates' in file '" << a_pathToFile <<
"' !" << endl);
259 uint64_t event_number_sum = 0;
275 m_nbRespGates*m_nbCardGates,
279 Cerr(
"***** oDynamicDataManager::InitDynamicDataGating() -> Error while trying to read 'nb_events_respiratory_gates' in file '" << a_pathToFile <<
"' !" << endl);
290 Cout(
" --> Provided gate duration, frame #" << fr <<
", gate #" << g <<
": " <<
m2p_durationPerGate[fr][g] << endl);
311 "nb_motion_triggers",
316 Cerr(
"***** oDynamicDataManager::InitDynamicDataPatientMotion() -> Involuntary motion correction enabled but no dynamic configuration file has been provided with the -im option," << endl
317 <<
"***** or the number of triggers could not be found in the dynamic file '" << a_pathToFile <<
"' !" << endl);
339 "timestamp_motion_triggers",
344 Cerr(
"***** oDynamicDataManager::InitDynamicDataPatientMotion() -> Involuntary motion correction enabled but list of triggers" 345 <<
" not found in the dynamic file '" << a_pathToFile <<
"' !" << endl);
358 for (
int pm=(m_nbPMotionTriggers-1) ; pm>0 ; pm--)
360 new_m_nbPMotionTriggers--;
361 m_nbPMotionTriggers = new_m_nbPMotionTriggers;
371 Cerr(
"***** oDynamicDataManager::InitDynamicDataPatientMotion() -> " 372 <<
" Error, the first motion trigger must be 0 ms" 373 <<
" (the corresponding transformation parameters are usually set to 0," 374 <<
" as the acquisition start in the reference position!" << endl);
428 if (
m_verbose>=
VERBOSE_DETAIL)
Cout(
"oDynamicDataManager::InitDynamicDataPatientMotion() -> First / Last motion trigger index for each dynamic frame: " << endl);
457 uint32_t motion_subset_stop_time_ms;
482 if (mp_frameNbPMotionIndexes[fr] > 1)
487 for (
int ipm = 0; ipm < mp_frameNbPMotionIndexes[fr]; ipm++)
498 if (mp_frameNbPMotionIndexes[fr] > 1)
501 uint32_t motion_subset_stop_time_ms;
505 for (
int ipm = 0; ipm < mp_frameNbPMotionIndexes[fr] - 1; ipm++)
511 * (
long double) motion_subset_start_time_ms
514 * (
long double) (motion_subset_stop_time_ms - motion_subset_start_time_ms)
527 * (
long double)motion_subset_start_time_ms
530 * (
long double)(motion_subset_stop_time_ms - motion_subset_start_time_ms)
543 for(
int ipm=0 ; ipm<mp_frameNbPMotionIndexes[fr] ; ipm++ )
562 if (m_nbRespGates>1 || m_nbCardGates>1)
577 uint64_t total_events_in_frame = 0;
588 Cout(
" --> Cardiac gating correction factors :" << endl);
590 Cout(
" Frame #" << fr <<
", cardiac gate #" << g <<
" = " << a2p_quantificationFactors[fr][g] << endl);
610 uint64_t total_events_in_frame = 0;
621 Cout(
" --> Respiratory gating correction factors :" << endl);
623 Cout(
" Frame #" << fr <<
", gate #" << rg <<
" = " << a2p_quantificationFactors[fr][rg] << endl);
642 if (
m_verbose>=
VERBOSE_DETAIL)
Cout(
"oDynamicDataManager::CheckParameters() -> Check parameters for dynamic data settings" << endl);
646 Cerr(
"***** oDynamicDataManager::CheckParameters() -> No image dimensions provided !" << endl);
650 if (m_nbTimeFrames<0)
652 Cerr(
"***** oDynamicDataManager::CheckParameters() -> Wrong number of time frames !" << endl);
658 Cerr(
"***** oDynamicDataManager::CheckParameters() -> Wrong number of respiratory gates !" << endl);
664 Cerr(
"***** oDynamicDataManager::CheckParameters() -> Wrong number of respiratory gates !" << endl);
668 if (m_nbPMotionTriggers<0)
670 Cerr(
"***** oDynamicDataManager::CheckParameters() -> Wrong number of involuntary motion subsets provided !" << endl);
676 Cerr(
"***** oDynamicDataManager::CheckParameters() -> Wrong verbosity level provided !" << endl);
683 if (
m_respGatingFlag)
Cout(
"oDynamicDataManager::CheckParameters() -> Respiratory gating is enabled" << endl);
684 if (
m_rMotionCorrFlag)
Cout(
"oDynamicDataManager::CheckParameters() -> Respiratory motion correction enabled" << endl);
685 if (
m_cardGatingFlag)
Cout(
"oDynamicDataManager::CheckParameters() -> Cardiac gating is enabled" << endl);
686 if (
m_cMotionCorrFlag)
Cout(
"oDynamicDataManager::CheckParameters() -> Cardiac motion correction is enabled" << endl);
687 if (
m_pMotionCorrFlag)
Cout(
"oDynamicDataManager::CheckParameters() -> Involuntary motion correction is enabled" << endl);
693 int last_fr = m_nbTimeFrames-1;
694 int last_rg = m_nbRespGates-1;
697 Cerr(
"***** oDynamicDataManager::CheckParameters() -> Problem while checking consistency of dynamic data !" << endl
698 <<
" The number of events in the datafile (" << a_nbEvents
699 <<
") is different from the total number of events in respiratory gates (" <<
m2p_indexLastEventRespGate[last_fr][last_rg]+1 <<
") as initialized in the gating file !" << endl);
705 int last_fr = m_nbTimeFrames-1;
709 Cerr(
"***** oDynamicDataManager::CheckParameters() -> Problem while checking consistency of dynamic data !" << endl
710 <<
" The number of events in the datafile (" << a_nbEvents
711 <<
") is different to the total number of events in cardiac gates (" <<
m2p_indexLastEventCardGate[last_fr][last_cg]+1 <<
") as initialized in the gating file !" << endl);
770 <<
" at event #" << a_currentEventIndex <<
", timestamp = " << a_currentTime << endl);
791 bool frame_has_changed =
false;
800 if (a_currentTime<mp_ID->GetFrameTimeStopInMs(a_bed,fr))
806 frame_has_changed =
true;
814 else if (fr==m_nbTimeFrames-1)
822 Cout(
"oDynamicDataManager::DynamicSwitch() -> Thread " << a_th <<
", frame switched to " <<
mp_currentFrameIndex[a_th] << endl);
831 bool resp_gate_has_changed =
false;
837 if (frame_has_changed)
844 bool resp_gate_found =
false;
859 <<
" on event " << a_currentEventIndex << endl
867 resp_gate_has_changed =
true;
870 resp_gate_found =
true;
888 if (frame_has_changed || resp_gate_has_changed)
894 bool card_gate_found =
false;
908 <<
" on event " << a_currentEventIndex << endl
918 card_gate_found =
true;
uint32_t GetFrameTimeStartInMs(int a_bed, int a_frame)
int InitDynamicDataGating(const string &a_pathToGateFile)
int CheckParameters(int64_t a_nbEvents)
FLTNB GetFrameDurationInSec(int a_bed, int a_frame)
int * mp_currentCardGateIndex
void ResetCurrentDynamicIndices()
Reset to 0 the multithreaded dynamic arrays gathering the indices of current frame, gates and involuntary motion.
HPFLTNB ** m2p_listPMotionWeightInFrame
#define DYNAMIC_SWITCH_DEFORMATION
int * mp_currentPMotionIndex
FLTNB GetFrameTimeStartInSec(int a_bed, int a_frame)
oImageDimensionsAndQuantification * mp_ID
int InitDynamicData(int a_nbRespGates, int a_nbCardGates, const string &a_pathTo4DDataSplittingFile, int a_rmMCorrFlag, int a_cMmCorrFlag, int a_pMotionCorrFlag)
int DynamicSwitch(int64_t a_index, uint32_t a_time, int a_bed, int a_th)
uint32_t GetFrameDurationInMs(int a_bed, int a_frame)
uint16_t * mp_framePMotionLastIndex
int * mp_currentFrameIndex
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
#define DYNAMIC_SWITCH_NOTHING
int64_t ** m2p_nbEventsPerRespGate
~oDynamicDataManager()
oDynamicDataManager destructor.
bool m_gateDurationProvidedFlag
oDynamicDataManager()
oDynamicDataManager constructor. Initialize the member variables to their default values...
int64_t ** m2p_indexLastEventCardGate
int64_t ** m2p_nbEventsPerCardGate
uint16_t * mp_frameNbPMotionIndexes
int SetDynamicSpecificQuantificationFactors(FLTNB **a2p_quantificationFactors)
#define DYNAMIC_SWITCH_CONTINUE
#define KEYWORD_MANDATORY
uint16_t * mp_framePMotionFirstIndex
#define VERBOSE_DEBUG_NORMAL
int InitDynamicDataPatientMotion(const string &a_pathToFile)
int64_t ** m2p_indexLastEventRespGate
HPFLTNB ** m2p_durationPerGate
int GetNbTimeFrames()
Get the number of time frames.
int GetNbThreadsForProjection()
Get the number of threads used for projections.
uint32_t GetFrameTimeStopInMs(int a_bed, int a_frame)
uint32_t * mp_listPMotionTriggers
#define VERBOSE_DEBUG_LIGHT
int ReadDataASCIIFile(const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter a...
#define DYNAMIC_SWITCH_END_LOOP
int * mp_currentRespGateIndex
int ** mp_MotionTriggersIndexInFrame
#define KEYWORD_OPTIONAL_ERROR
#define VERBOSE_DEBUG_EVENT