Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // 27 // File I/O manager class for writing or reading calcuated dose 28 // distribution and some event information 29 // 30 // 31 // Mar. 31, 2009 : release for the gMocrenFile driver 32 // 33 // Akinori Kimura 34 // 35 // gMocren home page: 36 // http://geant4.kek.jp/gMocren/ 37 // 38 #ifndef GMOCRENIO_HH 39 #define GMOCRENIO_HH 40 41 #include <vector> 42 #include <string> 43 #include <fstream> 44 #include <map> 45 46 // 47 //----- GMocrenDataPrimitive class -----// 48 // data primitive class for volume data 49 // 50 template <typename T> class GMocrenDataPrimitive { 51 protected: 52 int kSize[3]; 53 double kScale; 54 T kMinmax[2]; 55 float kCenter[3]; 56 std::vector<T *> kImage; 57 std::string kDataName; 58 //std::vector<std::vector<T>> image; 59 60 public: 61 GMocrenDataPrimitive(); 62 //GMocrenDataPrimitive(GMocrenDataPrimitive<T> & _prim); 63 ~GMocrenDataPrimitive(); 64 65 GMocrenDataPrimitive<T> & operator = (const GMocrenDataPrimitive<T> & _right); 66 GMocrenDataPrimitive<T> & operator + (const GMocrenDataPrimitive<T> & _right); 67 GMocrenDataPrimitive<T> & operator += (const GMocrenDataPrimitive<T> & _right); 68 69 void clear(); 70 void clearImage(); 71 void setSize(int _size[3]); 72 void getSize(int _size[3]); 73 void setScale(double & _scale); 74 double getScale(); 75 void setMinMax(T _minmax[2]); 76 void getMinMax(T _minmax[2]); 77 void setImage(std::vector<T *> & _image); 78 void addImage(T * _image); 79 std::vector<T *> & getImage(); 80 T * getImage(int _z); // get image of each layer 81 void setCenterPosition(float _center[3]); 82 void getCenterPosition(float _center[3]); 83 void setName(std::string & _name); 84 std::string getName(); 85 }; 86 87 88 // 89 //----- GMocrenTrack class -----// 90 // 91 class GMocrenTrack { 92 public: 93 struct Step { 94 float startPoint[3]; 95 float endPoint[3]; 96 }; 97 protected: 98 std::vector<struct Step> kTrack; 99 unsigned char kColor[3]; 100 101 public: 102 GMocrenTrack(); 103 ~GMocrenTrack(){;} 104 105 106 int getNumberOfSteps() {return (int)kTrack.size();} 107 void addStep(float _startx, float _starty, float _startz, 108 float _endx, float _endy, float _endz); 109 void getStep(float & _startx, float & _starty, float & _startz, 110 float & _endx, float & _endy, float & _endz, 111 int _num); 112 void setTrack(std::vector<struct Step> & _aTrack) {kTrack = _aTrack;} 113 void setColor(unsigned char _color[3]) { 114 for(int i = 0; i < 3; i++) kColor[i] = _color[i]; 115 } 116 void getColor(unsigned char _color[3]) { 117 for(int i = 0; i < 3; i++) _color[i] = kColor[i]; 118 } 119 void translate(std::vector<float> & _tranlate); 120 }; 121 122 123 124 // 125 //----- GMocrenDetector class -----// 126 // 127 class GMocrenDetector { 128 public: 129 struct Edge { 130 float startPoint[3]; 131 float endPoint[3]; 132 }; 133 protected: 134 std::vector<struct Edge> kDetector; 135 unsigned char kColor[3]; 136 std::string kName; 137 138 public: 139 GMocrenDetector(); 140 ~GMocrenDetector(){;} 141 142 143 int getNumberOfEdges() {return (int)kDetector.size();} 144 void addEdge(float _startx, float _starty, float _startz, 145 float _endx, float _endy, float _endz); 146 void getEdge(float & _startx, float & _starty, float & _startz, 147 float & _endx, float & _endy, float & _endz, 148 int _num); 149 void setDetector(std::vector<struct Edge> & _aDetector) {kDetector = _aDetector;} 150 void setColor(unsigned char _color[3]) { 151 for(int i = 0; i < 3; i++) kColor[i] = _color[i]; 152 } 153 void getColor(unsigned char _color[3]) { 154 for(int i = 0; i < 3; i++) _color[i] = kColor[i]; 155 } 156 void setName(std::string & _name) { kName = _name;} 157 std::string getName() {return kName;} 158 159 void translate(std::vector<float> & _tranlate); 160 }; 161 162 163 // 164 //----- G4GMocrenIO class -----// 165 // 166 class G4GMocrenIO { 167 public: 168 // file id 169 static std::string kId; 170 171 // file version 172 static std::string kVersion; 173 174 // data file name 175 static std::string kFileName; 176 177 // file data endian: little or not 178 static char kLittleEndianInput; 179 static char kLittleEndianOutput; 180 181 static std::string kComment; 182 183 // number of events 184 static int kNumberOfEvents; 185 186 // pointer to the modality image data 187 static unsigned int kPointerToModalityData; 188 // pointer to the dose distribution image data 189 static std::vector<unsigned int> kPointerToDoseDistData; 190 // pointer to the ROI image data 191 static unsigned int kPointerToROIData; 192 // pointer to the track data 193 static unsigned int kPointerToTrackData; 194 // pointer to the detector data 195 static unsigned int kPointerToDetectorData; 196 197 // voxel spacing (universal size) 198 static float kVoxelSpacing[3]; 199 200 //----- modality image -----// 201 static class GMocrenDataPrimitive<short> kModality; 202 // density map to modality (CT) values 203 static std::vector<float> kModalityImageDensityMap; 204 static std::string kModalityUnit; 205 206 //----- dose distribution -----// 207 static std::vector<class GMocrenDataPrimitive<double> > kDose; 208 //std::vector<short *> kShortDose; 209 static std::string kDoseUnit; 210 211 //----- RoI -----// 212 static std::vector<class GMocrenDataPrimitive<short> > kRoi; 213 214 //----- track information -----// 215 static std::vector<float *> kSteps; // begin (x,y,z), end (x,y,z) 216 static std::vector<unsigned char *> kStepColors; // r, g, b 217 218 static std::vector<class GMocrenTrack> kTracks; 219 bool kTracksWillBeStored; 220 221 //----- detector information -----// 222 static std::vector<class GMocrenDetector> kDetectors; 223 224 //----- verbose information -----// 225 static int kVerbose; // verbose level : 0 - 5 (none - overtalk) 226 227 public: 228 // constructor 229 G4GMocrenIO(); 230 // destructor 231 ~G4GMocrenIO(); 232 233 // initialize 234 void initialize(); 235 236 // set the gMocren data file name 237 void setFileName(std::string & _filename) {kFileName = _filename;} 238 void setFileName(char * _filename) {kFileName = _filename;} 239 // get the gMocren data file name 240 std::string & getFileName() {return kFileName;} 241 // store all data in the gMocren data file 242 bool storeData(char * _filename); // interface for version 4 243 bool storeData(); 244 bool storeData2(char * _filename); // version 2 245 bool storeData2(); 246 bool storeData3(char * _filename); // version 3 247 bool storeData3(); 248 bool storeData4(char * _filename); // version 4 249 bool storeData4(); 250 // retrieve all data from the gMocren data file 251 bool retrieveData(char * _filename); // interface 252 bool retrieveData(); 253 bool retrieveData2(char * _filename); //version 2 254 bool retrieveData2(); 255 bool retrieveData3(char * _filename); // version 3 256 bool retrieveData3(); 257 bool retrieveData4(char * _filename); // version 4 258 bool retrieveData4(); 259 260 // get & set the file id 261 std::string & getID() {return kId;} 262 void setID(); 263 void setID(std::string & _id) {kId = _id;} 264 265 // get & set the file version 266 std::string & getVersion(); 267 void setVersion(std::string & _version); 268 269 // set endians of input/output data 270 void setLittleEndianInput(bool _little); 271 void setLittleEndianOutput(bool _little); 272 273 // get & set comment 274 std::string & getComment() {return kComment;} 275 void setComment(std::string & _comment) {kComment = _comment;} 276 277 278 // voxel spacing 279 void setVoxelSpacing(float _spacing[3]); 280 void getVoxelSpacing(float _spacing[3]); 281 282 // get & set number of events 283 int & getNumberOfEvents(); 284 void setNumberOfEvents(int & _numberOfEvents); 285 void addOneEvent(); 286 287 // set pointer the modality image data 288 void setPointerToModalityData(unsigned int & _pointer); 289 unsigned int getPointerToModalityData(); 290 // set pointer the dose distribution image data 291 void addPointerToDoseDistData(unsigned int & _pointer); 292 unsigned int getPointerToDoseDistData(int _elem = 0); 293 // set pointer the ROI image data 294 void setPointerToROIData(unsigned int & _pointer); 295 unsigned int getPointerToROIData(); 296 // set pointer the track data 297 void setPointerToTrackData(unsigned int & _pointer); 298 unsigned int getPointerToTrackData(); 299 private: 300 // calculate pointers 301 void calcPointers4(); 302 void calcPointers3(); 303 void calcPointers2(); 304 305 306 //----- Modality image -----// 307 public: 308 // get & set the modality image size 309 void getModalityImageSize(int _size[3]); 310 void setModalityImageSize(int _size[3]); 311 // get & set the modality image spacing size 312 void getModalityImageVoxelSpacing(float _size[3]); // un-usable 313 void setModalityImageVoxelSpacing(float _size[3]); // un-usable 314 // get & set the modality image size 315 void setModalityImageScale(double & _scale); 316 double getModalityImageScale(); 317 // set the modality image in CT 318 void setModalityImage(short * _image); 319 short * getModalityImage(int _z); 320 void clearModalityImage(); 321 // set/get the modality image density map 322 void setModalityImageDensityMap(std::vector<float> & _map); 323 std::vector<float> & getModalityImageDensityMap(); 324 // set the modality image min./max. 325 void setModalityImageMinMax(short _minmax[2]); 326 // get min. & max. of the modality image 327 void getModalityImageMinMax(short _minmax[2]); 328 short getModalityImageMax(); 329 short getModalityImageMin(); 330 // set center of the modality image position 331 void setModalityCenterPosition(float _center[3]); 332 void getModalityCenterPosition(float _center[3]); 333 // get & set the modality image unit 334 std::string getModalityImageUnit(); 335 void setModalityImageUnit(std::string & _unit); 336 337 short convertDensityToHU(float & _dens); 338 339 //----- Dose distribution -----// 340 341 // instanciate a dose distribution data object 342 void newDoseDist(); 343 // get number of dose distribion data 344 int getNumDoseDist(); 345 // get & set the dose distribution unit 346 std::string getDoseDistUnit(int _num = 0); 347 void setDoseDistUnit(std::string & _unit, int _num = 0); 348 // get & set the dose distribution image size 349 void getDoseDistSize(int _size[3], int _num = 0); 350 void setDoseDistSize(int _size[3], int _num = 0); 351 // get min. & max. of the dose distribution image 352 void setDoseDistMinMax(short _minmax[2], int _num = 0); 353 void getDoseDistMinMax(short _minmax[2], int _num = 0); 354 // get min. & max. of the dose distribution 355 void setDoseDistMinMax(double _minmax[2], int _num = 0); 356 void getDoseDistMinMax(double _minmax[2], int _num = 0); 357 // get & set scale value of the dose distribution for the image 358 void setDoseDistScale(double & _scale, int _num = 0); 359 double getDoseDistScale(int _num = 0); 360 // set the dose distribution image 361 void setShortDoseDist(short * _image, int _num = 0); 362 void getShortDoseDist(short * _data, int _z, int _num = 0); 363 void getShortDoseDistMinMax(short _minmax[2], int _num = 0); 364 // set the dose distribution 365 void setDoseDist(double * _image, int _num = 0); 366 double * getDoseDist(int _z, int _num = 0); 367 // add another dose ditribution map to this map 368 bool addDoseDist(std::vector<double *> & _image, int _num = 0); 369 370 // get & get center position of calculated dose region 371 void getDoseDistCenterPosition(float _center[3], int _num = 0); 372 void setDoseDistCenterPosition(float _center[3], int _num = 0); 373 374 // get & get name of calculated dose distribution 375 std::string getDoseDistName(int _num = 0); 376 void setDoseDistName(std::string _name, int _num = 0); 377 378 // copy dose distributions 379 void copyDoseDist(std::vector<class GMocrenDataPrimitive<double> > & _dose); 380 // merge two dose distributions 381 bool mergeDoseDist(std::vector<class GMocrenDataPrimitive<double> > & _dose); 382 383 // clear all dose distributions 384 void clearDoseDistAll(); 385 protected: 386 // check whether dose variable is empty or not 387 bool isDoseEmpty(); 388 // calcuated scale value to convert dose distribution into image 389 void calcDoseDistScale(); 390 391 public: 392 //----- RoI -----// 393 394 // instanciate an RoI data object 395 void newROI(); 396 // get number of RoI data 397 int getNumROI(); 398 // get & set the ROI image scale 399 double getROIScale(int _num = 0); 400 void setROIScale(double & _scale, int _num = 0); 401 // get & set the ROI image 402 short * getROI(int _z, int _num = 0); 403 void setROI(short * _image, int _num = 0); 404 // get & set the ROI image size 405 void getROISize(int _size[3], int _num = 0); 406 void setROISize(int _size[3], int _num = 0); 407 // get & set position of the ROI region center 408 void getROICenterPosition(float _center[3], int _num = 0); 409 void setROICenterPosition(float _center[3], int _num = 0); 410 // get & set the ROI image min. and max. 411 void getROIMinMax(short _minmax[2], int _num = 0); 412 void setROIMinMax(short _minmax[2], int _num = 0); 413 void clearROIAll(); 414 protected: 415 // check whether RoI variable is empty or not 416 bool isROIEmpty(); 417 418 419 public: 420 //----- Track -----// 421 // get number of tracks 422 int getNumTracks(); 423 int getNumTracks4(); 424 // get & set tracks 425 std::vector<float *> & getTracks(); 426 void getTrack(int _num, std::vector<float *> & _steps, 427 std::vector<unsigned char * > & _color); 428 void addTrack(float * _tracks); 429 void setTracks(std::vector<float *> & _tracks); 430 std::vector<unsigned char *> & getTrackColors(); 431 void addTrackColor(unsigned char * _colors); 432 void setTrackColors(std::vector<unsigned char *> & _trackColors); 433 void copyTracks(std::vector<float *> & _tracks, std::vector<unsigned char *> & _colors); 434 void mergeTracks(std::vector<float *> & _tracks, std::vector<unsigned char *> & _colors); 435 void addTrack(std::vector<float *> & _steps, unsigned char _color[3]); 436 437 void notStoredTracks() {kTracksWillBeStored = false;}; 438 void translateTracks(std::vector<float> & _translateo); 439 void clearTracks() {kTracks.clear();} 440 441 442 //----- Detectors -----// 443 // get number of detectors 444 int getNumberOfDetectors(); 445 // add one detector which consists of edges (float[6]) 446 void addDetector(std::string & _name, std::vector<float *> & _det, unsigned char _color[3]); 447 void getDetector(int _num, std::vector<float *> & _edges, 448 std::vector<unsigned char *> & _color, 449 std::string & _detectorName); 450 void translateDetector(std::vector<float> & _translate); 451 void clearDetector() {kDetectors.clear();} 452 453 protected: 454 // endian conversion 455 template <typename Type> void convertEndian(char *, Type &); 456 // byte order inversion 457 template <typename T> void invertByteOrder(char * _val, T & _rval); 458 459 460 public: 461 //----- verbose information -----// 462 void setVerboseLevel(int _level); 463 464 }; 465 466 #endif 467 468