source: trunk/source/visualization/gMocren/include/G4GMocrenIO.hh@ 1195

Last change on this file since 1195 was 1142, checked in by garnier, 16 years ago

update

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