CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
castor-GATEMacToGeom.cc
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2018 all CASToR contributors listed below:
18 
19  --> current contributors: Thibaut MERLIN, Simon STUTE, Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Mael MILLARDET
20  --> past contributors: Valentin VIELZEUF
21 
22 This is CASToR version 2.0.
23 */
24 
35 #include <iostream>
36 #include <vector>
37 #include <string>
38 #include <cstring>
39 #include <fstream>
40 #include <sstream>
41 #include <math.h>
42 
44 
45 using namespace std;
46 
47 // =====================================================================
48 // ---------------------------------------------------------------------
49 // ---------------------------------------------------------------------
50 // =====================================================================
56 void showHelp(int a_returnCode)
57 {
58  cout << endl;
59  cout << " Usage: castor-GATEMacToGeom -m input_mac_file" << endl;
60  cout << " -o output_geom_file" << endl;
61  cout << " -v verbose" << endl;
62  cout << endl;
63  cout << "[Input settings]:" << endl;
64  cout << " -m input_mac_file : give the path to a GATE macro file describing a cylindricalPET, ecat or SPECThead system" << endl;
65  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;
66  //cout << " -v verbose : verbosity level" << endl;
67  cout << endl;
68  #ifdef CASTOR_VERSION
69  cout << " This program is part of the CASToR release version " << CASTOR_VERSION << "." << endl;
70  cout << endl;
71  #endif
72  Exit(a_returnCode);
73 }
74 
75 
76 
77 
78 // =====================================================================
79 // ---------------------------------------------------------------------
80 // ---------------------------------------------------------------------
81 // =====================================================================
82 // Basic checking and processing the input
83 
84 int main(int argc, char *argv[])
85 {
86  // Path to mac file
87  string path_to_mac = "";
88  // Path to the output geometric file
89  string path_to_geom = "";
90 
91  if (argc < 3)
92  {
93  cerr << "Invalid number of arguments. Please read the help section." << endl;
94  showHelp(0);
95  }
96  else
97  {
98  for (int i=1; i<argc; i++)
99  {
100  string option = (string)argv[i];
101 
102  // .mac file
103  if (option=="-m")
104  {
105  if (argv[i+1] == NULL)
106  {
107  Cerr("***** castor-GATEMacToGeom :: argument missing for option: " << option << endl);
108  Exit(EXIT_FAILURE);
109  }
110  else
111  path_to_mac = argv[i+1];
112 
113  // Check if the file exists
114  ifstream fcheck(path_to_mac.c_str());
115  if(!fcheck.good())
116  {
117  Cerr("***** castor-GATEMacToGeom :: cannot read provided mac file : " << path_to_mac << endl);
118  Exit(EXIT_FAILURE);
119  }
120  fcheck.close();
121  i++;
122  }
123 
124  // output file
125  else if (option=="-o")
126  {
127  if (argv[i+1] == NULL)
128  {
129  Cerr("***** castor-GATEMacToGeom :: argument missing for option: " << option << endl);
130  Exit(EXIT_FAILURE);
131  }
132  else
133  path_to_geom = argv[i+1];
134  i++;
135  }
136 
137  else
138  {
139  Cerr(endl << "***** castor-GATERootToCastor :: Unknown option '" << option << "' !" << endl);
140  showHelp(0);
141  Exit(EXIT_FAILURE);
142  }
143  }
144  }
145 
146 
147  // ============================================================================================================
148  // SOutputManager object initialisation:
149  // ============================================================================================================
150 
151  sOutputManager* p_outputManager = sOutputManager::GetInstance();
152 
153  // Set path to the config directory
154  if (p_outputManager->CheckConfigDir(""))
155  {
156  Cerr("***** castor-GATEMacToGeom :: A problem occured while checking for the config directory path !" << endl);
157  Exit(EXIT_FAILURE);
158  }
159 
160  string scanner_repository = sOutputManager::GetInstance()->GetPathToConfigDir() + "scanner" + OS_SEP;
161  path_to_geom = scanner_repository + path_to_geom + ".geom";
162 
163  cout << "path mac " << path_to_mac << endl;
164  // ============================================================================================================
165  // Get & check system type
166  // ============================================================================================================
167  switch ( GetGATESystemType(path_to_mac) )
168  {
170  cout << endl << " --- CylindricalPET system detected. Proceeding to conversion... --- " << endl << endl;
171 
172  if(CreateGeomWithCylindrical(path_to_mac , path_to_geom) )
173  {
174  Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for cylindrical system: " << path_to_mac << endl);
175  Exit(EXIT_FAILURE);
176  }
177  break;
178 
179  case GATE_SYS_ECAT:
180  cout << endl << " --- ECAT system detected. Proceeding to conversion... --- " << endl;
181  if(CreateGeomWithECAT(path_to_mac , path_to_geom) )
182  {
183  Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for ecat system: " << path_to_mac << endl);
184  Exit(EXIT_FAILURE);
185  }
186  break;
187 
188  case GATE_SYS_SPECT:
189  cout << endl << " --- SPECThead system detected. Proceeding to conversion... --- " << endl;
190  if(CreateGeomWithSPECT(path_to_mac , path_to_geom) )
191  {
192  Cerr("***** castor-GATEMacToGeom :: An error occured while trying to process mac file for SPECT system: " << path_to_mac << endl);
193  Exit(EXIT_FAILURE);
194  }
195  break;
196 
197  default: // Unknown system
198  Cerr("***** castor-GATEMacToGeom :: System type not supported : " << endl);
199  Cerr(" This script only supports conversion for cylindricalPET ecat and SPECThead systems" << endl);
200  Cerr(" The system type is recovered from the lines '/gate/systems/...'" << endl);
201  Exit(EXIT_FAILURE);
202  break;
203  }
204  cout << endl << " --- Conversion completed --- " << endl << endl;
205  return 0;
206 }
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:70
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...