CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
gDataConversionUtilities.hh
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-2019 all CASToR contributors listed below:
18 
19  --> Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Thibaut MERLIN, Mael MILLARDET, Simon STUTE, Valentin VIELZEUF
20 
21 This is CASToR version 3.0.
22 */
23 
30 #ifndef UTILS_HH
31 #define UTILS_HH 1
32 
33 #include "gVariables.hh"
34 #include "gOptions.hh"
35 #include "iDataFilePET.hh"
36 #include "sOutputManager.hh"
37 #include "sScannerManager.hh"
38 #include "oInterfileIO.hh"
39 
40 #ifdef CASTOR_ROOT
41  #ifdef _WIN32
42  #include "Windows4Root.h"
43  #endif
44  #include "TROOT.h"
45  #include "TApplication.h"
46  #include "TGClient.h"
47  #include "TCanvas.h"
48  #include "TSystem.h"
49  #include "TTree.h"
50  #include "TBranch.h"
51  #include "TFile.h"
52 #endif
53 
62 #define GATE_SYS_UNKNOWN -1
63 
64 #define GATE_SYS_CYLINDRICAL 0
65 
66 #define GATE_SYS_ECAT 1
67 
68 #define GATE_SYS_SPECT 2
69 
72 #define GATE_NB_MAX_LAYERS 4 // Max number of layer in GATE = 4
73 
74 
84 vector<string> CheckGATECommand(const string& a_key, const string& a_line);
85 
92 vector<string> Split(string a_line);
93 
94 
101 void ConvertValuesTomm(vector<string>& values);
102 
103 
110 template <class T>
111 string toString(T a_val)
112 {
113  stringstream ss;
114  ss << a_val;
115  return ss.str();
116 }
117 
118 
127 template <typename T>
128 int WriteVector(ofstream& file, const string& a_key, vector <T> a_vals);
129 
138 int WriteVector(ofstream& file, const string& a_key, vector <string> a_vals);
139 
148 int WriteVector(ofstream& file, const string& a_key, vector <vector<string> > a_vals);
149 
150 
151 
158 int GetGATESystemType(const string& a_pathMac);
159 
160 
161 
162 
170 int GetGATEMacFiles(const string& a_pathMac, vector<string> &ap_pathToMacFiles);
171 
172 
173 
174 
193 int GetGATEAliasesCylindrical(vector<string> path_mac_files,
194  string& rsector_name,
195  string& module_name,
196  string& submodule_name,
197  string& crystal_name,
198  vector<string>& layers_name ,
199  int vb );
200 
201 
202 
203 
217 int GetGATEAliasesEcat(vector<string> path_mac_files,
218  string& block_name,
219  string& crystal_name,
220  int vb );
221 
222 
223 
224 
240 int GetGATEAliasesSPECT(vector<string> path_mac_files,
241  string& base_name,
242  string& crystal_name,
243  string& pixel_name,
244  int vb );
245 
246 
247 
248 
265 uint32_t ConvertIDecat(int32_t nBlocksPerRing,
266  int32_t nBlocksLine,
267  int32_t nCrystalsTransaxial,
268  int32_t nCrystalsAxial,
269  int32_t crystalID,
270  int32_t blockID);
271 
272 
273 
274 
275 
288 uint32_t ConvertIDSPECTRoot1( int32_t a_headID,
289  float_t a_rotAngle,
290  float_t a_angStep,
291  uint32_t a_nProjectionsByHead);
292 
293 
294 
325 uint32_t ConvertIDSPECTRoot2( uint32_t a_nbSimulatedPixels,
326  uint32_t a_nPixTrs,
327  uint32_t a_nPixAxl,
328  int32_t a_headID,
329  int32_t a_crystalID,
330  int32_t a_pixelID,
331  float_t a_rotAngle,
332  float_t a_headAngPitch,
333  float_t a_crystalSizeAxl,
334  float_t a_crystalSizeTrs,
335  float_t a_gPosX,
336  float_t a_gPosY,
337  float_t a_gPosZ);
338 
339 
340 
341 
384 uint32_t ConvertIDcylindrical(uint32_t nRsectorsAngPos,
385  uint32_t nRsectorsAxial,
386  bool a_invertDetOrder,
387  int a_rsectorIdOrder,
388  uint32_t nModulesTransaxial,
389  uint32_t nModulesAxial,
390  uint32_t nSubmodulesTransaxial,
391  uint32_t nSubmodulesAxial,
392  uint32_t nCrystalsTransaxial,
393  uint32_t nCrystalsAxial,
394  uint8_t nLayers,
395  uint32_t* nCrystalPerLayer,
396  vector<uint32_t> nLayersRptTransaxial,
397  vector<uint32_t> nLayersRptAxial,
398  int32_t layerID,
399  int32_t crystalID,
400  int32_t submoduleID,
401  int32_t moduleID,
402  int32_t rsectorID);
403 
417 int ComputeKindGATEEvent(uint32_t eventID1, uint32_t eventID2,
418  int comptonPhantom1, int comptonPhantom2,
419  int rayleighPhantom1, int rayleighPhantom2);
420 
421 
422 
444 int ReadMacECAT(string a_pathMac,
445  uint32_t &nCrystalsTot,
446  uint32_t &nCrystalsAxial,
447  uint32_t &nCrystalsTransaxial,
448  uint32_t &nBlocksLine,
449  uint32_t &nBlocksPerRing,
450  uint32_t &start_time_ms,
451  uint32_t &duration_ms,
452  int vb);
453 
454 
491 int ReadMacSPECT( string a_pathMac,
492  float_t &distToDetector,
493  uint32_t &nHeads,
494  uint32_t &nPixAxl,
495  uint32_t &nPixTrs,
496  float_t &crystalSizeAxl,
497  float_t &crystalSizeTrs,
498  uint32_t &nProjectionsTot,
499  uint32_t &nProjectionsByHead,
500  float_t &head1stAngle,
501  float_t &headAngPitch,
502  float_t &headAngStepDeg,
503  int &headRotDirection,
504  uint32_t &start_time_ms,
505  uint32_t &duration_ms,
506  int vb);
507 
508 
509 
510 
511 
547 int ReadIntfSPECT(string a_pathIntf,
548  float_t &ap_distToDetector,
549  uint32_t &ap_nHeads,
550  uint32_t &ap_nPixAxl,
551  uint32_t &ap_nPixTrs,
552  float_t &ap_crystalSizeAxl,
553  float_t &ap_crystalSizeTrs,
554  uint32_t &ap_nProjectionsTot,
555  uint32_t &ap_nProjectionsByHead,
556  float_t &ap_head1stAngle,
557  float_t &ap_headAngPitch,
558  float_t &headAngStepDeg,
559  int &ap_headRotDirection,
560  uint32_t &ap_start_time_ms,
561  uint32_t &ap_duration_ms,
562  int vb);
563 
564 
565 
566 
607 int ReadMacCylindrical( string a_pathMac,
608  uint8_t &nLayers,
609  uint32_t *nb_crystal_per_layer,
610  uint32_t &nCrystalsTot,
611  uint32_t &nCrystalsAxial,
612  uint32_t &nCrystalsTransaxial,
613  vector<uint32_t> &nLayersRptAxial,
614  vector<uint32_t> &nLayersRptTransaxial,
615  uint32_t &nSubmodulesAxial,
616  uint32_t &nSubmodulesTransaxial,
617  uint32_t &nModulesAxial,
618  uint32_t &nModulesTransaxial,
619  uint32_t &nRsectorsAxial,
620  uint32_t &nRsectorsAngPos,
621  bool &invert_det_order,
622  int &rsector_id_order,
623  uint32_t &start_time_ms,
624  uint32_t &duration_ms,
625  int vb);
626 
627 
628 
636 int CreateGeomWithECAT(string a_pathMac, string a_pathGeom);
637 
638 
639 
640 
648 int CreateGeomWithCylindrical(string a_pathMac, string a_pathGeom);
649 
650 
651 
652 
660 int CreateGeomWithSPECT(string a_pathMac, string a_pathGeom);
661 
662 #endif
uint32_t ConvertIDSPECTRoot1(int32_t a_headID, float_t a_rotAngle, float_t a_angStep, uint32_t a_nProjectionsByHead)
Compute a CASToR projection index of a GATE SPECThead system.
void ConvertValuesTomm(vector< string > &values)
Check if the vector of strings passed in parameter contains the &#39;cm&#39; unit In this case...
This header file is mainly used to declare some macro definitions and all includes needed from the st...
vector< string > CheckGATECommand(const string &a_key, const string &a_line)
Check if the line contains the provided GATE command. In this case, parse the line and returns the va...
int ReadMacSPECT(string a_pathMac, float_t &distToDetector, uint32_t &nHeads, uint32_t &nPixAxl, uint32_t &nPixTrs, float_t &crystalSizeAxl, float_t &crystalSizeTrs, uint32_t &nProjectionsTot, uint32_t &nProjectionsByHead, float_t &head1stAngle, float_t &headAngPitch, float_t &headAngStepDeg, int &headRotDirection, uint32_t &start_time_ms, uint32_t &duration_ms, int vb)
Recover informations about the scanner element of an ECAT system, and acquisition duration...
int GetGATEAliasesSPECT(vector< string > path_mac_files, string &base_name, string &crystal_name, string &pixel_name, int vb)
Loop over a list of path to GATE macro files passed in parameter to recover aliases of the different ...
int GetGATEAliasesEcat(vector< string > path_mac_files, string &block_name, string &crystal_name, int vb)
Loop over a list of path to GATE macro files passed in parameter to recover aliases of the different ...
Declaration of class iDataFilePET.
int GetGATEAliasesCylindrical(vector< string > path_mac_files, string &rsector_name, string &module_name, string &submodule_name, string &crystal_name, vector< string > &layers_name, int vb)
Loop over a list of path to GATE macro files passed in parameter to recover aliases of the different ...
int ReadMacCylindrical(string a_pathMac, uint8_t &nLayers, uint32_t *nb_crystal_per_layer, uint32_t &nCrystalsTot, uint32_t &nCrystalsAxial, uint32_t &nCrystalsTransaxial, vector< uint32_t > &nLayersRptAxial, vector< uint32_t > &nLayersRptTransaxial, uint32_t &nSubmodulesAxial, uint32_t &nSubmodulesTransaxial, uint32_t &nModulesAxial, uint32_t &nModulesTransaxial, uint32_t &nRsectorsAxial, uint32_t &nRsectorsAngPos, bool &invert_det_order, int &rsector_id_order, uint32_t &start_time_ms, uint32_t &duration_ms, int vb)
Recover informations about the scanner element of a cylindricalPET system and acquisition duration...
int ComputeKindGATEEvent(uint32_t eventID1, uint32_t eventID2, int comptonPhantom1, int comptonPhantom2, int rayleighPhantom1, int rayleighPhantom2)
Determine kind of a given coincidence event, from its attributes.
int ReadMacECAT(string a_pathMac, uint32_t &nCrystalsTot, uint32_t &nCrystalsAxial, uint32_t &nCrystalsTransaxial, uint32_t &nBlocksLine, uint32_t &nBlocksPerRing, uint32_t &start_time_ms, uint32_t &duration_ms, int vb)
Recover informations about the scanner element of an ECAT system and acquisition duration, from a GATE macro file.
Declaration of class sScannerManager.
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...
uint32_t ConvertIDcylindrical(uint32_t nRsectorsAngPos, uint32_t nRsectorsAxial, bool a_invertDetOrder, int a_rsectorIdOrder, uint32_t nModulesTransaxial, uint32_t nModulesAxial, uint32_t nSubmodulesTransaxial, uint32_t nSubmodulesAxial, uint32_t nCrystalsTransaxial, uint32_t nCrystalsAxial, uint8_t nLayers, uint32_t *nCrystalPerLayer, vector< uint32_t > nLayersRptTransaxial, vector< uint32_t > nLayersRptAxial, int32_t layerID, int32_t crystalID, int32_t submoduleID, int32_t moduleID, int32_t rsectorID)
Compute a CASToR crystal index of a GATE cylindricalPET system from its indexes (rsector/module/submo...
int WriteVector(ofstream &file, const string &a_key, vector< T > a_vals)
Write the key and its values in the file provided in parameter.
string toString(T a_val)
Convert a value of any type into string.
Declaration of class sOutputManager.
int GetGATEMacFiles(const string &a_pathMac, vector< string > &ap_pathToMacFiles)
Extract the paths to each macro file contained in the main macro file.
This file is used for all kind of different functions designed for options parsing and ASCII file rea...
vector< string > Split(string a_line)
Split the line provided in parameter into a vector of strings (separator is blankspace) ...
This group of functions manages Interfile image file format.
uint32_t ConvertIDecat(int32_t nBlocksPerRing, int32_t nBlocksLine, int32_t nCrystalsTransaxial, int32_t nCrystalsAxial, int32_t crystalID, int32_t blockID)
Compute a CASToR crystal index of a GATE ecat system from its indexes (block/crystal) and the system ...
int ReadIntfSPECT(string a_pathIntf, float_t &ap_distToDetector, uint32_t &ap_nHeads, uint32_t &ap_nPixAxl, uint32_t &ap_nPixTrs, float_t &ap_crystalSizeAxl, float_t &ap_crystalSizeTrs, uint32_t &ap_nProjectionsTot, uint32_t &ap_nProjectionsByHead, float_t &ap_head1stAngle, float_t &ap_headAngPitch, float_t &headAngStepDeg, int &ap_headRotDirection, uint32_t &ap_start_time_ms, uint32_t &ap_duration_ms, int vb)
Recover informations about the scanner element of an ECAT system, and acquisition duration...
int GetGATESystemType(const string &a_pathMac)
Read a GATE macro file and identify the system type from the &#39;gate/systems/&#39; 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...
uint32_t ConvertIDSPECTRoot2(uint32_t a_nbSimulatedPixels, uint32_t a_nPixTrs, uint32_t a_nPixAxl, int32_t a_headID, int32_t a_crystalID, int32_t a_pixelID, float_t a_rotAngle, float_t a_headAngPitch, float_t a_crystalSizeAxl, float_t a_crystalSizeTrs, float_t a_gPosX, float_t a_gPosY, float_t a_gPosZ)
Compute a CASToR crystal index of a GATE SPECThead system.