![]() |
CASToR
1.0
Tomographic Reconstruction (PET/SPECT)
|
00001 00014 #include <iostream> 00015 #include <vector> 00016 #include <string> 00017 #include <cstring> 00018 #include <fstream> 00019 #include <sstream> 00020 #include <math.h> 00021 00022 #include "gDataConversionUtilities.hh" 00023 00024 using namespace std; 00025 00026 00027 // ===================================================================== 00028 // --------------------------------------------------------------------- 00029 // --------------------------------------------------------------------- 00030 // ===================================================================== 00036 void showHelp(int a_returnCode) 00037 { 00038 cout << endl; 00039 cout << " Usage: castor-GATEMacToGeom -m input_mac_file" << endl; 00040 cout << " -o output_geom_file" << endl; 00041 cout << " -v verbose" << endl; 00042 cout << endl; 00043 00044 cout << "[Input settings]:" << endl; 00045 cout << " -m input_mac_file : give the path to a GATE macro file describing a cylindricalPET, SPECThead or ecat system" << endl; 00046 cout << " -o output_geom_file : give the alias of the output geom file which will be generated in the scanner repository (default location: config/scanner/)" << endl; 00047 cout << " -v verbose : verbosity level" << endl; 00048 cout << endl; 00049 00050 Exit(a_returnCode); 00051 } 00052 00053 00054 00055 00056 // ===================================================================== 00057 // --------------------------------------------------------------------- 00058 // --------------------------------------------------------------------- 00059 // ===================================================================== 00060 // Basic checking and processing the input 00061 00062 int main(int argc, char *argv[]) 00063 { 00064 // Path to mac file 00065 string path_to_mac = ""; 00066 // Path to the output geometric file 00067 string path_to_geom = ""; 00068 00069 if (argc < 3) 00070 { 00071 cerr << "Invalid number of arguments. Please read the help section." << endl; 00072 showHelp(0); 00073 } 00074 else 00075 { 00076 for (int i=1; i<argc; i++) 00077 { 00078 string option = (string)argv[i]; 00079 00080 // .mac file 00081 if (option=="-m") 00082 { 00083 if (argv[i+1] == NULL) 00084 { 00085 Cerr("***** castor-GATEMacToGeom :: argument missing for option: " << option << endl); 00086 Exit(EXIT_FAILURE); 00087 } 00088 else 00089 path_to_mac = argv[i+1]; 00090 00091 // Check if the file exists 00092 ifstream fcheck(path_to_mac.c_str()); 00093 if(!fcheck.good()) 00094 { 00095 Cerr("***** castor-GATEMacToGeom :: cannot read provided mac file : " << path_to_mac << endl); 00096 Exit(EXIT_FAILURE); 00097 } 00098 fcheck.close(); 00099 i++; 00100 } 00101 00102 // output file 00103 else if (option=="-o") 00104 { 00105 if (argv[i+1] == NULL) 00106 { 00107 Cerr("***** castor-GATEMacToGeom :: argument missing for option: " << option << endl); 00108 Exit(EXIT_FAILURE); 00109 } 00110 else 00111 path_to_geom = argv[i+1]; 00112 i++; 00113 } 00114 } 00115 } 00116 00117 00118 // ============================================================================================================ 00119 // SOutputManager object initialisation: 00120 // ============================================================================================================ 00121 00122 sOutputManager* p_outputManager = sOutputManager::GetInstance(); 00123 00124 // Set path to the config directory 00125 if (p_outputManager->CheckConfigDir("")) 00126 { 00127 Cerr("***** castor-GATEMacToGeom :: A problem occured while checking for the config directory path !" << endl); 00128 Exit(EXIT_FAILURE); 00129 } 00130 00131 string scanner_repository = sOutputManager::GetInstance()->GetPathToConfigDir() + "scanner" + OS_SEP; 00132 path_to_geom = scanner_repository + path_to_geom + ".geom"; 00133 00134 00135 // ============================================================================================================ 00136 // Get & check system type 00137 // ============================================================================================================ 00138 switch ( GetGATESystemType(path_to_mac) ) 00139 { 00140 case GATE_SYS_CYLINDRICAL: 00141 cout << endl << " --- CylindricalPET system detected. Proceeding to conversion... --- " << endl << endl; 00142 00143 if(CreateGeomWithCylindrical(path_to_mac , path_to_geom) ) 00144 { 00145 Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for cylindrical system: " << path_to_mac << endl); 00146 Exit(EXIT_FAILURE); 00147 } 00148 break; 00149 00150 case GATE_SYS_ECAT: 00151 cout << endl << " --- ECAT system detected. Proceeding to conversion... --- " << endl; 00152 if(CreateGeomWithECAT(path_to_mac , path_to_geom) ) 00153 { 00154 Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for ecat system: " << path_to_mac << endl); 00155 Exit(EXIT_FAILURE); 00156 } 00157 break; 00158 /* // Not yet validated 00159 case GATE_SYS_SPECT: 00160 cout << endl << " --- SPECThead system detected. Proceeding to conversion... --- " << endl; 00161 if(CreateGeomWithSPECT(path_to_mac , path_to_geom) ) 00162 { 00163 Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for SPECT system: " << path_to_mac << endl); 00164 Exit(EXIT_FAILURE); 00165 } 00166 break;*/ 00167 00168 default: // Unknown system 00169 Cerr("***** castor-GATEMacToGeom :: System type not supported : " << endl); 00170 Cerr(" This script only supports conversion for cylindricalPET and ecat systems" << endl); 00171 //Cerr(" This script only supports conversion for cylindricalPET ecat and SPECThead systems" << endl); 00172 Cerr(" The system type is recovered from the lines '/gate/systems/...'" << endl); 00173 Exit(EXIT_FAILURE); 00174 break; 00175 } 00176 00177 cout << endl << " --- Conversion completed --- " << endl << endl; 00178 return 0; 00179 }