00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
00048
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
00059
00060 public:
00061 GMocrenDataPrimitive();
00062
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);
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
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
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
00165
00166 class G4GMocrenIO {
00167 public:
00168
00169 static std::string kId;
00170
00171
00172 static std::string kVersion;
00173
00174
00175 static std::string kFileName;
00176
00177
00178 static char kLittleEndianInput;
00179 static char kLittleEndianOutput;
00180
00181 static std::string kComment;
00182
00183
00184 static int kNumberOfEvents;
00185
00186
00187 static unsigned int kPointerToModalityData;
00188
00189 static std::vector<unsigned int> kPointerToDoseDistData;
00190
00191 static unsigned int kPointerToROIData;
00192
00193 static unsigned int kPointerToTrackData;
00194
00195 static unsigned int kPointerToDetectorData;
00196
00197
00198 static float kVoxelSpacing[3];
00199
00200
00201 static class GMocrenDataPrimitive<short> kModality;
00202
00203 static std::vector<float> kModalityImageDensityMap;
00204 static std::string kModalityUnit;
00205
00206
00207 static std::vector<class GMocrenDataPrimitive<double> > kDose;
00208
00209 static std::string kDoseUnit;
00210
00211
00212 static std::vector<class GMocrenDataPrimitive<short> > kRoi;
00213
00214
00215 static std::vector<float *> kSteps;
00216 static std::vector<unsigned char *> kStepColors;
00217
00218 static std::vector<class GMocrenTrack> kTracks;
00219 bool kTracksWillBeStored;
00220
00221
00222 static std::vector<class GMocrenDetector> kDetectors;
00223
00224
00225 static int kVerbose;
00226
00227 public:
00228
00229 G4GMocrenIO();
00230
00231 ~G4GMocrenIO();
00232
00233
00234 void initialize();
00235
00236
00237 void setFileName(std::string & _filename) {kFileName = _filename;}
00238 void setFileName(char * _filename) {kFileName = _filename;}
00239
00240 std::string & getFileName() {return kFileName;}
00241
00242 bool storeData(char * _filename);
00243 bool storeData();
00244 bool storeData2(char * _filename);
00245 bool storeData2();
00246 bool storeData3(char * _filename);
00247 bool storeData3();
00248 bool storeData4(char * _filename);
00249 bool storeData4();
00250
00251 bool retrieveData(char * _filename);
00252 bool retrieveData();
00253 bool retrieveData2(char * _filename);
00254 bool retrieveData2();
00255 bool retrieveData3(char * _filename);
00256 bool retrieveData3();
00257 bool retrieveData4(char * _filename);
00258 bool retrieveData4();
00259
00260
00261 std::string & getID() {return kId;}
00262 void setID();
00263 void setID(std::string & _id) {kId = _id;}
00264
00265
00266 std::string & getVersion();
00267 void setVersion(std::string & _version);
00268
00269
00270 void setLittleEndianInput(bool _little);
00271 void setLittleEndianOutput(bool _little);
00272
00273
00274 std::string & getComment() {return kComment;}
00275 void setComment(std::string & _comment) {kComment = _comment;}
00276
00277
00278
00279 void setVoxelSpacing(float _spacing[3]);
00280 void getVoxelSpacing(float _spacing[3]);
00281
00282
00283 int & getNumberOfEvents();
00284 void setNumberOfEvents(int & _numberOfEvents);
00285 void addOneEvent();
00286
00287
00288 void setPointerToModalityData(unsigned int & _pointer);
00289 unsigned int getPointerToModalityData();
00290
00291 void addPointerToDoseDistData(unsigned int & _pointer);
00292 unsigned int getPointerToDoseDistData(int _elem = 0);
00293
00294 void setPointerToROIData(unsigned int & _pointer);
00295 unsigned int getPointerToROIData();
00296
00297 void setPointerToTrackData(unsigned int & _pointer);
00298 unsigned int getPointerToTrackData();
00299 private:
00300
00301 void calcPointers4();
00302 void calcPointers3();
00303 void calcPointers2();
00304
00305
00306
00307 public:
00308
00309 void getModalityImageSize(int _size[3]);
00310 void setModalityImageSize(int _size[3]);
00311
00312 void getModalityImageVoxelSpacing(float _size[3]);
00313 void setModalityImageVoxelSpacing(float _size[3]);
00314
00315 void setModalityImageScale(double & _scale);
00316 double getModalityImageScale();
00317
00318 void setModalityImage(short * _image);
00319 short * getModalityImage(int _z);
00320 void clearModalityImage();
00321
00322 void setModalityImageDensityMap(std::vector<float> & _map);
00323 std::vector<float> & getModalityImageDensityMap();
00324
00325 void setModalityImageMinMax(short _minmax[2]);
00326
00327 void getModalityImageMinMax(short _minmax[2]);
00328 short getModalityImageMax();
00329 short getModalityImageMin();
00330
00331 void setModalityCenterPosition(float _center[3]);
00332 void getModalityCenterPosition(float _center[3]);
00333
00334 std::string getModalityImageUnit();
00335 void setModalityImageUnit(std::string & _unit);
00336
00337 short convertDensityToHU(float & _dens);
00338
00339
00340
00341
00342 void newDoseDist();
00343
00344 int getNumDoseDist();
00345
00346 std::string getDoseDistUnit(int _num = 0);
00347 void setDoseDistUnit(std::string & _unit, int _num = 0);
00348
00349 void getDoseDistSize(int _size[3], int _num = 0);
00350 void setDoseDistSize(int _size[3], int _num = 0);
00351
00352 void setDoseDistMinMax(short _minmax[2], int _num = 0);
00353 void getDoseDistMinMax(short _minmax[2], int _num = 0);
00354
00355 void setDoseDistMinMax(double _minmax[2], int _num = 0);
00356 void getDoseDistMinMax(double _minmax[2], int _num = 0);
00357
00358 void setDoseDistScale(double & _scale, int _num = 0);
00359 double getDoseDistScale(int _num = 0);
00360
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
00365 void setDoseDist(double * _image, int _num = 0);
00366 double * getDoseDist(int _z, int _num = 0);
00367
00368 bool addDoseDist(std::vector<double *> & _image, int _num = 0);
00369
00370
00371 void getDoseDistCenterPosition(float _center[3], int _num = 0);
00372 void setDoseDistCenterPosition(float _center[3], int _num = 0);
00373
00374
00375 std::string getDoseDistName(int _num = 0);
00376 void setDoseDistName(std::string _name, int _num = 0);
00377
00378
00379 void copyDoseDist(std::vector<class GMocrenDataPrimitive<double> > & _dose);
00380
00381 bool mergeDoseDist(std::vector<class GMocrenDataPrimitive<double> > & _dose);
00382
00383
00384 void clearDoseDistAll();
00385 protected:
00386
00387 bool isDoseEmpty();
00388
00389 void calcDoseDistScale();
00390
00391 public:
00392
00393
00394
00395 void newROI();
00396
00397 int getNumROI();
00398
00399 double getROIScale(int _num = 0);
00400 void setROIScale(double & _scale, int _num = 0);
00401
00402 short * getROI(int _z, int _num = 0);
00403 void setROI(short * _image, int _num = 0);
00404
00405 void getROISize(int _size[3], int _num = 0);
00406 void setROISize(int _size[3], int _num = 0);
00407
00408 void getROICenterPosition(float _center[3], int _num = 0);
00409 void setROICenterPosition(float _center[3], int _num = 0);
00410
00411 void getROIMinMax(short _minmax[2], int _num = 0);
00412 void setROIMinMax(short _minmax[2], int _num = 0);
00413 void clearROIAll();
00414 protected:
00415
00416 bool isROIEmpty();
00417
00418
00419 public:
00420
00421
00422 int getNumTracks();
00423 int getNumTracks4();
00424
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
00443
00444 int getNumberOfDetectors();
00445
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
00455 template <typename Type> void convertEndian(char *, Type &);
00456
00457 template <typename T> void invertByteOrder(char * _val, T & _rval);
00458
00459
00460 public:
00461
00462 void setVerboseLevel(int _level);
00463
00464 };
00465
00466 #endif
00467