116 for (
int bed=0; bed<
m_nbBeds; bed++)
147 if (a_flipOut==
"x" || a_flipOut==
"X")
153 else if (a_flipOut==
"y" || a_flipOut==
"Y")
159 else if (a_flipOut==
"z" || a_flipOut==
"Z")
165 else if (a_flipOut==
"xy" || a_flipOut==
"yx" || a_flipOut==
"XY" || a_flipOut==
"YX")
171 else if (a_flipOut==
"zy" || a_flipOut==
"yz" || a_flipOut==
"ZY" || a_flipOut==
"YZ")
177 else if (a_flipOut==
"xz" || a_flipOut==
"zx" || a_flipOut==
"XZ" || a_flipOut==
"ZX")
183 else if ( a_flipOut==
"xyz" || a_flipOut==
"xzy" || a_flipOut==
"yxz" || a_flipOut==
"yzx" || a_flipOut==
"zxy" || a_flipOut==
"zyx" ||
184 a_flipOut==
"XYZ" || a_flipOut==
"XZY" || a_flipOut==
"YXZ" || a_flipOut==
"YZX" || a_flipOut==
"ZXY" || a_flipOut==
"ZYX" )
193 Cerr(
"***** oImageDimensionsAndQuantification::SetFlipOut() -> Output flip settings is incorrect !" << endl);
213 size_t first_comma = a_nbThreads.find_first_of(
",");
214 size_t last_comma = a_nbThreads.find_last_of(
",");
215 if (first_comma!=last_comma || first_comma==0 || first_comma==a_nbThreads.length()-1)
217 Cerr(
"***** oImageDimensionsAndQuantification::SetNbThreads() -> Wrong syntax in the thread parameters ! See help." << endl);
222 if (first_comma==string::npos)
237 Cerr(
"***** oImageDimensionsAndQuantification::SetNbThreads() -> Negative number of threads provided for projection computation !" << endl);
242 Cerr(
"***** oImageDimensionsAndQuantification::SetNbThreads() -> Negative number of threads provided for image computation !" << endl);
268 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Should provide a strictly positive number of threads !" << endl);
274 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Should provide strictly positive number of voxels !" << endl);
280 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Should provide strictly positive voxel or FOV dimensions !" << endl);
286 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Both FOV and voxels dimensions provided, should not provide both !" << endl);
290 if (m_fovOutPercent<0. || m_fovOutPercent>100.)
292 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Output transaxial FOV percentage must be in ]0:100] !" << endl);
296 if (m_nbSliceOutMask<0 || m_nbSliceOutMask>
m_nbVoxZ/2)
298 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Number of output axial slices to be masked is incorrectly set !" << endl);
304 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Error : DynamicDataManager object not initialized !" << endl);
323 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> Cannot initialize before a call to CheckParameters() !" << endl);
328 if (
m_verbose>=2)
Cout(
"oImageDimensionsAndQuantification::Initialize() -> Initialize image dimensions, basis functions and quantification" << endl);
352 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing framing and quantification tabs !" << endl);
359 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing time basis functions !" << endl);
366 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing respiratory basis functions !" << endl);
373 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing cardiac basis functions !" << endl);
380 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing ignored corrections !" << endl);
426 for (
int bed=0; bed<
m_nbBeds; bed++)
433 Cerr(
"!!!!! oImageDimensionsAndQuantification::CheckNumberOfProjectionThreadsConsistencyWithDatafileSize() !!!!!" << endl);
434 Cerr(
" --> The number of projection threads was reduced to the provided datafile's number of events: " <<
m_nbThreadsForProjection << endl);
451 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Number of beds must be set before setting the framing of the acquisition !" << endl);
461 for (
int bed=0; bed<
m_nbBeds; bed++)
475 for (
int bed=0; bed<
m_nbBeds; bed++)
493 uint32_t time_start = 0;
497 size_t comma_pos = 0;
498 while ((comma_pos=frame_list.find_first_of(
","))!=string::npos)
501 string param = frame_list.substr(0,comma_pos);
503 size_t semi_column_pos = param.find(
";0");
505 if (semi_column_pos==string::npos)
510 for (
int bed=0; bed<
m_nbBeds; bed++)
517 FLTNB duration = atof(param.c_str());
520 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Found a duration which is negative or null !" << endl);
524 for (
int bed=0; bed<
m_nbBeds; bed++)
530 for (
int bed=0; bed<
m_nbBeds; bed++)
537 if (semi_column_pos!=param.size()-2)
539 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Invalid dead frame format '" << param <<
"' !" << endl);
543 FLTNB duration = atof( (param.substr(0,semi_column_pos)).c_str() );
546 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Found a duration which is negative or null !" << endl);
550 time_start += ((uint32_t)(duration*1000.));
553 frame_list = frame_list.substr(comma_pos+1);
556 size_t semi_column_pos = frame_list.find(
";0");
558 if (semi_column_pos==string::npos)
563 for (
int bed=0; bed<
m_nbBeds; bed++)
570 FLTNB duration = atof(frame_list.c_str());
573 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Found a duration which is negative or null !" << endl);
577 for (
int bed=0; bed<
m_nbBeds; bed++)
583 for (
int bed=0; bed<
m_nbBeds; bed++)
594 for (
int bed=0; bed<
m_nbBeds; bed++)
646 Cerr(
"***** oImageDimensionsAndQuantification::InitializeTimeBasisFunctions() -> Input time basis functions file '" <<
m_timeBasisFunctionsFile <<
"' is missing or corrupted !" << endl);
650 for (
int tbf=0; tbf<m_nbTimeBasisFunctions; tbf++) for (int fr=0; fr<m_nbTimeFrames; fr++) fin >>
m2p_timeBasisFunctions[tbf][fr];
696 Cerr(
"***** oImageDimensionsAndQuantification::InitializeRespBasisFunctions() -> Input respiratory basis functions file '" <<
m_respBasisFunctionsFile <<
"' is missing or corrupted !" << endl);
700 for (
int rbf=0; rbf<m_nbRespBasisFunctions; rbf++) for (int rg=0; rg<m_nbRespGates; rg++) fin >>
m2p_respBasisFunctions[rbf][rg];
745 Cerr(
"***** oImageDimensionsAndQuantification::InitializeCardBasisFunctions() -> Input cardiac basis functions file '" <<
m_cardBasisFunctionsFile <<
"' is missing or corrupted !" << endl);
749 for (
int cbf=0; cbf<m_nbCardBasisFunctions; cbf++) for (int cg=0; cg<m_nbCardGates; cg++) fin >>
m2p_cardBasisFunctions[cbf][cg];
782 string *p_keywords =
new string[nb_keywords];
786 Cerr(
"***** oImageDimensionsAndQuantification::InitializeIgnoredCorrections() -> An error occured while reading the list of ignored corrections !" << endl);
791 for (
size_t k=0; k<nb_keywords; k++)
804 Cerr(
"***** oImageDimensionsAndQuantification::InitializeIgnoredCorrections() -> Unknown keyword '" << p_keywords[k] <<
"' in the provided ignored corrections list !" << endl);
824 Cerr(
"***** oImageDimensionsAndQuantification::SetAcquisitionTime() -> Object not initialized !" << endl);
855 Cout(
"oImageDimensionsAndQuantification::SetAcquisitionTime() -> Static single bed acquisition with duration [ " <<
GetFrameTimeStartInSec(0,0) <<
" : "
861 Cout(
"oImageDimensionsAndQuantification::SetAcquisitionTime() -> Static " <<
m_nbBeds <<
" beds acquisition with following bed durations:" << endl);
862 for (
int bed=0; bed<
m_nbBeds; bed++)
868 Cout(
"oImageDimensionsAndQuantification::SetAcquisitionTime() -> Dynamic single bed acquisition with following " <<
m_nbTimeFrames <<
" frame durations:" << endl);
875 Cout(
"oImageDimensionsAndQuantification::SetAcquisitionTime() -> Dynamic " <<
m_nbBeds <<
" beds acquistion with following " <<
m_nbTimeFrames <<
" frame durations:" << endl);
876 for (
int bed=0; bed<
m_nbBeds; bed++)
878 Cout(
" --> Bed " << bed+1 <<
" as following framing:" << endl);
885 else Cout(
" --> Correct for frame duration" << endl);
901 Cerr(
"***** oImageDimensionsAndQuantification::SetCalibrationFactor() -> Object not initialized !" << endl);
908 if (
m_verbose>=2 && a_bed==
m_nbBeds-1)
Cout(
"oImageDimensionsAndQuantification::SetCalibrationFactor() -> Ignore calibration factor correction" << endl);
913 if (a_calibrationFactor<=0.)
915 Cerr(
"***** oImageDimensionsAndQuantification::SetCalibrationFactor() -> Provided calibration factor (" << a_calibrationFactor <<
") is negative or null !" << endl);
927 Cout(
"oImageDimensionsAndQuantification::SetCalibrationFactor() -> Correct for following calibration factor: " << a_calibrationFactor << endl);
942 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> Object not initialized !" << endl);
950 if (a_quantificationFile==
"")
return 0;
955 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> Multi-bed gated acquisitions cannot be reconstructed !" << endl);
960 if (
m_verbose>=2)
Cout(
"oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors()-> Processing quantification file '" << a_quantificationFile <<
"'" << endl);
976 for (
int bed=0 ; bed<
m_nbBeds ; bed++)
987 string *bed_name =
new string[m_nbBeds + 1];
988 for(
int bed=0 ; bed<
m_nbBeds ; bed++)
990 ostringstream oss( ostringstream::out );
991 oss <<
"bed" << bed+1;
992 bed_name[bed] = oss.str();
996 for (
int bed=0 ; bed<
m_nbBeds ; bed++)
1001 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> Didn't found quantitative factors in file " << a_quantificationFile <<
" !" << endl);
1004 else if(return_value == 1)
1006 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> An error occured while trying to recover specific quantitative factors for frame !" << endl);
1009 else if(return_value == 0)
1011 for(
int bed=0 ; bed<
m_nbBeds ; bed++)
1014 if (pp_dynamic_quantification_factors[bed][fr][g] <= 0)
1016 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> Provided quantification factor (" << pp_dynamic_quantification_factors[bed][fr][g] <<
") is negative or null !" << endl);
1027 for (
int bed=0; bed<
m_nbBeds; bed++)
1029 for (
int fr=0; fr<
m_nbTimeFrames; fr++)
delete pp_dynamic_quantification_factors[bed][fr];
1030 delete[] pp_dynamic_quantification_factors[bed];
1032 delete[] pp_dynamic_quantification_factors;
1066 Cerr(
"***** oImageDimensionsAndQuantification::SetSPECTIsotope() -> Object not initialized !" << endl);
1086 Cerr(
"***** oImageDimensionsAndQuantification::SetPETIsotope() -> Object not initialized !" << endl);
1098 Cout(
"oImageDimensionsAndQuantification::SetPETIsotope() -> Ignore isotope dependent corrections" << endl);
1108 if (a_isotope==
"UNKNOWN" || a_isotope==
"Unknown" || a_isotope==
"unknown")
1112 Cout(
"oImageDimensionsAndQuantification::SetPETIsotope() -> Un-specified isotope; no decay nor branching ratio correction" << endl);
1126 string file_name = config_dir +
"/misc/isotopes_pet.txt";
1127 ifstream fin(file_name.c_str());
1131 Cerr(
"***** oImageDimensionsAndQuantification::SetPETIsotope() -> Failed to open PET isotopes data file '" << file_name <<
"' !" << endl);
1136 int line_max_size = 10240;
1137 char *line =
new char[line_max_size];
1138 FLTNB half_life = -1.;
1139 FLTNB branching_ratio = -1.;
1140 bool found_it =
false;
1141 fin.getline(line,line_max_size);
1145 size_t found_position;
1147 string test = (string)line;
1149 if ((found_position=test.find(
"#"))==0)
1152 fin.getline(line,line_max_size);
1156 found_position = test.find(a_isotope);
1157 if (found_position!=string::npos)
1161 test = test.substr(found_position+1+a_isotope.length());
1163 istringstream fstr(test);
1164 fstr >> half_life >> branching_ratio;
1170 fin.getline(line,line_max_size);
1181 if (branching_ratio<=0. || branching_ratio>1.)
1183 Cerr(
"***** oImageDimensionsAndQuantification::SetPETIsotope() -> Branching ratio (" << branching_ratio <<
") is not in the ]0:1] range !" << endl);
1191 Cout(
"oImageDimensionsAndQuantification::SetPETIsotope() -> Isotope " << a_isotope <<
" has infinite half life and " << branching_ratio <<
" branching ratio" << endl);
1193 Cout(
"oImageDimensionsAndQuantification::SetPETIsotope() -> Isotope " << a_isotope <<
" has " << half_life <<
" seconds half life and " << branching_ratio <<
" branching ratio" << endl);
1199 Cerr(
"***** oImageDimensionsAndQuantification::SetPETIsotope() -> Did not find " << a_isotope <<
" isotope in the PET isotope data file, please add it !" << endl);
1231 long double lambda = log(2.0)/half_life;
1264 int a_respMotionCorrectionFlag,
1265 int a_cardMotionCorrectionFlag,
1266 int a_doubleMotionCorrectionFlag,
1267 int a_invMotionCorrectionFlag,
1268 int a_nbRespGates,
int a_nbCardGates )
1270 if (
m_verbose>=5)
Cout(
"oImageDimensionsAndQuantification::InitDynamicData()" << endl);
1274 a_respMotionCorrectionFlag, a_cardMotionCorrectionFlag, a_doubleMotionCorrectionFlag, a_invMotionCorrectionFlag ))
1276 Cerr(
"***** oImageDimensionsAndQuantification::InitDynamicData() -> A problem occured while initializing the dynamic data from dynamic data manager !" << endl);
1289 if (
m_verbose>=5)
Cout(
"oImageDimensionsAndQuantification::CheckDynamicParameters()" << endl);
string m_cardBasisFunctionsFile
int InitializeFramingAndQuantification()
A function used to initialize the framing and quantification tables.
string m_respBasisFunctionsFile
int CheckParameters(int64_t a_nbEvents)
Check all mandatory parameters.
This class is designed to be a mother virtual class for Datafile.
int SetSPECTIsotope(int a_bed, const string &a_isotope)
Set the SPECT isotope for the provided bed.
int SetPETIsotope(int a_bed, const string &a_isotope)
Set the PET isotope for the provided bed.
Declaration of class oImageDimensionsAndQuantification.
int InitDynamicData(string a_pathTo4DDataSplittingFile, int a_respMotionCorrectionFlag, int a_cardMotionCorrectionFlag, int a_doubleMotionCorrectionFlag, int a_invMotionCorrectionFlag, int a_nbRespGates, int a_nbCardGates)
Call the eponym function from the oDynamicDataManager object in order to initialize its data...
void SetVerbose(int a_verboseLevel)
set verbosity
oImageDimensionsAndQuantification()
The constructor of oImageDimensionsAndQuantification.
FLTNB ** m2p_cardBasisFunctions
FLTNB GetFrameTimeStartInSec(int a_bed, int a_frame)
Get the frame time start for the given bed, in seconds as a FLTNB.
oDynamicDataManager * mp_DynamicDataManager
This class gathers the information about the dynamic splitting of the data.
FLTNB ** m2p_timeBasisFunctions
bool m_ignoreNormCorrectionFlag
bool m_ignoreRandCorrectionFlag
bool m_ignoreAttnCorrectionFlag
int SetCalibrationFactor(int a_bed, FLTNB a_calibrationFactor)
Set the calibration factor for the provided bed.
int m_nbCardBasisFunctions
bool m_ignoreFdurCorrectionFlag
bool m_ignoreCaliCorrectionFlag
int m_nbThreadsForImageComputation
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
int m_nbThreadsForProjection
int SetNbThreads(const string &a_nbThreads)
Set the number of threads.
~oImageDimensionsAndQuantification()
The destructor of oImageDimensionsAndQuantification.
int CheckParameters()
A function used to check the parameters settings.
int Initialize()
A function used to initialize all that is needed.
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
const string & GetPathToConfigDir()
Return the path to the CASTOR config directory.
int m_nbRespBasisFunctions
string m_ignoredCorrectionsList
string m_timeBasisFunctionsFile
Declaration of class vDataFile.
uint32_t ** m2p_frameDurationsInMs
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...
int InitializeTimeBasisFunctions()
A function used to initialize the time basis functions.
void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
set the pointer to the oImageDimensionsAndQuantification object
bool m_ignoreBratCorrectionFlag
FLTNB GetQuantificationFactor(int a_bed, int a_frame, int a_respGate, int a_cardGate)
Get the quantification factor corresponding to the provided bed, frame, respiratory and cardiac gates...
bool m_ignoreScatCorrectionFlag
int SetDynamicSpecificQuantificationFactors(FLTNB **a2p_quantificationFactors)
Compute gate-specific quantificative factors using the number of events within each gate...
#define KEYWORD_MANDATORY
int m_nbTimeBasisFunctions
uint32_t ** m2p_frameTimeStopInMs
int CheckDynamicParameters(int64_t a_nbEvents)
Call the eponym function from the oDynamicDataManager object in order to check its parameters...
int InitializeRespBasisFunctions()
A function used to initialize the respiratory basis functions.
FLTNB GetFrameTimeStopInSec(int a_bed, int a_frame)
Get the frame time stop for the given bed, in seconds as a FLTNB.
int SetAcquisitionTime(int a_bed, FLTNB a_timeStartInSec, FLTNB a_durationInSec)
Set the acquisition time if not already set by the SetTimeFrames()
int InitDynamicData(int a_nbRespGates, int a_nbCardGates, const string &a_pathTo4DDataSplittingFile, int a_rmMCorrFlag, int a_cMmCorrFlag, int a_dmCorrFlag, int a_pMotionCorrFlag)
Main function for instanciation and initialization of the member variables and arrays. Call the specific initialization function depending of the type of dataset.
int InitializeCardBasisFunctions()
A function used to initialize the cardiac basis functions.
FLTNB GetFrameDurationInSec(int a_bed, int a_frame)
Get the frame duration for the given bed, in seconds as a FLTNB.
bool m_ignoreDecaCorrectionFlag
uint32_t ** m2p_frameTimeStartInMs
int ReadStringOption(const string &a_input, T *ap_return, int a_nbElts, const string &sep, const string &a_option)
Parse the 'a_input' string corresponding to the 'a_option' into 'a_nbElts' elements, using the 'sep' separator. The results are returned in the templated 'ap_return' dynamic templated array. Call "ConvertFromString()" to perform the correct conversion depending on the type of the data to convert.
int InitializeIgnoredCorrections()
A function used to initialize the ignored corrections.
void CheckNumberOfProjectionThreadsConsistencyWithDatafileSize(vDataFile **a2p_Datafile)
int SetFlipOut(const string &a_flipOut)
Set the output flip options, the parameter being a string potentially containing the letters x...
int SetDynamicSpecificQuantificationFactors(const string &a_quantificationFile)
Apply specific quantification factors manually provided as an option.
FLTNB *** m3p_quantificationFactors
FLTNB ** m2p_respBasisFunctions