132 for (
int bed=0; bed<
m_nbBeds; bed++)
165 if (a_flipOut==
"x" || a_flipOut==
"X")
171 else if (a_flipOut==
"y" || a_flipOut==
"Y")
177 else if (a_flipOut==
"z" || a_flipOut==
"Z")
183 else if (a_flipOut==
"xy" || a_flipOut==
"yx" || a_flipOut==
"XY" || a_flipOut==
"YX")
189 else if (a_flipOut==
"zy" || a_flipOut==
"yz" || a_flipOut==
"ZY" || a_flipOut==
"YZ")
195 else if (a_flipOut==
"xz" || a_flipOut==
"zx" || a_flipOut==
"XZ" || a_flipOut==
"ZX")
201 else if ( a_flipOut==
"xyz" || a_flipOut==
"xzy" || a_flipOut==
"yxz" || a_flipOut==
"yzx" || a_flipOut==
"zxy" || a_flipOut==
"zyx" ||
202 a_flipOut==
"XYZ" || a_flipOut==
"XZY" || a_flipOut==
"YXZ" || a_flipOut==
"YZX" || a_flipOut==
"ZXY" || a_flipOut==
"ZYX" )
211 Cerr(
"***** oImageDimensionsAndQuantification::SetFlipOut() -> Output flip settings is incorrect !" << endl);
231 size_t first_comma = a_nbThreads.find_first_of(
",");
232 size_t last_comma = a_nbThreads.find_last_of(
",");
233 if (first_comma!=last_comma || first_comma==0 || first_comma==a_nbThreads.length()-1)
235 Cerr(
"***** oImageDimensionsAndQuantification::SetNbThreads() -> Wrong syntax in the thread parameters ! See help." << endl);
240 if (first_comma==string::npos)
255 Cerr(
"***** oImageDimensionsAndQuantification::SetNbThreads() -> Negative number of threads provided for projection computation !" << endl);
260 Cerr(
"***** oImageDimensionsAndQuantification::SetNbThreads() -> Negative number of threads provided for image computation !" << endl);
304 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Should provide a strictly positive number of threads !" << endl);
311 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Should provide strictly positive number of voxels !" << endl);
317 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Should provide strictly positive voxel or FOV dimensions !" << endl);
323 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Both FOV and voxels dimensions provided, should not provide both !" << endl);
327 if (m_fovOutPercent<0. || m_fovOutPercent>100.)
329 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Output transaxial FOV percentage must be in ]0:100] !" << endl);
333 if (m_nbSliceOutMask<0 || m_nbSliceOutMask>
m_nbVoxZ/2)
335 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Number of output axial slices to be masked is incorrectly set !" << endl);
341 Cerr(
"***** oImageDimensionsAndQuantification::CheckParameters() -> Error : DynamicDataManager object not initialized !" << endl);
360 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> Cannot initialize before a call to CheckParameters() !" << endl);
365 if (
m_verbose>=2)
Cout(
"oImageDimensionsAndQuantification::Initialize() -> Initialize image dimensions, basis functions and quantification" << endl);
389 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing framing and quantification tabs !" << endl);
396 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing time basis functions !" << endl);
403 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing respiratory basis functions !" << endl);
410 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing cardiac basis functions !" << endl);
417 Cerr(
"***** oImageDimensionsAndQuantification::Initialize() -> A problem occured while initializing ignored corrections !" << endl);
463 for (
int bed=0; bed<
m_nbBeds; bed++)
470 Cerr(
"!!!!! oImageDimensionsAndQuantification::CheckNumberOfProjectionThreadsConsistencyWithDataFileSize() !!!!!" << endl);
471 Cerr(
" --> The number of projection threads was reduced to the provided datafile's number of events: " <<
m_nbThreadsForProjection << endl);
500 if (a2p_DataFile[0]->GetBedPositionFlag())
505 for (
int bed=0; bed<
m_nbBeds; bed++) center += a2p_DataFile[bed]->GetRelativeBedPosition();
506 center /= ((
FLTNB)m_nbBeds);
508 for (
int bed=0; bed<
m_nbBeds; bed++)
mp_bedPositions[bed] = a2p_DataFile[bed]->GetRelativeBedPosition() - center;
521 Cerr(
"***** oImageDimensionsAndQuantification::DealWithBedPositions() -> Bed displacement between two successive bed positions must be strictly positive !" << endl);
525 for (
int bed=0; bed<
m_nbBeds; bed++)
528 FLTNB bed_offset = 0.;
543 Cout(
"oImageDimensionsAndQuantification::DealWithBedPositions() -> Use following relative bed positions:" << endl);
544 for (
int bed=0; bed<
m_nbBeds; bed++)
Cout(
" --> Bed " << bed <<
" | Relative axial position: " <<
mp_bedPositions[bed] <<
" mm" << endl);
563 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Number of beds must be set before setting the framing of the acquisition !" << endl);
573 for (
int bed=0; bed<
m_nbBeds; bed++)
587 for (
int bed=0; bed<
m_nbBeds; bed++)
606 uint32_t time_start = 0;
610 size_t comma_pos = 0;
611 while ((comma_pos=frame_list.find_first_of(
","))!=string::npos)
614 string param = frame_list.substr(0,comma_pos);
616 size_t semi_column_pos = param.find(
"df");
618 if (semi_column_pos==string::npos)
623 for (
int bed=0; bed<
m_nbBeds; bed++)
630 FLTNB duration = atof(param.c_str());
634 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Found a duration which is negative or null !" << endl);
638 for (
int bed=0; bed<
m_nbBeds; bed++)
644 for (
int bed=0; bed<
m_nbBeds; bed++)
651 if (semi_column_pos!=param.size()-2)
653 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Invalid dead frame format '" << param <<
"' !" << endl);
657 FLTNB duration = atof( (param.substr(0,semi_column_pos)).c_str() );
661 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Found a duration which is negative or null !" << endl);
665 time_start += ((uint32_t)(duration*1000.));
668 frame_list = frame_list.substr(comma_pos+1);
671 size_t semi_column_pos = frame_list.find(
"df");
673 if (semi_column_pos==string::npos)
678 for (
int bed=0; bed<
m_nbBeds; bed++)
685 FLTNB duration = atof(frame_list.c_str());
688 Cerr(
"***** oImageDimensionsAndQuantification::InitializeFramingAndQuantification() -> Found a duration which is negative or null !" << endl);
692 for (
int bed=0; bed<
m_nbBeds; bed++)
698 for (
int bed=0; bed<
m_nbBeds; bed++)
709 for (
int bed=0; bed<
m_nbBeds; bed++)
761 Cerr(
"***** oImageDimensionsAndQuantification::InitializeTimeBasisFunctions() -> Input time basis functions file '" <<
m_timeBasisFunctionsFile <<
"' is missing or corrupted !" << endl);
765 for (
int tbf=0; tbf<m_nbTimeBasisFunctions; tbf++) for (int fr=0; fr<m_nbTimeFrames; fr++) fin >>
m2p_timeBasisFunctions[tbf][fr];
811 Cerr(
"***** oImageDimensionsAndQuantification::InitializeRespBasisFunctions() -> Input respiratory basis functions file '" <<
m_respBasisFunctionsFile <<
"' is missing or corrupted !" << endl);
815 for (
int rbf=0; rbf<m_nbRespBasisFunctions; rbf++) for (int rg=0; rg<m_nbRespGates; rg++) fin >>
m2p_respBasisFunctions[rbf][rg];
860 Cerr(
"***** oImageDimensionsAndQuantification::InitializeCardBasisFunctions() -> Input cardiac basis functions file '" <<
m_cardBasisFunctionsFile <<
"' is missing or corrupted !" << endl);
864 for (
int cbf=0; cbf<m_nbCardBasisFunctions; cbf++) for (int cg=0; cg<m_nbCardGates; cg++) fin >>
m2p_cardBasisFunctions[cbf][cg];
897 string *p_keywords =
new string[nb_keywords];
901 Cerr(
"***** oImageDimensionsAndQuantification::InitializeIgnoredCorrections() -> An error occured while reading the list of ignored corrections !" << endl);
906 for (
size_t k=0; k<nb_keywords; k++)
919 Cerr(
"***** oImageDimensionsAndQuantification::InitializeIgnoredCorrections() -> Unknown keyword '" << p_keywords[k] <<
"' in the provided ignored corrections list !" << endl);
939 Cerr(
"***** oImageDimensionsAndQuantification::SetAcquisitionTime() -> Object not initialized !" << endl);
970 Cout(
"oImageDimensionsAndQuantification::SetAcquisitionTime() -> Static single bed acquisition with duration [ " <<
GetFrameTimeStartInSec(0,0) <<
" : "
976 Cout(
"oImageDimensionsAndQuantification::SetAcquisitionTime() -> Static " <<
m_nbBeds <<
" beds acquisition with following bed durations:" << endl);
977 for (
int bed=0; bed<
m_nbBeds; bed++)
983 Cout(
"oImageDimensionsAndQuantification::SetAcquisitionTime() -> Dynamic single bed acquisition with following " <<
m_nbTimeFrames <<
" frame durations:" << endl);
990 Cout(
"oImageDimensionsAndQuantification::SetAcquisitionTime() -> Dynamic " <<
m_nbBeds <<
" beds acquistion with following " <<
m_nbTimeFrames <<
" frame durations:" << endl);
991 for (
int bed=0; bed<
m_nbBeds; bed++)
993 Cout(
" --> Bed " << bed+1 <<
" as following framing:" << endl);
1000 else Cout(
" --> Correct for frame duration" << endl);
1016 Cerr(
"***** oImageDimensionsAndQuantification::SetCalibrationFactor() -> Object not initialized !" << endl);
1023 if (
m_verbose>=2 && a_bed==
m_nbBeds-1)
Cout(
"oImageDimensionsAndQuantification::SetCalibrationFactor() -> Ignore calibration factor correction" << endl);
1028 if (a_calibrationFactor<=0.)
1030 Cerr(
"***** oImageDimensionsAndQuantification::SetCalibrationFactor() -> Provided calibration factor (" << a_calibrationFactor <<
") is negative or null !" << endl);
1042 Cout(
"oImageDimensionsAndQuantification::SetCalibrationFactor() -> Correct for following calibration factor: " << a_calibrationFactor << endl);
1057 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> Object not initialized !" << endl);
1065 if (a_quantificationFile==
"")
return 0;
1070 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> Multi-bed gated acquisitions cannot be reconstructed !" << endl);
1075 if (
m_verbose>=2)
Cout(
"oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors()-> Processing quantification file '" << a_quantificationFile <<
"'" << endl);
1091 for (
int bed=0 ; bed<
m_nbBeds ; bed++)
1102 string *bed_name =
new string[m_nbBeds + 1];
1104 for(
int bed=0 ; bed<
m_nbBeds ; bed++)
1106 ostringstream oss( ostringstream::out );
1107 oss <<
"bed" << bed+1;
1108 bed_name[bed] = oss.str();
1113 for (
int bed=0 ; bed<
m_nbBeds ; bed++)
1118 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> Didn't found quantitative factors in file " << a_quantificationFile <<
" !" << endl);
1121 else if(return_value == 1)
1123 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> An error occured while trying to recover specific quantitative factors for frame !" << endl);
1126 else if(return_value == 0)
1128 for(
int bed=0 ; bed<
m_nbBeds ; bed++)
1131 if (pp_dynamic_quantification_factors[bed][fr][g] <= 0)
1133 Cerr(
"***** oImageDimensionsAndQuantification::SetDynamicSpecificQuantificationFactors() -> Provided quantification factor (" << pp_dynamic_quantification_factors[bed][fr][g] <<
") is negative or null !" << endl);
1144 for (
int bed=0; bed<
m_nbBeds; bed++)
1146 for (
int fr=0; fr<
m_nbTimeFrames; fr++)
delete pp_dynamic_quantification_factors[bed][fr];
1147 delete[] pp_dynamic_quantification_factors[bed];
1149 delete[] pp_dynamic_quantification_factors;
1183 Cerr(
"***** oImageDimensionsAndQuantification::SetSPECTIsotope() -> Object not initialized !" << endl);
1203 Cerr(
"***** oImageDimensionsAndQuantification::SetPETIsotope() -> Object not initialized !" << endl);
1215 Cout(
"oImageDimensionsAndQuantification::SetPETIsotope() -> Ignore isotope dependent corrections" << endl);
1225 if (a_isotope==
"UNKNOWN" || a_isotope==
"Unknown" || a_isotope==
"unknown")
1229 Cout(
"oImageDimensionsAndQuantification::SetPETIsotope() -> Un-specified isotope; no decay nor branching ratio correction" << endl);
1243 string file_name = config_dir +
"/misc/isotopes_pet.txt";
1244 ifstream fin(file_name.c_str());
1248 Cerr(
"***** oImageDimensionsAndQuantification::SetPETIsotope() -> Failed to open PET isotopes data file '" << file_name <<
"' !" << endl);
1253 int line_max_size = 10240;
1254 char *line =
new char[line_max_size];
1255 FLTNB half_life = -1.;
1256 FLTNB branching_ratio = -1.;
1257 bool found_it =
false;
1258 fin.getline(line,line_max_size);
1262 size_t found_position;
1264 string test = (string)line;
1266 if ((found_position=test.find(
"#"))==0)
1269 fin.getline(line,line_max_size);
1273 found_position = test.find(a_isotope);
1274 if (found_position!=string::npos)
1278 test = test.substr(found_position+1+a_isotope.length());
1280 istringstream fstr(test);
1281 fstr >> half_life >> branching_ratio;
1287 fin.getline(line,line_max_size);
1298 if (branching_ratio<=0. || branching_ratio>1.)
1300 Cerr(
"***** oImageDimensionsAndQuantification::SetPETIsotope() -> Branching ratio (" << branching_ratio <<
") is not in the ]0:1] range !" << endl);
1308 Cout(
"oImageDimensionsAndQuantification::SetPETIsotope() -> Isotope " << a_isotope <<
" has infinite half life and " << branching_ratio <<
" branching ratio" << endl);
1310 Cout(
"oImageDimensionsAndQuantification::SetPETIsotope() -> Isotope " << a_isotope <<
" has " << half_life <<
" seconds half life and " << branching_ratio <<
" branching ratio" << endl);
1316 Cerr(
"***** oImageDimensionsAndQuantification::SetPETIsotope() -> Did not find " << a_isotope <<
" isotope in the PET isotope data file, please add it !" << endl);
1348 long double lambda = log(2.0)/half_life;
1381 int a_respMotionCorrectionFlag,
1382 int a_cardMotionCorrectionFlag,
1383 int a_doubleMotionCorrectionFlag,
1384 int a_invMotionCorrectionFlag,
1385 int a_nbRespGates,
int a_nbCardGates )
1387 if (
m_verbose>=5)
Cout(
"oImageDimensionsAndQuantification::InitDynamicData()" << endl);
1391 a_respMotionCorrectionFlag, a_cardMotionCorrectionFlag, a_doubleMotionCorrectionFlag, a_invMotionCorrectionFlag ))
1393 Cerr(
"***** oImageDimensionsAndQuantification::InitDynamicData() -> A problem occured while initializing the dynamic data from dynamic data manager !" << endl);
1406 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.
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
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.
void CheckNumberOfProjectionThreadsConsistencyWithDataFileSize(vDataFile **a2p_DataFile)
int DealWithBedPositions(vDataFile **a2p_DataFile)
Deal with provided or default bed relative positions.
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.
bool GetBedPositionFlag()
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
vScanner * GetScannerObject()
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 GetDefaultBedDisplacementInMm()
FLTNB GetFrameTimeStopInSec(int a_bed, int a_frame)
Get the frame time stop for the given bed, in seconds as a FLTNB.
FLTNB GetRelativeBedPosition()
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.
void SetDefault()
A function used to set number of threads and MPI instances to 1 and bypass the CheckParameters() func...
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.
bool m_providedBedPosition
Generic class for scanner objects.
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