G4GMocrenIO.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // File I/O manager class for writing or reading calcuated dose
00028 // distribution and some event information
00029 //
00030 //
00031 //  Mar. 31, 2009 :  release for the gMocrenFile driver
00032 //
00033 //                               Akinori Kimura
00034 //
00035 //                               gMocren home page:
00036 //                               http://geant4.kek.jp/gMocren/
00037 //
00038 #ifndef GMOCRENIO_HH
00039 #define GMOCRENIO_HH
00040 
00041 #include <vector>
00042 #include <string>
00043 #include <fstream>
00044 #include <map>
00045 
00046 //
00047 //----- GMocrenDataPrimitive class -----//
00048 // data primitive class for volume data
00049 //
00050 template <typename T> class GMocrenDataPrimitive {
00051 protected:
00052   int kSize[3];
00053   double kScale;
00054   T kMinmax[2];
00055   float kCenter[3];
00056   std::vector<T *> kImage;
00057   std::string kDataName;
00058   //std::vector<std::vector<T>> image;
00059 
00060 public:
00061   GMocrenDataPrimitive();
00062   //GMocrenDataPrimitive(GMocrenDataPrimitive<T> & _prim);
00063   ~GMocrenDataPrimitive();
00064 
00065   GMocrenDataPrimitive<T> & operator = (const GMocrenDataPrimitive<T> & _right);
00066   GMocrenDataPrimitive<T> & operator + (const GMocrenDataPrimitive<T> & _right);
00067   GMocrenDataPrimitive<T> & operator += (const GMocrenDataPrimitive<T> & _right);
00068 
00069   void clear();
00070   void clearImage();
00071   void setSize(int _size[3]);
00072   void getSize(int _size[3]);
00073   void setScale(double & _scale);
00074   double getScale();
00075   void setMinMax(T _minmax[2]);
00076   void getMinMax(T _minmax[2]);
00077   void setImage(std::vector<T *> & _image);
00078   void addImage(T * _image);
00079   std::vector<T *> & getImage();
00080   T * getImage(int _z);  // get image of each layer
00081   void setCenterPosition(float _center[3]);
00082   void getCenterPosition(float _center[3]);
00083   void setName(std::string & _name);
00084   std::string getName();
00085 };
00086 
00087 
00088 //
00089 //----- GMocrenTrack class -----//
00090 //
00091 class GMocrenTrack {
00092 public:
00093   struct Step {
00094     float startPoint[3];
00095     float endPoint[3];
00096   };
00097 protected:
00098   std::vector<struct Step> kTrack;
00099   unsigned char kColor[3];
00100 
00101 public:
00102   GMocrenTrack();
00103   ~GMocrenTrack(){;}
00104 
00105   
00106   int getNumberOfSteps() {return (int)kTrack.size();}
00107   void addStep(float _startx, float _starty, float _startz,
00108                float _endx, float _endy, float _endz);
00109   void getStep(float & _startx, float & _starty, float & _startz,
00110                float & _endx, float & _endy, float & _endz,
00111                int _num);
00112   void setTrack(std::vector<struct Step> & _aTrack) {kTrack = _aTrack;}
00113   void setColor(unsigned char _color[3]) {
00114     for(int i = 0; i < 3; i++) kColor[i] = _color[i];
00115   }
00116   void getColor(unsigned char _color[3]) {
00117     for(int i = 0; i < 3; i++) _color[i] = kColor[i];
00118   }
00119   void translate(std::vector<float> & _tranlate);
00120 };
00121 
00122 
00123 
00124 //
00125 //----- GMocrenDetector class -----//
00126 //
00127 class GMocrenDetector {
00128 public:
00129   struct Edge {
00130     float startPoint[3];
00131     float endPoint[3];
00132   };
00133 protected:
00134   std::vector<struct Edge> kDetector;
00135   unsigned char kColor[3];
00136   std::string kName;
00137 
00138 public:
00139   GMocrenDetector();
00140   ~GMocrenDetector(){;}
00141 
00142   
00143   int getNumberOfEdges() {return (int)kDetector.size();}
00144   void addEdge(float _startx, float _starty, float _startz,
00145                float _endx, float _endy, float _endz);
00146   void getEdge(float & _startx, float & _starty, float & _startz,
00147                float & _endx, float & _endy, float & _endz,
00148                int _num);
00149   void setDetector(std::vector<struct Edge> & _aDetector) {kDetector = _aDetector;}
00150   void setColor(unsigned char _color[3]) {
00151     for(int i = 0; i < 3; i++) kColor[i] = _color[i];
00152   }
00153   void getColor(unsigned char _color[3]) {
00154     for(int i = 0; i < 3; i++) _color[i] = kColor[i];
00155   }
00156   void setName(std::string & _name) { kName = _name;}
00157   std::string getName() {return kName;}
00158 
00159   void translate(std::vector<float> & _tranlate);
00160 };
00161 
00162 
00163 //
00164 //----- G4GMocrenIO class -----//
00165 //
00166 class G4GMocrenIO {
00167 public:
00168   // file id
00169   static std::string kId;
00170 
00171   // file version
00172   static std::string kVersion;
00173 
00174   // data file name 
00175   static std::string kFileName;
00176 
00177   // file data endian: little or not
00178   static char kLittleEndianInput;
00179   static char kLittleEndianOutput;
00180 
00181   static std::string kComment;
00182 
00183   // number of events
00184   static int kNumberOfEvents;
00185 
00186   // pointer to the modality image data
00187   static unsigned int kPointerToModalityData;
00188   // pointer to the dose distribution image data
00189   static std::vector<unsigned int> kPointerToDoseDistData;
00190   // pointer to the ROI image data
00191   static unsigned int kPointerToROIData;
00192   // pointer to the track data
00193   static unsigned int kPointerToTrackData;
00194   // pointer to the detector data
00195   static unsigned int kPointerToDetectorData;
00196 
00197   // voxel spacing (universal size)
00198   static float kVoxelSpacing[3];
00199 
00200   //----- modality image -----//
00201   static class GMocrenDataPrimitive<short> kModality;
00202   // density map to modality (CT) values
00203   static std::vector<float> kModalityImageDensityMap;
00204   static std::string kModalityUnit;
00205 
00206   //----- dose distribution -----//
00207   static std::vector<class GMocrenDataPrimitive<double> > kDose;
00208   //std::vector<short *> kShortDose;
00209   static std::string kDoseUnit;
00210 
00211   //----- RoI -----//
00212   static std::vector<class GMocrenDataPrimitive<short> > kRoi;
00213 
00214   //----- track information -----//
00215   static std::vector<float *> kSteps; // begin (x,y,z), end (x,y,z)
00216   static std::vector<unsigned char *> kStepColors; // r, g, b
00217 
00218   static std::vector<class GMocrenTrack> kTracks;
00219   bool kTracksWillBeStored;
00220 
00221   //----- detector information -----//
00222   static std::vector<class GMocrenDetector> kDetectors;
00223 
00224   //----- verbose information -----//
00225   static int kVerbose; // verbose level :  0 - 5 (none - overtalk)
00226 
00227 public:
00228   // constructor
00229   G4GMocrenIO();
00230   // destructor
00231   ~G4GMocrenIO();
00232 
00233   // initialize
00234   void initialize();
00235 
00236   // set the gMocren data file name
00237   void setFileName(std::string & _filename) {kFileName = _filename;}
00238   void setFileName(char * _filename) {kFileName = _filename;}
00239   // get the gMocren data file name
00240   std::string & getFileName() {return kFileName;}
00241   // store all data in the gMocren data file
00242   bool storeData(char * _filename); // interface for version 4
00243   bool storeData();
00244   bool storeData2(char * _filename); // version 2
00245   bool storeData2();
00246   bool storeData3(char * _filename); // version 3
00247   bool storeData3();
00248   bool storeData4(char * _filename); // version 4
00249   bool storeData4();
00250   // retrieve all data from the gMocren data file
00251   bool retrieveData(char * _filename); // interface
00252   bool retrieveData();
00253   bool retrieveData2(char * _filename); //version 2
00254   bool retrieveData2();
00255   bool retrieveData3(char * _filename); // version 3
00256   bool retrieveData3();
00257   bool retrieveData4(char * _filename); // version 4
00258   bool retrieveData4();
00259     
00260   // get & set the file id
00261   std::string & getID() {return kId;}
00262   void setID();
00263   void setID(std::string & _id) {kId = _id;}
00264 
00265   // get & set the file version
00266   std::string & getVersion();
00267   void setVersion(std::string & _version);
00268 
00269   // set endians of input/output data
00270   void setLittleEndianInput(bool _little);
00271   void setLittleEndianOutput(bool _little);
00272 
00273   // get & set comment
00274   std::string & getComment() {return kComment;}
00275   void setComment(std::string & _comment) {kComment = _comment;}
00276   
00277 
00278   // voxel spacing
00279   void setVoxelSpacing(float _spacing[3]);
00280   void getVoxelSpacing(float _spacing[3]);
00281 
00282   // get & set number of events
00283   int & getNumberOfEvents();
00284   void setNumberOfEvents(int & _numberOfEvents);
00285   void addOneEvent();
00286 
00287   // set pointer the modality image data
00288   void setPointerToModalityData(unsigned int & _pointer);
00289   unsigned int getPointerToModalityData();
00290   // set pointer the dose distribution image data
00291   void addPointerToDoseDistData(unsigned int & _pointer);
00292   unsigned int getPointerToDoseDistData(int _elem = 0);
00293   // set pointer the ROI image data
00294   void setPointerToROIData(unsigned int & _pointer);
00295   unsigned int getPointerToROIData();
00296   // set pointer the track data
00297   void setPointerToTrackData(unsigned int & _pointer);
00298   unsigned int getPointerToTrackData();
00299 private:
00300   // calculate pointers
00301   void calcPointers4();
00302   void calcPointers3();
00303   void calcPointers2();
00304 
00305 
00306   //----- Modality image -----//
00307 public:
00308   // get & set the modality image size
00309   void getModalityImageSize(int _size[3]);
00310   void setModalityImageSize(int _size[3]);
00311   // get & set the modality image spacing size
00312   void getModalityImageVoxelSpacing(float _size[3]); // un-usable
00313   void setModalityImageVoxelSpacing(float _size[3]); // un-usable
00314   // get & set the modality image size
00315   void setModalityImageScale(double & _scale);
00316   double getModalityImageScale();
00317   // set the modality image in CT 
00318   void setModalityImage(short * _image);
00319   short * getModalityImage(int _z);
00320   void clearModalityImage();
00321   // set/get the modality image density map
00322   void setModalityImageDensityMap(std::vector<float> & _map);
00323   std::vector<float> & getModalityImageDensityMap();
00324   // set the modality image min./max.
00325   void setModalityImageMinMax(short _minmax[2]);
00326   // get min. & max. of the modality image 
00327   void getModalityImageMinMax(short _minmax[2]);
00328   short getModalityImageMax();
00329   short getModalityImageMin();
00330   // set center of the modality image position
00331   void setModalityCenterPosition(float _center[3]);
00332   void getModalityCenterPosition(float _center[3]);
00333   // get & set the modality image unit
00334   std::string getModalityImageUnit();
00335   void setModalityImageUnit(std::string & _unit);
00336 
00337   short convertDensityToHU(float & _dens);
00338 
00339   //----- Dose distribution -----//
00340 
00341   // instanciate a dose distribution data object
00342   void newDoseDist();
00343   // get number of dose distribion data
00344   int getNumDoseDist();
00345   // get & set the dose distribution unit
00346   std::string getDoseDistUnit(int _num = 0);
00347   void setDoseDistUnit(std::string & _unit, int _num = 0);
00348   // get & set the dose distribution image size
00349   void getDoseDistSize(int _size[3], int _num = 0);
00350   void setDoseDistSize(int _size[3], int _num = 0);
00351   // get min. & max. of the dose distribution image
00352   void setDoseDistMinMax(short _minmax[2], int _num = 0);
00353   void getDoseDistMinMax(short _minmax[2], int _num = 0);
00354   // get min. & max. of the dose distribution 
00355   void setDoseDistMinMax(double _minmax[2], int _num = 0);
00356   void getDoseDistMinMax(double _minmax[2], int _num = 0);
00357   // get & set scale value of the dose distribution for the image
00358   void setDoseDistScale(double & _scale, int _num = 0);
00359   double getDoseDistScale(int _num = 0);
00360   // set the dose distribution image
00361   void setShortDoseDist(short * _image, int _num = 0);
00362   void getShortDoseDist(short * _data, int _z, int _num = 0);
00363   void getShortDoseDistMinMax(short _minmax[2], int _num = 0);
00364   // set the dose distribution 
00365   void setDoseDist(double * _image, int _num = 0);
00366   double * getDoseDist(int _z, int _num = 0);
00367   // add another dose ditribution map to this map
00368   bool addDoseDist(std::vector<double *> & _image, int _num = 0);
00369 
00370   // get & get center position of calculated dose region
00371   void getDoseDistCenterPosition(float _center[3], int _num = 0);
00372   void setDoseDistCenterPosition(float _center[3], int _num = 0);
00373 
00374   // get & get name of calculated dose distribution
00375   std::string getDoseDistName(int _num = 0);
00376   void setDoseDistName(std::string _name, int _num = 0);
00377 
00378   // copy dose distributions
00379   void copyDoseDist(std::vector<class GMocrenDataPrimitive<double> > & _dose);
00380   // merge two dose distributions
00381   bool mergeDoseDist(std::vector<class GMocrenDataPrimitive<double> > & _dose);
00382 
00383   // clear all dose distributions
00384   void clearDoseDistAll();
00385 protected:
00386   // check whether dose variable is empty or not
00387   bool isDoseEmpty();
00388   // calcuated scale value to convert dose distribution into image
00389   void calcDoseDistScale();
00390 
00391 public:
00392   //----- RoI -----//
00393 
00394   // instanciate an RoI data object
00395   void newROI();
00396   // get number of RoI data
00397   int getNumROI();
00398   // get & set the ROI image scale
00399   double getROIScale(int _num = 0);
00400   void setROIScale(double & _scale, int _num = 0);
00401   // get & set the ROI image 
00402   short * getROI(int _z, int _num = 0);
00403   void setROI(short * _image, int _num = 0);
00404   // get & set the ROI image size
00405   void getROISize(int _size[3], int _num = 0);
00406   void setROISize(int _size[3], int _num = 0);
00407   // get & set position of the ROI region center
00408   void getROICenterPosition(float _center[3], int _num = 0);
00409   void setROICenterPosition(float _center[3], int _num = 0);
00410   // get & set the ROI image min. and max.
00411   void getROIMinMax(short _minmax[2], int _num = 0);
00412   void setROIMinMax(short _minmax[2], int _num = 0);
00413   void clearROIAll();
00414 protected:
00415   // check whether RoI variable is empty or not
00416   bool isROIEmpty();
00417 
00418 
00419 public:
00420   //----- Track -----//
00421   // get number of tracks
00422   int getNumTracks();
00423   int getNumTracks4();
00424   // get & set tracks
00425   std::vector<float *> & getTracks();
00426   void getTrack(int _num, std::vector<float *> & _steps, 
00427                 std::vector<unsigned char * > & _color);
00428   void addTrack(float * _tracks);
00429   void setTracks(std::vector<float *> & _tracks);
00430   std::vector<unsigned char *> & getTrackColors();
00431   void addTrackColor(unsigned char * _colors);
00432   void setTrackColors(std::vector<unsigned char *> & _trackColors);
00433   void copyTracks(std::vector<float *> & _tracks, std::vector<unsigned char *> & _colors);
00434   void mergeTracks(std::vector<float *> & _tracks, std::vector<unsigned char *> & _colors);
00435   void addTrack(std::vector<float *> & _steps, unsigned char _color[3]);
00436 
00437   void notStoredTracks() {kTracksWillBeStored = false;};
00438   void translateTracks(std::vector<float> & _translateo);
00439   void clearTracks() {kTracks.clear();}
00440 
00441 
00442   //----- Detectors -----//
00443   // get number of detectors
00444   int getNumberOfDetectors();
00445   // add one detector which consists of edges (float[6])
00446   void addDetector(std::string & _name, std::vector<float *> & _det, unsigned char _color[3]);
00447   void getDetector(int _num, std::vector<float *> & _edges,
00448                    std::vector<unsigned char *> & _color,
00449                    std::string & _detectorName);
00450   void translateDetector(std::vector<float> & _translate);
00451   void clearDetector() {kDetectors.clear();}
00452 
00453 protected:
00454   // endian conversion
00455   template <typename Type> void convertEndian(char *, Type &);
00456   // byte order inversion
00457   template <typename T> void invertByteOrder(char * _val, T & _rval);
00458 
00459 
00460 public:
00461   //----- verbose information -----//
00462   void setVerboseLevel(int _level);
00463 
00464 };
00465 
00466 #endif
00467 

Generated on Mon May 27 17:48:23 2013 for Geant4 by  doxygen 1.4.7