CASToR  1.1
Tomographic Reconstruction (PET/SPECT)
 All Classes Files Functions Variables Typedefs Macros Groups Pages
castor-GATEMacToGeom.cc
Go to the documentation of this file.
1 
14 #include <iostream>
15 #include <vector>
16 #include <string>
17 #include <cstring>
18 #include <fstream>
19 #include <sstream>
20 #include <math.h>
21 
23 
24 using namespace std;
25 
26 
27 // =====================================================================
28 // ---------------------------------------------------------------------
29 // ---------------------------------------------------------------------
30 // =====================================================================
36 void showHelp(int a_returnCode)
37 {
38  cout << endl;
39  cout << " Usage: castor-GATEMacToGeom -m input_mac_file" << endl;
40  cout << " -o output_geom_file" << endl;
41  cout << " -v verbose" << endl;
42  cout << endl;
43  cout << "[Input settings]:" << endl;
44  cout << " -m input_mac_file : give the path to a GATE macro file describing a cylindricalPET, ecat or SPECThead system" << endl;
45  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;
46  //cout << " -v verbose : verbosity level" << endl;
47  cout << endl;
48  #ifdef CASTOR_VERSION
49  cout << " This program is part of the CASToR release version " << CASTOR_VERSION << "." << endl;
50  cout << endl;
51  #endif
52  Exit(a_returnCode);
53 }
54 
55 
56 
57 
58 // =====================================================================
59 // ---------------------------------------------------------------------
60 // ---------------------------------------------------------------------
61 // =====================================================================
62 // Basic checking and processing the input
63 
64 int main(int argc, char *argv[])
65 {
66  // Path to mac file
67  string path_to_mac = "";
68  // Path to the output geometric file
69  string path_to_geom = "";
70 
71  if (argc < 3)
72  {
73  cerr << "Invalid number of arguments. Please read the help section." << endl;
74  showHelp(0);
75  }
76  else
77  {
78  for (int i=1; i<argc; i++)
79  {
80  string option = (string)argv[i];
81 
82  // .mac file
83  if (option=="-m")
84  {
85  if (argv[i+1] == NULL)
86  {
87  Cerr("***** castor-GATEMacToGeom :: argument missing for option: " << option << endl);
88  Exit(EXIT_FAILURE);
89  }
90  else
91  path_to_mac = argv[i+1];
92 
93  // Check if the file exists
94  ifstream fcheck(path_to_mac.c_str());
95  if(!fcheck.good())
96  {
97  Cerr("***** castor-GATEMacToGeom :: cannot read provided mac file : " << path_to_mac << endl);
98  Exit(EXIT_FAILURE);
99  }
100  fcheck.close();
101  i++;
102  }
103 
104  // output file
105  else if (option=="-o")
106  {
107  if (argv[i+1] == NULL)
108  {
109  Cerr("***** castor-GATEMacToGeom :: argument missing for option: " << option << endl);
110  Exit(EXIT_FAILURE);
111  }
112  else
113  path_to_geom = argv[i+1];
114  i++;
115  }
116 
117  else
118  {
119  Cerr(endl << "***** castor-GATERootToCastor :: Unknown option '" << option << "' !" << endl);
120  showHelp(0);
121  Exit(EXIT_FAILURE);
122  }
123  }
124  }
125 
126 
127  // ============================================================================================================
128  // SOutputManager object initialisation:
129  // ============================================================================================================
130 
131  sOutputManager* p_outputManager = sOutputManager::GetInstance();
132 
133  // Set path to the config directory
134  if (p_outputManager->CheckConfigDir(""))
135  {
136  Cerr("***** castor-GATEMacToGeom :: A problem occured while checking for the config directory path !" << endl);
137  Exit(EXIT_FAILURE);
138  }
139 
140  string scanner_repository = sOutputManager::GetInstance()->GetPathToConfigDir() + "scanner" + OS_SEP;
141  path_to_geom = scanner_repository + path_to_geom + ".geom";
142 
143  cout << "path mac " << path_to_mac << endl;
144  // ============================================================================================================
145  // Get & check system type
146  // ============================================================================================================
147  switch ( GetGATESystemType(path_to_mac) )
148  {
150  cout << endl << " --- CylindricalPET system detected. Proceeding to conversion... --- " << endl << endl;
151 
152  if(CreateGeomWithCylindrical(path_to_mac , path_to_geom) )
153  {
154  Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for cylindrical system: " << path_to_mac << endl);
155  Exit(EXIT_FAILURE);
156  }
157  break;
158 
159  case GATE_SYS_ECAT:
160  cout << endl << " --- ECAT system detected. Proceeding to conversion... --- " << endl;
161  if(CreateGeomWithECAT(path_to_mac , path_to_geom) )
162  {
163  Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for ecat system: " << path_to_mac << endl);
164  Exit(EXIT_FAILURE);
165  }
166  break;
167 
168  case GATE_SYS_SPECT:
169  cout << endl << " --- SPECThead system detected. Proceeding to conversion... --- " << endl;
170  if(CreateGeomWithSPECT(path_to_mac , path_to_geom) )
171  {
172  Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for SPECT system: " << path_to_mac << endl);
173  Exit(EXIT_FAILURE);
174  }
175  break;
176 
177  default: // Unknown system
178  Cerr("***** castor-GATEMacToGeom :: System type not supported : " << endl);
179  Cerr(" This script only supports conversion for cylindricalPET ecat and SPECThead systems" << endl);
180  Cerr(" The system type is recovered from the lines '/gate/systems/...'" << endl);
181  Exit(EXIT_FAILURE);
182  break;
183  }
184  cout << endl << " --- Conversion completed --- " << endl << endl;
185  return 0;
186 }
This file gathers various function dedicated to data conversion in order to convert various type of G...
#define GATE_SYS_ECAT
#define GATE_SYS_SPECT
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
void Exit(int code)
int CheckConfigDir(const string &a_path)
Set the path to the CASTOR config directory from the given path if not empty or through the existence...
#define Cerr(MESSAGE)
int main(int argc, char *argv[])
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 CreateGeomWithECAT(string a_pathMac, string a_pathGeom)
Read a GATE macro file containing the description of an ecat system, and convert it to a geom file...
#define GATE_SYS_CYLINDRICAL
#define OS_SEP
#define CASTOR_VERSION
Definition: gVariables.hh:44
void showHelp(int a_returnCode)
int GetGATESystemType(const string &a_pathMac)
Read a GATE macro file and identify the system type from the 'gate/systems/' command lines...
int CreateGeomWithCylindrical(string a_pathMac, string a_pathGeom)
Read a GATE macro file containing the description of a cylindricalPET system, and convert it to a geo...
int CreateGeomWithSPECT(string a_pathMac, string a_pathGeom)
Read a GATE macro file containing the description of a SPECThead system, and convert it to a geom fil...