10 #include "gVariables.hh" 11 #include "gOptions.hh" 12 #include "oImageDimensionsAndQuantification.hh" 13 #include "iDataFilePET.hh" 14 #include "iDataFileSPECT.hh" 15 #include "iDataFileCT.hh" 16 #include "sOutputManager.hh" 17 #include "sScannerManager.hh" 18 #include "sRandomNumberGenerator.hh" 19 #include "iScannerPET.hh" 20 #include "sAddonManager.hh" 31 #define IF_TYPE_UNKNOWN -1 35 #define IF_TYPE_GEOM 1 56 cout <<
"Usage: castor-scannerLUTExplorer -df datafile.cdh [settings]" << endl;
58 cout <<
"This program can be used to explore a datafile and get some info about it. By default, it simply prints general information recovered" << endl;
59 cout <<
"from the reader. If the '-e' option is supply, an element-by-element exploration will be performed: information about each element will be" << endl;
60 cout <<
"displayed." << endl;
61 cout <<
"For CT scanners or SPECT cameras described by a .geom file, a datafile must also be provided in order to get information regarding the projection angles." << endl;
63 cout <<
"[Mandatory parameters]:" << endl;
64 cout <<
" -sf scan_file : Give the path to the header of a single lut file, or to a geom file." << endl;
66 cout <<
"[Options]:" << endl;
67 cout <<
" -e : Flag for scanner element by element exploration (will list the content of each element)." << endl;
68 cout <<
" -g : Flag for global exploration (geometric characteristics of all elements will be displayed)." << endl;
69 cout <<
" -o path_out_file : Path to an output file in which the data will be printed." << endl;
70 cout <<
" -df data_file : For CT or SPECT system, using a .geom file as input. Give the path to the header of a datafile in order to get projection informations." << endl;
71 cout <<
" -vb value : Give the verbosity level, from 0 (no verbose) to 2 (default: 1)" << endl;
72 cout <<
" --help,-h,-help : Print out this help page." << endl;
75 cout <<
" Build date: " << BUILD_DATE << endl;
79 cout <<
" This program is part of the CASToR release version " <<
CASTOR_VERSION <<
"." << endl;
95 void GetInputFileType(
string& ap_pathToScanFilename,
string& ap_pathToBinary,
int a_modality,
int& ap_inputFileType)
100 if(ap_pathToBinary.find(
".hscan") != string::npos
101 || ap_pathToBinary.find(
".lut") != string::npos)
104 if( ap_pathToBinary.find_last_of(
".hscan") != string::npos )
105 ap_pathToBinary = ap_pathToBinary.substr(ap_pathToBinary.find_last_of(
".hscan")) +
".lut";
107 ap_pathToScanFilename = ap_pathToBinary.substr(ap_pathToBinary.find_last_of(
".lut")) +
".hscan";
109 Cout(
" A scanner LUT binary file has been provided " << endl);
120 key_str =
"number of rsectors";
122 key_str =
"number of detector heads";
124 key_str =
"detector radius";
127 Cerr(
"***** castor-scannerLUTExplorer() -> Error, this modality is not implemented yet !" << endl);
135 Cerr(
"***** castor-scannerLUTExplorer() -> An error occurred while trying to read a mandatory parameter for a .geom file in the scanner header file !" << endl);
138 else if (rvalue == 1)
140 Cerr(
"***** castor-scannerLUTExplorer() -> The provided file has not been identified as a scanner binary file (no .hscan or .lut extension), nor a .geom file (a mandatory key is missing) !" << endl);
146 Cout(
" A generic geometry file has been provided " << endl);
162 int main(
int argc,
char** argv)
170 MPI_Init(&argc, &argv);
171 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
172 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
173 if (mpi_rank!=0)
return 0;
188 string path_to_scan_filename =
"";
191 string path_to_data_filename =
"";
199 bool elt_by_elt_flag =
false;
201 bool global_flag =
false;
205 string path_fout =
"";
213 for (
int i=1; i<argc; i++)
216 string option = (string)argv[i];
218 if (option==
"-h" || option==
"--help" || option==
"-help")
224 else if (option==
"-vb")
228 Cerr(
"***** castor-scannerLUTExplorer() -> Argument missing for option: " << option << endl);
233 Cerr(
"***** castor-scannerLUTExplorer() -> Exception when trying to read provided verbosity level '" << verbose <<
" for option: " << option << endl);
239 else if (option==
"-sf")
243 Cerr(
"***** castor-scannerLUTExplorer() -> Argument missing for option: " << option << endl);
246 path_to_scan_filename = (string)argv[i+1];
250 else if (option==
"-df")
254 Cerr(
"***** castor-scannerLUTExplorer() -> Argument missing for option: " << option << endl);
257 path_to_data_filename = (string)argv[i+1];
261 else if (option==
"-e")
263 elt_by_elt_flag =
true;
266 else if (option==
"-g")
270 else if (option==
"-o")
274 Cerr(
"***** castor-scannerLUTExplorer()) -> Argument missing for option: " << option << endl);
277 path_fout = argv[i+1];
284 Cerr(
"***** castor-scannerLUTExplorer() -> Unknown option '" << option <<
"' !" << endl);
294 if (path_to_scan_filename==
"")
296 Cerr(
"***** castor-scannerLUTExplorer() -> Please provide a datafile name !" << endl);
302 Cerr(
"***** castor-scannerLUTExplorer() -> Verbose less than 1 has no sense for a program used to solely print out information on screen !" << endl);
306 if (verbose>2) verbose = 2;
308 if (global_flag && elt_by_elt_flag)
310 Cerr(
"***** castor-scannerLUTExplorer() -> Cannot use global and element-by-element mode at the same time !" << endl);
321 string path_to_binary = path_to_scan_filename;
329 Cout(
"==============================================================" << endl);
330 Cout(
"castor-scannerLUTExplorer() -> Initialization starts" << endl);
344 string modality_str =
"";
348 Cerr(
"***** castor-scannerLUTExplorer() -> Error when trying to read the 'modality' key in the scanner file !" << endl);
355 GetInputFileType(path_to_scan_filename, path_to_binary, modality, input_file_type);
370 Cerr(
"***** castor-proj() -> A problem occurred while checking for the config directory path !" << endl);
377 Cerr(
"***** castor-proj() -> A problem occurred while initializing output directory !" << endl);
383 Cerr(
"***** castor-proj() -> A problem occurred while logging command line arguments !" << endl);
392 string scanner_name =
"";
395 Cerr(
"***** castor-scannerLUTExplorer() -> A problem occurred while trying to find the system name in the datafile header !" << endl);
400 if (p_ScannerManager->
InitScannerWithFile(path_to_scan_filename, scanner_name, input_file_type) )
402 Cerr(
"***** castor-scannerLUTExplorer() -> A problem occurred during scanner object initialization ! !" << endl);
408 Cerr(
"***** castor-scannerLUTExplorer() -> A problem occurred during scanner object construction ! !" << endl);
413 Cerr(
"***** castor-scannerLUTExplorer() -> A problem occurred while creating Scanner object !" << endl);
420 if(path_to_data_filename ==
"")
422 Cerr(
"***** castor-scannerLUTExplorer() -> Error : For SPECT / CT systems, a datafile is required to compute the look-up-table from a geom file (i.e projection angles) !" << endl);
427 Cerr(
"***** castor-scannerLUTExplorer() -> A problem occurred while retrieving scanner fields from the datafile header !" << endl);
433 Cerr(
"***** castor-scannerLUTExplorer() -> A problem occurred while generating/reading the LUT !" << endl);
438 Cerr(
"***** castor-scannerLUTExplorer() -> A problem occurred while checking scanner manager parameters !" << endl);
443 Cerr(
"***** castor-scannerLUTExplorer() -> A problem occurred while initializing scanner !" << endl);
448 Cout(
"castor-scannerLUTExplorer() -> End of initialization" << endl);
449 Cout(
"==============================================================" << endl);
459 Cout(
"==============================================================" << endl);
467 Cout(
"castor-scannerLUTExplorer() -> Start exploration of all scanner elements" << endl);
469 int64_t index_start = 0; int64_t index_stop = p_ScannerManager->
GetSystemNbElts();
472 int64_t index = index_start;
473 while (index>=index_start && index<index_stop)
476 Cout(
"------------------------- Element index " << index <<
" -------------------------" << endl);
479 FLTNB position1[3], position2[3];
480 FLTNB orientation1[3], orientation2[3];
485 Cout(
"Scanner element center location (x,y,z): "<< position2[0] <<
" ; " << position2[1] <<
" ; " << position2[2] <<
" ." ;);
486 Cout(
"Orientation (x,y,z): "<< orientation2[0] <<
" ; " << orientation2[1] <<
" ; " << orientation2[2] << endl;);
489 cout <<
"--------> Give an element index or simply press enter for next element: " << flush;
491 string answer =
""; getline(cin,answer);
494 if (answer==
"") index++;
499 int64_t next_index = stoll(answer);
500 if (next_index<index_start || next_index>=index_stop)
502 Cerr(
"***** castor-scannerLUTExplorer() -> The provided element index (" << next_index <<
") is out of datafile range" 503 <<
" [" << index_start <<
":" << index_stop <<
"[ !" << endl);
506 else index = next_index;
510 Cout(
"==============================================================" << endl);
517 else if (global_flag)
520 Cout(
"castor-scannerLUTExplorer() -> Start global exploration of all elements" << endl);
523 int64_t index_start = 0; int64_t index_stop = p_ScannerManager->
GetSystemNbElts();
526 for (int64_t index=index_start ; index<index_stop ; index++)
529 FLTNB position1[3], position2[3];
530 FLTNB orientation1[3], orientation2[3];
534 Cout(
"Scanner element center location (x,y,z): "<< position2[0] <<
" ; " << position2[1] <<
" ; " << position2[2] <<
" ." ;);
535 Cout(
"Orientation (x,y,z): "<< orientation2[0] <<
" ; " << orientation2[1] <<
" ; " << orientation2[2] << endl;);
538 Cout(
"==============================================================" << endl);
544 Cout(
"==============================================================" << endl);
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
void SetVerbose(int a_verbose)
int BuildScannerObject()
Instantiate the specific scanner object related to the modality, and set verbosity of scanner object...
int GetModalityFromString(string a_systemStr)
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
int CheckParameters()
Check if all parameters have been correctly initialized, and call the CheckParameters function of the...
int InstantiateScanner()
Instantiate scanner using the related function in the scanner classes.
int LogCommandLine(int argc, char **argv)
int CheckConfigDir(const string &a_path)
#define SCANNER_SPECT_CONVERGENT
int BuildLUT()
Call the eponym function of the scanner class.
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
Singleton class that Instantiate and initialize the scanner object.
vScanner * GetScannerObject()
#define KEYWORD_MANDATORY
int Initialize()
Initialization : .
void GetUserEndianness()
Check user/host computer endianness and write it to the global variable User_Endianness.
int InitOutputDirectory(const string &a_pathFout, const string &a_pathDout)
int ConvertFromString(const string &a_str, string *a_result)
Copy the 'a_str' string in the position pointed by 'a_result'.
void Describe()
Call the eponym function from the Scanner object (if initialized)
void SetVerbose(int a_verboseLevel)
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 GetGeometricInfoFromDataFile(string a_pathToDataFilename)
virtual int GetPositionsAndOrientations(int a_index1, int a_index2, FLTNB ap_Position1[3], FLTNB ap_Position2[3], FLTNB ap_Orientation1[3], FLTNB ap_Orientation2[3], FLTNB *ap_POI1=NULL, FLTNB *ap_POI2=NULL)=0
int InitScannerWithFile(string a_pathScanFile, string a_scannerName, int a_fileTypeFlag)