Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4GMocrenIO.cc,v 1.4 2009/11/05 03:14:12 akimura Exp $ >> 28 // GEANT4 tag $Name: geant4-09-03 $ 27 // 29 // 28 // 30 // 29 // File I/O manager class for writing or readi 31 // File I/O manager class for writing or reading calcuated dose 30 // distribution and some event information 32 // distribution and some event information 31 // 33 // 32 // Created: Mar. 31, 2009 Akinori Kimura : r 34 // Created: Mar. 31, 2009 Akinori Kimura : release for the gMocrenFile driver 33 // 35 // 34 // Akinori Kimur 36 // Akinori Kimura 35 // gMocren home 37 // gMocren home page: 36 // http://geant4 38 // http://geant4.kek.jp/gMocren/ 37 // 39 // 38 // 40 // 39 #include "G4GMocrenIO.hh" 41 #include "G4GMocrenIO.hh" >> 42 40 #include <iostream> 43 #include <iostream> 41 #include <ctime> 44 #include <ctime> 42 #include <sstream> 45 #include <sstream> 43 #include <iomanip> 46 #include <iomanip> 44 #include <cstdlib> 47 #include <cstdlib> 45 #include <cstring> 48 #include <cstring> 46 << 47 #include "globals.hh" << 48 #include "G4VisManager.hh" << 49 << 50 #if defined(_WIN32) 49 #if defined(_WIN32) 51 #define LITTLE_ENDIAN 1234 50 #define LITTLE_ENDIAN 1234 52 #define BYTE_ORDER LITTLE_ENDIAN 51 #define BYTE_ORDER LITTLE_ENDIAN 53 #endif 52 #endif 54 53 55 const int DOSERANGE = 25000; 54 const int DOSERANGE = 25000; 56 55 57 //----- GMocrenDataPrimitive class in the GMoc 56 //----- GMocrenDataPrimitive class in the GMocrenDataIO class-----// 58 template <typename T> 57 template <typename T> 59 GMocrenDataPrimitive<T>::GMocrenDataPrimitive 58 GMocrenDataPrimitive<T>::GMocrenDataPrimitive () { 60 clear(); 59 clear(); 61 } 60 } 62 template <typename T> 61 template <typename T> 63 GMocrenDataPrimitive<T>::~GMocrenDataPrimitive 62 GMocrenDataPrimitive<T>::~GMocrenDataPrimitive () { 64 /* 63 /* 65 std::vector<short *>::iterator itr = image 64 std::vector<short *>::iterator itr = image.begin(); 66 for(; itr != image.end(); itr++) { 65 for(; itr != image.end(); itr++) { 67 delete [] *itr; 66 delete [] *itr; 68 } 67 } 69 */ 68 */ 70 } 69 } 71 70 72 template <typename T> GMocrenDataPrimitive<T> 71 template <typename T> GMocrenDataPrimitive<T> & 73 GMocrenDataPrimitive<T>::operator = (const GMo 72 GMocrenDataPrimitive<T>::operator = (const GMocrenDataPrimitive<T> & _right) { 74 if (this == &_right) return *this; << 75 for(int i = 0; i < 3; i++) { 73 for(int i = 0; i < 3; i++) { 76 kSize[i] = _right.kSize[i]; 74 kSize[i] = _right.kSize[i]; 77 kCenter[i] = _right.kCenter[i]; 75 kCenter[i] = _right.kCenter[i]; 78 } 76 } 79 kScale = _right.kScale; 77 kScale = _right.kScale; 80 for(int i = 0; i < 2; i++) kMinmax[i] = _rig 78 for(int i = 0; i < 2; i++) kMinmax[i] = _right.kMinmax[i]; 81 int num = kSize[0]*kSize[1]; 79 int num = kSize[0]*kSize[1]; 82 kImage.clear(); 80 kImage.clear(); 83 for(int z = 0; z < kSize[2]; z++) { 81 for(int z = 0; z < kSize[2]; z++) { 84 T * img = new T[num]; 82 T * img = new T[num]; 85 for(int i = 0; i < num; i++) img[i] =_righ 83 for(int i = 0; i < num; i++) img[i] =_right.kImage[z][i]; 86 kImage.push_back(img); 84 kImage.push_back(img); 87 } 85 } 88 return *this; 86 return *this; 89 } 87 } 90 88 91 template <typename T> GMocrenDataPrimitive<T> 89 template <typename T> GMocrenDataPrimitive<T> & 92 GMocrenDataPrimitive<T>::operator + (const GMo 90 GMocrenDataPrimitive<T>::operator + (const GMocrenDataPrimitive<T> & _right) { 93 91 94 GMocrenDataPrimitive<T> rprim; 92 GMocrenDataPrimitive<T> rprim; 95 bool stat = true; 93 bool stat = true; 96 for(int i = 0; i < 3; i++) { 94 for(int i = 0; i < 3; i++) { 97 if(kSize[i] != _right.kSize[i]) stat = fal 95 if(kSize[i] != _right.kSize[i]) stat = false; 98 if(kCenter[i] != _right.kCenter[i]) stat = 96 if(kCenter[i] != _right.kCenter[i]) stat = false; 99 } 97 } 100 if(!stat) { 98 if(!stat) { 101 if (G4VisManager::GetVerbosity() >= G4VisM << 99 std::cerr << "Warning: operator + " 102 G4cout << "Warning: operator + " << 100 << " Cannot do the operator +" 103 << " Cannot do the operator +" << 101 << std::endl; 104 << G4endl; << 105 return *this; 102 return *this; 106 } 103 } 107 104 108 rprim.setSize(kSize); 105 rprim.setSize(kSize); 109 rprim.setCenterPosition(kCenter); 106 rprim.setCenterPosition(kCenter); 110 107 111 T mms[2] = {9e100,-9e100}; << 108 T mm[2] = {9e100,-9e100}; 112 //if(mms[0] > _right.minmax[0]) mms[0] = _ri << 109 //if(mm[0] > _right.minmax[0]) mm[0] = _right.minmax[0]; 113 //if(mms[1] < _right.minmax[1]) mms[1] = _ri << 110 //if(mm[1] < _right.minmax[1]) mm[1] = _right.minmax[1]; 114 111 115 int num = kSize[0]*kSize[1]; 112 int num = kSize[0]*kSize[1]; 116 for(int z = 0; z < kSize[2]; z++) { 113 for(int z = 0; z < kSize[2]; z++) { 117 T * img = new T[num]; 114 T * img = new T[num]; 118 for(int xy = 0; xy < num; xy++) { 115 for(int xy = 0; xy < num; xy++) { 119 img[xy] = kImage[z][xy] + _right.kImage[ 116 img[xy] = kImage[z][xy] + _right.kImage[z][xy]; 120 if(mms[0] > img[xy]) mms[0] = img[xy]; << 117 if(mm[0] > img[xy]) mm[0] = img[xy]; 121 if(mms[1] < img[xy]) mms[1] = img[xy]; << 118 if(mm[1] < img[xy]) mm[1] = img[xy]; 122 } 119 } 123 rprim.addImage(img); 120 rprim.addImage(img); 124 } 121 } 125 rprim.setMinMax(mms); << 122 rprim.setMinMax(mm); 126 123 127 T scl = mms[1]/DOSERANGE; << 124 T scl = mm[1]/DOSERANGE; 128 rprim.setScale(scl); 125 rprim.setScale(scl); 129 126 130 return rprim; 127 return rprim; 131 } 128 } 132 129 133 template <typename T> GMocrenDataPrimitive<T> 130 template <typename T> GMocrenDataPrimitive<T> & 134 GMocrenDataPrimitive<T>::operator += (const GM 131 GMocrenDataPrimitive<T>::operator += (const GMocrenDataPrimitive<T> & _right) { 135 132 136 bool stat = true; 133 bool stat = true; 137 for(int i = 0; i < 3; i++) { 134 for(int i = 0; i < 3; i++) { 138 if(kSize[i] != _right.kSize[i]) stat = fal 135 if(kSize[i] != _right.kSize[i]) stat = false; 139 if(kCenter[i] != _right.kCenter[i]) stat = 136 if(kCenter[i] != _right.kCenter[i]) stat = false; 140 } 137 } 141 if(!stat) { 138 if(!stat) { 142 if (G4VisManager::GetVerbosity() >= G4VisM << 139 std::cerr << "Warning: operator += " << std::endl 143 G4cout << "Warning: operator += " << G4e << 140 << " Cannot do the operator +=" 144 << " Cannot do the operator +=" << 141 << std::endl; 145 << G4endl; << 146 return *this; 142 return *this; 147 } 143 } 148 144 149 if(kMinmax[0] > _right.kMinmax[0]) kMinmax[0 145 if(kMinmax[0] > _right.kMinmax[0]) kMinmax[0] = _right.kMinmax[0]; 150 if(kMinmax[1] < _right.kMinmax[1]) kMinmax[1 146 if(kMinmax[1] < _right.kMinmax[1]) kMinmax[1] = _right.kMinmax[1]; 151 147 152 int num = kSize[0]*kSize[1]; 148 int num = kSize[0]*kSize[1]; 153 for(int z = 0; z < kSize[2]; z++) { 149 for(int z = 0; z < kSize[2]; z++) { 154 for(int xy = 0; xy < num; xy++) { 150 for(int xy = 0; xy < num; xy++) { 155 kImage[z][xy] += _right.kImage[z][xy]; 151 kImage[z][xy] += _right.kImage[z][xy]; 156 if(kMinmax[0] > kImage[z][xy]) kMinmax[0 152 if(kMinmax[0] > kImage[z][xy]) kMinmax[0] = kImage[z][xy]; 157 if(kMinmax[1] < kImage[z][xy]) kMinmax[1 153 if(kMinmax[1] < kImage[z][xy]) kMinmax[1] = kImage[z][xy]; 158 } 154 } 159 } 155 } 160 156 161 kScale = kMinmax[1]/DOSERANGE; 157 kScale = kMinmax[1]/DOSERANGE; 162 158 163 return *this; 159 return *this; 164 } 160 } 165 161 166 template <typename T> 162 template <typename T> 167 void GMocrenDataPrimitive<T>::clear() { 163 void GMocrenDataPrimitive<T>::clear() { 168 for(int i = 0; i < 3; i++) { 164 for(int i = 0; i < 3; i++) { 169 kSize[i] = 0; 165 kSize[i] = 0; 170 kCenter[i] = 0.; 166 kCenter[i] = 0.; 171 } 167 } 172 kScale = 1.; 168 kScale = 1.; 173 kMinmax[0] = (T)32109; 169 kMinmax[0] = (T)32109; 174 kMinmax[1] = (T)-32109; 170 kMinmax[1] = (T)-32109; 175 171 176 clearImage(); << 172 /* 177 } << 173 if(!image.empty()) { 178 template <typename T> << 174 typename std::vector<T *>::iterator itr; 179 void GMocrenDataPrimitive<T>::clearImage() { << 175 for(itr = image.begin(); itr != image.end(); itr++) { 180 typename std::vector<T *>::iterator itr; << 181 for(itr = kImage.begin(); itr != kImage.end( << 182 delete [] *itr; 176 delete [] *itr; 183 } << 177 } >> 178 } >> 179 */ 184 kImage.clear(); 180 kImage.clear(); 185 } 181 } 186 template <typename T> 182 template <typename T> 187 void GMocrenDataPrimitive<T>::setSize(int _siz 183 void GMocrenDataPrimitive<T>::setSize(int _size[3]) { 188 for(int i = 0; i < 3; i++) kSize[i] = _size[ 184 for(int i = 0; i < 3; i++) kSize[i] = _size[i]; 189 } 185 } 190 template <typename T> 186 template <typename T> 191 void GMocrenDataPrimitive<T>::getSize(int _siz 187 void GMocrenDataPrimitive<T>::getSize(int _size[3]) { 192 for(int i = 0; i < 3; i++) _size[i] = kSize[ 188 for(int i = 0; i < 3; i++) _size[i] = kSize[i]; 193 } 189 } 194 template <typename T> 190 template <typename T> 195 void GMocrenDataPrimitive<T>::setScale(double 191 void GMocrenDataPrimitive<T>::setScale(double & _scale) { 196 kScale = _scale; 192 kScale = _scale; 197 } 193 } 198 template <typename T> 194 template <typename T> 199 double GMocrenDataPrimitive<T>::getScale() { 195 double GMocrenDataPrimitive<T>::getScale() { 200 return kScale; 196 return kScale; 201 } 197 } 202 template <typename T> 198 template <typename T> 203 void GMocrenDataPrimitive<T>::setMinMax(T _min 199 void GMocrenDataPrimitive<T>::setMinMax(T _minmax[2]) { 204 for(int i = 0; i < 2; i++) kMinmax[i] = _min 200 for(int i = 0; i < 2; i++) kMinmax[i] = _minmax[i]; 205 } 201 } 206 template <typename T> 202 template <typename T> 207 void GMocrenDataPrimitive<T>::getMinMax(T _min 203 void GMocrenDataPrimitive<T>::getMinMax(T _minmax[2]) { 208 for(int i = 0; i < 2; i++) _minmax[i] = kMin 204 for(int i = 0; i < 2; i++) _minmax[i] = kMinmax[i]; 209 205 210 } 206 } 211 template <typename T> 207 template <typename T> 212 void GMocrenDataPrimitive<T>::setImage(std::ve 208 void GMocrenDataPrimitive<T>::setImage(std::vector<T *> & _image) { 213 kImage = _image; 209 kImage = _image; 214 } 210 } 215 template <typename T> 211 template <typename T> 216 void GMocrenDataPrimitive<T>::addImage(T * _im 212 void GMocrenDataPrimitive<T>::addImage(T * _image) { 217 kImage.push_back(_image); 213 kImage.push_back(_image); 218 } 214 } 219 template <typename T> 215 template <typename T> 220 std::vector<T *> & GMocrenDataPrimitive<T>::ge 216 std::vector<T *> & GMocrenDataPrimitive<T>::getImage() { 221 return kImage; 217 return kImage; 222 } 218 } 223 template <typename T> 219 template <typename T> 224 T * GMocrenDataPrimitive<T>::getImage(int _z) 220 T * GMocrenDataPrimitive<T>::getImage(int _z) { 225 if(_z >= (int)kImage.size()) return 0; 221 if(_z >= (int)kImage.size()) return 0; 226 return kImage[_z]; 222 return kImage[_z]; 227 } 223 } 228 template <typename T> 224 template <typename T> 229 void GMocrenDataPrimitive<T>::setCenterPositio 225 void GMocrenDataPrimitive<T>::setCenterPosition(float _center[3]) { 230 for(int i = 0; i < 3; i++) kCenter[i] = _cen 226 for(int i = 0; i < 3; i++) kCenter[i] = _center[i]; 231 } 227 } 232 template <typename T> 228 template <typename T> 233 void GMocrenDataPrimitive<T>::getCenterPositio 229 void GMocrenDataPrimitive<T>::getCenterPosition(float _center[3]) { 234 for(int i = 0; i < 3; i++) _center[i] = kCen 230 for(int i = 0; i < 3; i++) _center[i] = kCenter[i]; 235 } 231 } 236 template <typename T> 232 template <typename T> 237 void GMocrenDataPrimitive<T>::setName(std::str 233 void GMocrenDataPrimitive<T>::setName(std::string & _name) { 238 kDataName = _name; 234 kDataName = _name; 239 } 235 } 240 template <typename T> 236 template <typename T> 241 std::string GMocrenDataPrimitive<T>::getName() 237 std::string GMocrenDataPrimitive<T>::getName() { 242 return kDataName; 238 return kDataName; 243 } 239 } 244 240 245 241 246 242 247 243 248 244 249 GMocrenTrack::GMocrenTrack() { 245 GMocrenTrack::GMocrenTrack() { 250 kTrack.clear(); 246 kTrack.clear(); 251 for(int i = 0; i < 3; i++) kColor[i] = 0; 247 for(int i = 0; i < 3; i++) kColor[i] = 0; 252 } 248 } 253 249 254 void GMocrenTrack::addStep(float _startx, floa 250 void GMocrenTrack::addStep(float _startx, float _starty, float _startz, 255 float _endx, float _endy, float _endz 251 float _endx, float _endy, float _endz) { 256 struct Step step; 252 struct Step step; 257 step.startPoint[0] = _startx; 253 step.startPoint[0] = _startx; 258 step.startPoint[1] = _starty; 254 step.startPoint[1] = _starty; 259 step.startPoint[2] = _startz; 255 step.startPoint[2] = _startz; 260 step.endPoint[0] = _endx; 256 step.endPoint[0] = _endx; 261 step.endPoint[1] = _endy; 257 step.endPoint[1] = _endy; 262 step.endPoint[2] = _endz; 258 step.endPoint[2] = _endz; 263 kTrack.push_back(step); 259 kTrack.push_back(step); 264 } 260 } 265 void GMocrenTrack::getStep(float & _startx, fl 261 void GMocrenTrack::getStep(float & _startx, float & _starty, float & _startz, 266 float & _endx, float & _endy, float & 262 float & _endx, float & _endy, float & _endz, 267 int _num) { 263 int _num) { 268 if(_num >= (int)kTrack.size()) { 264 if(_num >= (int)kTrack.size()) { 269 if (G4VisManager::GetVerbosity() >= G4VisM << 265 std::cerr << "GMocrenTrack::getStep(...) Error: " 270 G4cout << "GMocrenTrack::getStep(...) Er << 266 << "invalid step # : " << _num << std::endl; 271 << "invalid step # : " << _num << G4end << 272 return; 267 return; 273 } 268 } 274 269 275 _startx = kTrack[_num].startPoint[0]; 270 _startx = kTrack[_num].startPoint[0]; 276 _starty = kTrack[_num].startPoint[1]; 271 _starty = kTrack[_num].startPoint[1]; 277 _startz = kTrack[_num].startPoint[2]; 272 _startz = kTrack[_num].startPoint[2]; 278 _endx = kTrack[_num].endPoint[0]; 273 _endx = kTrack[_num].endPoint[0]; 279 _endy = kTrack[_num].endPoint[1]; 274 _endy = kTrack[_num].endPoint[1]; 280 _endz = kTrack[_num].endPoint[2]; 275 _endz = kTrack[_num].endPoint[2]; 281 } 276 } 282 void GMocrenTrack::translate(std::vector<float 277 void GMocrenTrack::translate(std::vector<float> & _translate) { 283 std::vector<struct Step>::iterator itr = kTr 278 std::vector<struct Step>::iterator itr = kTrack.begin(); 284 for(; itr != kTrack.end(); itr++) { 279 for(; itr != kTrack.end(); itr++) { 285 for(int i = 0; i < 3; i++ ) { 280 for(int i = 0; i < 3; i++ ) { 286 itr->startPoint[i] += _translate[i]; 281 itr->startPoint[i] += _translate[i]; 287 itr->endPoint[i] += _translate[i]; 282 itr->endPoint[i] += _translate[i]; 288 } 283 } 289 } 284 } 290 } 285 } 291 286 292 287 293 288 294 289 295 290 296 291 297 292 298 293 299 294 300 GMocrenDetector::GMocrenDetector() { 295 GMocrenDetector::GMocrenDetector() { 301 kDetector.clear(); 296 kDetector.clear(); 302 for(int i = 0; i < 3; i++) kColor[i] = 0; 297 for(int i = 0; i < 3; i++) kColor[i] = 0; 303 } 298 } 304 299 305 void GMocrenDetector::addEdge(float _startx, f 300 void GMocrenDetector::addEdge(float _startx, float _starty, float _startz, 306 float _endx, float _endy, float _e 301 float _endx, float _endy, float _endz) { 307 struct Edge edge; 302 struct Edge edge; 308 edge.startPoint[0] = _startx; 303 edge.startPoint[0] = _startx; 309 edge.startPoint[1] = _starty; 304 edge.startPoint[1] = _starty; 310 edge.startPoint[2] = _startz; 305 edge.startPoint[2] = _startz; 311 edge.endPoint[0] = _endx; 306 edge.endPoint[0] = _endx; 312 edge.endPoint[1] = _endy; 307 edge.endPoint[1] = _endy; 313 edge.endPoint[2] = _endz; 308 edge.endPoint[2] = _endz; 314 kDetector.push_back(edge); 309 kDetector.push_back(edge); 315 } 310 } 316 void GMocrenDetector::getEdge(float & _startx, 311 void GMocrenDetector::getEdge(float & _startx, float & _starty, float & _startz, 317 float & _endx, float & _endy, float & 312 float & _endx, float & _endy, float & _endz, 318 int _num) { 313 int _num) { 319 if(_num >= (int)kDetector.size()) { 314 if(_num >= (int)kDetector.size()) { 320 if (G4VisManager::GetVerbosity() >= G4VisM << 315 std::cerr << "GMocrenDetector::getEdge(...) Error: " 321 G4cout << "GMocrenDetector::getEdge(...) << 316 << "invalid edge # : " << _num << std::endl; 322 << "invalid edge # : " << _num << G4end << 323 return; 317 return; 324 } 318 } 325 319 326 _startx = kDetector[_num].startPoint[0]; 320 _startx = kDetector[_num].startPoint[0]; 327 _starty = kDetector[_num].startPoint[1]; 321 _starty = kDetector[_num].startPoint[1]; 328 _startz = kDetector[_num].startPoint[2]; 322 _startz = kDetector[_num].startPoint[2]; 329 _endx = kDetector[_num].endPoint[0]; 323 _endx = kDetector[_num].endPoint[0]; 330 _endy = kDetector[_num].endPoint[1]; 324 _endy = kDetector[_num].endPoint[1]; 331 _endz = kDetector[_num].endPoint[2]; 325 _endz = kDetector[_num].endPoint[2]; 332 } 326 } 333 void GMocrenDetector::translate(std::vector<fl 327 void GMocrenDetector::translate(std::vector<float> & _translate) { 334 std::vector<struct Edge>::iterator itr = kDe 328 std::vector<struct Edge>::iterator itr = kDetector.begin(); 335 for(; itr != kDetector.end(); itr++) { 329 for(; itr != kDetector.end(); itr++) { 336 for(int i = 0; i < 3; i++) { 330 for(int i = 0; i < 3; i++) { 337 itr->startPoint[i] += _translate[i]; 331 itr->startPoint[i] += _translate[i]; 338 itr->endPoint[i] += _translate[i]; 332 itr->endPoint[i] += _translate[i]; 339 } 333 } 340 } 334 } 341 } 335 } 342 336 343 337 344 338 345 339 346 340 347 341 348 342 349 343 350 344 351 // file information 345 // file information 352 std::string G4GMocrenIO::kId; 346 std::string G4GMocrenIO::kId; 353 std::string G4GMocrenIO::kVersion = "2.0.0"; 347 std::string G4GMocrenIO::kVersion = "2.0.0"; 354 int G4GMocrenIO::kNumberOfEvents = 0; 348 int G4GMocrenIO::kNumberOfEvents = 0; 355 char G4GMocrenIO::kLittleEndianInput = true; 349 char G4GMocrenIO::kLittleEndianInput = true; 356 350 357 #if BYTE_ORDER == LITTLE_ENDIAN 351 #if BYTE_ORDER == LITTLE_ENDIAN 358 char G4GMocrenIO::kLittleEndianOutput = true; 352 char G4GMocrenIO::kLittleEndianOutput = true; 359 #else 353 #else 360 char G4GMocrenIO::kLittleEndianOutput = false; 354 char G4GMocrenIO::kLittleEndianOutput = false; // Big endian 361 #endif 355 #endif 362 std::string G4GMocrenIO::kComment; 356 std::string G4GMocrenIO::kComment; 363 // 357 // 364 std::string G4GMocrenIO::kFileName = "dose.gdd 358 std::string G4GMocrenIO::kFileName = "dose.gdd"; 365 359 366 // 360 // 367 unsigned int G4GMocrenIO::kPointerToModalityDa 361 unsigned int G4GMocrenIO::kPointerToModalityData = 0; 368 std::vector<unsigned int> G4GMocrenIO::kPointe 362 std::vector<unsigned int> G4GMocrenIO::kPointerToDoseDistData; 369 unsigned int G4GMocrenIO::kPointerToROIData = 363 unsigned int G4GMocrenIO::kPointerToROIData = 0; 370 unsigned int G4GMocrenIO::kPointerToTrackData 364 unsigned int G4GMocrenIO::kPointerToTrackData = 0; 371 unsigned int G4GMocrenIO::kPointerToDetectorDa 365 unsigned int G4GMocrenIO::kPointerToDetectorData = 0; 372 366 373 // modality 367 // modality 374 float G4GMocrenIO::kVoxelSpacing[3] = {0., 0., 368 float G4GMocrenIO::kVoxelSpacing[3] = {0., 0., 0.}; 375 class GMocrenDataPrimitive<short> G4GMocrenIO 369 class GMocrenDataPrimitive<short> G4GMocrenIO::kModality; 376 std::vector<float> G4GMocrenIO::kModalityImage 370 std::vector<float> G4GMocrenIO::kModalityImageDensityMap; 377 std::string G4GMocrenIO::kModalityUnit = "g/cm 371 std::string G4GMocrenIO::kModalityUnit = "g/cm3 "; // 12 Bytes 378 372 379 // dose 373 // dose 380 std::vector<class GMocrenDataPrimitive<double> 374 std::vector<class GMocrenDataPrimitive<double> > G4GMocrenIO::kDose; 381 std::string G4GMocrenIO::kDoseUnit = "keV 375 std::string G4GMocrenIO::kDoseUnit = "keV "; // 12 Bytes 382 376 383 // ROI 377 // ROI 384 std::vector<class GMocrenDataPrimitive<short> 378 std::vector<class GMocrenDataPrimitive<short> > G4GMocrenIO::kRoi; 385 379 386 // track 380 // track 387 std::vector<float *> G4GMocrenIO::kSteps; 381 std::vector<float *> G4GMocrenIO::kSteps; 388 std::vector<unsigned char *> G4GMocrenIO::kSte 382 std::vector<unsigned char *> G4GMocrenIO::kStepColors; 389 std::vector<class GMocrenTrack> G4GMocrenIO::k 383 std::vector<class GMocrenTrack> G4GMocrenIO::kTracks; 390 384 391 // detector 385 // detector 392 std::vector<class GMocrenDetector> G4GMocrenIO 386 std::vector<class GMocrenDetector> G4GMocrenIO::kDetectors; 393 387 394 // verbose 388 // verbose 395 int G4GMocrenIO::kVerbose = 0; 389 int G4GMocrenIO::kVerbose = 0; 396 390 397 const int IDLENGTH = 21; 391 const int IDLENGTH = 21; 398 const int VERLENGTH = 6; 392 const int VERLENGTH = 6; 399 393 400 // constructor 394 // constructor 401 G4GMocrenIO::G4GMocrenIO() 395 G4GMocrenIO::G4GMocrenIO() 402 : kTracksWillBeStored(true) { 396 : kTracksWillBeStored(true) { 403 ; 397 ; 404 } 398 } 405 399 406 // destructor 400 // destructor 407 G4GMocrenIO::~G4GMocrenIO() { 401 G4GMocrenIO::~G4GMocrenIO() { 408 ; 402 ; 409 } 403 } 410 404 411 // initialize 405 // initialize 412 void G4GMocrenIO::initialize() { 406 void G4GMocrenIO::initialize() { 413 407 414 kId.clear(); 408 kId.clear(); 415 kVersion = "2.0.0"; 409 kVersion = "2.0.0"; 416 kNumberOfEvents = 0; 410 kNumberOfEvents = 0; 417 kLittleEndianInput = true; 411 kLittleEndianInput = true; 418 #if BYTE_ORDER == LITTLE_ENDIAN 412 #if BYTE_ORDER == LITTLE_ENDIAN 419 kLittleEndianOutput = true; 413 kLittleEndianOutput = true; 420 #else // Big endian 414 #else // Big endian 421 kLittleEndianOutput = false; 415 kLittleEndianOutput = false; 422 #endif 416 #endif 423 kComment.clear(); 417 kComment.clear(); 424 kFileName = "dose.gdd"; 418 kFileName = "dose.gdd"; 425 kPointerToModalityData = 0; 419 kPointerToModalityData = 0; 426 kPointerToDoseDistData.clear(); 420 kPointerToDoseDistData.clear(); 427 kPointerToROIData = 0; 421 kPointerToROIData = 0; 428 kPointerToTrackData = 0; 422 kPointerToTrackData = 0; 429 // modality 423 // modality 430 for(int i = 0; i < 3; i++) kVoxelSpacing[i] 424 for(int i = 0; i < 3; i++) kVoxelSpacing[i] = 0.; 431 kModality.clear(); 425 kModality.clear(); 432 kModalityImageDensityMap.clear(); 426 kModalityImageDensityMap.clear(); 433 kModalityUnit = "g/cm3 "; // 12 Bytes 427 kModalityUnit = "g/cm3 "; // 12 Bytes 434 // dose 428 // dose 435 kDose.clear(); 429 kDose.clear(); 436 kDoseUnit = "keV "; // 12 Bytes 430 kDoseUnit = "keV "; // 12 Bytes 437 // ROI 431 // ROI 438 kRoi.clear(); 432 kRoi.clear(); 439 // track 433 // track 440 std::vector<float *>::iterator itr; 434 std::vector<float *>::iterator itr; 441 for(itr = kSteps.begin(); itr != kSteps.end( 435 for(itr = kSteps.begin(); itr != kSteps.end(); itr++) delete [] *itr; 442 kSteps.clear(); 436 kSteps.clear(); 443 std::vector<unsigned char *>::iterator citr; 437 std::vector<unsigned char *>::iterator citr; 444 for(citr = kStepColors.begin(); citr != kSte 438 for(citr = kStepColors.begin(); citr != kStepColors.end(); citr++) 445 delete [] *citr; 439 delete [] *citr; 446 kStepColors.clear(); 440 kStepColors.clear(); 447 kTracksWillBeStored = true; 441 kTracksWillBeStored = true; 448 442 449 // verbose 443 // verbose 450 kVerbose = 0; 444 kVerbose = 0; 451 } 445 } 452 446 453 bool G4GMocrenIO::storeData() { 447 bool G4GMocrenIO::storeData() { 454 return storeData4(); 448 return storeData4(); 455 } 449 } 456 // 450 // 457 bool G4GMocrenIO::storeData(char * _filename) 451 bool G4GMocrenIO::storeData(char * _filename) { 458 return storeData4(_filename); 452 return storeData4(_filename); 459 } 453 } 460 454 461 bool G4GMocrenIO::storeData4() { 455 bool G4GMocrenIO::storeData4() { 462 456 463 bool DEBUG = false;// 457 bool DEBUG = false;// 464 458 465 if(DEBUG || kVerbose > 0) 459 if(DEBUG || kVerbose > 0) 466 G4cout << ">>>>>>> store data (ver.4) <<< << 460 std::cout << ">>>>>>> store data (ver.4) <<<<<<<" << std::endl; 467 if(DEBUG || kVerbose > 0) 461 if(DEBUG || kVerbose > 0) 468 G4cout << " " << kFileName << G4en << 462 std::cout << " " << kFileName << std::endl; 469 463 470 // output file open 464 // output file open 471 std::ofstream ofile(kFileName.c_str(), 465 std::ofstream ofile(kFileName.c_str(), 472 std::ios_base::out|std::ios_base::bi 466 std::ios_base::out|std::ios_base::binary); 473 if(DEBUG || kVerbose > 0) 467 if(DEBUG || kVerbose > 0) 474 G4cout << " file open status: " << << 468 std::cout << " file open status: " << ofile << std::endl; 475 469 476 // file identifier 470 // file identifier 477 ofile.write("gMocren ", 8); 471 ofile.write("gMocren ", 8); 478 472 479 // file version 473 // file version 480 unsigned char ver = 0x04; 474 unsigned char ver = 0x04; 481 ofile.write((char *)&ver, 1); 475 ofile.write((char *)&ver, 1); 482 476 483 // endian 477 // endian 484 //ofile.write((char *)&kLittleEndianOutput, 478 //ofile.write((char *)&kLittleEndianOutput, sizeof(char)); 485 char littleEndian = 0x01; 479 char littleEndian = 0x01; 486 ofile.write((char *)&littleEndian, sizeof(ch 480 ofile.write((char *)&littleEndian, sizeof(char)); 487 if(DEBUG || kVerbose > 0) { 481 if(DEBUG || kVerbose > 0) { 488 //G4cout << "Endian: " << (int)kLittleEndi << 482 //std::cout << "Endian: " << (int)kLittleEndianOutput << std::endl; 489 G4cout << "Endian: " << (int)littleEndian << 483 std::cout << "Endian: " << (int)littleEndian << std::endl; 490 } 484 } 491 485 492 // for inverting the byte order 486 // for inverting the byte order 493 float ftmp[6]; 487 float ftmp[6]; 494 int itmp[6]; 488 int itmp[6]; 495 short stmp[6]; 489 short stmp[6]; 496 490 497 // comment length (fixed size) 491 // comment length (fixed size) 498 int commentLength = 1024; 492 int commentLength = 1024; 499 if(kLittleEndianOutput) { 493 if(kLittleEndianOutput) { 500 ofile.write((char *)&commentLength, 4); 494 ofile.write((char *)&commentLength, 4); 501 } else { 495 } else { 502 invertByteOrder((char *)&commentLength, it 496 invertByteOrder((char *)&commentLength, itmp[0]); 503 ofile.write((char *)itmp, 4); 497 ofile.write((char *)itmp, 4); 504 } 498 } 505 499 506 // comment 500 // comment 507 char cmt[1025]; 501 char cmt[1025]; 508 std::strncpy(cmt, kComment.c_str(), 1024); << 502 for(int i = 0; i < 1025; i++) cmt[i] = '\0'; 509 cmt[1024] = '\0'; << 503 //std::strncpy(cmt, kComment.c_str(), 1024); 510 ofile.write(cmt, 1024); << 504 std::strcpy(cmt, kComment.c_str()); >> 505 ofile.write((char *)cmt, 1024); 511 if(DEBUG || kVerbose > 0) { 506 if(DEBUG || kVerbose > 0) { 512 G4cout << "Data comment : " << 507 std::cout << "Data comment : " 513 << kComment << G4endl; << 508 << kComment << std::endl; 514 } 509 } 515 510 516 // voxel spacings for all images 511 // voxel spacings for all images 517 if(kLittleEndianOutput) { 512 if(kLittleEndianOutput) { 518 ofile.write((char *)kVoxelSpacing, 12); 513 ofile.write((char *)kVoxelSpacing, 12); 519 } else { 514 } else { 520 for(int j = 0; j < 3; j++) 515 for(int j = 0; j < 3; j++) 521 invertByteOrder((char *)&kVoxelSpacing[j 516 invertByteOrder((char *)&kVoxelSpacing[j], ftmp[j]); 522 ofile.write((char *)ftmp, 12); 517 ofile.write((char *)ftmp, 12); 523 } 518 } 524 if(DEBUG || kVerbose > 0) { 519 if(DEBUG || kVerbose > 0) { 525 G4cout << "Voxel spacing : (" << 520 std::cout << "Voxel spacing : (" 526 << kVoxelSpacing[0] << ", " 521 << kVoxelSpacing[0] << ", " 527 << kVoxelSpacing[1] << ", " 522 << kVoxelSpacing[1] << ", " 528 << kVoxelSpacing[2] 523 << kVoxelSpacing[2] 529 << ") mm " << G4endl; << 524 << ") mm " << std::endl; 530 } 525 } 531 526 532 calcPointers4(); 527 calcPointers4(); 533 if(!kTracksWillBeStored) kPointerToTrackData 528 if(!kTracksWillBeStored) kPointerToTrackData = 0; 534 529 535 // offset from file starting point to the mo 530 // offset from file starting point to the modality image data 536 if(kLittleEndianOutput) { 531 if(kLittleEndianOutput) { 537 ofile.write((char *)&kPointerToModalityDat 532 ofile.write((char *)&kPointerToModalityData, 4); 538 } else { 533 } else { 539 invertByteOrder((char *)&kPointerToModalit 534 invertByteOrder((char *)&kPointerToModalityData, itmp[0]); 540 ofile.write((char *)itmp, 4); 535 ofile.write((char *)itmp, 4); 541 } 536 } 542 537 543 // # of dose distributions 538 // # of dose distributions 544 //int nDoseDist = (int)pointerToDoseDistData 539 //int nDoseDist = (int)pointerToDoseDistData.size(); 545 int nDoseDist = getNumDoseDist(); 540 int nDoseDist = getNumDoseDist(); 546 if(kLittleEndianOutput) { 541 if(kLittleEndianOutput) { 547 ofile.write((char *)&nDoseDist, 4); 542 ofile.write((char *)&nDoseDist, 4); 548 } else { 543 } else { 549 invertByteOrder((char *)&nDoseDist, itmp[0 544 invertByteOrder((char *)&nDoseDist, itmp[0]); 550 ofile.write((char *)itmp, 4); 545 ofile.write((char *)itmp, 4); 551 } 546 } 552 547 553 // offset from file starting point to the do 548 // offset from file starting point to the dose image data 554 if(kLittleEndianOutput) { 549 if(kLittleEndianOutput) { 555 for(int i = 0; i < nDoseDist; i++) { 550 for(int i = 0; i < nDoseDist; i++) { 556 ofile.write((char *)&kPointerToDoseDistD 551 ofile.write((char *)&kPointerToDoseDistData[i], 4); 557 } 552 } 558 } else { 553 } else { 559 for(int i = 0; i < nDoseDist; i++) { 554 for(int i = 0; i < nDoseDist; i++) { 560 invertByteOrder((char *)&kPointerToDoseD 555 invertByteOrder((char *)&kPointerToDoseDistData[i], itmp[0]); 561 ofile.write((char *)itmp, 4); 556 ofile.write((char *)itmp, 4); 562 } 557 } 563 } 558 } 564 559 565 // offset from file starting point to the RO 560 // offset from file starting point to the ROI image data 566 if(kLittleEndianOutput) { 561 if(kLittleEndianOutput) { 567 ofile.write((char *)&kPointerToROIData, 4) 562 ofile.write((char *)&kPointerToROIData, 4); 568 } else { 563 } else { 569 invertByteOrder((char *)&kPointerToROIData 564 invertByteOrder((char *)&kPointerToROIData, itmp[0]); 570 ofile.write((char *)itmp, 4); 565 ofile.write((char *)itmp, 4); 571 } 566 } 572 567 573 // offset from file starting point to the tr 568 // offset from file starting point to the track data 574 if(kLittleEndianOutput) { 569 if(kLittleEndianOutput) { 575 ofile.write((char *)&kPointerToTrackData, 570 ofile.write((char *)&kPointerToTrackData, 4); 576 } else { 571 } else { 577 invertByteOrder((char *)&kPointerToTrackDa 572 invertByteOrder((char *)&kPointerToTrackData, itmp[0]); 578 ofile.write((char *)itmp, 4); 573 ofile.write((char *)itmp, 4); 579 } 574 } 580 575 581 // offset from file starting point to the de 576 // offset from file starting point to the detector data 582 if(kLittleEndianOutput) { 577 if(kLittleEndianOutput) { 583 ofile.write((char *)&kPointerToDetectorDat 578 ofile.write((char *)&kPointerToDetectorData, 4); 584 } else { 579 } else { 585 invertByteOrder((char *)&kPointerToDetecto 580 invertByteOrder((char *)&kPointerToDetectorData, itmp[0]); 586 ofile.write((char *)itmp, 4); 581 ofile.write((char *)itmp, 4); 587 } 582 } 588 583 589 if(DEBUG || kVerbose > 0) { 584 if(DEBUG || kVerbose > 0) { 590 G4cout << "Each pointer to data : " << 585 std::cout << "Each pointer to data : " 591 << kPointerToModalityData << ", "; 586 << kPointerToModalityData << ", "; 592 for(int i = 0; i < nDoseDist; i++) { 587 for(int i = 0; i < nDoseDist; i++) { 593 G4cout << kPointerToDoseDistData[i] << " << 588 std::cout << kPointerToDoseDistData[i] << ", "; 594 } 589 } 595 G4cout << kPointerToROIData << ", " << 590 std::cout << kPointerToROIData << ", " 596 << kPointerToTrackData << ", " 591 << kPointerToTrackData << ", " 597 << kPointerToDetectorData 592 << kPointerToDetectorData 598 << G4endl; << 593 << std::endl; 599 } 594 } 600 595 601 //----- modality image -----// 596 //----- modality image -----// 602 597 603 int size[3]; 598 int size[3]; 604 float scale; 599 float scale; 605 short minmax[2]; 600 short minmax[2]; 606 float fCenter[3]; 601 float fCenter[3]; 607 int iCenter[3]; 602 int iCenter[3]; 608 // modality image size 603 // modality image size 609 kModality.getSize(size); 604 kModality.getSize(size); 610 605 611 if(kLittleEndianOutput) { 606 if(kLittleEndianOutput) { 612 ofile.write((char *)size, 3*sizeof(int)); 607 ofile.write((char *)size, 3*sizeof(int)); 613 } else { 608 } else { 614 for(int j = 0; j < 3; j++) 609 for(int j = 0; j < 3; j++) 615 invertByteOrder((char *)&size[j], itmp[j 610 invertByteOrder((char *)&size[j], itmp[j]); 616 ofile.write((char *)itmp, 12); 611 ofile.write((char *)itmp, 12); 617 } 612 } 618 613 619 if(DEBUG || kVerbose > 0) { 614 if(DEBUG || kVerbose > 0) { 620 G4cout << "Modality image size : (" << 615 std::cout << "Modality image size : (" 621 << size[0] << ", " 616 << size[0] << ", " 622 << size[1] << ", " 617 << size[1] << ", " 623 << size[2] << ")" 618 << size[2] << ")" 624 << G4endl; << 619 << std::endl; 625 } 620 } 626 621 627 // modality image max. & min. 622 // modality image max. & min. 628 kModality.getMinMax(minmax); 623 kModality.getMinMax(minmax); 629 if(kLittleEndianOutput) { 624 if(kLittleEndianOutput) { 630 ofile.write((char *)minmax, 4); 625 ofile.write((char *)minmax, 4); 631 } else { 626 } else { 632 for(int j = 0; j < 2; j++) 627 for(int j = 0; j < 2; j++) 633 invertByteOrder((char *)&minmax[j], stmp 628 invertByteOrder((char *)&minmax[j], stmp[j]); 634 ofile.write((char *)stmp, 4); 629 ofile.write((char *)stmp, 4); 635 } 630 } 636 631 637 // modality image unit 632 // modality image unit 638 char munit[13] = "g/cm3\0"; 633 char munit[13] = "g/cm3\0"; 639 ofile.write((char *)munit, 12); 634 ofile.write((char *)munit, 12); 640 635 641 // modality image scale 636 // modality image scale 642 scale = (float)kModality.getScale(); 637 scale = (float)kModality.getScale(); 643 if(kLittleEndianOutput) { 638 if(kLittleEndianOutput) { 644 ofile.write((char *)&scale, 4); 639 ofile.write((char *)&scale, 4); 645 } else { 640 } else { 646 invertByteOrder((char *)&scale, ftmp[0]); 641 invertByteOrder((char *)&scale, ftmp[0]); 647 ofile.write((char *)ftmp, 4); 642 ofile.write((char *)ftmp, 4); 648 } 643 } 649 if(DEBUG || kVerbose > 0) { 644 if(DEBUG || kVerbose > 0) { 650 G4cout << "Modality image min., max., scal << 645 std::cout << "Modality image min., max., scale : " 651 << minmax[0] << ", " 646 << minmax[0] << ", " 652 << minmax[1] << ", " 647 << minmax[1] << ", " 653 << scale << G4endl; << 648 << scale << std::endl; 654 } 649 } 655 650 656 // modality image 651 // modality image 657 int psize = size[0]*size[1]; 652 int psize = size[0]*size[1]; 658 if(DEBUG || kVerbose > 0) G4cout << "Modalit << 653 if(DEBUG || kVerbose > 0) std::cout << "Modality image : "; 659 for(int i = 0; i < size[2]; i++) { 654 for(int i = 0; i < size[2]; i++) { 660 short * image = kModality.getImage(i); 655 short * image = kModality.getImage(i); 661 if(kLittleEndianOutput) { 656 if(kLittleEndianOutput) { 662 ofile.write((char *)image, psize*sizeof( 657 ofile.write((char *)image, psize*sizeof(short)); 663 } else { 658 } else { 664 for(int j = 0; j < psize; j++) { 659 for(int j = 0; j < psize; j++) { 665 invertByteOrder((char *)&image[j], stmp[0]); 660 invertByteOrder((char *)&image[j], stmp[0]); 666 ofile.write((char *)stmp, 2); 661 ofile.write((char *)stmp, 2); 667 } 662 } 668 } 663 } 669 664 670 if(DEBUG || kVerbose > 0) G4cout << "[" << << 665 if(DEBUG || kVerbose > 0) std::cout << "[" << i << "]" << image[(size_t)(psize*0.55)] << ", "; 671 } 666 } 672 if(DEBUG || kVerbose > 0) G4cout << G4endl; << 667 if(DEBUG || kVerbose > 0) std::cout << std::endl; 673 668 674 // modality desity map for CT value 669 // modality desity map for CT value 675 size_t msize = minmax[1] - minmax[0]+1; 670 size_t msize = minmax[1] - minmax[0]+1; 676 if(DEBUG || kVerbose > 0) 671 if(DEBUG || kVerbose > 0) 677 G4cout << "modality image : " << minmax[0] << 672 std::cout << "modality image : " << minmax[0] << ", " << minmax[1] << std::endl; 678 float * pdmap = new float[msize]; 673 float * pdmap = new float[msize]; 679 for(int i = 0; i < (int)msize; i++) pdmap[i] 674 for(int i = 0; i < (int)msize; i++) pdmap[i] =kModalityImageDensityMap[i]; 680 675 681 if(kLittleEndianOutput) { 676 if(kLittleEndianOutput) { 682 ofile.write((char *)pdmap, msize*sizeof(fl 677 ofile.write((char *)pdmap, msize*sizeof(float)); 683 } else { 678 } else { 684 for(int j = 0; j < (int)msize; j++) { 679 for(int j = 0; j < (int)msize; j++) { 685 invertByteOrder((char *)&pdmap[j], ftmp[ 680 invertByteOrder((char *)&pdmap[j], ftmp[0]); 686 ofile.write((char *)ftmp, 4); 681 ofile.write((char *)ftmp, 4); 687 } 682 } 688 } 683 } 689 684 690 if(DEBUG || kVerbose > 0) { 685 if(DEBUG || kVerbose > 0) { 691 G4cout << "density map : " << std::ends; << 686 std::cout << "density map : " << std::ends; 692 for(int i = 0; i < (int)msize; i+=50) 687 for(int i = 0; i < (int)msize; i+=50) 693 G4cout <<kModalityImageDensityMap[i] << << 688 std::cout <<kModalityImageDensityMap[i] << ", "; 694 G4cout << G4endl; << 689 std::cout << std::endl; 695 } 690 } 696 delete [] pdmap; 691 delete [] pdmap; 697 692 698 693 699 //----- dose distribution image -----// 694 //----- dose distribution image -----// 700 695 701 if(!isDoseEmpty()) { 696 if(!isDoseEmpty()) { 702 697 703 calcDoseDistScale(); 698 calcDoseDistScale(); 704 699 705 for(int ndose = 0; ndose < nDoseDist; ndos 700 for(int ndose = 0; ndose < nDoseDist; ndose++) { 706 // dose distrbution image size 701 // dose distrbution image size 707 kDose[ndose].getSize(size); 702 kDose[ndose].getSize(size); 708 if(kLittleEndianOutput) { 703 if(kLittleEndianOutput) { 709 ofile.write((char *)size, 3*sizeof(int)); 704 ofile.write((char *)size, 3*sizeof(int)); 710 } else { 705 } else { 711 for(int j = 0; j < 3; j++) 706 for(int j = 0; j < 3; j++) 712 invertByteOrder((char *)&size[j], itmp[j]) 707 invertByteOrder((char *)&size[j], itmp[j]); 713 ofile.write((char *)itmp, 12); 708 ofile.write((char *)itmp, 12); 714 } 709 } 715 if(DEBUG || kVerbose > 0) { 710 if(DEBUG || kVerbose > 0) { 716 G4cout << "Dose dist. [" << ndose << "] imag << 711 std::cout << "Dose dist. [" << ndose << "] image size : (" 717 << size[0] << ", " 712 << size[0] << ", " 718 << size[1] << ", " 713 << size[1] << ", " 719 << size[2] << ")" 714 << size[2] << ")" 720 << G4endl; << 715 << std::endl; 721 } 716 } 722 717 723 // dose distribution max. & min. 718 // dose distribution max. & min. 724 getShortDoseDistMinMax(minmax, ndose); 719 getShortDoseDistMinMax(minmax, ndose); 725 if(kLittleEndianOutput) { 720 if(kLittleEndianOutput) { 726 ofile.write((char *)minmax, 2*2); // sizeof( 721 ofile.write((char *)minmax, 2*2); // sizeof(shorft)*2 727 } else { 722 } else { 728 for(int j = 0; j < 2; j++) 723 for(int j = 0; j < 2; j++) 729 invertByteOrder((char *)&minmax[j], stmp[j 724 invertByteOrder((char *)&minmax[j], stmp[j]); 730 ofile.write((char *)stmp, 4); 725 ofile.write((char *)stmp, 4); 731 } 726 } 732 727 733 // dose distribution unit 728 // dose distribution unit 734 char cdunit[13]; 729 char cdunit[13]; 735 std::strncpy(cdunit, kDoseUnit.c_str(), << 730 for(int i = 0; i < 13; i++) cdunit[i] = '\0'; 736 cdunit[12] = '\0'; << 731 std::strcpy(cdunit, kDoseUnit.c_str()); 737 ofile.write(cdunit, 12); << 732 ofile.write((char *)cdunit, 12); 738 if(DEBUG || kVerbose > 0) { 733 if(DEBUG || kVerbose > 0) { 739 G4cout << "Dose dist. unit : " << kDoseUnit << 734 std::cout << "Dose dist. unit : " << kDoseUnit << std::endl; 740 } 735 } 741 736 742 // dose distribution scaling 737 // dose distribution scaling 743 double dscale; 738 double dscale; 744 dscale = getDoseDistScale(ndose); 739 dscale = getDoseDistScale(ndose); 745 scale = float(dscale); 740 scale = float(dscale); 746 if(kLittleEndianOutput) { 741 if(kLittleEndianOutput) { 747 ofile.write((char *)&scale, 4); 742 ofile.write((char *)&scale, 4); 748 } else { 743 } else { 749 invertByteOrder((char *)&scale, ftmp[0]); 744 invertByteOrder((char *)&scale, ftmp[0]); 750 ofile.write((char *)ftmp, 4); 745 ofile.write((char *)ftmp, 4); 751 } 746 } 752 if(DEBUG || kVerbose > 0) { 747 if(DEBUG || kVerbose > 0) { 753 G4cout << "Dose dist. [" << ndose << 748 std::cout << "Dose dist. [" << ndose 754 << "] image min., max., scale : " 749 << "] image min., max., scale : " 755 << minmax[0] << ", " 750 << minmax[0] << ", " 756 << minmax[1] << ", " 751 << minmax[1] << ", " 757 << scale << G4endl; << 752 << scale << std::endl; 758 } 753 } 759 754 760 // dose distribution image 755 // dose distribution image 761 int dsize = size[0]*size[1]; 756 int dsize = size[0]*size[1]; 762 short * dimage = new short[dsize]; 757 short * dimage = new short[dsize]; 763 for(int z = 0; z < size[2]; z++) { 758 for(int z = 0; z < size[2]; z++) { 764 getShortDoseDist(dimage, z, ndose); 759 getShortDoseDist(dimage, z, ndose); 765 if(kLittleEndianOutput) { 760 if(kLittleEndianOutput) { 766 ofile.write((char *)dimage, dsize*2); //si 761 ofile.write((char *)dimage, dsize*2); //sizeof(short) 767 } else { 762 } else { 768 for(int j = 0; j < dsize; j++) { 763 for(int j = 0; j < dsize; j++) { 769 invertByteOrder((char *)&dimage[j], stmp 764 invertByteOrder((char *)&dimage[j], stmp[0]); 770 ofile.write((char *)stmp, 2); 765 ofile.write((char *)stmp, 2); 771 } 766 } 772 } 767 } 773 768 774 if(DEBUG || kVerbose > 0) { 769 if(DEBUG || kVerbose > 0) { 775 for(int j = 0; j < dsize; j++) { 770 for(int j = 0; j < dsize; j++) { 776 if(dimage[j] < 0) 771 if(dimage[j] < 0) 777 G4cout << "[" << j << "," << z << "]" << 772 std::cout << "[" << j << "," << z << "]" 778 << dimage[j] << ", "; 773 << dimage[j] << ", "; 779 } 774 } 780 } 775 } 781 } 776 } 782 if(DEBUG || kVerbose > 0) G4cout << G4en << 777 if(DEBUG || kVerbose > 0) std::cout << std::endl; 783 delete [] dimage; 778 delete [] dimage; 784 779 785 // relative location of the dose distrib 780 // relative location of the dose distribution image for 786 // the modality image 781 // the modality image 787 getDoseDistCenterPosition(fCenter, ndose 782 getDoseDistCenterPosition(fCenter, ndose); 788 for(int i = 0; i < 3; i++) iCenter[i] = 783 for(int i = 0; i < 3; i++) iCenter[i] = (int)fCenter[i]; 789 if(kLittleEndianOutput) { 784 if(kLittleEndianOutput) { 790 ofile.write((char *)iCenter, 3*4); // 3*size 785 ofile.write((char *)iCenter, 3*4); // 3*sizeof(int) 791 } else { 786 } else { 792 for(int j = 0; j < 3; j++) 787 for(int j = 0; j < 3; j++) 793 invertByteOrder((char *)&iCenter[j], itmp[ 788 invertByteOrder((char *)&iCenter[j], itmp[j]); 794 ofile.write((char *)itmp, 12); 789 ofile.write((char *)itmp, 12); 795 } 790 } 796 if(DEBUG || kVerbose > 0) { 791 if(DEBUG || kVerbose > 0) { 797 G4cout << "Dose dist. [" << ndose << 792 std::cout << "Dose dist. [" << ndose 798 << "]image relative location : (" 793 << "]image relative location : (" 799 << iCenter[0] << ", " 794 << iCenter[0] << ", " 800 << iCenter[1] << ", " 795 << iCenter[1] << ", " 801 << iCenter[2] << ")" << G4endl; << 796 << iCenter[2] << ")" << std::endl; 802 } 797 } 803 798 804 // dose distribution name 799 // dose distribution name 805 std::string name = getDoseDistName(ndose 800 std::string name = getDoseDistName(ndose); 806 if(name.size() == 0) name = "dose"; 801 if(name.size() == 0) name = "dose"; 807 name.resize(80); 802 name.resize(80); 808 ofile.write((char *)name.c_str(), 80); 803 ofile.write((char *)name.c_str(), 80); 809 if(DEBUG || kVerbose > 0) { 804 if(DEBUG || kVerbose > 0) { 810 G4cout << "Dose dist. name : " << name << G4 << 805 std::cout << "Dose dist. name : " << name << std::endl; 811 } 806 } 812 807 813 } 808 } 814 } 809 } 815 810 816 //----- ROI image -----// 811 //----- ROI image -----// 817 if(!isROIEmpty()) { 812 if(!isROIEmpty()) { 818 // ROI image size 813 // ROI image size 819 kRoi[0].getSize(size); 814 kRoi[0].getSize(size); 820 if(kLittleEndianOutput) { 815 if(kLittleEndianOutput) { 821 ofile.write((char *)size, 3*sizeof(int)) 816 ofile.write((char *)size, 3*sizeof(int)); 822 } else { 817 } else { 823 for(int j = 0; j < 3; j++) 818 for(int j = 0; j < 3; j++) 824 invertByteOrder((char *)&size[j], itmp[j]); 819 invertByteOrder((char *)&size[j], itmp[j]); 825 ofile.write((char *)itmp, 12); 820 ofile.write((char *)itmp, 12); 826 } 821 } 827 if(DEBUG || kVerbose > 0) { 822 if(DEBUG || kVerbose > 0) { 828 G4cout << "ROI image size : (" << 823 std::cout << "ROI image size : (" 829 << size[0] << ", " 824 << size[0] << ", " 830 << size[1] << ", " 825 << size[1] << ", " 831 << size[2] << ")" 826 << size[2] << ")" 832 << G4endl; << 827 << std::endl; 833 } 828 } 834 829 835 // ROI max. & min. 830 // ROI max. & min. 836 kRoi[0].getMinMax(minmax); 831 kRoi[0].getMinMax(minmax); 837 if(kLittleEndianOutput) { 832 if(kLittleEndianOutput) { 838 ofile.write((char *)minmax, sizeof(short 833 ofile.write((char *)minmax, sizeof(short)*2); 839 } else { 834 } else { 840 for(int j = 0; j < 2; j++) 835 for(int j = 0; j < 2; j++) 841 invertByteOrder((char *)&minmax[j], stmp[j]) 836 invertByteOrder((char *)&minmax[j], stmp[j]); 842 ofile.write((char *)stmp, 4); 837 ofile.write((char *)stmp, 4); 843 } 838 } 844 839 845 // ROI distribution scaling 840 // ROI distribution scaling 846 scale = (float)kRoi[0].getScale(); 841 scale = (float)kRoi[0].getScale(); 847 if(kLittleEndianOutput) { 842 if(kLittleEndianOutput) { 848 ofile.write((char *)&scale, sizeof(float 843 ofile.write((char *)&scale, sizeof(float)); 849 } else { 844 } else { 850 invertByteOrder((char *)&scale, ftmp[0]) 845 invertByteOrder((char *)&scale, ftmp[0]); 851 ofile.write((char *)ftmp, 4); 846 ofile.write((char *)ftmp, 4); 852 } 847 } 853 if(DEBUG || kVerbose > 0) { 848 if(DEBUG || kVerbose > 0) { 854 G4cout << "ROI image min., max., scale : << 849 std::cout << "ROI image min., max., scale : " 855 << minmax[0] << ", " 850 << minmax[0] << ", " 856 << minmax[1] << ", " 851 << minmax[1] << ", " 857 << scale << G4endl; << 852 << scale << std::endl; 858 } 853 } 859 854 860 // ROI image 855 // ROI image 861 int rsize = size[0]*size[1]; 856 int rsize = size[0]*size[1]; 862 for(int i = 0; i < size[2]; i++) { 857 for(int i = 0; i < size[2]; i++) { 863 short * rimage = kRoi[0].getImage(i); 858 short * rimage = kRoi[0].getImage(i); 864 if(kLittleEndianOutput) { 859 if(kLittleEndianOutput) { 865 ofile.write((char *)rimage, rsize*sizeof(sho 860 ofile.write((char *)rimage, rsize*sizeof(short)); 866 } else { 861 } else { 867 for(int j = 0; j < rsize; j++) { 862 for(int j = 0; j < rsize; j++) { 868 invertByteOrder((char *)&rimage[j], stmp[0 863 invertByteOrder((char *)&rimage[j], stmp[0]); 869 ofile.write((char *)stmp, 2); 864 ofile.write((char *)stmp, 2); 870 } 865 } 871 } 866 } 872 867 873 } 868 } 874 869 875 // ROI relative location 870 // ROI relative location 876 kRoi[0].getCenterPosition(fCenter); 871 kRoi[0].getCenterPosition(fCenter); 877 for(int i = 0; i < 3; i++) iCenter[i] = (i 872 for(int i = 0; i < 3; i++) iCenter[i] = (int)fCenter[i]; 878 if(kLittleEndianOutput) { 873 if(kLittleEndianOutput) { 879 ofile.write((char *)iCenter, 3*sizeof(in 874 ofile.write((char *)iCenter, 3*sizeof(int)); 880 } else { 875 } else { 881 for(int j = 0; j < 3; j++) 876 for(int j = 0; j < 3; j++) 882 invertByteOrder((char *)&iCenter[j], itmp[j] 877 invertByteOrder((char *)&iCenter[j], itmp[j]); 883 ofile.write((char *)itmp, 12); 878 ofile.write((char *)itmp, 12); 884 } 879 } 885 if(DEBUG || kVerbose > 0) { 880 if(DEBUG || kVerbose > 0) { 886 G4cout << "ROI image relative location : << 881 std::cout << "ROI image relative location : (" 887 << iCenter[0] << ", " 882 << iCenter[0] << ", " 888 << iCenter[1] << ", " 883 << iCenter[1] << ", " 889 << iCenter[2] << ")" << G4endl; << 884 << iCenter[2] << ")" << std::endl; 890 } 885 } 891 } 886 } 892 887 893 //----- track information -----// 888 //----- track information -----// 894 // number of track 889 // number of track 895 if(kPointerToTrackData > 0) { 890 if(kPointerToTrackData > 0) { 896 891 897 int ntrk = (int)kTracks.size(); << 892 int ntrk = kTracks.size(); 898 if(kLittleEndianOutput) { 893 if(kLittleEndianOutput) { 899 ofile.write((char *)&ntrk, sizeof(int)); 894 ofile.write((char *)&ntrk, sizeof(int)); 900 } else { 895 } else { 901 invertByteOrder((char *)&ntrk, itmp[0]); 896 invertByteOrder((char *)&ntrk, itmp[0]); 902 ofile.write((char *)itmp, 4); 897 ofile.write((char *)itmp, 4); 903 } 898 } 904 if(DEBUG || kVerbose > 0) { 899 if(DEBUG || kVerbose > 0) { 905 G4cout << "# of tracks : " << 900 std::cout << "# of tracks : " 906 << ntrk << G4endl; << 901 << ntrk << std::endl; 907 } 902 } 908 903 909 for(int nt = 0; nt < ntrk; nt++) { 904 for(int nt = 0; nt < ntrk; nt++) { 910 905 911 // # of steps in a track 906 // # of steps in a track 912 int nsteps = kTracks[nt].getNumberOfStep 907 int nsteps = kTracks[nt].getNumberOfSteps(); 913 if(kLittleEndianOutput) { 908 if(kLittleEndianOutput) { 914 ofile.write((char *)&nsteps, sizeof(int)); 909 ofile.write((char *)&nsteps, sizeof(int)); 915 } else { 910 } else { 916 invertByteOrder((char *)&nsteps, itmp[0]); 911 invertByteOrder((char *)&nsteps, itmp[0]); 917 ofile.write((char *)itmp, 4); 912 ofile.write((char *)itmp, 4); 918 } 913 } 919 if(DEBUG || kVerbose > 0) { 914 if(DEBUG || kVerbose > 0) { 920 G4cout << "# of steps : " << nsteps << G4end << 915 std::cout << "# of steps : " << nsteps << std::endl; 921 } 916 } 922 917 923 // track color 918 // track color 924 unsigned char tcolor[3]; 919 unsigned char tcolor[3]; 925 kTracks[nt].getColor(tcolor); 920 kTracks[nt].getColor(tcolor); 926 ofile.write((char *)tcolor, 3); 921 ofile.write((char *)tcolor, 3); 927 922 928 // steps 923 // steps 929 float stepPoints[6]; 924 float stepPoints[6]; 930 for(int isteps = 0; isteps < nsteps; ist << 925 for(int ns = 0; ns < nsteps; ns++) { 931 kTracks[nt].getStep(stepPoints[0], stepPoint 926 kTracks[nt].getStep(stepPoints[0], stepPoints[1], stepPoints[2], 932 stepPoints[3], stepPoints[4], stepPo 927 stepPoints[3], stepPoints[4], stepPoints[5], 933 isteps); << 928 ns); 934 929 935 if(kLittleEndianOutput) { 930 if(kLittleEndianOutput) { 936 ofile.write((char *)stepPoints, sizeof(flo 931 ofile.write((char *)stepPoints, sizeof(float)*6); 937 } else { 932 } else { 938 for(int j = 0; j < 6; j++) 933 for(int j = 0; j < 6; j++) 939 invertByteOrder((char *)&stepPoints[j], 934 invertByteOrder((char *)&stepPoints[j], ftmp[j]); 940 ofile.write((char *)ftmp, 24); 935 ofile.write((char *)ftmp, 24); 941 } 936 } 942 } 937 } 943 } 938 } 944 } 939 } 945 940 946 //----- detector information -----// 941 //----- detector information -----// 947 // number of detectors 942 // number of detectors 948 if(kPointerToDetectorData > 0) { 943 if(kPointerToDetectorData > 0) { 949 int ndet = (int)kDetectors.size(); << 944 int ndet = kDetectors.size(); 950 if(kLittleEndianOutput) { 945 if(kLittleEndianOutput) { 951 ofile.write((char *)&ndet, sizeof(int)); 946 ofile.write((char *)&ndet, sizeof(int)); 952 } else { 947 } else { 953 invertByteOrder((char *)&ndet, itmp[0]); 948 invertByteOrder((char *)&ndet, itmp[0]); 954 ofile.write((char *)itmp, 4); 949 ofile.write((char *)itmp, 4); 955 } 950 } 956 if(DEBUG || kVerbose > 0) { 951 if(DEBUG || kVerbose > 0) { 957 G4cout << "# of detectors : " << 952 std::cout << "# of detectors : " 958 << ndet << G4endl; << 953 << ndet << std::endl; 959 } 954 } 960 955 961 for(int nd = 0; nd < ndet; nd++) { 956 for(int nd = 0; nd < ndet; nd++) { 962 957 963 // # of edges of a detector 958 // # of edges of a detector 964 int nedges = kDetectors[nd].getNumberOfE 959 int nedges = kDetectors[nd].getNumberOfEdges(); 965 if(kLittleEndianOutput) { 960 if(kLittleEndianOutput) { 966 ofile.write((char *)&nedges, sizeof(int)); 961 ofile.write((char *)&nedges, sizeof(int)); 967 } else { 962 } else { 968 invertByteOrder((char *)&nedges, itmp[0]); 963 invertByteOrder((char *)&nedges, itmp[0]); 969 ofile.write((char *)itmp, 4); 964 ofile.write((char *)itmp, 4); 970 } 965 } 971 if(DEBUG || kVerbose > 0) { 966 if(DEBUG || kVerbose > 0) { 972 G4cout << "# of edges in a detector : " << n << 967 std::cout << "# of edges in a detector : " << nedges << std::endl; 973 } 968 } 974 969 975 // edges 970 // edges 976 float edgePoints[6]; 971 float edgePoints[6]; 977 for(int ne = 0; ne < nedges; ne++) { 972 for(int ne = 0; ne < nedges; ne++) { 978 kDetectors[nd].getEdge(edgePoints[0], edgePo 973 kDetectors[nd].getEdge(edgePoints[0], edgePoints[1], edgePoints[2], 979 edgePoints[3], edgePoints[4], edg 974 edgePoints[3], edgePoints[4], edgePoints[5], 980 ne); 975 ne); 981 976 982 if(kLittleEndianOutput) { 977 if(kLittleEndianOutput) { 983 ofile.write((char *)edgePoints, sizeof(flo 978 ofile.write((char *)edgePoints, sizeof(float)*6); 984 } else { 979 } else { 985 for(int j = 0; j < 6; j++) 980 for(int j = 0; j < 6; j++) 986 invertByteOrder((char *)&edgePoints[j], 981 invertByteOrder((char *)&edgePoints[j], ftmp[j]); 987 ofile.write((char *)ftmp, 24); 982 ofile.write((char *)ftmp, 24); 988 } 983 } 989 984 990 if(DEBUG || kVerbose > 0) { 985 if(DEBUG || kVerbose > 0) { 991 if(ne < 1) { 986 if(ne < 1) { 992 G4cout << " edge : (" << edgePoints[0] < << 987 std::cout << " edge : (" << edgePoints[0] << ", " 993 << edgePoints[1] << ", " 988 << edgePoints[1] << ", " 994 << edgePoints[2] << ") - (" 989 << edgePoints[2] << ") - (" 995 << edgePoints[3] << ", " 990 << edgePoints[3] << ", " 996 << edgePoints[4] << ", " 991 << edgePoints[4] << ", " 997 << edgePoints[5] << ")" << G4endl; << 992 << edgePoints[5] << ")" << std::endl; 998 } 993 } 999 } 994 } 1000 } 995 } 1001 996 1002 // detector color 997 // detector color 1003 unsigned char dcolor[3]; 998 unsigned char dcolor[3]; 1004 kDetectors[nd].getColor(dcolor); 999 kDetectors[nd].getColor(dcolor); 1005 ofile.write((char *)dcolor, 3); 1000 ofile.write((char *)dcolor, 3); 1006 if(DEBUG || kVerbose > 0) { 1001 if(DEBUG || kVerbose > 0) { 1007 G4cout << " rgb : (" << (int)dcolor[0] << " << 1002 std::cout << " rgb : (" << (int)dcolor[0] << ", " 1008 << (int)dcolor[1] << ", " 1003 << (int)dcolor[1] << ", " 1009 << (int)dcolor[2] << ")" << G4endl; << 1004 << (int)dcolor[2] << ")" << std::endl; 1010 } 1005 } 1011 1006 1012 // detector name 1007 // detector name 1013 std::string dname = kDetectors[nd].getN 1008 std::string dname = kDetectors[nd].getName(); 1014 dname.resize(80); 1009 dname.resize(80); 1015 ofile.write((char *)dname.c_str(), 80); 1010 ofile.write((char *)dname.c_str(), 80); 1016 if(DEBUG || kVerbose > 0) { 1011 if(DEBUG || kVerbose > 0) { 1017 G4cout << " detector name : " << dname << G << 1012 std::cout << " detector name : " << dname << std::endl; 1018 1013 1019 } 1014 } 1020 } 1015 } 1021 } 1016 } 1022 1017 1023 // file end mark 1018 // file end mark 1024 ofile.write("END", 3); 1019 ofile.write("END", 3); 1025 1020 1026 ofile.close(); 1021 ofile.close(); 1027 if(DEBUG || kVerbose > 0) 1022 if(DEBUG || kVerbose > 0) 1028 G4cout << ">>>> closed gdd file: " << kFi << 1023 std::cout << ">>>> closed gdd file: " << kFileName << std::endl; 1029 1024 1030 return true; 1025 return true; 1031 } 1026 } 1032 bool G4GMocrenIO::storeData3() { 1027 bool G4GMocrenIO::storeData3() { 1033 1028 1034 if(kVerbose > 0) G4cout << ">>>>>>> store << 1029 if(kVerbose > 0) std::cout << ">>>>>>> store data (ver.3) <<<<<<<" << std::endl; 1035 if(kVerbose > 0) G4cout << " " << k << 1030 if(kVerbose > 0) std::cout << " " << kFileName << std::endl; 1036 1031 1037 bool DEBUG = false;// 1032 bool DEBUG = false;// 1038 1033 1039 // output file open 1034 // output file open 1040 std::ofstream ofile(kFileName.c_str(), 1035 std::ofstream ofile(kFileName.c_str(), 1041 std::ios_base::out|std::ios_base::b 1036 std::ios_base::out|std::ios_base::binary); 1042 1037 1043 // file identifier 1038 // file identifier 1044 ofile.write("gMocren ", 8); 1039 ofile.write("gMocren ", 8); 1045 1040 1046 // file version 1041 // file version 1047 unsigned char ver = 0x03; 1042 unsigned char ver = 0x03; 1048 ofile.write((char *)&ver, 1); 1043 ofile.write((char *)&ver, 1); 1049 1044 1050 // endian 1045 // endian 1051 ofile.write((char *)&kLittleEndianOutput, s 1046 ofile.write((char *)&kLittleEndianOutput, sizeof(char)); 1052 1047 1053 // comment length (fixed size) 1048 // comment length (fixed size) 1054 int commentLength = 1024; 1049 int commentLength = 1024; 1055 ofile.write((char *)&commentLength, 4); 1050 ofile.write((char *)&commentLength, 4); 1056 1051 1057 // comment 1052 // comment 1058 char cmt[1025]; 1053 char cmt[1025]; 1059 std::strncpy(cmt, kComment.c_str(), 1024); 1054 std::strncpy(cmt, kComment.c_str(), 1024); 1060 ofile.write((char *)cmt, 1024); 1055 ofile.write((char *)cmt, 1024); 1061 if(DEBUG || kVerbose > 0) { 1056 if(DEBUG || kVerbose > 0) { 1062 G4cout << "Data comment : " << 1057 std::cout << "Data comment : " 1063 << kComment << G4endl; << 1058 << kComment << std::endl; 1064 } 1059 } 1065 1060 1066 // voxel spacings for all images 1061 // voxel spacings for all images 1067 ofile.write((char *)kVoxelSpacing, 12); 1062 ofile.write((char *)kVoxelSpacing, 12); 1068 if(DEBUG || kVerbose > 0) { 1063 if(DEBUG || kVerbose > 0) { 1069 G4cout << "Voxel spacing : (" << 1064 std::cout << "Voxel spacing : (" 1070 << kVoxelSpacing[0] << ", " 1065 << kVoxelSpacing[0] << ", " 1071 << kVoxelSpacing[1] << ", " 1066 << kVoxelSpacing[1] << ", " 1072 << kVoxelSpacing[2] 1067 << kVoxelSpacing[2] 1073 << ") mm " << G4endl; << 1068 << ") mm " << std::endl; 1074 } 1069 } 1075 1070 1076 calcPointers3(); 1071 calcPointers3(); 1077 1072 1078 // offset from file starting point to the m 1073 // offset from file starting point to the modality image data 1079 ofile.write((char *)&kPointerToModalityData 1074 ofile.write((char *)&kPointerToModalityData, 4); 1080 1075 1081 // # of dose distributions 1076 // # of dose distributions 1082 //int nDoseDist = (int)pointerToDoseDistDat 1077 //int nDoseDist = (int)pointerToDoseDistData.size(); 1083 int nDoseDist = getNumDoseDist(); 1078 int nDoseDist = getNumDoseDist(); 1084 ofile.write((char *)&nDoseDist, 4); 1079 ofile.write((char *)&nDoseDist, 4); 1085 1080 1086 // offset from file starting point to the d 1081 // offset from file starting point to the dose image data 1087 for(int i = 0; i < nDoseDist; i++) { 1082 for(int i = 0; i < nDoseDist; i++) { 1088 ofile.write((char *)&kPointerToDoseDistDa 1083 ofile.write((char *)&kPointerToDoseDistData[i], 4); 1089 } 1084 } 1090 1085 1091 // offset from file starting point to the R 1086 // offset from file starting point to the ROI image data 1092 ofile.write((char *)&kPointerToROIData, 4); 1087 ofile.write((char *)&kPointerToROIData, 4); 1093 1088 1094 // offset from file starting point to the t 1089 // offset from file starting point to the track data 1095 ofile.write((char *)&kPointerToTrackData, 4 1090 ofile.write((char *)&kPointerToTrackData, 4); 1096 if(DEBUG || kVerbose > 0) { 1091 if(DEBUG || kVerbose > 0) { 1097 G4cout << "Each pointer to data : " << 1092 std::cout << "Each pointer to data : " 1098 << kPointerToModalityData << ", "; 1093 << kPointerToModalityData << ", "; 1099 for(int i = 0; i < nDoseDist; i++) { 1094 for(int i = 0; i < nDoseDist; i++) { 1100 G4cout << kPointerToDoseDistData[i] << << 1095 std::cout << kPointerToDoseDistData[i] << ", "; 1101 } 1096 } 1102 G4cout << kPointerToROIData << ", " << 1097 std::cout << kPointerToROIData << ", " 1103 << kPointerToTrackData << G4endl; << 1098 << kPointerToTrackData << std::endl; 1104 } 1099 } 1105 1100 1106 //----- modality image -----// 1101 //----- modality image -----// 1107 1102 1108 int size[3]; 1103 int size[3]; 1109 float scale; 1104 float scale; 1110 short minmax[2]; 1105 short minmax[2]; 1111 float fCenter[3]; 1106 float fCenter[3]; 1112 int iCenter[3]; 1107 int iCenter[3]; 1113 // modality image size 1108 // modality image size 1114 kModality.getSize(size); 1109 kModality.getSize(size); 1115 ofile.write((char *)size, 3*sizeof(int)); 1110 ofile.write((char *)size, 3*sizeof(int)); 1116 if(DEBUG || kVerbose > 0) { 1111 if(DEBUG || kVerbose > 0) { 1117 G4cout << "Modality image size : (" << 1112 std::cout << "Modality image size : (" 1118 << size[0] << ", " 1113 << size[0] << ", " 1119 << size[1] << ", " 1114 << size[1] << ", " 1120 << size[2] << ")" 1115 << size[2] << ")" 1121 << G4endl; << 1116 << std::endl; 1122 } 1117 } 1123 1118 1124 // modality image max. & min. 1119 // modality image max. & min. 1125 kModality.getMinMax(minmax); 1120 kModality.getMinMax(minmax); 1126 ofile.write((char *)minmax, 4); 1121 ofile.write((char *)minmax, 4); 1127 1122 1128 // modality image unit 1123 // modality image unit 1129 char munit[13] = "g/cm3 "; 1124 char munit[13] = "g/cm3 "; 1130 ofile.write((char *)munit, 12); 1125 ofile.write((char *)munit, 12); 1131 1126 1132 // modality image scale 1127 // modality image scale 1133 scale = (float)kModality.getScale(); 1128 scale = (float)kModality.getScale(); 1134 ofile.write((char *)&scale, 4); 1129 ofile.write((char *)&scale, 4); 1135 if(DEBUG || kVerbose > 0) { 1130 if(DEBUG || kVerbose > 0) { 1136 G4cout << "Modality image min., max., sca << 1131 std::cout << "Modality image min., max., scale : " 1137 << minmax[0] << ", " 1132 << minmax[0] << ", " 1138 << minmax[1] << ", " 1133 << minmax[1] << ", " 1139 << scale << G4endl; << 1134 << scale << std::endl; 1140 } 1135 } 1141 1136 1142 // modality image 1137 // modality image 1143 int psize = size[0]*size[1]; 1138 int psize = size[0]*size[1]; 1144 if(DEBUG || kVerbose > 0) G4cout << "Modali << 1139 if(DEBUG || kVerbose > 0) std::cout << "Modality image : "; 1145 for(int i = 0; i < size[2]; i++) { 1140 for(int i = 0; i < size[2]; i++) { 1146 short * image = kModality.getImage(i); 1141 short * image = kModality.getImage(i); 1147 ofile.write((char *)image, psize*sizeof(s 1142 ofile.write((char *)image, psize*sizeof(short)); 1148 1143 1149 if(DEBUG || kVerbose > 0) G4cout << "[" < << 1144 if(DEBUG || kVerbose > 0) std::cout << "[" << i << "]" << image[(size_t)(psize*0.55)] << ", "; 1150 } 1145 } 1151 if(DEBUG || kVerbose > 0) G4cout << G4endl; << 1146 if(DEBUG || kVerbose > 0) std::cout << std::endl; 1152 1147 1153 // modality desity map for CT value 1148 // modality desity map for CT value 1154 size_t msize = minmax[1] - minmax[0]+1; 1149 size_t msize = minmax[1] - minmax[0]+1; 1155 float * pdmap = new float[msize]; 1150 float * pdmap = new float[msize]; 1156 for(int i = 0; i < (int)msize; i++) pdmap[i 1151 for(int i = 0; i < (int)msize; i++) pdmap[i] =kModalityImageDensityMap[i]; 1157 ofile.write((char *)pdmap, msize*sizeof(flo 1152 ofile.write((char *)pdmap, msize*sizeof(float)); 1158 if(DEBUG || kVerbose > 0) { 1153 if(DEBUG || kVerbose > 0) { 1159 G4cout << "density map : " << std::ends; << 1154 std::cout << "density map : " << std::ends; 1160 for(int i = 0; i < (int)msize; i+=50) 1155 for(int i = 0; i < (int)msize; i+=50) 1161 G4cout <<kModalityImageDensityMap[i] << << 1156 std::cout <<kModalityImageDensityMap[i] << ", "; 1162 G4cout << G4endl; << 1157 std::cout << std::endl; 1163 } 1158 } 1164 delete [] pdmap; 1159 delete [] pdmap; 1165 1160 1166 1161 1167 //----- dose distribution image -----// 1162 //----- dose distribution image -----// 1168 1163 1169 if(!isDoseEmpty()) { 1164 if(!isDoseEmpty()) { 1170 1165 1171 calcDoseDistScale(); 1166 calcDoseDistScale(); 1172 1167 1173 for(int ndose = 0; ndose < nDoseDist; ndo 1168 for(int ndose = 0; ndose < nDoseDist; ndose++) { 1174 // dose distrbution image size 1169 // dose distrbution image size 1175 kDose[ndose].getSize(size); 1170 kDose[ndose].getSize(size); 1176 ofile.write((char *)size, 3*sizeof(int) 1171 ofile.write((char *)size, 3*sizeof(int)); 1177 if(DEBUG || kVerbose > 0) { 1172 if(DEBUG || kVerbose > 0) { 1178 G4cout << "Dose dist. [" << ndose << "] ima << 1173 std::cout << "Dose dist. [" << ndose << "] image size : (" 1179 << size[0] << ", " 1174 << size[0] << ", " 1180 << size[1] << ", " 1175 << size[1] << ", " 1181 << size[2] << ")" 1176 << size[2] << ")" 1182 << G4endl; << 1177 << std::endl; 1183 } 1178 } 1184 1179 1185 // dose distribution max. & min. 1180 // dose distribution max. & min. 1186 getShortDoseDistMinMax(minmax, ndose); 1181 getShortDoseDistMinMax(minmax, ndose); 1187 ofile.write((char *)minmax, 2*2); // si 1182 ofile.write((char *)minmax, 2*2); // sizeof(shorft)*2 1188 1183 1189 // dose distribution unit 1184 // dose distribution unit 1190 ofile.write((char *)kDoseUnit.c_str(), 1185 ofile.write((char *)kDoseUnit.c_str(), 12); 1191 if(DEBUG || kVerbose > 0) { 1186 if(DEBUG || kVerbose > 0) { 1192 G4cout << "Dose dist. unit : " << kDoseUnit << 1187 std::cout << "Dose dist. unit : " << kDoseUnit << std::endl; 1193 } 1188 } 1194 1189 1195 // dose distribution scaling 1190 // dose distribution scaling 1196 double dscale; 1191 double dscale; 1197 dscale = getDoseDistScale(ndose); 1192 dscale = getDoseDistScale(ndose); 1198 scale = float(dscale); 1193 scale = float(dscale); 1199 ofile.write((char *)&scale, 4); 1194 ofile.write((char *)&scale, 4); 1200 if(DEBUG || kVerbose > 0) { 1195 if(DEBUG || kVerbose > 0) { 1201 G4cout << "Dose dist. [" << ndose << 1196 std::cout << "Dose dist. [" << ndose 1202 << "] image min., max., scale : " 1197 << "] image min., max., scale : " 1203 << minmax[0] << ", " 1198 << minmax[0] << ", " 1204 << minmax[1] << ", " 1199 << minmax[1] << ", " 1205 << scale << G4endl; << 1200 << scale << std::endl; 1206 } 1201 } 1207 1202 1208 // dose distribution image 1203 // dose distribution image 1209 int dsize = size[0]*size[1]; 1204 int dsize = size[0]*size[1]; 1210 short * dimage = new short[dsize]; 1205 short * dimage = new short[dsize]; 1211 for(int z = 0; z < size[2]; z++) { 1206 for(int z = 0; z < size[2]; z++) { 1212 getShortDoseDist(dimage, z, ndose); 1207 getShortDoseDist(dimage, z, ndose); 1213 ofile.write((char *)dimage, dsize*2); //siz 1208 ofile.write((char *)dimage, dsize*2); //sizeof(short) 1214 1209 1215 if(DEBUG || kVerbose > 0) { 1210 if(DEBUG || kVerbose > 0) { 1216 for(int j = 0; j < dsize; j++) { 1211 for(int j = 0; j < dsize; j++) { 1217 if(dimage[j] < 0) 1212 if(dimage[j] < 0) 1218 G4cout << "[" << j << "," << z << "]" << 1213 std::cout << "[" << j << "," << z << "]" 1219 << dimage[j] << ", "; 1214 << dimage[j] << ", "; 1220 } 1215 } 1221 } 1216 } 1222 } 1217 } 1223 if(DEBUG || kVerbose > 0) G4cout << G4e << 1218 if(DEBUG || kVerbose > 0) std::cout << std::endl; 1224 delete [] dimage; 1219 delete [] dimage; 1225 1220 1226 // relative location of the dose distri 1221 // relative location of the dose distribution image for 1227 // the modality image 1222 // the modality image 1228 getDoseDistCenterPosition(fCenter, ndos 1223 getDoseDistCenterPosition(fCenter, ndose); 1229 for(int i = 0; i < 3; i++) iCenter[i] = 1224 for(int i = 0; i < 3; i++) iCenter[i] = (int)fCenter[i]; 1230 ofile.write((char *)iCenter, 3*4); // 3 1225 ofile.write((char *)iCenter, 3*4); // 3*sizeof(int) 1231 if(DEBUG || kVerbose > 0) { 1226 if(DEBUG || kVerbose > 0) { 1232 G4cout << "Dose dist. [" << ndose << 1227 std::cout << "Dose dist. [" << ndose 1233 << "]image relative location : (" 1228 << "]image relative location : (" 1234 << iCenter[0] << ", " 1229 << iCenter[0] << ", " 1235 << iCenter[1] << ", " 1230 << iCenter[1] << ", " 1236 << iCenter[2] << ")" << G4endl; << 1231 << iCenter[2] << ")" << std::endl; 1237 } 1232 } 1238 } 1233 } 1239 } 1234 } 1240 1235 1241 //----- ROI image -----// 1236 //----- ROI image -----// 1242 if(!isROIEmpty()) { 1237 if(!isROIEmpty()) { 1243 // ROI image size 1238 // ROI image size 1244 kRoi[0].getSize(size); 1239 kRoi[0].getSize(size); 1245 ofile.write((char *)size, 3*sizeof(int)); 1240 ofile.write((char *)size, 3*sizeof(int)); 1246 if(DEBUG || kVerbose > 0) { 1241 if(DEBUG || kVerbose > 0) { 1247 G4cout << "ROI image size : (" << 1242 std::cout << "ROI image size : (" 1248 << size[0] << ", " 1243 << size[0] << ", " 1249 << size[1] << ", " 1244 << size[1] << ", " 1250 << size[2] << ")" 1245 << size[2] << ")" 1251 << G4endl; << 1246 << std::endl; 1252 } 1247 } 1253 1248 1254 // ROI max. & min. 1249 // ROI max. & min. 1255 kRoi[0].getMinMax(minmax); 1250 kRoi[0].getMinMax(minmax); 1256 ofile.write((char *)minmax, sizeof(short) 1251 ofile.write((char *)minmax, sizeof(short)*2); 1257 1252 1258 // ROI distribution scaling 1253 // ROI distribution scaling 1259 scale = (float)kRoi[0].getScale(); 1254 scale = (float)kRoi[0].getScale(); 1260 ofile.write((char *)&scale, sizeof(float) 1255 ofile.write((char *)&scale, sizeof(float)); 1261 if(DEBUG || kVerbose > 0) { 1256 if(DEBUG || kVerbose > 0) { 1262 G4cout << "ROI image min., max., scale << 1257 std::cout << "ROI image min., max., scale : " 1263 << minmax[0] << ", " 1258 << minmax[0] << ", " 1264 << minmax[1] << ", " 1259 << minmax[1] << ", " 1265 << scale << G4endl; << 1260 << scale << std::endl; 1266 } 1261 } 1267 1262 1268 // ROI image 1263 // ROI image 1269 int rsize = size[0]*size[1]; 1264 int rsize = size[0]*size[1]; 1270 for(int i = 0; i < size[2]; i++) { 1265 for(int i = 0; i < size[2]; i++) { 1271 short * rimage = kRoi[0].getImage(i); 1266 short * rimage = kRoi[0].getImage(i); 1272 ofile.write((char *)rimage, rsize*sizeo 1267 ofile.write((char *)rimage, rsize*sizeof(short)); 1273 1268 1274 } 1269 } 1275 1270 1276 // ROI relative location 1271 // ROI relative location 1277 kRoi[0].getCenterPosition(fCenter); 1272 kRoi[0].getCenterPosition(fCenter); 1278 for(int i = 0; i < 3; i++) iCenter[i] = ( 1273 for(int i = 0; i < 3; i++) iCenter[i] = (int)fCenter[i]; 1279 ofile.write((char *)iCenter, 3*sizeof(int 1274 ofile.write((char *)iCenter, 3*sizeof(int)); 1280 if(DEBUG || kVerbose > 0) { 1275 if(DEBUG || kVerbose > 0) { 1281 G4cout << "ROI image relative location << 1276 std::cout << "ROI image relative location : (" 1282 << iCenter[0] << ", " 1277 << iCenter[0] << ", " 1283 << iCenter[1] << ", " 1278 << iCenter[1] << ", " 1284 << iCenter[2] << ")" << G4endl; << 1279 << iCenter[2] << ")" << std::endl; 1285 } 1280 } 1286 } 1281 } 1287 1282 1288 //----- track information -----// 1283 //----- track information -----// 1289 // number of track 1284 // number of track 1290 int ntrk = (int)kSteps.size(); << 1285 int ntrk = kSteps.size(); 1291 ofile.write((char *)&ntrk, sizeof(int)); 1286 ofile.write((char *)&ntrk, sizeof(int)); 1292 if(DEBUG || kVerbose > 0) { 1287 if(DEBUG || kVerbose > 0) { 1293 G4cout << "# of tracks : " << 1288 std::cout << "# of tracks : " 1294 << ntrk << G4endl; << 1289 << ntrk << std::endl; 1295 } 1290 } 1296 // track position 1291 // track position 1297 for(int i = 0; i < ntrk; i++) { 1292 for(int i = 0; i < ntrk; i++) { 1298 float * tp = kSteps[i]; 1293 float * tp = kSteps[i]; 1299 ofile.write((char *)tp, sizeof(float)*6); 1294 ofile.write((char *)tp, sizeof(float)*6); 1300 } 1295 } 1301 // track color 1296 // track color 1302 int ntcolor = int(kStepColors.size()); 1297 int ntcolor = int(kStepColors.size()); 1303 if(ntrk != ntcolor) 1298 if(ntrk != ntcolor) 1304 if (G4VisManager::GetVerbosity() >= G4Vis << 1299 std::cerr << "# of track color information must be the same as # of tracks." 1305 G4cout << "# of track color information << 1300 << std::endl; 1306 << G4endl; << 1307 unsigned char white[3] = {255,255,255}; // 1301 unsigned char white[3] = {255,255,255}; // default color 1308 for(int i = 0; i < ntrk; i++) { 1302 for(int i = 0; i < ntrk; i++) { 1309 if(i < ntcolor) { 1303 if(i < ntcolor) { 1310 unsigned char * tcolor = kStepColors[i] 1304 unsigned char * tcolor = kStepColors[i]; 1311 ofile.write((char *)tcolor, 3); 1305 ofile.write((char *)tcolor, 3); 1312 } else { 1306 } else { 1313 ofile.write((char *)white, 3); 1307 ofile.write((char *)white, 3); 1314 } 1308 } 1315 } 1309 } 1316 1310 1317 // file end mark 1311 // file end mark 1318 ofile.write("END", 3); 1312 ofile.write("END", 3); 1319 1313 1320 ofile.close(); 1314 ofile.close(); 1321 1315 1322 return true; 1316 return true; 1323 } 1317 } 1324 // 1318 // 1325 bool G4GMocrenIO::storeData4(char * _filename 1319 bool G4GMocrenIO::storeData4(char * _filename) { 1326 kFileName = _filename; 1320 kFileName = _filename; 1327 return storeData4(); 1321 return storeData4(); 1328 } 1322 } 1329 1323 1330 // version 2 1324 // version 2 1331 bool G4GMocrenIO::storeData2() { 1325 bool G4GMocrenIO::storeData2() { 1332 1326 1333 if(kVerbose > 0) G4cout << ">>>>>>> store << 1327 if(kVerbose > 0) std::cout << ">>>>>>> store data (ver.2) <<<<<<<" << std::endl; 1334 if(kVerbose > 0) G4cout << " " << k << 1328 if(kVerbose > 0) std::cout << " " << kFileName << std::endl; 1335 1329 1336 bool DEBUG = false;// 1330 bool DEBUG = false;// 1337 1331 1338 // output file open 1332 // output file open 1339 std::ofstream ofile(kFileName.c_str(), 1333 std::ofstream ofile(kFileName.c_str(), 1340 std::ios_base::out|std::ios_base::b 1334 std::ios_base::out|std::ios_base::binary); 1341 1335 1342 // file identifier 1336 // file identifier 1343 ofile.write("GRAPE ", 8); 1337 ofile.write("GRAPE ", 8); 1344 1338 1345 // file version 1339 // file version 1346 unsigned char ver = 0x02; 1340 unsigned char ver = 0x02; 1347 ofile.write((char *)&ver, 1); 1341 ofile.write((char *)&ver, 1); 1348 // file id for old file format support 1342 // file id for old file format support 1349 ofile.write(kId.c_str(), IDLENGTH); 1343 ofile.write(kId.c_str(), IDLENGTH); 1350 // file version for old file format support 1344 // file version for old file format support 1351 ofile.write(kVersion.c_str(), VERLENGTH); 1345 ofile.write(kVersion.c_str(), VERLENGTH); 1352 // endian 1346 // endian 1353 ofile.write((char *)&kLittleEndianOutput, s 1347 ofile.write((char *)&kLittleEndianOutput, sizeof(char)); 1354 1348 1355 /* 1349 /* 1356 // event number 1350 // event number 1357 ofile.write((char *)&numberOfEvents, sizeof 1351 ofile.write((char *)&numberOfEvents, sizeof(int)); 1358 float imageSpacing[3]; 1352 float imageSpacing[3]; 1359 imageSpacing[0] = modalityImageVoxelSpacing 1353 imageSpacing[0] = modalityImageVoxelSpacing[0]; 1360 imageSpacing[1] = modalityImageVoxelSpacing 1354 imageSpacing[1] = modalityImageVoxelSpacing[1]; 1361 imageSpacing[2] = modalityImageVoxelSpacing 1355 imageSpacing[2] = modalityImageVoxelSpacing[2]; 1362 ofile.write((char *)imageSpacing, 12); 1356 ofile.write((char *)imageSpacing, 12); 1363 */ 1357 */ 1364 1358 1365 1359 1366 // voxel spacings for all images 1360 // voxel spacings for all images 1367 ofile.write((char *)kVoxelSpacing, 12); 1361 ofile.write((char *)kVoxelSpacing, 12); 1368 if(DEBUG || kVerbose > 0) { 1362 if(DEBUG || kVerbose > 0) { 1369 G4cout << "Voxel spacing : (" << 1363 std::cout << "Voxel spacing : (" 1370 << kVoxelSpacing[0] << ", " 1364 << kVoxelSpacing[0] << ", " 1371 << kVoxelSpacing[1] << ", " 1365 << kVoxelSpacing[1] << ", " 1372 << kVoxelSpacing[2] 1366 << kVoxelSpacing[2] 1373 << ") mm " << G4endl; << 1367 << ") mm " << std::endl; 1374 } 1368 } 1375 1369 1376 calcPointers2(); 1370 calcPointers2(); 1377 // offset from file starting point to the m 1371 // offset from file starting point to the modality image data 1378 ofile.write((char *)&kPointerToModalityData 1372 ofile.write((char *)&kPointerToModalityData, 4); 1379 1373 1380 // offset from file starting point to the d 1374 // offset from file starting point to the dose image data 1381 ofile.write((char *)&kPointerToDoseDistData 1375 ofile.write((char *)&kPointerToDoseDistData[0], 4); 1382 1376 1383 // offset from file starting point to the R 1377 // offset from file starting point to the ROI image data 1384 ofile.write((char *)&kPointerToROIData, 4); 1378 ofile.write((char *)&kPointerToROIData, 4); 1385 1379 1386 // offset from file starting point to the t 1380 // offset from file starting point to the track data 1387 ofile.write((char *)&kPointerToTrackData, 4 1381 ofile.write((char *)&kPointerToTrackData, 4); 1388 if(DEBUG || kVerbose > 0) { 1382 if(DEBUG || kVerbose > 0) { 1389 G4cout << "Each pointer to data : " << 1383 std::cout << "Each pointer to data : " 1390 << kPointerToModalityData << ", " 1384 << kPointerToModalityData << ", " 1391 << kPointerToDoseDistData[0] << ", " 1385 << kPointerToDoseDistData[0] << ", " 1392 << kPointerToROIData << ", " 1386 << kPointerToROIData << ", " 1393 << kPointerToTrackData << G4endl; << 1387 << kPointerToTrackData << std::endl; 1394 } 1388 } 1395 1389 1396 //----- modality image -----// 1390 //----- modality image -----// 1397 1391 1398 int size[3]; 1392 int size[3]; 1399 float scale; 1393 float scale; 1400 short minmax[2]; 1394 short minmax[2]; 1401 float fCenter[3]; 1395 float fCenter[3]; 1402 int iCenter[3]; 1396 int iCenter[3]; 1403 // modality image size 1397 // modality image size 1404 kModality.getSize(size); 1398 kModality.getSize(size); 1405 ofile.write((char *)size, 3*sizeof(int)); 1399 ofile.write((char *)size, 3*sizeof(int)); 1406 if(DEBUG || kVerbose > 0) { 1400 if(DEBUG || kVerbose > 0) { 1407 G4cout << "Modality image size : (" << 1401 std::cout << "Modality image size : (" 1408 << size[0] << ", " 1402 << size[0] << ", " 1409 << size[1] << ", " 1403 << size[1] << ", " 1410 << size[2] << ")" 1404 << size[2] << ")" 1411 << G4endl; << 1405 << std::endl; 1412 } 1406 } 1413 1407 1414 // modality image max. & min. 1408 // modality image max. & min. 1415 kModality.getMinMax(minmax); 1409 kModality.getMinMax(minmax); 1416 ofile.write((char *)minmax, 4); 1410 ofile.write((char *)minmax, 4); 1417 1411 1418 // modality image unit 1412 // modality image unit 1419 //char munit[13] = "g/cm3 "; 1413 //char munit[13] = "g/cm3 "; 1420 //ofile.write((char *)&munit, 12); 1414 //ofile.write((char *)&munit, 12); 1421 1415 1422 // modality image scale 1416 // modality image scale 1423 scale = (float)kModality.getScale(); 1417 scale = (float)kModality.getScale(); 1424 ofile.write((char *)&scale, 4); 1418 ofile.write((char *)&scale, 4); 1425 if(DEBUG || kVerbose > 0) { 1419 if(DEBUG || kVerbose > 0) { 1426 G4cout << "Modality image min., max., sca << 1420 std::cout << "Modality image min., max., scale : " 1427 << minmax[0] << ", " 1421 << minmax[0] << ", " 1428 << minmax[1] << ", " 1422 << minmax[1] << ", " 1429 << scale << G4endl; << 1423 << scale << std::endl; 1430 } 1424 } 1431 1425 1432 // modality image 1426 // modality image 1433 int psize = size[0]*size[1]; 1427 int psize = size[0]*size[1]; 1434 if(DEBUG || kVerbose > 0) G4cout << "Modali << 1428 if(DEBUG || kVerbose > 0) std::cout << "Modality image : "; 1435 for(int i = 0; i < size[2]; i++) { 1429 for(int i = 0; i < size[2]; i++) { 1436 short * image =kModality.getImage(i); 1430 short * image =kModality.getImage(i); 1437 ofile.write((char *)image, psize*sizeof(s 1431 ofile.write((char *)image, psize*sizeof(short)); 1438 1432 1439 if(DEBUG || kVerbose > 0) G4cout << "[" < << 1433 if(DEBUG || kVerbose > 0) std::cout << "[" << i << "]" << image[(size_t)(psize*0.55)] << ", "; 1440 } 1434 } 1441 if(DEBUG || kVerbose > 0) G4cout << G4endl; << 1435 if(DEBUG || kVerbose > 0) std::cout << std::endl; 1442 1436 1443 // modality desity map for CT value 1437 // modality desity map for CT value 1444 size_t msize = minmax[1] - minmax[0]+1; 1438 size_t msize = minmax[1] - minmax[0]+1; 1445 float * pdmap = new float[msize]; 1439 float * pdmap = new float[msize]; 1446 for(int i = 0; i < (int)msize; i++) pdmap[i 1440 for(int i = 0; i < (int)msize; i++) pdmap[i] =kModalityImageDensityMap[i]; 1447 ofile.write((char *)pdmap, msize*sizeof(flo 1441 ofile.write((char *)pdmap, msize*sizeof(float)); 1448 if(DEBUG || kVerbose > 0) { 1442 if(DEBUG || kVerbose > 0) { 1449 G4cout << "density map : " << std::ends; << 1443 std::cout << "density map : " << std::ends; 1450 for(int i = 0; i < (int)msize; i+=50) 1444 for(int i = 0; i < (int)msize; i+=50) 1451 G4cout <<kModalityImageDensityMap[i] << << 1445 std::cout <<kModalityImageDensityMap[i] << ", "; 1452 G4cout << G4endl; << 1446 std::cout << std::endl; 1453 } 1447 } 1454 delete [] pdmap; 1448 delete [] pdmap; 1455 1449 1456 1450 1457 //----- dose distribution image -----// 1451 //----- dose distribution image -----// 1458 1452 1459 if(!isDoseEmpty()) { 1453 if(!isDoseEmpty()) { 1460 calcDoseDistScale(); 1454 calcDoseDistScale(); 1461 1455 1462 // dose distrbution image size 1456 // dose distrbution image size 1463 kDose[0].getSize(size); 1457 kDose[0].getSize(size); 1464 ofile.write((char *)size, 3*sizeof(int)); 1458 ofile.write((char *)size, 3*sizeof(int)); 1465 if(DEBUG || kVerbose > 0) { 1459 if(DEBUG || kVerbose > 0) { 1466 G4cout << "Dose dist. image size : (" << 1460 std::cout << "Dose dist. image size : (" 1467 << size[0] << ", " 1461 << size[0] << ", " 1468 << size[1] << ", " 1462 << size[1] << ", " 1469 << size[2] << ")" 1463 << size[2] << ")" 1470 << G4endl; << 1464 << std::endl; 1471 } 1465 } 1472 1466 1473 // dose distribution max. & min. 1467 // dose distribution max. & min. 1474 getShortDoseDistMinMax(minmax); 1468 getShortDoseDistMinMax(minmax); 1475 ofile.write((char *)minmax, sizeof(short) 1469 ofile.write((char *)minmax, sizeof(short)*2); 1476 1470 1477 // dose distribution scaling 1471 // dose distribution scaling 1478 scale = (float)kDose[0].getScale(); 1472 scale = (float)kDose[0].getScale(); 1479 ofile.write((char *)&scale, sizeof(float) 1473 ofile.write((char *)&scale, sizeof(float)); 1480 if(DEBUG || kVerbose > 0) { 1474 if(DEBUG || kVerbose > 0) { 1481 G4cout << "Dose dist. image min., max., << 1475 std::cout << "Dose dist. image min., max., scale : " 1482 << minmax[0] << ", " 1476 << minmax[0] << ", " 1483 << minmax[1] << ", " 1477 << minmax[1] << ", " 1484 << scale << G4endl; << 1478 << scale << std::endl; 1485 } 1479 } 1486 1480 1487 // dose distribution image 1481 // dose distribution image 1488 int dsize = size[0]*size[1]; 1482 int dsize = size[0]*size[1]; 1489 short * dimage = new short[dsize]; 1483 short * dimage = new short[dsize]; 1490 for(int z = 0; z < size[2]; z++) { 1484 for(int z = 0; z < size[2]; z++) { 1491 getShortDoseDist(dimage, z); 1485 getShortDoseDist(dimage, z); 1492 ofile.write((char *)dimage, dsize*sizeo 1486 ofile.write((char *)dimage, dsize*sizeof(short)); 1493 1487 1494 if(DEBUG || kVerbose > 0) { 1488 if(DEBUG || kVerbose > 0) { 1495 for(int j = 0; j < dsize; j++) { 1489 for(int j = 0; j < dsize; j++) { 1496 if(dimage[j] < 0) 1490 if(dimage[j] < 0) 1497 G4cout << "[" << j << "," << z << "]" << 1491 std::cout << "[" << j << "," << z << "]" 1498 << dimage[j] << ", "; 1492 << dimage[j] << ", "; 1499 } 1493 } 1500 } 1494 } 1501 } 1495 } 1502 if(DEBUG || kVerbose > 0) G4cout << G4end << 1496 if(DEBUG || kVerbose > 0) std::cout << std::endl; 1503 delete [] dimage; 1497 delete [] dimage; 1504 1498 1505 // relative location of the dose distribu 1499 // relative location of the dose distribution image for 1506 // the modality image 1500 // the modality image 1507 kDose[0].getCenterPosition(fCenter); 1501 kDose[0].getCenterPosition(fCenter); 1508 for(int i = 0; i < 3; i++) iCenter[i] = ( 1502 for(int i = 0; i < 3; i++) iCenter[i] = (int)fCenter[i]; 1509 ofile.write((char *)iCenter, 3*sizeof(int 1503 ofile.write((char *)iCenter, 3*sizeof(int)); 1510 if(DEBUG || kVerbose > 0) { 1504 if(DEBUG || kVerbose > 0) { 1511 G4cout << "Dose dist. image relative lo << 1505 std::cout << "Dose dist. image relative location : (" 1512 << iCenter[0] << ", " 1506 << iCenter[0] << ", " 1513 << iCenter[1] << ", " 1507 << iCenter[1] << ", " 1514 << iCenter[2] << ")" << G4endl; << 1508 << iCenter[2] << ")" << std::endl; 1515 } 1509 } 1516 1510 1517 } 1511 } 1518 1512 1519 //----- ROI image -----// 1513 //----- ROI image -----// 1520 if(!isROIEmpty()) { 1514 if(!isROIEmpty()) { 1521 // ROI image size 1515 // ROI image size 1522 kRoi[0].getSize(size); 1516 kRoi[0].getSize(size); 1523 ofile.write((char *)size, 3*sizeof(int)); 1517 ofile.write((char *)size, 3*sizeof(int)); 1524 if(DEBUG || kVerbose > 0) { 1518 if(DEBUG || kVerbose > 0) { 1525 G4cout << "ROI image size : (" << 1519 std::cout << "ROI image size : (" 1526 << size[0] << ", " 1520 << size[0] << ", " 1527 << size[1] << ", " 1521 << size[1] << ", " 1528 << size[2] << ")" 1522 << size[2] << ")" 1529 << G4endl; << 1523 << std::endl; 1530 } 1524 } 1531 1525 1532 // ROI max. & min. 1526 // ROI max. & min. 1533 kRoi[0].getMinMax(minmax); 1527 kRoi[0].getMinMax(minmax); 1534 ofile.write((char *)minmax, sizeof(short) 1528 ofile.write((char *)minmax, sizeof(short)*2); 1535 1529 1536 // ROI distribution scaling 1530 // ROI distribution scaling 1537 scale = (float)kRoi[0].getScale(); 1531 scale = (float)kRoi[0].getScale(); 1538 ofile.write((char *)&scale, sizeof(float) 1532 ofile.write((char *)&scale, sizeof(float)); 1539 if(DEBUG || kVerbose > 0) { 1533 if(DEBUG || kVerbose > 0) { 1540 G4cout << "ROI image min., max., scale << 1534 std::cout << "ROI image min., max., scale : " 1541 << minmax[0] << ", " 1535 << minmax[0] << ", " 1542 << minmax[1] << ", " 1536 << minmax[1] << ", " 1543 << scale << G4endl; << 1537 << scale << std::endl; 1544 } 1538 } 1545 1539 1546 // ROI image 1540 // ROI image 1547 int rsize = size[0]*size[1]; 1541 int rsize = size[0]*size[1]; 1548 for(int i = 0; i < size[2]; i++) { 1542 for(int i = 0; i < size[2]; i++) { 1549 short * rimage = kRoi[0].getImage(i); 1543 short * rimage = kRoi[0].getImage(i); 1550 ofile.write((char *)rimage, rsize*sizeo 1544 ofile.write((char *)rimage, rsize*sizeof(short)); 1551 1545 1552 } 1546 } 1553 1547 1554 // ROI relative location 1548 // ROI relative location 1555 kRoi[0].getCenterPosition(fCenter); 1549 kRoi[0].getCenterPosition(fCenter); 1556 for(int i = 0; i < 3; i++) iCenter[i] = ( 1550 for(int i = 0; i < 3; i++) iCenter[i] = (int)fCenter[i]; 1557 ofile.write((char *)iCenter, 3*sizeof(int 1551 ofile.write((char *)iCenter, 3*sizeof(int)); 1558 if(DEBUG || kVerbose > 0) { 1552 if(DEBUG || kVerbose > 0) { 1559 G4cout << "ROI image relative location << 1553 std::cout << "ROI image relative location : (" 1560 << iCenter[0] << ", " 1554 << iCenter[0] << ", " 1561 << iCenter[1] << ", " 1555 << iCenter[1] << ", " 1562 << iCenter[2] << ")" << G4endl; << 1556 << iCenter[2] << ")" << std::endl; 1563 } 1557 } 1564 } 1558 } 1565 1559 1566 1560 1567 //----- track information -----// 1561 //----- track information -----// 1568 // track 1562 // track 1569 int ntrk = (int)kSteps.size(); << 1563 int ntrk = kSteps.size(); 1570 ofile.write((char *)&ntrk, sizeof(int)); 1564 ofile.write((char *)&ntrk, sizeof(int)); 1571 if(DEBUG || kVerbose > 0) { 1565 if(DEBUG || kVerbose > 0) { 1572 G4cout << "# of tracks : " << 1566 std::cout << "# of tracks : " 1573 << ntrk << G4endl; << 1567 << ntrk << std::endl; 1574 } 1568 } 1575 for(int i = 0; i < ntrk; i++) { 1569 for(int i = 0; i < ntrk; i++) { 1576 float * tp = kSteps[i]; 1570 float * tp = kSteps[i]; 1577 ofile.write((char *)tp, sizeof(float)*6); 1571 ofile.write((char *)tp, sizeof(float)*6); 1578 } 1572 } 1579 1573 1580 1574 1581 // file end mark 1575 // file end mark 1582 ofile.write("END", 3); 1576 ofile.write("END", 3); 1583 1577 1584 ofile.close(); 1578 ofile.close(); 1585 1579 1586 return true; 1580 return true; 1587 } 1581 } 1588 // 1582 // 1589 bool G4GMocrenIO::storeData2(char * _filename 1583 bool G4GMocrenIO::storeData2(char * _filename) { 1590 kFileName = _filename; 1584 kFileName = _filename; 1591 return storeData(); 1585 return storeData(); 1592 } 1586 } 1593 1587 1594 bool G4GMocrenIO::retrieveData() { 1588 bool G4GMocrenIO::retrieveData() { 1595 1589 1596 // input file open 1590 // input file open 1597 std::ifstream ifile(kFileName.c_str(), std: 1591 std::ifstream ifile(kFileName.c_str(), std::ios_base::in|std::ios_base::binary); 1598 if(!ifile) { 1592 if(!ifile) { 1599 if (G4VisManager::GetVerbosity() >= G4Vis << 1593 std::cerr << "Cannot open file: " << kFileName 1600 G4cout << "Cannot open file: " << kFile << 1594 << " in G4GMocrenIO::retrieveData()." << std::endl; 1601 << " in G4GMocrenIO::retrieveData()." << 1602 return false; 1595 return false; 1603 } 1596 } 1604 1597 1605 // file identifier 1598 // file identifier 1606 char verid[9]; 1599 char verid[9]; 1607 ifile.read((char *)verid, 8); 1600 ifile.read((char *)verid, 8); 1608 // file version 1601 // file version 1609 unsigned char ver; 1602 unsigned char ver; 1610 ifile.read((char *)&ver, 1); 1603 ifile.read((char *)&ver, 1); 1611 ifile.close(); 1604 ifile.close(); 1612 1605 1613 if(std::strncmp(verid, "gMocren", 7) == 0) 1606 if(std::strncmp(verid, "gMocren", 7) == 0) { 1614 if(ver == 0x03) { 1607 if(ver == 0x03) { 1615 G4cout << ">>>>>>> retrieve data (ver. << 1608 std::cout << ">>>>>>> retrieve data (ver.3) <<<<<<<" << std::endl; 1616 G4cout << " " << kFileName << G << 1609 std::cout << " " << kFileName << std::endl; 1617 retrieveData3(); 1610 retrieveData3(); 1618 } else if (ver == 0x04) { 1611 } else if (ver == 0x04) { 1619 G4cout << ">>>>>>> retrieve data (ver. << 1612 std::cout << ">>>>>>> retrieve data (ver.4) <<<<<<<" << std::endl; 1620 G4cout << " " << kFileName << G << 1613 std::cout << " " << kFileName << std::endl; 1621 retrieveData4(); 1614 retrieveData4(); 1622 } else { 1615 } else { 1623 if (G4VisManager::GetVerbosity() >= G4V << 1616 std::cerr << "Error -- invalid file version : " << (int)ver 1624 G4cout << "Error -- invalid file version : << 1617 << std::endl; 1625 << G4endl; << 1618 std::cerr << " " << kFileName << std::endl; 1626 G4cout << " " << kFileName << G4end << 1619 std::exit(-1); 1627 } << 1628 G4Exception("G4GMocrenIO::retrieveDadta << 1629 "gMocren2001", FatalExcepti << 1630 "Error."); << 1631 << 1632 } 1620 } 1633 } else if(std::strncmp(verid, "GRAPE", 5) = 1621 } else if(std::strncmp(verid, "GRAPE", 5) == 0) { 1634 G4cout << ">>>>>>> retrieve data (ver.2) << 1622 std::cout << ">>>>>>> retrieve data (ver.2) <<<<<<<" << std::endl; 1635 G4cout << " " << kFileName << G4e << 1623 std::cout << " " << kFileName << std::endl; 1636 retrieveData2(); 1624 retrieveData2(); 1637 } else { 1625 } else { 1638 if (G4VisManager::GetVerbosity() >= G4Vis << 1626 std::cerr << kFileName << " was not gdd file." << std::endl; 1639 G4cout << kFileName << " was not gdd fi << 1640 return false; 1627 return false; 1641 } 1628 } 1642 1629 1643 return true; 1630 return true; 1644 } 1631 } 1645 1632 1646 bool G4GMocrenIO::retrieveData(char * _filena 1633 bool G4GMocrenIO::retrieveData(char * _filename) { 1647 kFileName = _filename; 1634 kFileName = _filename; 1648 return retrieveData(); 1635 return retrieveData(); 1649 } 1636 } 1650 1637 1651 // 1638 // 1652 bool G4GMocrenIO::retrieveData4() { 1639 bool G4GMocrenIO::retrieveData4() { 1653 1640 1654 bool DEBUG = false;// 1641 bool DEBUG = false;// 1655 1642 1656 // input file open 1643 // input file open 1657 std::ifstream ifile(kFileName.c_str(), std: 1644 std::ifstream ifile(kFileName.c_str(), std::ios_base::in|std::ios_base::binary); 1658 if(!ifile) { 1645 if(!ifile) { 1659 if (G4VisManager::GetVerbosity() >= G4Vis << 1646 std::cerr << "Cannot open file: " << kFileName 1660 G4cout << "Cannot open file: " << kFile << 1647 << " in G4GMocrenIO::retrieveData3()." << std::endl; 1661 << " in G4GMocrenIO::retrieveData3()." << << 1662 return false; 1648 return false; 1663 } 1649 } 1664 1650 1665 // data buffer 1651 // data buffer 1666 char ctmp[24]; << 1652 char ctmp[12]; 1667 1653 1668 // file identifier 1654 // file identifier 1669 char verid[9]; 1655 char verid[9]; 1670 ifile.read((char *)verid, 8); 1656 ifile.read((char *)verid, 8); 1671 1657 1672 // file version 1658 // file version 1673 unsigned char ver; 1659 unsigned char ver; 1674 ifile.read((char *)&ver, 1); 1660 ifile.read((char *)&ver, 1); 1675 std::stringstream ss; 1661 std::stringstream ss; 1676 ss << (int)ver; 1662 ss << (int)ver; 1677 kVersion = ss.str(); 1663 kVersion = ss.str(); 1678 if(DEBUG || kVerbose > 0) G4cout << "File v << 1664 if(DEBUG || kVerbose > 0) std::cout << "File version : " << kVersion << std::endl; 1679 1665 1680 // endian 1666 // endian 1681 ifile.read((char *)&kLittleEndianInput, siz 1667 ifile.read((char *)&kLittleEndianInput, sizeof(char)); 1682 if(DEBUG || kVerbose > 0) { 1668 if(DEBUG || kVerbose > 0) { 1683 G4cout << "Endian : "; << 1669 std::cout << "Endian : "; 1684 if(kLittleEndianInput == 1) 1670 if(kLittleEndianInput == 1) 1685 G4cout << " little" << G4endl; << 1671 std::cout << " little" << std::endl; 1686 else { 1672 else { 1687 G4cout << " big" << G4endl; << 1673 std::cout << " big" << std::endl; 1688 } 1674 } 1689 } 1675 } 1690 1676 1691 // comment length (fixed size) 1677 // comment length (fixed size) 1692 int clength; 1678 int clength; 1693 ifile.read((char *)ctmp, 4); 1679 ifile.read((char *)ctmp, 4); 1694 convertEndian(ctmp, clength); 1680 convertEndian(ctmp, clength); 1695 // comment 1681 // comment 1696 char cmt[1025]; 1682 char cmt[1025]; 1697 ifile.read((char *)cmt, clength); 1683 ifile.read((char *)cmt, clength); 1698 std::string scmt = cmt; 1684 std::string scmt = cmt; 1699 scmt += '\0'; 1685 scmt += '\0'; 1700 setComment(scmt); 1686 setComment(scmt); 1701 if(DEBUG || kVerbose > 0) { 1687 if(DEBUG || kVerbose > 0) { 1702 G4cout << "Data comment : " << 1688 std::cout << "Data comment : " 1703 << kComment << G4endl; << 1689 << kComment << std::endl; 1704 } 1690 } 1705 1691 1706 // voxel spacings for all images 1692 // voxel spacings for all images 1707 ifile.read((char *)ctmp, 12); 1693 ifile.read((char *)ctmp, 12); 1708 convertEndian(ctmp, kVoxelSpacing[0]); 1694 convertEndian(ctmp, kVoxelSpacing[0]); 1709 convertEndian(ctmp+4, kVoxelSpacing[1]); 1695 convertEndian(ctmp+4, kVoxelSpacing[1]); 1710 convertEndian(ctmp+8, kVoxelSpacing[2]); 1696 convertEndian(ctmp+8, kVoxelSpacing[2]); 1711 if(DEBUG || kVerbose > 0) { 1697 if(DEBUG || kVerbose > 0) { 1712 G4cout << "Voxel spacing : (" << 1698 std::cout << "Voxel spacing : (" 1713 << kVoxelSpacing[0] << ", " 1699 << kVoxelSpacing[0] << ", " 1714 << kVoxelSpacing[1] << ", " 1700 << kVoxelSpacing[1] << ", " 1715 << kVoxelSpacing[2] 1701 << kVoxelSpacing[2] 1716 << ") mm " << G4endl; << 1702 << ") mm " << std::endl; 1717 } 1703 } 1718 1704 1719 1705 1720 // offset from file starting point to the m 1706 // offset from file starting point to the modality image data 1721 ifile.read((char *)ctmp, 4); 1707 ifile.read((char *)ctmp, 4); 1722 convertEndian(ctmp, kPointerToModalityData) 1708 convertEndian(ctmp, kPointerToModalityData); 1723 1709 1724 // # of dose distributions 1710 // # of dose distributions 1725 ifile.read((char *)ctmp, 4); 1711 ifile.read((char *)ctmp, 4); 1726 int nDoseDist; 1712 int nDoseDist; 1727 convertEndian(ctmp, nDoseDist); 1713 convertEndian(ctmp, nDoseDist); 1728 1714 1729 // offset from file starting point to the d 1715 // offset from file starting point to the dose image data 1730 for(int i = 0; i < nDoseDist; i++) { 1716 for(int i = 0; i < nDoseDist; i++) { 1731 ifile.read((char *)ctmp, 4); 1717 ifile.read((char *)ctmp, 4); 1732 unsigned int dptr; 1718 unsigned int dptr; 1733 convertEndian(ctmp, dptr); 1719 convertEndian(ctmp, dptr); 1734 addPointerToDoseDistData(dptr); 1720 addPointerToDoseDistData(dptr); 1735 } 1721 } 1736 1722 1737 // offset from file starting point to the R 1723 // offset from file starting point to the ROI image data 1738 ifile.read((char *)ctmp, 4); 1724 ifile.read((char *)ctmp, 4); 1739 convertEndian(ctmp, kPointerToROIData); 1725 convertEndian(ctmp, kPointerToROIData); 1740 1726 1741 // offset from file starting point to the t 1727 // offset from file starting point to the track data 1742 ifile.read((char *)ctmp, 4); 1728 ifile.read((char *)ctmp, 4); 1743 convertEndian(ctmp, kPointerToTrackData); 1729 convertEndian(ctmp, kPointerToTrackData); 1744 1730 1745 // offset from file starting point to the d 1731 // offset from file starting point to the detector data 1746 ifile.read((char *)ctmp, 4); 1732 ifile.read((char *)ctmp, 4); 1747 convertEndian(ctmp, kPointerToDetectorData) 1733 convertEndian(ctmp, kPointerToDetectorData); 1748 1734 1749 if(DEBUG || kVerbose > 0) { 1735 if(DEBUG || kVerbose > 0) { 1750 G4cout << "Each pointer to data : " << 1736 std::cout << "Each pointer to data : " 1751 << kPointerToModalityData << ", "; 1737 << kPointerToModalityData << ", "; 1752 for(int i = 0; i < nDoseDist; i++) 1738 for(int i = 0; i < nDoseDist; i++) 1753 G4cout << kPointerToDoseDistData[i] << << 1739 std::cout << kPointerToDoseDistData[i] << ", "; 1754 G4cout << kPointerToROIData << ", " << 1740 std::cout << kPointerToROIData << ", " 1755 << kPointerToTrackData << ", " 1741 << kPointerToTrackData << ", " 1756 << kPointerToDetectorData 1742 << kPointerToDetectorData 1757 << G4endl; << 1743 << std::endl; 1758 } 1744 } 1759 1745 1760 1746 1761 1747 1762 if(kPointerToModalityData == 0 && kPointerT 1748 if(kPointerToModalityData == 0 && kPointerToDoseDistData.size() == 0 && 1763 kPointerToROIData == 0 && kPointerToTrac 1749 kPointerToROIData == 0 && kPointerToTrackData == 0) { 1764 if(DEBUG || kVerbose > 0) { 1750 if(DEBUG || kVerbose > 0) { 1765 G4cout << "No data." << G4endl; << 1751 std::cout << "No data." << std::endl; 1766 } 1752 } 1767 return false; 1753 return false; 1768 } 1754 } 1769 1755 1770 // event number 1756 // event number 1771 /* ver 1 1757 /* ver 1 1772 ifile.read(ctmp, sizeof(int)); 1758 ifile.read(ctmp, sizeof(int)); 1773 convertEndian(ctmp, numberOfEvents); 1759 convertEndian(ctmp, numberOfEvents); 1774 */ 1760 */ 1775 1761 1776 int size[3]; 1762 int size[3]; 1777 float scale; 1763 float scale; 1778 double dscale; 1764 double dscale; 1779 short minmax[2]; 1765 short minmax[2]; 1780 float fCenter[3]; 1766 float fCenter[3]; 1781 int iCenter[3]; 1767 int iCenter[3]; 1782 1768 1783 //----- Modality image -----// 1769 //----- Modality image -----// 1784 // modality image size 1770 // modality image size 1785 ifile.read(ctmp, 3*sizeof(int)); 1771 ifile.read(ctmp, 3*sizeof(int)); 1786 convertEndian(ctmp, size[0]); 1772 convertEndian(ctmp, size[0]); 1787 convertEndian(ctmp+sizeof(int), size[1]); 1773 convertEndian(ctmp+sizeof(int), size[1]); 1788 convertEndian(ctmp+2*sizeof(int), size[2]); 1774 convertEndian(ctmp+2*sizeof(int), size[2]); 1789 if(DEBUG || kVerbose > 0) { 1775 if(DEBUG || kVerbose > 0) { 1790 G4cout << "Modality image size : (" << 1776 std::cout << "Modality image size : (" 1791 << size[0] << ", " 1777 << size[0] << ", " 1792 << size[1] << ", " 1778 << size[1] << ", " 1793 << size[2] << ")" 1779 << size[2] << ")" 1794 << G4endl; << 1780 << std::endl; 1795 } 1781 } 1796 kModality.setSize(size); 1782 kModality.setSize(size); 1797 1783 1798 // modality image voxel spacing 1784 // modality image voxel spacing 1799 /* 1785 /* 1800 ifile.read(ctmp, 3*sizeof(float)); 1786 ifile.read(ctmp, 3*sizeof(float)); 1801 convertEndian(ctmp, modalityImageVoxelSpa 1787 convertEndian(ctmp, modalityImageVoxelSpacing[0]); 1802 convertEndian(ctmp+sizeof(float), modalit 1788 convertEndian(ctmp+sizeof(float), modalityImageVoxelSpacing[1]); 1803 convertEndian(ctmp+2*sizeof(float), modal 1789 convertEndian(ctmp+2*sizeof(float), modalityImageVoxelSpacing[2]); 1804 */ 1790 */ 1805 1791 1806 if(kPointerToModalityData != 0) { 1792 if(kPointerToModalityData != 0) { 1807 1793 1808 // modality density max. & min. 1794 // modality density max. & min. 1809 ifile.read((char *)ctmp, 4); 1795 ifile.read((char *)ctmp, 4); 1810 convertEndian(ctmp, minmax[0]); 1796 convertEndian(ctmp, minmax[0]); 1811 convertEndian(ctmp+2, minmax[1]); 1797 convertEndian(ctmp+2, minmax[1]); 1812 kModality.setMinMax(minmax); 1798 kModality.setMinMax(minmax); 1813 1799 1814 // modality image unit 1800 // modality image unit 1815 char munit[13]; 1801 char munit[13]; 1816 munit[12] = '\0'; 1802 munit[12] = '\0'; 1817 ifile.read((char *)munit, 12); 1803 ifile.read((char *)munit, 12); 1818 std::string smunit = munit; 1804 std::string smunit = munit; 1819 setModalityImageUnit(smunit); 1805 setModalityImageUnit(smunit); 1820 1806 1821 // modality density scale 1807 // modality density scale 1822 ifile.read((char *)ctmp, 4); 1808 ifile.read((char *)ctmp, 4); 1823 convertEndian(ctmp, scale); 1809 convertEndian(ctmp, scale); 1824 kModality.setScale(dscale = scale); 1810 kModality.setScale(dscale = scale); 1825 if(DEBUG || kVerbose > 0) { 1811 if(DEBUG || kVerbose > 0) { 1826 G4cout << "Modality image min., max., s << 1812 std::cout << "Modality image min., max., scale : " 1827 << minmax[0] << ", " 1813 << minmax[0] << ", " 1828 << minmax[1] << ", " 1814 << minmax[1] << ", " 1829 << scale << G4endl; << 1815 << scale << std::endl; 1830 } 1816 } 1831 1817 1832 // modality density 1818 // modality density 1833 int psize = size[0]*size[1]; 1819 int psize = size[0]*size[1]; 1834 if(DEBUG || kVerbose > 0) G4cout << "Moda << 1820 if(DEBUG || kVerbose > 0) std::cout << "Modality image (" << psize << "): "; 1835 char * cimage = new char[psize*sizeof(sho 1821 char * cimage = new char[psize*sizeof(short)]; 1836 for(int i = 0; i < size[2]; i++) { 1822 for(int i = 0; i < size[2]; i++) { 1837 ifile.read((char *)cimage, psize*sizeof 1823 ifile.read((char *)cimage, psize*sizeof(short)); 1838 short * mimage = new short[psize]; 1824 short * mimage = new short[psize]; 1839 for(int j = 0; j < psize; j++) { 1825 for(int j = 0; j < psize; j++) { 1840 convertEndian(cimage+j*sizeof(short), mimag 1826 convertEndian(cimage+j*sizeof(short), mimage[j]); 1841 } 1827 } 1842 kModality.addImage(mimage); 1828 kModality.addImage(mimage); 1843 1829 1844 if(DEBUG || kVerbose > 0) G4cout << "[" << 1830 if(DEBUG || kVerbose > 0) std::cout << "[" << i << "]" << mimage[(size_t)(psize*0.55)] << ", "; 1845 } 1831 } 1846 if(DEBUG || kVerbose > 0) G4cout << G4end << 1832 if(DEBUG || kVerbose > 0) std::cout << std::endl; 1847 delete [] cimage; 1833 delete [] cimage; 1848 1834 1849 // modality desity map for CT value 1835 // modality desity map for CT value 1850 size_t msize = minmax[1]-minmax[0]+1; 1836 size_t msize = minmax[1]-minmax[0]+1; 1851 if(DEBUG || kVerbose > 0) G4cout << "msiz << 1837 if(DEBUG || kVerbose > 0) std::cout << "msize: " << msize << std::endl; 1852 char * pdmap = new char[msize*sizeof(floa 1838 char * pdmap = new char[msize*sizeof(float)]; 1853 ifile.read((char *)pdmap, msize*sizeof(fl 1839 ifile.read((char *)pdmap, msize*sizeof(float)); 1854 float ftmp; 1840 float ftmp; 1855 for(int i = 0; i < (int)msize; i++) { 1841 for(int i = 0; i < (int)msize; i++) { 1856 convertEndian(pdmap+i*sizeof(float), ft 1842 convertEndian(pdmap+i*sizeof(float), ftmp); 1857 kModalityImageDensityMap.push_back(ftmp 1843 kModalityImageDensityMap.push_back(ftmp); 1858 } 1844 } 1859 delete [] pdmap; << 1860 << 1861 if(DEBUG || kVerbose > 0) { 1845 if(DEBUG || kVerbose > 0) { 1862 G4cout << "density map : " << std::ends << 1846 std::cout << "density map : " << std::ends; 1863 for(int i = 0; i < 10; i++) 1847 for(int i = 0; i < 10; i++) 1864 G4cout <<kModalityImageDensityMap[i] << ", << 1848 std::cout <<kModalityImageDensityMap[i] << ", "; 1865 G4cout << G4endl; << 1849 std::cout << std::endl; 1866 for(int i = 0; i < 10; i++) G4cout << " << 1850 for(int i = 0; i < 10; i++) std::cout << ".."; 1867 G4cout << G4endl; << 1851 std::cout << std::endl; 1868 for(size_t i =kModalityImageDensityMap. 1852 for(size_t i =kModalityImageDensityMap.size() - 10; i <kModalityImageDensityMap.size(); i++) 1869 G4cout <<kModalityImageDensityMap[i] << ", << 1853 std::cout <<kModalityImageDensityMap[i] << ", "; 1870 G4cout << G4endl; << 1854 std::cout << std::endl; 1871 } 1855 } 1872 1856 1873 } 1857 } 1874 1858 1875 1859 1876 //----- dose distribution image -----// 1860 //----- dose distribution image -----// 1877 for(int ndose = 0; ndose < nDoseDist; ndose 1861 for(int ndose = 0; ndose < nDoseDist; ndose++) { 1878 1862 1879 newDoseDist(); 1863 newDoseDist(); 1880 1864 1881 // dose distrbution image size 1865 // dose distrbution image size 1882 ifile.read((char *)ctmp, 3*sizeof(int)); 1866 ifile.read((char *)ctmp, 3*sizeof(int)); 1883 convertEndian(ctmp, size[0]); 1867 convertEndian(ctmp, size[0]); 1884 convertEndian(ctmp+sizeof(int), size[1]); 1868 convertEndian(ctmp+sizeof(int), size[1]); 1885 convertEndian(ctmp+2*sizeof(int), size[2] 1869 convertEndian(ctmp+2*sizeof(int), size[2]); 1886 if(DEBUG || kVerbose > 0) { 1870 if(DEBUG || kVerbose > 0) { 1887 G4cout << "Dose dist. image size : (" << 1871 std::cout << "Dose dist. image size : (" 1888 << size[0] << ", " 1872 << size[0] << ", " 1889 << size[1] << ", " 1873 << size[1] << ", " 1890 << size[2] << ")" 1874 << size[2] << ")" 1891 << G4endl; << 1875 << std::endl; 1892 } 1876 } 1893 kDose[ndose].setSize(size); 1877 kDose[ndose].setSize(size); 1894 1878 1895 // dose distribution max. & min. 1879 // dose distribution max. & min. 1896 ifile.read((char *)ctmp, sizeof(short)*2) 1880 ifile.read((char *)ctmp, sizeof(short)*2); 1897 convertEndian(ctmp, minmax[0]); 1881 convertEndian(ctmp, minmax[0]); 1898 convertEndian(ctmp+2, minmax[1]); 1882 convertEndian(ctmp+2, minmax[1]); 1899 1883 1900 // dose distribution unit 1884 // dose distribution unit 1901 char dunit[13]; 1885 char dunit[13]; 1902 dunit[12] = '\0'; 1886 dunit[12] = '\0'; 1903 ifile.read((char *)dunit, 12); 1887 ifile.read((char *)dunit, 12); 1904 std::string sdunit = dunit; 1888 std::string sdunit = dunit; 1905 setDoseDistUnit(sdunit, ndose); 1889 setDoseDistUnit(sdunit, ndose); 1906 if(DEBUG || kVerbose > 0) { 1890 if(DEBUG || kVerbose > 0) { 1907 G4cout << "Dose dist. unit : " << kDose << 1891 std::cout << "Dose dist. unit : " << kDoseUnit << std::endl; 1908 } 1892 } 1909 1893 1910 // dose distribution scaling 1894 // dose distribution scaling 1911 ifile.read((char *)ctmp, 4); // sizeof(fl 1895 ifile.read((char *)ctmp, 4); // sizeof(float) 1912 convertEndian(ctmp, scale); 1896 convertEndian(ctmp, scale); 1913 kDose[ndose].setScale(dscale = scale); 1897 kDose[ndose].setScale(dscale = scale); 1914 1898 1915 double dminmax[2]; 1899 double dminmax[2]; 1916 for(int i = 0; i < 2; i++) dminmax[i] = m 1900 for(int i = 0; i < 2; i++) dminmax[i] = minmax[i]*dscale; 1917 kDose[ndose].setMinMax(dminmax); 1901 kDose[ndose].setMinMax(dminmax); 1918 1902 1919 if(DEBUG || kVerbose > 0) { 1903 if(DEBUG || kVerbose > 0) { 1920 G4cout << "Dose dist. image min., max., << 1904 std::cout << "Dose dist. image min., max., scale : " 1921 << dminmax[0] << ", " 1905 << dminmax[0] << ", " 1922 << dminmax[1] << ", " 1906 << dminmax[1] << ", " 1923 << scale << G4endl; << 1907 << scale << std::endl; 1924 } 1908 } 1925 1909 1926 // dose distribution image 1910 // dose distribution image 1927 int dsize = size[0]*size[1]; 1911 int dsize = size[0]*size[1]; 1928 if(DEBUG || kVerbose > 0) G4cout << "Dose << 1912 if(DEBUG || kVerbose > 0) std::cout << "Dose dist. (" << dsize << "): "; 1929 char * di = new char[dsize*sizeof(short)] 1913 char * di = new char[dsize*sizeof(short)]; 1930 short * shimage = new short[dsize]; 1914 short * shimage = new short[dsize]; 1931 for(int z = 0; z < size[2]; z++) { 1915 for(int z = 0; z < size[2]; z++) { 1932 ifile.read((char *)di, dsize*sizeof(sho 1916 ifile.read((char *)di, dsize*sizeof(short)); 1933 double * dimage = new double[dsize]; 1917 double * dimage = new double[dsize]; 1934 for(int xy = 0; xy < dsize; xy++) { 1918 for(int xy = 0; xy < dsize; xy++) { 1935 convertEndian(di+xy*sizeof(short), shimage[ 1919 convertEndian(di+xy*sizeof(short), shimage[xy]); 1936 dimage[xy] = shimage[xy]*dscale; 1920 dimage[xy] = shimage[xy]*dscale; 1937 } 1921 } 1938 kDose[ndose].addImage(dimage); 1922 kDose[ndose].addImage(dimage); 1939 1923 1940 if(DEBUG || kVerbose > 0) G4cout << "[" << 1924 if(DEBUG || kVerbose > 0) std::cout << "[" << z << "]" << dimage[(size_t)(dsize*0.55)] << ", "; 1941 1925 1942 if(DEBUG || kVerbose > 0) { 1926 if(DEBUG || kVerbose > 0) { 1943 for(int j = 0; j < dsize; j++) { 1927 for(int j = 0; j < dsize; j++) { 1944 if(dimage[j] < 0) 1928 if(dimage[j] < 0) 1945 G4cout << "[" << j << "," << z << "]" << 1929 std::cout << "[" << j << "," << z << "]" 1946 << dimage[j] << ", "; 1930 << dimage[j] << ", "; 1947 } 1931 } 1948 } 1932 } 1949 } 1933 } 1950 delete [] shimage; 1934 delete [] shimage; 1951 delete [] di; 1935 delete [] di; 1952 if(DEBUG || kVerbose > 0) G4cout << G4end << 1936 if(DEBUG || kVerbose > 0) std::cout << std::endl; 1953 1937 1954 ifile.read((char *)ctmp, 3*4); // 3*sizeo 1938 ifile.read((char *)ctmp, 3*4); // 3*sizeof(int) 1955 convertEndian(ctmp, iCenter[0]); 1939 convertEndian(ctmp, iCenter[0]); 1956 convertEndian(ctmp+4, iCenter[1]); 1940 convertEndian(ctmp+4, iCenter[1]); 1957 convertEndian(ctmp+8, iCenter[2]); 1941 convertEndian(ctmp+8, iCenter[2]); 1958 for(int i = 0; i < 3; i++) fCenter[i] = ( 1942 for(int i = 0; i < 3; i++) fCenter[i] = (float)iCenter[i]; 1959 kDose[ndose].setCenterPosition(fCenter); 1943 kDose[ndose].setCenterPosition(fCenter); 1960 1944 1961 if(DEBUG || kVerbose > 0) { 1945 if(DEBUG || kVerbose > 0) { 1962 G4cout << "Dose dist. image relative lo << 1946 std::cout << "Dose dist. image relative location : (" 1963 << fCenter[0] << ", " 1947 << fCenter[0] << ", " 1964 << fCenter[1] << ", " 1948 << fCenter[1] << ", " 1965 << fCenter[2] << ")" << G4endl; << 1949 << fCenter[2] << ")" << std::endl; 1966 } 1950 } 1967 1951 1968 1952 1969 // dose distribution name 1953 // dose distribution name 1970 char cname[81]; 1954 char cname[81]; 1971 ifile.read((char *)cname, 80); 1955 ifile.read((char *)cname, 80); 1972 std::string dosename = cname; 1956 std::string dosename = cname; 1973 setDoseDistName(dosename, ndose); 1957 setDoseDistName(dosename, ndose); 1974 if(DEBUG || kVerbose > 0) { 1958 if(DEBUG || kVerbose > 0) { 1975 G4cout << "Dose dist. name : " << dosen << 1959 std::cout << "Dose dist. name : " << dosename << std::endl; 1976 } 1960 } 1977 1961 1978 } 1962 } 1979 1963 1980 //----- ROI image -----// 1964 //----- ROI image -----// 1981 if(kPointerToROIData != 0) { 1965 if(kPointerToROIData != 0) { 1982 1966 1983 newROI(); 1967 newROI(); 1984 1968 1985 // ROI image size 1969 // ROI image size 1986 ifile.read((char *)ctmp, 3*sizeof(int)); 1970 ifile.read((char *)ctmp, 3*sizeof(int)); 1987 convertEndian(ctmp, size[0]); 1971 convertEndian(ctmp, size[0]); 1988 convertEndian(ctmp+sizeof(int), size[1]); 1972 convertEndian(ctmp+sizeof(int), size[1]); 1989 convertEndian(ctmp+2*sizeof(int), size[2] 1973 convertEndian(ctmp+2*sizeof(int), size[2]); 1990 kRoi[0].setSize(size); 1974 kRoi[0].setSize(size); 1991 if(DEBUG || kVerbose > 0) { 1975 if(DEBUG || kVerbose > 0) { 1992 G4cout << "ROI image size : (" << 1976 std::cout << "ROI image size : (" 1993 << size[0] << ", " 1977 << size[0] << ", " 1994 << size[1] << ", " 1978 << size[1] << ", " 1995 << size[2] << ")" 1979 << size[2] << ")" 1996 << G4endl; << 1980 << std::endl; 1997 } 1981 } 1998 1982 1999 // ROI max. & min. 1983 // ROI max. & min. 2000 ifile.read((char *)ctmp, sizeof(short)*2) 1984 ifile.read((char *)ctmp, sizeof(short)*2); 2001 convertEndian(ctmp, minmax[0]); 1985 convertEndian(ctmp, minmax[0]); 2002 convertEndian(ctmp+sizeof(short), minmax[ 1986 convertEndian(ctmp+sizeof(short), minmax[1]); 2003 kRoi[0].setMinMax(minmax); 1987 kRoi[0].setMinMax(minmax); 2004 1988 2005 // ROI distribution scaling 1989 // ROI distribution scaling 2006 ifile.read((char *)ctmp, sizeof(float)); 1990 ifile.read((char *)ctmp, sizeof(float)); 2007 convertEndian(ctmp, scale); 1991 convertEndian(ctmp, scale); 2008 kRoi[0].setScale(dscale = scale); 1992 kRoi[0].setScale(dscale = scale); 2009 if(DEBUG || kVerbose > 0) { 1993 if(DEBUG || kVerbose > 0) { 2010 G4cout << "ROI image min., max., scale << 1994 std::cout << "ROI image min., max., scale : " 2011 << minmax[0] << ", " 1995 << minmax[0] << ", " 2012 << minmax[1] << ", " 1996 << minmax[1] << ", " 2013 << scale << G4endl; << 1997 << scale << std::endl; 2014 } 1998 } 2015 1999 2016 // ROI image 2000 // ROI image 2017 int rsize = size[0]*size[1]; 2001 int rsize = size[0]*size[1]; 2018 char * ri = new char[rsize*sizeof(short)] 2002 char * ri = new char[rsize*sizeof(short)]; 2019 for(int i = 0; i < size[2]; i++) { 2003 for(int i = 0; i < size[2]; i++) { 2020 ifile.read((char *)ri, rsize*sizeof(sho 2004 ifile.read((char *)ri, rsize*sizeof(short)); 2021 short * rimage = new short[rsize]; 2005 short * rimage = new short[rsize]; 2022 for(int j = 0; j < rsize; j++) { 2006 for(int j = 0; j < rsize; j++) { 2023 convertEndian(ri+j*sizeof(short), rimage[j] 2007 convertEndian(ri+j*sizeof(short), rimage[j]); 2024 } 2008 } 2025 kRoi[0].addImage(rimage); 2009 kRoi[0].addImage(rimage); 2026 2010 2027 } 2011 } 2028 delete [] ri; 2012 delete [] ri; 2029 2013 2030 // ROI relative location 2014 // ROI relative location 2031 ifile.read((char *)ctmp, 3*sizeof(int)); 2015 ifile.read((char *)ctmp, 3*sizeof(int)); 2032 convertEndian(ctmp, iCenter[0]); 2016 convertEndian(ctmp, iCenter[0]); 2033 convertEndian(ctmp+sizeof(int), iCenter[1 2017 convertEndian(ctmp+sizeof(int), iCenter[1]); 2034 convertEndian(ctmp+2*sizeof(int), iCenter 2018 convertEndian(ctmp+2*sizeof(int), iCenter[2]); 2035 for(int i = 0; i < 3; i++) fCenter[i] = i 2019 for(int i = 0; i < 3; i++) fCenter[i] = iCenter[i]; 2036 kRoi[0].setCenterPosition(fCenter); 2020 kRoi[0].setCenterPosition(fCenter); 2037 if(DEBUG || kVerbose > 0) { 2021 if(DEBUG || kVerbose > 0) { 2038 G4cout << "ROI image relative location << 2022 std::cout << "ROI image relative location : (" 2039 << fCenter[0] << ", " 2023 << fCenter[0] << ", " 2040 << fCenter[1] << ", " 2024 << fCenter[1] << ", " 2041 << fCenter[2] << ")" << G4endl; << 2025 << fCenter[2] << ")" << std::endl; 2042 } 2026 } 2043 2027 2044 } 2028 } 2045 2029 2046 //----- track information -----// 2030 //----- track information -----// 2047 if(kPointerToTrackData != 0) { 2031 if(kPointerToTrackData != 0) { 2048 2032 2049 // track 2033 // track 2050 ifile.read((char *)ctmp, sizeof(int)); 2034 ifile.read((char *)ctmp, sizeof(int)); 2051 int ntrk; 2035 int ntrk; 2052 convertEndian(ctmp, ntrk); 2036 convertEndian(ctmp, ntrk); 2053 if(DEBUG || kVerbose > 0) { 2037 if(DEBUG || kVerbose > 0) { 2054 G4cout << "# of tracks: " << ntrk << G4 << 2038 std::cout << "# of tracks: " << ntrk << std::endl; 2055 } 2039 } 2056 2040 2057 // track position 2041 // track position 2058 unsigned char rgb[3]; 2042 unsigned char rgb[3]; 2059 for(int i = 0; i < ntrk; i++) { 2043 for(int i = 0; i < ntrk; i++) { 2060 2044 2061 2045 2062 // # of steps in a track 2046 // # of steps in a track 2063 ifile.read((char *)ctmp, sizeof(int)); 2047 ifile.read((char *)ctmp, sizeof(int)); 2064 int nsteps; 2048 int nsteps; 2065 convertEndian(ctmp, nsteps); 2049 convertEndian(ctmp, nsteps); 2066 2050 2067 // track color 2051 // track color 2068 ifile.read((char *)rgb, 3); 2052 ifile.read((char *)rgb, 3); 2069 2053 2070 std::vector<float *> steps; 2054 std::vector<float *> steps; 2071 // steps 2055 // steps 2072 for(int j = 0; j < nsteps; j++) { 2056 for(int j = 0; j < nsteps; j++) { 2073 2057 2074 float * steppoint = new float[6]; 2058 float * steppoint = new float[6]; 2075 ifile.read((char *)ctmp, sizeof(float)*6); 2059 ifile.read((char *)ctmp, sizeof(float)*6); 2076 2060 2077 for(int k = 0; k < 6; k++) { 2061 for(int k = 0; k < 6; k++) { 2078 convertEndian(ctmp+k*sizeof(float), stepp 2062 convertEndian(ctmp+k*sizeof(float), steppoint[k]); 2079 } 2063 } 2080 2064 2081 steps.push_back(steppoint); 2065 steps.push_back(steppoint); 2082 } 2066 } 2083 2067 2084 // add a track to the track container 2068 // add a track to the track container 2085 addTrack(steps, rgb); 2069 addTrack(steps, rgb); 2086 2070 2087 if(DEBUG || kVerbose > 0) { 2071 if(DEBUG || kVerbose > 0) { 2088 if(i < 5) { 2072 if(i < 5) { 2089 G4cout << i << ": " ; << 2073 std::cout << i << ": " ; 2090 for(int j = 0; j < 3; j++) G4cout << step << 2074 for(int j = 0; j < 3; j++) std::cout << steps[0][j] << " "; 2091 int nstp = (int)steps.size(); << 2075 int nstp = steps.size(); 2092 G4cout << "<-> "; << 2076 std::cout << "<-> "; 2093 for(int j = 3; j < 6; j++) G4cout << step << 2077 for(int j = 3; j < 6; j++) std::cout << steps[nstp-1][j] << " "; 2094 G4cout << " rgb( "; << 2078 std::cout << " rgb( "; 2095 for(int j = 0; j < 3; j++) G4cout << (int << 2079 for(int j = 0; j < 3; j++) std::cout << (int)rgb[j] << " "; 2096 G4cout << ")" << G4endl; << 2080 std::cout << ")" << std::endl; 2097 } 2081 } 2098 } 2082 } 2099 } 2083 } 2100 2084 2101 2085 2102 } 2086 } 2103 2087 2104 2088 2105 //----- detector information -----// 2089 //----- detector information -----// 2106 if(kPointerToDetectorData != 0) { 2090 if(kPointerToDetectorData != 0) { 2107 2091 2108 // number of detectors 2092 // number of detectors 2109 ifile.read((char *)ctmp, sizeof(int)); 2093 ifile.read((char *)ctmp, sizeof(int)); 2110 int ndet; 2094 int ndet; 2111 convertEndian(ctmp, ndet); 2095 convertEndian(ctmp, ndet); 2112 2096 2113 if(DEBUG || kVerbose > 0) { 2097 if(DEBUG || kVerbose > 0) { 2114 G4cout << "# of detectors : " << 2098 std::cout << "# of detectors : " 2115 << ndet << G4endl; << 2099 << ndet << std::endl; 2116 } 2100 } 2117 2101 2118 for(int nd = 0; nd < ndet; nd++) { 2102 for(int nd = 0; nd < ndet; nd++) { 2119 2103 2120 // # of edges of a detector 2104 // # of edges of a detector 2121 ifile.read((char *)ctmp, sizeof(int)); 2105 ifile.read((char *)ctmp, sizeof(int)); 2122 int nedges; 2106 int nedges; 2123 convertEndian(ctmp, nedges); 2107 convertEndian(ctmp, nedges); 2124 if(DEBUG || kVerbose > 0) { 2108 if(DEBUG || kVerbose > 0) { 2125 G4cout << "# of edges in a detector : " << << 2109 std::cout << "# of edges in a detector : " << nedges << std::endl; 2126 } 2110 } 2127 2111 2128 // edges 2112 // edges 2129 std::vector<float *> detector; 2113 std::vector<float *> detector; 2130 char cftmp[24]; 2114 char cftmp[24]; 2131 for(int ne = 0; ne < nedges; ne++) { 2115 for(int ne = 0; ne < nedges; ne++) { 2132 2116 2133 ifile.read((char *)cftmp, sizeof(float)*6); 2117 ifile.read((char *)cftmp, sizeof(float)*6); 2134 float * edgePoints = new float[6]; 2118 float * edgePoints = new float[6]; 2135 for(int j = 0; j < 6; j++) convertEndian(&c 2119 for(int j = 0; j < 6; j++) convertEndian(&cftmp[sizeof(float)*j], edgePoints[j]); 2136 detector.push_back(edgePoints); 2120 detector.push_back(edgePoints); 2137 2121 2138 } 2122 } 2139 2123 2140 if(DEBUG || kVerbose > 0) { 2124 if(DEBUG || kVerbose > 0) { 2141 G4cout << " first edge : (" << detector[0][ << 2125 std::cout << " first edge : (" << detector[0][0] << ", " 2142 << detector[0][1] << ", " 2126 << detector[0][1] << ", " 2143 << detector[0][2] << ") - (" 2127 << detector[0][2] << ") - (" 2144 << detector[0][3] << ", " 2128 << detector[0][3] << ", " 2145 << detector[0][4] << ", " 2129 << detector[0][4] << ", " 2146 << detector[0][5] << ")" << G4endl; << 2130 << detector[0][5] << ")" << std::endl; 2147 } 2131 } 2148 2132 2149 // detector color 2133 // detector color 2150 unsigned char dcolor[3]; 2134 unsigned char dcolor[3]; 2151 ifile.read((char *)dcolor, 3); 2135 ifile.read((char *)dcolor, 3); 2152 if(DEBUG || kVerbose > 0) { 2136 if(DEBUG || kVerbose > 0) { 2153 G4cout << " detector color : rgb(" << 2137 std::cout << " detector color : rgb(" 2154 << (int)dcolor[0] << ", " 2138 << (int)dcolor[0] << ", " 2155 << (int)dcolor[1] << ", " 2139 << (int)dcolor[1] << ", " 2156 << (int)dcolor[2] << G4endl; << 2140 << (int)dcolor[2] << std::endl; 2157 } 2141 } 2158 2142 2159 2143 2160 // detector name 2144 // detector name 2161 char cname[80]; 2145 char cname[80]; 2162 ifile.read((char *)cname, 80); 2146 ifile.read((char *)cname, 80); 2163 std::string dname = cname; 2147 std::string dname = cname; 2164 if(DEBUG || kVerbose > 0) { 2148 if(DEBUG || kVerbose > 0) { 2165 G4cout << " detector name : " << dname << G << 2149 std::cout << " detector name : " << dname << std::endl; 2166 } 2150 } 2167 2151 2168 2152 2169 addDetector(dname, detector, dcolor); 2153 addDetector(dname, detector, dcolor); 2170 2154 2171 } 2155 } 2172 } 2156 } 2173 2157 2174 2158 2175 ifile.close(); 2159 ifile.close(); 2176 2160 2177 return true; 2161 return true; 2178 } 2162 } 2179 bool G4GMocrenIO::retrieveData4(char * _filen 2163 bool G4GMocrenIO::retrieveData4(char * _filename) { 2180 kFileName = _filename; 2164 kFileName = _filename; 2181 return retrieveData(); 2165 return retrieveData(); 2182 } 2166 } 2183 2167 2184 // 2168 // 2185 bool G4GMocrenIO::retrieveData3() { 2169 bool G4GMocrenIO::retrieveData3() { 2186 2170 2187 bool DEBUG = false;// 2171 bool DEBUG = false;// 2188 2172 2189 // input file open 2173 // input file open 2190 std::ifstream ifile(kFileName.c_str(), std: 2174 std::ifstream ifile(kFileName.c_str(), std::ios_base::in|std::ios_base::binary); 2191 if(!ifile) { 2175 if(!ifile) { 2192 if (G4VisManager::GetVerbosity() >= G4Vis << 2176 std::cerr << "Cannot open file: " << kFileName 2193 G4cout << "Cannot open file: " << kFile << 2177 << " in G4GMocrenIO::retrieveData3()." << std::endl; 2194 << " in G4GMocrenIO::retrieveData3()." << << 2195 return false; 2178 return false; 2196 } 2179 } 2197 2180 2198 // data buffer 2181 // data buffer 2199 char ctmp[12]; 2182 char ctmp[12]; 2200 2183 2201 // file identifier 2184 // file identifier 2202 char verid[9]; 2185 char verid[9]; 2203 ifile.read((char *)verid, 8); 2186 ifile.read((char *)verid, 8); 2204 2187 2205 // file version 2188 // file version 2206 unsigned char ver; 2189 unsigned char ver; 2207 ifile.read((char *)&ver, 1); 2190 ifile.read((char *)&ver, 1); 2208 std::stringstream ss; 2191 std::stringstream ss; 2209 ss << (int)ver; 2192 ss << (int)ver; 2210 kVersion = ss.str(); 2193 kVersion = ss.str(); 2211 if(DEBUG || kVerbose > 0) G4cout << "File v << 2194 if(DEBUG || kVerbose > 0) std::cout << "File version : " << kVersion << std::endl; 2212 2195 2213 // endian 2196 // endian 2214 ifile.read((char *)&kLittleEndianInput, siz 2197 ifile.read((char *)&kLittleEndianInput, sizeof(char)); 2215 if(DEBUG || kVerbose > 0) { 2198 if(DEBUG || kVerbose > 0) { 2216 G4cout << "Endian : "; << 2199 std::cout << "Endian : "; 2217 if(kLittleEndianInput == 1) 2200 if(kLittleEndianInput == 1) 2218 G4cout << " little" << G4endl; << 2201 std::cout << " little" << std::endl; 2219 else { 2202 else { 2220 G4cout << " big" << G4endl; << 2203 std::cout << " big" << std::endl; 2221 } 2204 } 2222 } 2205 } 2223 2206 2224 // comment length (fixed size) 2207 // comment length (fixed size) 2225 int clength; 2208 int clength; 2226 ifile.read((char *)ctmp, 4); 2209 ifile.read((char *)ctmp, 4); 2227 convertEndian(ctmp, clength); 2210 convertEndian(ctmp, clength); 2228 // comment 2211 // comment 2229 char cmt[1025]; 2212 char cmt[1025]; 2230 ifile.read((char *)cmt, clength); 2213 ifile.read((char *)cmt, clength); 2231 std::string scmt = cmt; 2214 std::string scmt = cmt; 2232 setComment(scmt); 2215 setComment(scmt); 2233 if(DEBUG || kVerbose > 0) { 2216 if(DEBUG || kVerbose > 0) { 2234 G4cout << "Data comment : " << 2217 std::cout << "Data comment : " 2235 << kComment << G4endl; << 2218 << kComment << std::endl; 2236 } 2219 } 2237 2220 2238 // voxel spacings for all images 2221 // voxel spacings for all images 2239 ifile.read((char *)ctmp, 12); 2222 ifile.read((char *)ctmp, 12); 2240 convertEndian(ctmp, kVoxelSpacing[0]); 2223 convertEndian(ctmp, kVoxelSpacing[0]); 2241 convertEndian(ctmp+4, kVoxelSpacing[1]); 2224 convertEndian(ctmp+4, kVoxelSpacing[1]); 2242 convertEndian(ctmp+8, kVoxelSpacing[2]); 2225 convertEndian(ctmp+8, kVoxelSpacing[2]); 2243 if(DEBUG || kVerbose > 0) { 2226 if(DEBUG || kVerbose > 0) { 2244 G4cout << "Voxel spacing : (" << 2227 std::cout << "Voxel spacing : (" 2245 << kVoxelSpacing[0] << ", " 2228 << kVoxelSpacing[0] << ", " 2246 << kVoxelSpacing[1] << ", " 2229 << kVoxelSpacing[1] << ", " 2247 << kVoxelSpacing[2] 2230 << kVoxelSpacing[2] 2248 << ") mm " << G4endl; << 2231 << ") mm " << std::endl; 2249 } 2232 } 2250 2233 2251 2234 2252 // offset from file starting point to the m 2235 // offset from file starting point to the modality image data 2253 ifile.read((char *)ctmp, 4); 2236 ifile.read((char *)ctmp, 4); 2254 convertEndian(ctmp, kPointerToModalityData) 2237 convertEndian(ctmp, kPointerToModalityData); 2255 2238 2256 // # of dose distributions 2239 // # of dose distributions 2257 ifile.read((char *)ctmp, 4); 2240 ifile.read((char *)ctmp, 4); 2258 int nDoseDist; 2241 int nDoseDist; 2259 convertEndian(ctmp, nDoseDist); 2242 convertEndian(ctmp, nDoseDist); 2260 2243 2261 // offset from file starting point to the d 2244 // offset from file starting point to the dose image data 2262 for(int i = 0; i < nDoseDist; i++) { 2245 for(int i = 0; i < nDoseDist; i++) { 2263 ifile.read((char *)ctmp, 4); 2246 ifile.read((char *)ctmp, 4); 2264 unsigned int dptr; 2247 unsigned int dptr; 2265 convertEndian(ctmp, dptr); 2248 convertEndian(ctmp, dptr); 2266 addPointerToDoseDistData(dptr); 2249 addPointerToDoseDistData(dptr); 2267 } 2250 } 2268 2251 2269 // offset from file starting point to the R 2252 // offset from file starting point to the ROI image data 2270 ifile.read((char *)ctmp, 4); 2253 ifile.read((char *)ctmp, 4); 2271 convertEndian(ctmp, kPointerToROIData); 2254 convertEndian(ctmp, kPointerToROIData); 2272 2255 2273 // offset from file starting point to the t 2256 // offset from file starting point to the track data 2274 ifile.read((char *)ctmp, 4); 2257 ifile.read((char *)ctmp, 4); 2275 convertEndian(ctmp, kPointerToTrackData); 2258 convertEndian(ctmp, kPointerToTrackData); 2276 if(DEBUG || kVerbose > 0) { 2259 if(DEBUG || kVerbose > 0) { 2277 G4cout << "Each pointer to data : " << 2260 std::cout << "Each pointer to data : " 2278 << kPointerToModalityData << ", "; 2261 << kPointerToModalityData << ", "; 2279 for(int i = 0; i < nDoseDist; i++) 2262 for(int i = 0; i < nDoseDist; i++) 2280 G4cout << kPointerToDoseDistData[0] << << 2263 std::cout << kPointerToDoseDistData[0] << ", "; 2281 G4cout << kPointerToROIData << ", " << 2264 std::cout << kPointerToROIData << ", " 2282 << kPointerToTrackData << G4endl; << 2265 << kPointerToTrackData << std::endl; 2283 } 2266 } 2284 2267 2285 if(kPointerToModalityData == 0 && kPointerT 2268 if(kPointerToModalityData == 0 && kPointerToDoseDistData.size() == 0 && 2286 kPointerToROIData == 0 && kPointerToTrac 2269 kPointerToROIData == 0 && kPointerToTrackData == 0) { 2287 if(DEBUG || kVerbose > 0) { 2270 if(DEBUG || kVerbose > 0) { 2288 G4cout << "No data." << G4endl; << 2271 std::cout << "No data." << std::endl; 2289 } 2272 } 2290 return false; 2273 return false; 2291 } 2274 } 2292 2275 2293 // event number 2276 // event number 2294 /* ver 1 2277 /* ver 1 2295 ifile.read(ctmp, sizeof(int)); 2278 ifile.read(ctmp, sizeof(int)); 2296 convertEndian(ctmp, numberOfEvents); 2279 convertEndian(ctmp, numberOfEvents); 2297 */ 2280 */ 2298 2281 2299 int size[3]; 2282 int size[3]; 2300 float scale; 2283 float scale; 2301 double dscale; 2284 double dscale; 2302 short minmax[2]; 2285 short minmax[2]; 2303 float fCenter[3]; 2286 float fCenter[3]; 2304 int iCenter[3]; 2287 int iCenter[3]; 2305 2288 2306 //----- Modality image -----// 2289 //----- Modality image -----// 2307 // modality image size 2290 // modality image size 2308 ifile.read(ctmp, 3*sizeof(int)); 2291 ifile.read(ctmp, 3*sizeof(int)); 2309 convertEndian(ctmp, size[0]); 2292 convertEndian(ctmp, size[0]); 2310 convertEndian(ctmp+sizeof(int), size[1]); 2293 convertEndian(ctmp+sizeof(int), size[1]); 2311 convertEndian(ctmp+2*sizeof(int), size[2]); 2294 convertEndian(ctmp+2*sizeof(int), size[2]); 2312 if(DEBUG || kVerbose > 0) { 2295 if(DEBUG || kVerbose > 0) { 2313 G4cout << "Modality image size : (" << 2296 std::cout << "Modality image size : (" 2314 << size[0] << ", " 2297 << size[0] << ", " 2315 << size[1] << ", " 2298 << size[1] << ", " 2316 << size[2] << ")" 2299 << size[2] << ")" 2317 << G4endl; << 2300 << std::endl; 2318 } 2301 } 2319 kModality.setSize(size); 2302 kModality.setSize(size); 2320 2303 2321 // modality image voxel spacing 2304 // modality image voxel spacing 2322 /* 2305 /* 2323 ifile.read(ctmp, 3*sizeof(float)); 2306 ifile.read(ctmp, 3*sizeof(float)); 2324 convertEndian(ctmp, modalityImageVoxelSpa 2307 convertEndian(ctmp, modalityImageVoxelSpacing[0]); 2325 convertEndian(ctmp+sizeof(float), modalit 2308 convertEndian(ctmp+sizeof(float), modalityImageVoxelSpacing[1]); 2326 convertEndian(ctmp+2*sizeof(float), modal 2309 convertEndian(ctmp+2*sizeof(float), modalityImageVoxelSpacing[2]); 2327 */ 2310 */ 2328 2311 2329 if(kPointerToModalityData != 0) { 2312 if(kPointerToModalityData != 0) { 2330 2313 2331 // modality density max. & min. 2314 // modality density max. & min. 2332 ifile.read((char *)ctmp, 4); 2315 ifile.read((char *)ctmp, 4); 2333 convertEndian(ctmp, minmax[0]); 2316 convertEndian(ctmp, minmax[0]); 2334 convertEndian(ctmp+2, minmax[1]); 2317 convertEndian(ctmp+2, minmax[1]); 2335 kModality.setMinMax(minmax); 2318 kModality.setMinMax(minmax); 2336 2319 2337 // modality image unit 2320 // modality image unit 2338 char munit[13]; 2321 char munit[13]; 2339 ifile.read((char *)munit, 12); 2322 ifile.read((char *)munit, 12); 2340 std::string smunit = munit; 2323 std::string smunit = munit; 2341 setModalityImageUnit(smunit); 2324 setModalityImageUnit(smunit); 2342 2325 2343 // modality density scale 2326 // modality density scale 2344 ifile.read((char *)ctmp, 4); 2327 ifile.read((char *)ctmp, 4); 2345 convertEndian(ctmp, scale); 2328 convertEndian(ctmp, scale); 2346 kModality.setScale(dscale = scale); 2329 kModality.setScale(dscale = scale); 2347 if(DEBUG || kVerbose > 0) { 2330 if(DEBUG || kVerbose > 0) { 2348 G4cout << "Modality image min., max., s << 2331 std::cout << "Modality image min., max., scale : " 2349 << minmax[0] << ", " 2332 << minmax[0] << ", " 2350 << minmax[1] << ", " 2333 << minmax[1] << ", " 2351 << scale << G4endl; << 2334 << scale << std::endl; 2352 } 2335 } 2353 2336 2354 // modality density 2337 // modality density 2355 int psize = size[0]*size[1]; 2338 int psize = size[0]*size[1]; 2356 if(DEBUG || kVerbose > 0) G4cout << "Moda << 2339 if(DEBUG || kVerbose > 0) std::cout << "Modality image (" << psize << "): "; 2357 char * cimage = new char[psize*sizeof(sho 2340 char * cimage = new char[psize*sizeof(short)]; 2358 for(int i = 0; i < size[2]; i++) { 2341 for(int i = 0; i < size[2]; i++) { 2359 ifile.read((char *)cimage, psize*sizeof 2342 ifile.read((char *)cimage, psize*sizeof(short)); 2360 short * mimage = new short[psize]; 2343 short * mimage = new short[psize]; 2361 for(int j = 0; j < psize; j++) { 2344 for(int j = 0; j < psize; j++) { 2362 convertEndian(cimage+j*sizeof(short), mimag 2345 convertEndian(cimage+j*sizeof(short), mimage[j]); 2363 } 2346 } 2364 kModality.addImage(mimage); 2347 kModality.addImage(mimage); 2365 2348 2366 if(DEBUG || kVerbose > 0) G4cout << "[" << 2349 if(DEBUG || kVerbose > 0) std::cout << "[" << i << "]" << mimage[(size_t)(psize*0.55)] << ", "; 2367 } 2350 } 2368 if(DEBUG || kVerbose > 0) G4cout << G4end << 2351 if(DEBUG || kVerbose > 0) std::cout << std::endl; 2369 delete [] cimage; 2352 delete [] cimage; 2370 2353 2371 // modality desity map for CT value 2354 // modality desity map for CT value 2372 size_t msize = minmax[1]-minmax[0]+1; 2355 size_t msize = minmax[1]-minmax[0]+1; 2373 if(DEBUG || kVerbose > 0) G4cout << "msiz << 2356 if(DEBUG || kVerbose > 0) std::cout << "msize: " << msize << std::endl; 2374 char * pdmap = new char[msize*sizeof(floa 2357 char * pdmap = new char[msize*sizeof(float)]; 2375 ifile.read((char *)pdmap, msize*sizeof(fl 2358 ifile.read((char *)pdmap, msize*sizeof(float)); 2376 float ftmp; 2359 float ftmp; 2377 for(int i = 0; i < (int)msize; i++) { 2360 for(int i = 0; i < (int)msize; i++) { 2378 convertEndian(pdmap+i*sizeof(float), ft 2361 convertEndian(pdmap+i*sizeof(float), ftmp); 2379 kModalityImageDensityMap.push_back(ftmp 2362 kModalityImageDensityMap.push_back(ftmp); 2380 } 2363 } 2381 delete [] pdmap; << 2382 if(DEBUG || kVerbose > 0) { 2364 if(DEBUG || kVerbose > 0) { 2383 G4cout << "density map : " << std::ends << 2365 std::cout << "density map : " << std::ends; 2384 for(int i = 0; i < 10; i++) 2366 for(int i = 0; i < 10; i++) 2385 G4cout <<kModalityImageDensityMap[i] << ", << 2367 std::cout <<kModalityImageDensityMap[i] << ", "; 2386 G4cout << G4endl; << 2368 std::cout << std::endl; 2387 for(int i = 0; i < 10; i++) G4cout << " << 2369 for(int i = 0; i < 10; i++) std::cout << ".."; 2388 G4cout << G4endl; << 2370 std::cout << std::endl; 2389 for(size_t i =kModalityImageDensityMap. 2371 for(size_t i =kModalityImageDensityMap.size() - 10; i <kModalityImageDensityMap.size(); i++) 2390 G4cout <<kModalityImageDensityMap[i] << ", << 2372 std::cout <<kModalityImageDensityMap[i] << ", "; 2391 G4cout << G4endl; << 2373 std::cout << std::endl; 2392 } 2374 } 2393 2375 2394 } 2376 } 2395 2377 2396 2378 2397 //----- dose distribution image -----// 2379 //----- dose distribution image -----// 2398 for(int ndose = 0; ndose < nDoseDist; ndose 2380 for(int ndose = 0; ndose < nDoseDist; ndose++) { 2399 2381 2400 newDoseDist(); 2382 newDoseDist(); 2401 2383 2402 // dose distrbution image size 2384 // dose distrbution image size 2403 ifile.read((char *)ctmp, 3*sizeof(int)); 2385 ifile.read((char *)ctmp, 3*sizeof(int)); 2404 convertEndian(ctmp, size[0]); 2386 convertEndian(ctmp, size[0]); 2405 convertEndian(ctmp+sizeof(int), size[1]); 2387 convertEndian(ctmp+sizeof(int), size[1]); 2406 convertEndian(ctmp+2*sizeof(int), size[2] 2388 convertEndian(ctmp+2*sizeof(int), size[2]); 2407 if(DEBUG || kVerbose > 0) { 2389 if(DEBUG || kVerbose > 0) { 2408 G4cout << "Dose dist. image size : (" << 2390 std::cout << "Dose dist. image size : (" 2409 << size[0] << ", " 2391 << size[0] << ", " 2410 << size[1] << ", " 2392 << size[1] << ", " 2411 << size[2] << ")" 2393 << size[2] << ")" 2412 << G4endl; << 2394 << std::endl; 2413 } 2395 } 2414 kDose[ndose].setSize(size); 2396 kDose[ndose].setSize(size); 2415 2397 2416 // dose distribution max. & min. 2398 // dose distribution max. & min. 2417 ifile.read((char *)ctmp, sizeof(short)*2) 2399 ifile.read((char *)ctmp, sizeof(short)*2); 2418 convertEndian(ctmp, minmax[0]); 2400 convertEndian(ctmp, minmax[0]); 2419 convertEndian(ctmp+2, minmax[1]); 2401 convertEndian(ctmp+2, minmax[1]); 2420 2402 2421 // dose distribution unit 2403 // dose distribution unit 2422 char dunit[13]; 2404 char dunit[13]; 2423 ifile.read((char *)dunit, 12); 2405 ifile.read((char *)dunit, 12); 2424 std::string sdunit = dunit; 2406 std::string sdunit = dunit; 2425 setDoseDistUnit(sdunit, ndose); 2407 setDoseDistUnit(sdunit, ndose); 2426 if(DEBUG || kVerbose > 0) { 2408 if(DEBUG || kVerbose > 0) { 2427 G4cout << "Dose dist. unit : " << kDose << 2409 std::cout << "Dose dist. unit : " << kDoseUnit << std::endl; 2428 } 2410 } 2429 2411 2430 // dose distribution scaling 2412 // dose distribution scaling 2431 ifile.read((char *)ctmp, 4); // sizeof(fl 2413 ifile.read((char *)ctmp, 4); // sizeof(float) 2432 convertEndian(ctmp, scale); 2414 convertEndian(ctmp, scale); 2433 kDose[ndose].setScale(dscale = scale); 2415 kDose[ndose].setScale(dscale = scale); 2434 2416 2435 double dminmax[2]; 2417 double dminmax[2]; 2436 for(int i = 0; i < 2; i++) dminmax[i] = m 2418 for(int i = 0; i < 2; i++) dminmax[i] = minmax[i]*dscale; 2437 kDose[ndose].setMinMax(dminmax); 2419 kDose[ndose].setMinMax(dminmax); 2438 2420 2439 if(DEBUG || kVerbose > 0) { 2421 if(DEBUG || kVerbose > 0) { 2440 G4cout << "Dose dist. image min., max., << 2422 std::cout << "Dose dist. image min., max., scale : " 2441 << dminmax[0] << ", " 2423 << dminmax[0] << ", " 2442 << dminmax[1] << ", " 2424 << dminmax[1] << ", " 2443 << scale << G4endl; << 2425 << scale << std::endl; 2444 } 2426 } 2445 2427 2446 // dose distribution image 2428 // dose distribution image 2447 int dsize = size[0]*size[1]; 2429 int dsize = size[0]*size[1]; 2448 if(DEBUG || kVerbose > 0) G4cout << "Dose << 2430 if(DEBUG || kVerbose > 0) std::cout << "Dose dist. (" << dsize << "): "; 2449 char * di = new char[dsize*sizeof(short)] 2431 char * di = new char[dsize*sizeof(short)]; 2450 short * shimage = new short[dsize]; 2432 short * shimage = new short[dsize]; 2451 for(int z = 0; z < size[2]; z++) { 2433 for(int z = 0; z < size[2]; z++) { 2452 ifile.read((char *)di, dsize*sizeof(sho 2434 ifile.read((char *)di, dsize*sizeof(short)); 2453 double * dimage = new double[dsize]; 2435 double * dimage = new double[dsize]; 2454 for(int xy = 0; xy < dsize; xy++) { 2436 for(int xy = 0; xy < dsize; xy++) { 2455 convertEndian(di+xy*sizeof(short), shimage[ 2437 convertEndian(di+xy*sizeof(short), shimage[xy]); 2456 dimage[xy] = shimage[xy]*dscale; 2438 dimage[xy] = shimage[xy]*dscale; 2457 } 2439 } 2458 kDose[ndose].addImage(dimage); 2440 kDose[ndose].addImage(dimage); 2459 2441 2460 if(DEBUG || kVerbose > 0) G4cout << "[" << 2442 if(DEBUG || kVerbose > 0) std::cout << "[" << z << "]" << dimage[(size_t)(dsize*0.55)] << ", "; 2461 2443 2462 if(DEBUG || kVerbose > 0) { 2444 if(DEBUG || kVerbose > 0) { 2463 for(int j = 0; j < dsize; j++) { 2445 for(int j = 0; j < dsize; j++) { 2464 if(dimage[j] < 0) 2446 if(dimage[j] < 0) 2465 G4cout << "[" << j << "," << z << "]" << 2447 std::cout << "[" << j << "," << z << "]" 2466 << dimage[j] << ", "; 2448 << dimage[j] << ", "; 2467 } 2449 } 2468 } 2450 } 2469 } 2451 } 2470 delete [] shimage; 2452 delete [] shimage; 2471 delete [] di; 2453 delete [] di; 2472 if(DEBUG || kVerbose > 0) G4cout << G4end << 2454 if(DEBUG || kVerbose > 0) std::cout << std::endl; 2473 2455 2474 ifile.read((char *)ctmp, 3*4); // 3*sizeo 2456 ifile.read((char *)ctmp, 3*4); // 3*sizeof(int) 2475 convertEndian(ctmp, iCenter[0]); 2457 convertEndian(ctmp, iCenter[0]); 2476 convertEndian(ctmp+4, iCenter[1]); 2458 convertEndian(ctmp+4, iCenter[1]); 2477 convertEndian(ctmp+8, iCenter[2]); 2459 convertEndian(ctmp+8, iCenter[2]); 2478 for(int i = 0; i < 3; i++) fCenter[i] = ( 2460 for(int i = 0; i < 3; i++) fCenter[i] = (float)iCenter[i]; 2479 kDose[ndose].setCenterPosition(fCenter); 2461 kDose[ndose].setCenterPosition(fCenter); 2480 2462 2481 if(DEBUG || kVerbose > 0) { 2463 if(DEBUG || kVerbose > 0) { 2482 G4cout << "Dose dist. image relative lo << 2464 std::cout << "Dose dist. image relative location : (" 2483 << fCenter[0] << ", " 2465 << fCenter[0] << ", " 2484 << fCenter[1] << ", " 2466 << fCenter[1] << ", " 2485 << fCenter[2] << ")" << G4endl; << 2467 << fCenter[2] << ")" << std::endl; 2486 } 2468 } 2487 2469 2488 2470 2489 } 2471 } 2490 2472 2491 //----- ROI image -----// 2473 //----- ROI image -----// 2492 if(kPointerToROIData != 0) { 2474 if(kPointerToROIData != 0) { 2493 2475 2494 newROI(); 2476 newROI(); 2495 2477 2496 // ROI image size 2478 // ROI image size 2497 ifile.read((char *)ctmp, 3*sizeof(int)); 2479 ifile.read((char *)ctmp, 3*sizeof(int)); 2498 convertEndian(ctmp, size[0]); 2480 convertEndian(ctmp, size[0]); 2499 convertEndian(ctmp+sizeof(int), size[1]); 2481 convertEndian(ctmp+sizeof(int), size[1]); 2500 convertEndian(ctmp+2*sizeof(int), size[2] 2482 convertEndian(ctmp+2*sizeof(int), size[2]); 2501 kRoi[0].setSize(size); 2483 kRoi[0].setSize(size); 2502 if(DEBUG || kVerbose > 0) { 2484 if(DEBUG || kVerbose > 0) { 2503 G4cout << "ROI image size : (" << 2485 std::cout << "ROI image size : (" 2504 << size[0] << ", " 2486 << size[0] << ", " 2505 << size[1] << ", " 2487 << size[1] << ", " 2506 << size[2] << ")" 2488 << size[2] << ")" 2507 << G4endl; << 2489 << std::endl; 2508 } 2490 } 2509 2491 2510 // ROI max. & min. 2492 // ROI max. & min. 2511 ifile.read((char *)ctmp, sizeof(short)*2) 2493 ifile.read((char *)ctmp, sizeof(short)*2); 2512 convertEndian(ctmp, minmax[0]); 2494 convertEndian(ctmp, minmax[0]); 2513 convertEndian(ctmp+sizeof(short), minmax[ 2495 convertEndian(ctmp+sizeof(short), minmax[1]); 2514 kRoi[0].setMinMax(minmax); 2496 kRoi[0].setMinMax(minmax); 2515 2497 2516 // ROI distribution scaling 2498 // ROI distribution scaling 2517 ifile.read((char *)ctmp, sizeof(float)); 2499 ifile.read((char *)ctmp, sizeof(float)); 2518 convertEndian(ctmp, scale); 2500 convertEndian(ctmp, scale); 2519 kRoi[0].setScale(dscale = scale); 2501 kRoi[0].setScale(dscale = scale); 2520 if(DEBUG || kVerbose > 0) { 2502 if(DEBUG || kVerbose > 0) { 2521 G4cout << "ROI image min., max., scale << 2503 std::cout << "ROI image min., max., scale : " 2522 << minmax[0] << ", " 2504 << minmax[0] << ", " 2523 << minmax[1] << ", " 2505 << minmax[1] << ", " 2524 << scale << G4endl; << 2506 << scale << std::endl; 2525 } 2507 } 2526 2508 2527 // ROI image 2509 // ROI image 2528 int rsize = size[0]*size[1]; 2510 int rsize = size[0]*size[1]; 2529 char * ri = new char[rsize*sizeof(short)] 2511 char * ri = new char[rsize*sizeof(short)]; 2530 for(int i = 0; i < size[2]; i++) { 2512 for(int i = 0; i < size[2]; i++) { 2531 ifile.read((char *)ri, rsize*sizeof(sho 2513 ifile.read((char *)ri, rsize*sizeof(short)); 2532 short * rimage = new short[rsize]; 2514 short * rimage = new short[rsize]; 2533 for(int j = 0; j < rsize; j++) { 2515 for(int j = 0; j < rsize; j++) { 2534 convertEndian(ri+j*sizeof(short), rimage[j] 2516 convertEndian(ri+j*sizeof(short), rimage[j]); 2535 } 2517 } 2536 kRoi[0].addImage(rimage); 2518 kRoi[0].addImage(rimage); 2537 2519 2538 } 2520 } 2539 delete [] ri; 2521 delete [] ri; 2540 2522 2541 // ROI relative location 2523 // ROI relative location 2542 ifile.read((char *)ctmp, 3*sizeof(int)); 2524 ifile.read((char *)ctmp, 3*sizeof(int)); 2543 convertEndian(ctmp, iCenter[0]); 2525 convertEndian(ctmp, iCenter[0]); 2544 convertEndian(ctmp+sizeof(int), iCenter[1 2526 convertEndian(ctmp+sizeof(int), iCenter[1]); 2545 convertEndian(ctmp+2*sizeof(int), iCenter 2527 convertEndian(ctmp+2*sizeof(int), iCenter[2]); 2546 for(int i = 0; i < 3; i++) fCenter[i] = i 2528 for(int i = 0; i < 3; i++) fCenter[i] = iCenter[i]; 2547 kRoi[0].setCenterPosition(fCenter); 2529 kRoi[0].setCenterPosition(fCenter); 2548 if(DEBUG || kVerbose > 0) { 2530 if(DEBUG || kVerbose > 0) { 2549 G4cout << "ROI image relative location << 2531 std::cout << "ROI image relative location : (" 2550 << fCenter[0] << ", " 2532 << fCenter[0] << ", " 2551 << fCenter[1] << ", " 2533 << fCenter[1] << ", " 2552 << fCenter[2] << ")" << G4endl; << 2534 << fCenter[2] << ")" << std::endl; 2553 } 2535 } 2554 2536 2555 } 2537 } 2556 2538 2557 //----- track information -----// 2539 //----- track information -----// 2558 if(kPointerToTrackData != 0) { 2540 if(kPointerToTrackData != 0) { 2559 2541 2560 // track 2542 // track 2561 ifile.read((char *)ctmp, sizeof(int)); 2543 ifile.read((char *)ctmp, sizeof(int)); 2562 int ntrk; 2544 int ntrk; 2563 convertEndian(ctmp, ntrk); 2545 convertEndian(ctmp, ntrk); 2564 if(DEBUG || kVerbose > 0) { 2546 if(DEBUG || kVerbose > 0) { 2565 G4cout << "# of tracks: " << ntrk << G4 << 2547 std::cout << "# of tracks: " << ntrk << std::endl; 2566 } 2548 } 2567 2549 2568 // v4 2550 // v4 2569 std::vector<float *> trkv4; 2551 std::vector<float *> trkv4; 2570 2552 2571 // track position 2553 // track position 2572 for(int i = 0; i < ntrk; i++) { 2554 for(int i = 0; i < ntrk; i++) { 2573 float * tp = new float[6]; 2555 float * tp = new float[6]; 2574 2556 2575 ifile.read((char *)ctmp, sizeof(float)* 2557 ifile.read((char *)ctmp, sizeof(float)*3); 2576 if(DEBUG || kVerbose > 0) if(i < 10) G4 << 2558 if(DEBUG || kVerbose > 0) if(i < 10) std::cout << i << ": " ; 2577 for(int j = 0; j < 3; j++) { 2559 for(int j = 0; j < 3; j++) { 2578 convertEndian(ctmp+j*sizeof(float), tp[j]); 2560 convertEndian(ctmp+j*sizeof(float), tp[j]); 2579 if(DEBUG || kVerbose > 0) if(i < 10) G4cout << 2561 if(DEBUG || kVerbose > 0) if(i < 10) std::cout << tp[j] << ", "; 2580 } 2562 } 2581 2563 2582 ifile.read((char *)ctmp, sizeof(float)* 2564 ifile.read((char *)ctmp, sizeof(float)*3); 2583 for(int j = 0; j < 3; j++) { 2565 for(int j = 0; j < 3; j++) { 2584 convertEndian(ctmp+j*sizeof(float), tp[j+3] 2566 convertEndian(ctmp+j*sizeof(float), tp[j+3]); 2585 if(DEBUG || kVerbose > 0) if(i < 10) G4cout << 2567 if(DEBUG || kVerbose > 0) if(i < 10) std::cout << tp[j+3] << ", "; 2586 } 2568 } 2587 addTrack(tp); 2569 addTrack(tp); 2588 if(DEBUG || kVerbose > 0) if(i < 10) G4 << 2570 if(DEBUG || kVerbose > 0) if(i < 10) std::cout << std::endl; 2589 2571 2590 // v4 2572 // v4 2591 trkv4.push_back(tp); 2573 trkv4.push_back(tp); 2592 } 2574 } 2593 2575 2594 //v4 2576 //v4 2595 unsigned char trkcolorv4[3]; 2577 unsigned char trkcolorv4[3]; 2596 2578 2597 // track color 2579 // track color 2598 for(int i = 0; i < ntrk; i++) { 2580 for(int i = 0; i < ntrk; i++) { 2599 unsigned char * rgb = new unsigned char 2581 unsigned char * rgb = new unsigned char[3]; 2600 ifile.read((char *)rgb, 3); 2582 ifile.read((char *)rgb, 3); 2601 addTrackColor(rgb); 2583 addTrackColor(rgb); 2602 2584 2603 // v4 2585 // v4 2604 for(int j = 0; j < 3; j++) trkcolorv4[j 2586 for(int j = 0; j < 3; j++) trkcolorv4[j] = rgb[j]; 2605 std::vector<float *> trk; 2587 std::vector<float *> trk; 2606 trk.push_back(trkv4[i]); 2588 trk.push_back(trkv4[i]); 2607 addTrack(trk, trkcolorv4); 2589 addTrack(trk, trkcolorv4); 2608 2590 2609 } 2591 } 2610 2592 2611 } 2593 } 2612 2594 2613 ifile.close(); 2595 ifile.close(); 2614 2596 2615 return true; 2597 return true; 2616 } 2598 } 2617 bool G4GMocrenIO::retrieveData3(char * _filen 2599 bool G4GMocrenIO::retrieveData3(char * _filename) { 2618 kFileName = _filename; 2600 kFileName = _filename; 2619 return retrieveData(); 2601 return retrieveData(); 2620 } 2602 } 2621 2603 2622 // 2604 // 2623 bool G4GMocrenIO::retrieveData2() { 2605 bool G4GMocrenIO::retrieveData2() { 2624 2606 2625 bool DEBUG = false;// 2607 bool DEBUG = false;// 2626 2608 2627 // input file open 2609 // input file open 2628 std::ifstream ifile(kFileName.c_str(), std: 2610 std::ifstream ifile(kFileName.c_str(), std::ios_base::in|std::ios_base::binary); 2629 if(!ifile) { 2611 if(!ifile) { 2630 if (G4VisManager::GetVerbosity() >= G4Vis << 2612 std::cerr << "Cannot open file: " << kFileName 2631 G4cout << "Cannot open file: " << kFile << 2613 << " in G4GMocrenIO::retrieveData2()." << std::endl; 2632 << " in G4GMocrenIO::retrieveData2()." << << 2633 return false; 2614 return false; 2634 } 2615 } 2635 2616 2636 // data buffer 2617 // data buffer 2637 char ctmp[12]; 2618 char ctmp[12]; 2638 2619 2639 // file identifier 2620 // file identifier 2640 char verid[9]; 2621 char verid[9]; 2641 ifile.read((char *)verid, 8); 2622 ifile.read((char *)verid, 8); 2642 2623 2643 // file version 2624 // file version 2644 unsigned char ver; 2625 unsigned char ver; 2645 ifile.read((char *)&ver, 1); 2626 ifile.read((char *)&ver, 1); 2646 std::stringstream ss; 2627 std::stringstream ss; 2647 ss << (int)ver; 2628 ss << (int)ver; 2648 kVersion = ss.str(); 2629 kVersion = ss.str(); 2649 if(DEBUG || kVerbose > 0) G4cout << "File v << 2630 if(DEBUG || kVerbose > 0) std::cout << "File version : " << kVersion << std::endl; 2650 2631 2651 // id of version 1 2632 // id of version 1 2652 char idtmp[IDLENGTH]; 2633 char idtmp[IDLENGTH]; 2653 ifile.read((char *)idtmp, IDLENGTH); 2634 ifile.read((char *)idtmp, IDLENGTH); 2654 kId = idtmp; 2635 kId = idtmp; 2655 // version of version 1 2636 // version of version 1 2656 char vertmp[VERLENGTH]; 2637 char vertmp[VERLENGTH]; 2657 ifile.read((char *)vertmp, VERLENGTH); 2638 ifile.read((char *)vertmp, VERLENGTH); 2658 2639 2659 // endian 2640 // endian 2660 ifile.read((char *)&kLittleEndianInput, siz 2641 ifile.read((char *)&kLittleEndianInput, sizeof(char)); 2661 if(DEBUG || kVerbose > 0) { 2642 if(DEBUG || kVerbose > 0) { 2662 G4cout << "Endian : "; << 2643 std::cout << "Endian : "; 2663 if(kLittleEndianInput == 1) 2644 if(kLittleEndianInput == 1) 2664 G4cout << " little" << G4endl; << 2645 std::cout << " little" << std::endl; 2665 else { 2646 else { 2666 G4cout << " big" << G4endl; << 2647 std::cout << " big" << std::endl; 2667 } 2648 } 2668 } 2649 } 2669 2650 2670 // voxel spacings for all images 2651 // voxel spacings for all images 2671 ifile.read((char *)ctmp, 12); 2652 ifile.read((char *)ctmp, 12); 2672 convertEndian(ctmp, kVoxelSpacing[0]); 2653 convertEndian(ctmp, kVoxelSpacing[0]); 2673 convertEndian(ctmp+4, kVoxelSpacing[1]); 2654 convertEndian(ctmp+4, kVoxelSpacing[1]); 2674 convertEndian(ctmp+8, kVoxelSpacing[2]); 2655 convertEndian(ctmp+8, kVoxelSpacing[2]); 2675 if(DEBUG || kVerbose > 0) { 2656 if(DEBUG || kVerbose > 0) { 2676 G4cout << "Voxel spacing : (" << 2657 std::cout << "Voxel spacing : (" 2677 << kVoxelSpacing[0] << ", " 2658 << kVoxelSpacing[0] << ", " 2678 << kVoxelSpacing[1] << ", " 2659 << kVoxelSpacing[1] << ", " 2679 << kVoxelSpacing[2] 2660 << kVoxelSpacing[2] 2680 << ") mm " << G4endl; << 2661 << ") mm " << std::endl; 2681 } 2662 } 2682 2663 2683 2664 2684 // offset from file starting point to the m 2665 // offset from file starting point to the modality image data 2685 ifile.read((char *)ctmp, 4); 2666 ifile.read((char *)ctmp, 4); 2686 convertEndian(ctmp, kPointerToModalityData) 2667 convertEndian(ctmp, kPointerToModalityData); 2687 2668 2688 // offset from file starting point to the d 2669 // offset from file starting point to the dose image data 2689 unsigned int ptddd; 2670 unsigned int ptddd; 2690 ifile.read((char *)ctmp, 4); 2671 ifile.read((char *)ctmp, 4); 2691 convertEndian(ctmp, ptddd); 2672 convertEndian(ctmp, ptddd); 2692 kPointerToDoseDistData.push_back(ptddd); 2673 kPointerToDoseDistData.push_back(ptddd); 2693 2674 2694 // offset from file starting point to the R 2675 // offset from file starting point to the ROI image data 2695 ifile.read((char *)ctmp, 4); 2676 ifile.read((char *)ctmp, 4); 2696 convertEndian(ctmp, kPointerToROIData); 2677 convertEndian(ctmp, kPointerToROIData); 2697 2678 2698 // offset from file starting point to the t 2679 // offset from file starting point to the track data 2699 ifile.read((char *)ctmp, 4); 2680 ifile.read((char *)ctmp, 4); 2700 convertEndian(ctmp, kPointerToTrackData); 2681 convertEndian(ctmp, kPointerToTrackData); 2701 if(DEBUG || kVerbose > 0) { 2682 if(DEBUG || kVerbose > 0) { 2702 G4cout << "Each pointer to data : " << 2683 std::cout << "Each pointer to data : " 2703 << kPointerToModalityData << ", " 2684 << kPointerToModalityData << ", " 2704 << kPointerToDoseDistData[0] << ", " 2685 << kPointerToDoseDistData[0] << ", " 2705 << kPointerToROIData << ", " 2686 << kPointerToROIData << ", " 2706 << kPointerToTrackData << G4endl; << 2687 << kPointerToTrackData << std::endl; 2707 } 2688 } 2708 2689 2709 if(kPointerToModalityData == 0 && kPointerT 2690 if(kPointerToModalityData == 0 && kPointerToDoseDistData.size() == 0 && 2710 kPointerToROIData == 0 && kPointerToTrac 2691 kPointerToROIData == 0 && kPointerToTrackData == 0) { 2711 if(DEBUG || kVerbose > 0) { 2692 if(DEBUG || kVerbose > 0) { 2712 G4cout << "No data." << G4endl; << 2693 std::cout << "No data." << std::endl; 2713 } 2694 } 2714 return false; 2695 return false; 2715 } 2696 } 2716 2697 2717 // event number 2698 // event number 2718 /* ver 1 2699 /* ver 1 2719 ifile.read(ctmp, sizeof(int)); 2700 ifile.read(ctmp, sizeof(int)); 2720 convertEndian(ctmp, numberOfEvents); 2701 convertEndian(ctmp, numberOfEvents); 2721 */ 2702 */ 2722 2703 2723 int size[3]; 2704 int size[3]; 2724 float scale; 2705 float scale; 2725 double dscale; 2706 double dscale; 2726 short minmax[2]; 2707 short minmax[2]; 2727 float fCenter[3]; 2708 float fCenter[3]; 2728 int iCenter[3]; 2709 int iCenter[3]; 2729 2710 2730 //----- Modality image -----// 2711 //----- Modality image -----// 2731 // modality image size 2712 // modality image size 2732 ifile.read(ctmp, 3*sizeof(int)); 2713 ifile.read(ctmp, 3*sizeof(int)); 2733 convertEndian(ctmp, size[0]); 2714 convertEndian(ctmp, size[0]); 2734 convertEndian(ctmp+sizeof(int), size[1]); 2715 convertEndian(ctmp+sizeof(int), size[1]); 2735 convertEndian(ctmp+2*sizeof(int), size[2]); 2716 convertEndian(ctmp+2*sizeof(int), size[2]); 2736 if(DEBUG || kVerbose > 0) { 2717 if(DEBUG || kVerbose > 0) { 2737 G4cout << "Modality image size : (" << 2718 std::cout << "Modality image size : (" 2738 << size[0] << ", " 2719 << size[0] << ", " 2739 << size[1] << ", " 2720 << size[1] << ", " 2740 << size[2] << ")" 2721 << size[2] << ")" 2741 << G4endl; << 2722 << std::endl; 2742 } 2723 } 2743 kModality.setSize(size); 2724 kModality.setSize(size); 2744 2725 2745 // modality image voxel spacing 2726 // modality image voxel spacing 2746 /* 2727 /* 2747 ifile.read(ctmp, 3*sizeof(float)); 2728 ifile.read(ctmp, 3*sizeof(float)); 2748 convertEndian(ctmp, modalityImageVoxelSpa 2729 convertEndian(ctmp, modalityImageVoxelSpacing[0]); 2749 convertEndian(ctmp+sizeof(float), modalit 2730 convertEndian(ctmp+sizeof(float), modalityImageVoxelSpacing[1]); 2750 convertEndian(ctmp+2*sizeof(float), modal 2731 convertEndian(ctmp+2*sizeof(float), modalityImageVoxelSpacing[2]); 2751 */ 2732 */ 2752 2733 2753 if(kPointerToModalityData != 0) { 2734 if(kPointerToModalityData != 0) { 2754 2735 2755 // modality density max. & min. 2736 // modality density max. & min. 2756 ifile.read((char *)ctmp, 4); 2737 ifile.read((char *)ctmp, 4); 2757 convertEndian(ctmp, minmax[0]); 2738 convertEndian(ctmp, minmax[0]); 2758 convertEndian(ctmp+2, minmax[1]); 2739 convertEndian(ctmp+2, minmax[1]); 2759 kModality.setMinMax(minmax); 2740 kModality.setMinMax(minmax); 2760 2741 2761 // modality density scale 2742 // modality density scale 2762 ifile.read((char *)ctmp, 4); 2743 ifile.read((char *)ctmp, 4); 2763 convertEndian(ctmp, scale); 2744 convertEndian(ctmp, scale); 2764 kModality.setScale(dscale = scale); 2745 kModality.setScale(dscale = scale); 2765 if(DEBUG || kVerbose > 0) { 2746 if(DEBUG || kVerbose > 0) { 2766 G4cout << "Modality image min., max., s << 2747 std::cout << "Modality image min., max., scale : " 2767 << minmax[0] << ", " 2748 << minmax[0] << ", " 2768 << minmax[1] << ", " 2749 << minmax[1] << ", " 2769 << scale << G4endl; << 2750 << scale << std::endl; 2770 } 2751 } 2771 2752 2772 // modality density 2753 // modality density 2773 int psize = size[0]*size[1]; 2754 int psize = size[0]*size[1]; 2774 if(DEBUG || kVerbose > 0) G4cout << "Moda << 2755 if(DEBUG || kVerbose > 0) std::cout << "Modality image (" << psize << "): "; 2775 char * cimage = new char[psize*sizeof(sho 2756 char * cimage = new char[psize*sizeof(short)]; 2776 for(int i = 0; i < size[2]; i++) { 2757 for(int i = 0; i < size[2]; i++) { 2777 ifile.read((char *)cimage, psize*sizeof 2758 ifile.read((char *)cimage, psize*sizeof(short)); 2778 short * mimage = new short[psize]; 2759 short * mimage = new short[psize]; 2779 for(int j = 0; j < psize; j++) { 2760 for(int j = 0; j < psize; j++) { 2780 convertEndian(cimage+j*sizeof(short), mimag 2761 convertEndian(cimage+j*sizeof(short), mimage[j]); 2781 } 2762 } 2782 kModality.addImage(mimage); 2763 kModality.addImage(mimage); 2783 2764 2784 if(DEBUG || kVerbose > 0) G4cout << "[" << 2765 if(DEBUG || kVerbose > 0) std::cout << "[" << i << "]" << mimage[(size_t)(psize*0.55)] << ", "; 2785 } 2766 } 2786 if(DEBUG || kVerbose > 0) G4cout << G4end << 2767 if(DEBUG || kVerbose > 0) std::cout << std::endl; 2787 delete [] cimage; 2768 delete [] cimage; 2788 2769 2789 // modality desity map for CT value 2770 // modality desity map for CT value 2790 size_t msize = minmax[1]-minmax[0]+1; 2771 size_t msize = minmax[1]-minmax[0]+1; 2791 if(DEBUG || kVerbose > 0) G4cout << "msiz << 2772 if(DEBUG || kVerbose > 0) std::cout << "msize: " << msize << std::endl; 2792 char * pdmap = new char[msize*sizeof(floa 2773 char * pdmap = new char[msize*sizeof(float)]; 2793 ifile.read((char *)pdmap, msize*sizeof(fl 2774 ifile.read((char *)pdmap, msize*sizeof(float)); 2794 float ftmp; 2775 float ftmp; 2795 for(int i = 0; i < (int)msize; i++) { 2776 for(int i = 0; i < (int)msize; i++) { 2796 convertEndian(pdmap+i*sizeof(float), ft 2777 convertEndian(pdmap+i*sizeof(float), ftmp); 2797 kModalityImageDensityMap.push_back(ftmp 2778 kModalityImageDensityMap.push_back(ftmp); 2798 } 2779 } 2799 delete [] pdmap; << 2800 if(DEBUG || kVerbose > 0) { 2780 if(DEBUG || kVerbose > 0) { 2801 G4cout << "density map : " << std::ends << 2781 std::cout << "density map : " << std::ends; 2802 for(int i = 0; i < 10; i++) 2782 for(int i = 0; i < 10; i++) 2803 G4cout <<kModalityImageDensityMap[i] << ", << 2783 std::cout <<kModalityImageDensityMap[i] << ", "; 2804 G4cout << G4endl; << 2784 std::cout << std::endl; 2805 for(int i = 0; i < 10; i++) G4cout << " << 2785 for(int i = 0; i < 10; i++) std::cout << ".."; 2806 G4cout << G4endl; << 2786 std::cout << std::endl; 2807 for(size_t i =kModalityImageDensityMap. 2787 for(size_t i =kModalityImageDensityMap.size() - 10; i <kModalityImageDensityMap.size(); i++) 2808 G4cout <<kModalityImageDensityMap[i] << ", << 2788 std::cout <<kModalityImageDensityMap[i] << ", "; 2809 G4cout << G4endl; << 2789 std::cout << std::endl; 2810 } 2790 } 2811 2791 2812 } 2792 } 2813 2793 2814 2794 2815 //----- dose distribution image -----// 2795 //----- dose distribution image -----// 2816 if(kPointerToDoseDistData[0] != 0) { 2796 if(kPointerToDoseDistData[0] != 0) { 2817 2797 2818 newDoseDist(); 2798 newDoseDist(); 2819 2799 2820 // dose distrbution image size 2800 // dose distrbution image size 2821 ifile.read((char *)ctmp, 3*sizeof(int)); 2801 ifile.read((char *)ctmp, 3*sizeof(int)); 2822 convertEndian(ctmp, size[0]); 2802 convertEndian(ctmp, size[0]); 2823 convertEndian(ctmp+sizeof(int), size[1]); 2803 convertEndian(ctmp+sizeof(int), size[1]); 2824 convertEndian(ctmp+2*sizeof(int), size[2] 2804 convertEndian(ctmp+2*sizeof(int), size[2]); 2825 if(DEBUG || kVerbose > 0) { 2805 if(DEBUG || kVerbose > 0) { 2826 G4cout << "Dose dist. image size : (" << 2806 std::cout << "Dose dist. image size : (" 2827 << size[0] << ", " 2807 << size[0] << ", " 2828 << size[1] << ", " 2808 << size[1] << ", " 2829 << size[2] << ")" 2809 << size[2] << ")" 2830 << G4endl; << 2810 << std::endl; 2831 } 2811 } 2832 kDose[0].setSize(size); 2812 kDose[0].setSize(size); 2833 2813 2834 // dose distribution max. & min. 2814 // dose distribution max. & min. 2835 ifile.read((char *)ctmp, sizeof(short)*2) 2815 ifile.read((char *)ctmp, sizeof(short)*2); 2836 convertEndian(ctmp, minmax[0]); 2816 convertEndian(ctmp, minmax[0]); 2837 convertEndian(ctmp+2, minmax[1]); 2817 convertEndian(ctmp+2, minmax[1]); 2838 // dose distribution scaling 2818 // dose distribution scaling 2839 ifile.read((char *)ctmp, sizeof(float)); 2819 ifile.read((char *)ctmp, sizeof(float)); 2840 convertEndian(ctmp, scale); 2820 convertEndian(ctmp, scale); 2841 kDose[0].setScale(dscale = scale); 2821 kDose[0].setScale(dscale = scale); 2842 2822 2843 double dminmax[2]; 2823 double dminmax[2]; 2844 for(int i = 0; i < 2; i++) dminmax[i] = m 2824 for(int i = 0; i < 2; i++) dminmax[i] = minmax[i]*dscale; 2845 kDose[0].setMinMax(dminmax); 2825 kDose[0].setMinMax(dminmax); 2846 2826 2847 if(DEBUG || kVerbose > 0) { 2827 if(DEBUG || kVerbose > 0) { 2848 G4cout << "Dose dist. image min., max., << 2828 std::cout << "Dose dist. image min., max., scale : " 2849 << dminmax[0] << ", " 2829 << dminmax[0] << ", " 2850 << dminmax[1] << ", " 2830 << dminmax[1] << ", " 2851 << scale << G4endl; << 2831 << scale << std::endl; 2852 } 2832 } 2853 2833 2854 // dose distribution image 2834 // dose distribution image 2855 int dsize = size[0]*size[1]; 2835 int dsize = size[0]*size[1]; 2856 if(DEBUG || kVerbose > 0) G4cout << "Dose << 2836 if(DEBUG || kVerbose > 0) std::cout << "Dose dist. (" << dsize << "): "; 2857 char * di = new char[dsize*sizeof(short)] 2837 char * di = new char[dsize*sizeof(short)]; 2858 short * shimage = new short[dsize]; 2838 short * shimage = new short[dsize]; 2859 for(int z = 0; z < size[2]; z++) { 2839 for(int z = 0; z < size[2]; z++) { 2860 ifile.read((char *)di, dsize*sizeof(sho 2840 ifile.read((char *)di, dsize*sizeof(short)); 2861 double * dimage = new double[dsize]; 2841 double * dimage = new double[dsize]; 2862 for(int xy = 0; xy < dsize; xy++) { 2842 for(int xy = 0; xy < dsize; xy++) { 2863 convertEndian(di+xy*sizeof(short), shimage[ 2843 convertEndian(di+xy*sizeof(short), shimage[xy]); 2864 dimage[xy] = shimage[xy]*dscale; 2844 dimage[xy] = shimage[xy]*dscale; 2865 } 2845 } 2866 kDose[0].addImage(dimage); 2846 kDose[0].addImage(dimage); 2867 2847 2868 if(DEBUG || kVerbose > 0) G4cout << "[" << 2848 if(DEBUG || kVerbose > 0) std::cout << "[" << z << "]" << dimage[(size_t)(dsize*0.55)] << ", "; 2869 2849 2870 if(DEBUG || kVerbose > 0) { 2850 if(DEBUG || kVerbose > 0) { 2871 for(int j = 0; j < dsize; j++) { 2851 for(int j = 0; j < dsize; j++) { 2872 if(dimage[j] < 0) 2852 if(dimage[j] < 0) 2873 G4cout << "[" << j << "," << z << "]" << 2853 std::cout << "[" << j << "," << z << "]" 2874 << dimage[j] << ", "; 2854 << dimage[j] << ", "; 2875 } 2855 } 2876 } 2856 } 2877 } 2857 } 2878 delete [] shimage; 2858 delete [] shimage; 2879 delete [] di; 2859 delete [] di; 2880 if(DEBUG || kVerbose > 0) G4cout << G4end << 2860 if(DEBUG || kVerbose > 0) std::cout << std::endl; 2881 2861 2882 /* ver 1 2862 /* ver 1 2883 float doseDist; 2863 float doseDist; 2884 int dosePid; 2864 int dosePid; 2885 double * doseData = new double[numDose 2865 double * doseData = new double[numDoseImageVoxels]; 2886 for(int i = 0; i < numDose; i++) { 2866 for(int i = 0; i < numDose; i++) { 2887 ifile.read(ctmp, sizeof(int)); 2867 ifile.read(ctmp, sizeof(int)); 2888 convertEndian(ctmp, dosePid); 2868 convertEndian(ctmp, dosePid); 2889 for(int j = 0; j < numDoseImageVoxels; 2869 for(int j = 0; j < numDoseImageVoxels; j++) { 2890 ifile.read(ctmp, sizeof(float)); 2870 ifile.read(ctmp, sizeof(float)); 2891 convertEndian(ctmp, doseDist); 2871 convertEndian(ctmp, doseDist); 2892 doseData[j] = doseDist; 2872 doseData[j] = doseDist; 2893 } 2873 } 2894 setDose(dosePid, doseData); 2874 setDose(dosePid, doseData); 2895 } 2875 } 2896 delete [] doseData; 2876 delete [] doseData; 2897 if(totalDose == NULL) totalDose = new 2877 if(totalDose == NULL) totalDose = new double[numDoseImageVoxels]; 2898 for(int i = 0; i < numDoseImageVoxels; 2878 for(int i = 0; i < numDoseImageVoxels; i++) { 2899 ifile.read(ctmp, sizeof(float)); 2879 ifile.read(ctmp, sizeof(float)); 2900 convertEndian(ctmp, doseDist); 2880 convertEndian(ctmp, doseDist); 2901 totalDose[i] = doseDist; 2881 totalDose[i] = doseDist; 2902 } 2882 } 2903 */ 2883 */ 2904 2884 2905 /* ver 1 2885 /* ver 1 2906 // relative location between the two imag 2886 // relative location between the two images 2907 ifile.read(ctmp, 3*sizeof(float)); 2887 ifile.read(ctmp, 3*sizeof(float)); 2908 convertEndian(ctmp, relativeLocation[0]); 2888 convertEndian(ctmp, relativeLocation[0]); 2909 convertEndian(ctmp+sizeof(float), relativ 2889 convertEndian(ctmp+sizeof(float), relativeLocation[1]); 2910 convertEndian(ctmp+2*sizeof(float), relat 2890 convertEndian(ctmp+2*sizeof(float), relativeLocation[2]); 2911 */ 2891 */ 2912 2892 2913 // relative location of the dose distribu 2893 // relative location of the dose distribution image for 2914 // the modality image 2894 // the modality image 2915 //ofile.write((char *)relativeLocation, 3 2895 //ofile.write((char *)relativeLocation, 3*sizeof(float)); 2916 ifile.read((char *)ctmp, 3*sizeof(int)); 2896 ifile.read((char *)ctmp, 3*sizeof(int)); 2917 convertEndian(ctmp, iCenter[0]); 2897 convertEndian(ctmp, iCenter[0]); 2918 convertEndian(ctmp+sizeof(int), iCenter[1 2898 convertEndian(ctmp+sizeof(int), iCenter[1]); 2919 convertEndian(ctmp+2*sizeof(int), iCenter 2899 convertEndian(ctmp+2*sizeof(int), iCenter[2]); 2920 for(int i = 0; i < 3; i++) fCenter[i] = ( 2900 for(int i = 0; i < 3; i++) fCenter[i] = (float)iCenter[i]; 2921 kDose[0].setCenterPosition(fCenter); 2901 kDose[0].setCenterPosition(fCenter); 2922 2902 2923 if(DEBUG || kVerbose > 0) { 2903 if(DEBUG || kVerbose > 0) { 2924 G4cout << "Dose dist. image relative lo << 2904 std::cout << "Dose dist. image relative location : (" 2925 << fCenter[0] << ", " 2905 << fCenter[0] << ", " 2926 << fCenter[1] << ", " 2906 << fCenter[1] << ", " 2927 << fCenter[2] << ")" << G4endl; << 2907 << fCenter[2] << ")" << std::endl; 2928 } 2908 } 2929 2909 2930 2910 2931 } 2911 } 2932 2912 2933 //----- ROI image -----// 2913 //----- ROI image -----// 2934 if(kPointerToROIData != 0) { 2914 if(kPointerToROIData != 0) { 2935 2915 2936 newROI(); 2916 newROI(); 2937 2917 2938 // ROI image size 2918 // ROI image size 2939 ifile.read((char *)ctmp, 3*sizeof(int)); 2919 ifile.read((char *)ctmp, 3*sizeof(int)); 2940 convertEndian(ctmp, size[0]); 2920 convertEndian(ctmp, size[0]); 2941 convertEndian(ctmp+sizeof(int), size[1]); 2921 convertEndian(ctmp+sizeof(int), size[1]); 2942 convertEndian(ctmp+2*sizeof(int), size[2] 2922 convertEndian(ctmp+2*sizeof(int), size[2]); 2943 kRoi[0].setSize(size); 2923 kRoi[0].setSize(size); 2944 if(DEBUG || kVerbose > 0) { 2924 if(DEBUG || kVerbose > 0) { 2945 G4cout << "ROI image size : (" << 2925 std::cout << "ROI image size : (" 2946 << size[0] << ", " 2926 << size[0] << ", " 2947 << size[1] << ", " 2927 << size[1] << ", " 2948 << size[2] << ")" 2928 << size[2] << ")" 2949 << G4endl; << 2929 << std::endl; 2950 } 2930 } 2951 2931 2952 // ROI max. & min. 2932 // ROI max. & min. 2953 ifile.read((char *)ctmp, sizeof(short)*2) 2933 ifile.read((char *)ctmp, sizeof(short)*2); 2954 convertEndian(ctmp, minmax[0]); 2934 convertEndian(ctmp, minmax[0]); 2955 convertEndian(ctmp+sizeof(short), minmax[ 2935 convertEndian(ctmp+sizeof(short), minmax[1]); 2956 kRoi[0].setMinMax(minmax); 2936 kRoi[0].setMinMax(minmax); 2957 2937 2958 // ROI distribution scaling 2938 // ROI distribution scaling 2959 ifile.read((char *)ctmp, sizeof(float)); 2939 ifile.read((char *)ctmp, sizeof(float)); 2960 convertEndian(ctmp, scale); 2940 convertEndian(ctmp, scale); 2961 kRoi[0].setScale(dscale = scale); 2941 kRoi[0].setScale(dscale = scale); 2962 if(DEBUG || kVerbose > 0) { 2942 if(DEBUG || kVerbose > 0) { 2963 G4cout << "ROI image min., max., scale << 2943 std::cout << "ROI image min., max., scale : " 2964 << minmax[0] << ", " 2944 << minmax[0] << ", " 2965 << minmax[1] << ", " 2945 << minmax[1] << ", " 2966 << scale << G4endl; << 2946 << scale << std::endl; 2967 } 2947 } 2968 2948 2969 // ROI image 2949 // ROI image 2970 int rsize = size[0]*size[1]; 2950 int rsize = size[0]*size[1]; 2971 char * ri = new char[rsize*sizeof(short)] 2951 char * ri = new char[rsize*sizeof(short)]; 2972 for(int i = 0; i < size[2]; i++) { 2952 for(int i = 0; i < size[2]; i++) { 2973 ifile.read((char *)ri, rsize*sizeof(sho 2953 ifile.read((char *)ri, rsize*sizeof(short)); 2974 short * rimage = new short[rsize]; 2954 short * rimage = new short[rsize]; 2975 for(int j = 0; j < rsize; j++) { 2955 for(int j = 0; j < rsize; j++) { 2976 convertEndian(ri+j*sizeof(short), rimage[j] 2956 convertEndian(ri+j*sizeof(short), rimage[j]); 2977 } 2957 } 2978 kRoi[0].addImage(rimage); 2958 kRoi[0].addImage(rimage); 2979 2959 2980 } 2960 } 2981 delete [] ri; 2961 delete [] ri; 2982 2962 2983 // ROI relative location 2963 // ROI relative location 2984 ifile.read((char *)ctmp, 3*sizeof(int)); 2964 ifile.read((char *)ctmp, 3*sizeof(int)); 2985 convertEndian(ctmp, iCenter[0]); 2965 convertEndian(ctmp, iCenter[0]); 2986 convertEndian(ctmp+sizeof(int), iCenter[1 2966 convertEndian(ctmp+sizeof(int), iCenter[1]); 2987 convertEndian(ctmp+2*sizeof(int), iCenter 2967 convertEndian(ctmp+2*sizeof(int), iCenter[2]); 2988 for(int i = 0; i < 3; i++) fCenter[i] = i 2968 for(int i = 0; i < 3; i++) fCenter[i] = iCenter[i]; 2989 kRoi[0].setCenterPosition(fCenter); 2969 kRoi[0].setCenterPosition(fCenter); 2990 if(DEBUG || kVerbose > 0) { 2970 if(DEBUG || kVerbose > 0) { 2991 G4cout << "ROI image relative location << 2971 std::cout << "ROI image relative location : (" 2992 << fCenter[0] << ", " 2972 << fCenter[0] << ", " 2993 << fCenter[1] << ", " 2973 << fCenter[1] << ", " 2994 << fCenter[2] << ")" << G4endl; << 2974 << fCenter[2] << ")" << std::endl; 2995 } 2975 } 2996 2976 2997 } 2977 } 2998 2978 2999 //----- track information -----// 2979 //----- track information -----// 3000 if(kPointerToTrackData != 0) { 2980 if(kPointerToTrackData != 0) { 3001 2981 3002 // track 2982 // track 3003 ifile.read((char *)ctmp, sizeof(int)); 2983 ifile.read((char *)ctmp, sizeof(int)); 3004 int ntrk; 2984 int ntrk; 3005 convertEndian(ctmp, ntrk); 2985 convertEndian(ctmp, ntrk); 3006 if(DEBUG || kVerbose > 0) { 2986 if(DEBUG || kVerbose > 0) { 3007 G4cout << "# of tracks: " << ntrk << G4 << 2987 std::cout << "# of tracks: " << ntrk << std::endl; 3008 } 2988 } 3009 2989 3010 //v4 2990 //v4 3011 unsigned char trkcolorv4[3] = {255, 0, 0} 2991 unsigned char trkcolorv4[3] = {255, 0, 0}; 3012 2992 3013 for(int i = 0; i < ntrk; i++) { 2993 for(int i = 0; i < ntrk; i++) { 3014 float * tp = new float[6]; 2994 float * tp = new float[6]; 3015 // v4 2995 // v4 3016 std::vector<float *> trkv4; 2996 std::vector<float *> trkv4; 3017 2997 3018 ifile.read((char *)ctmp, sizeof(float)* 2998 ifile.read((char *)ctmp, sizeof(float)*3); 3019 if(DEBUG || kVerbose > 0) if(i < 10) G4 << 2999 if(DEBUG || kVerbose > 0) if(i < 10) std::cout << i << ": " ; 3020 for(int j = 0; j < 3; j++) { 3000 for(int j = 0; j < 3; j++) { 3021 convertEndian(ctmp+j*sizeof(float), tp[j]); 3001 convertEndian(ctmp+j*sizeof(float), tp[j]); 3022 if(DEBUG || kVerbose > 0) if(i < 10) G4cout << 3002 if(DEBUG || kVerbose > 0) if(i < 10) std::cout << tp[j] << ", "; 3023 } 3003 } 3024 3004 3025 ifile.read((char *)ctmp, sizeof(float)* 3005 ifile.read((char *)ctmp, sizeof(float)*3); 3026 for(int j = 0; j < 3; j++) { 3006 for(int j = 0; j < 3; j++) { 3027 convertEndian(ctmp+j*sizeof(float), tp[j+3] 3007 convertEndian(ctmp+j*sizeof(float), tp[j+3]); 3028 if(DEBUG || kVerbose > 0) if(i < 10) G4cout << 3008 if(DEBUG || kVerbose > 0) if(i < 10) std::cout << tp[j+3] << ", "; 3029 } 3009 } 3030 3010 3031 kSteps.push_back(tp); 3011 kSteps.push_back(tp); 3032 // v4 3012 // v4 3033 trkv4.push_back(tp); 3013 trkv4.push_back(tp); 3034 addTrack(trkv4, trkcolorv4); 3014 addTrack(trkv4, trkcolorv4); 3035 3015 3036 if(DEBUG || kVerbose > 0) if(i < 10) G4 << 3016 if(DEBUG || kVerbose > 0) if(i < 10) std::cout << std::endl; 3037 } 3017 } 3038 3018 3039 } 3019 } 3040 3020 3041 /* ver 1 3021 /* ver 1 3042 // track 3022 // track 3043 int ntracks; 3023 int ntracks; 3044 ifile.read(ctmp, sizeof(int)); 3024 ifile.read(ctmp, sizeof(int)); 3045 convertEndian(ctmp, ntracks); 3025 convertEndian(ctmp, ntracks); 3046 // track displacement 3026 // track displacement 3047 ifile.read(ctmp, 3*sizeof(float)); 3027 ifile.read(ctmp, 3*sizeof(float)); 3048 convertEndian(ctmp, trackDisplacement[0]); 3028 convertEndian(ctmp, trackDisplacement[0]); 3049 convertEndian(ctmp+sizeof(float), trackDisp 3029 convertEndian(ctmp+sizeof(float), trackDisplacement[2]); // exchanged with [1] 3050 convertEndian(ctmp+2*sizeof(float), trackDi 3030 convertEndian(ctmp+2*sizeof(float), trackDisplacement[1]); 3051 // 3031 // 3052 //for(int i = 0; i < ntracks && i < 100; i+ 3032 //for(int i = 0; i < ntracks && i < 100; i++) { 3053 for(int i = 0; i < ntracks; i++) { 3033 for(int i = 0; i < ntracks; i++) { 3054 DicomDoseTrack trk; 3034 DicomDoseTrack trk; 3055 short trackid, parentid, pid; 3035 short trackid, parentid, pid; 3056 int npoints; 3036 int npoints; 3057 ifile.read(ctmp, sizeof(short)); 3037 ifile.read(ctmp, sizeof(short)); 3058 convertEndian(ctmp, trackid); 3038 convertEndian(ctmp, trackid); 3059 trk.setID(trackid); 3039 trk.setID(trackid); 3060 ifile.read(ctmp, sizeof(short)); 3040 ifile.read(ctmp, sizeof(short)); 3061 convertEndian(ctmp, parentid); 3041 convertEndian(ctmp, parentid); 3062 trk.setParentID(parentid); 3042 trk.setParentID(parentid); 3063 ifile.read(ctmp, sizeof(short)); 3043 ifile.read(ctmp, sizeof(short)); 3064 convertEndian(ctmp, pid); 3044 convertEndian(ctmp, pid); 3065 trk.setPID(pid); 3045 trk.setPID(pid); 3066 ifile.read(ctmp, sizeof(int)); 3046 ifile.read(ctmp, sizeof(int)); 3067 convertEndian(ctmp, npoints); 3047 convertEndian(ctmp, npoints); 3068 for(int i = 0; i < npoints; i++) { 3048 for(int i = 0; i < npoints; i++) { 3069 ifile.read(ctmp, 3*sizeof(float)); 3049 ifile.read(ctmp, 3*sizeof(float)); 3070 // storing only start and end points 3050 // storing only start and end points 3071 //if(i == 0 || i == npoints - 1) { 3051 //if(i == 0 || i == npoints - 1) { 3072 float * point = new float[3]; 3052 float * point = new float[3]; 3073 convertEndian(ctmp, point[0]); 3053 convertEndian(ctmp, point[0]); 3074 convertEndian(ctmp+sizeof(float), point[1]) 3054 convertEndian(ctmp+sizeof(float), point[1]); 3075 convertEndian(ctmp+2*sizeof(float), point[2 3055 convertEndian(ctmp+2*sizeof(float), point[2]); 3076 trk.addPoint(point); 3056 trk.addPoint(point); 3077 //} 3057 //} 3078 } 3058 } 3079 track.push_back(trk); 3059 track.push_back(trk); 3080 } 3060 } 3081 */ 3061 */ 3082 3062 3083 ifile.close(); 3063 ifile.close(); 3084 3064 3085 return true; 3065 return true; 3086 } 3066 } 3087 3067 3088 bool G4GMocrenIO::retrieveData2(char * _filen 3068 bool G4GMocrenIO::retrieveData2(char * _filename) { 3089 kFileName = _filename; 3069 kFileName = _filename; 3090 return retrieveData(); 3070 return retrieveData(); 3091 } 3071 } 3092 3072 3093 void G4GMocrenIO::setID() { 3073 void G4GMocrenIO::setID() { 3094 time_t t; 3074 time_t t; 3095 time(&t); 3075 time(&t); 3096 3076 3097 tm * ti; 3077 tm * ti; 3098 ti = localtime(&t); 3078 ti = localtime(&t); 3099 3079 3100 char cmonth[12][4] = {"Jan", "Feb", "Mar", 3080 char cmonth[12][4] = {"Jan", "Feb", "Mar", "Apr", 3101 "May", "Jun", "Jul", "Aug", 3081 "May", "Jun", "Jul", "Aug", 3102 "Sep", "Oct", "Nov", "Dec"}; 3082 "Sep", "Oct", "Nov", "Dec"}; 3103 std::stringstream ss; 3083 std::stringstream ss; 3104 ss << std::setfill('0') 3084 ss << std::setfill('0') 3105 << std::setw(2) 3085 << std::setw(2) 3106 << ti->tm_hour << ":" 3086 << ti->tm_hour << ":" 3107 << std::setw(2) 3087 << std::setw(2) 3108 << ti->tm_min << ":" 3088 << ti->tm_min << ":" 3109 << std::setw(2) 3089 << std::setw(2) 3110 << ti->tm_sec << "," 3090 << ti->tm_sec << "," 3111 << cmonth[ti->tm_mon] << "." 3091 << cmonth[ti->tm_mon] << "." 3112 << std::setw(2) 3092 << std::setw(2) 3113 << ti->tm_mday << "," 3093 << ti->tm_mday << "," 3114 << ti->tm_year+1900; 3094 << ti->tm_year+1900; 3115 3095 3116 kId = ss.str(); 3096 kId = ss.str(); 3117 } 3097 } 3118 3098 3119 // get & set the file version 3099 // get & set the file version 3120 std::string & G4GMocrenIO::getVersion() {retu 3100 std::string & G4GMocrenIO::getVersion() {return kVersion;} 3121 void G4GMocrenIO::setVersion(std::string & _v 3101 void G4GMocrenIO::setVersion(std::string & _version) {kVersion = _version;} 3122 3102 3123 // set endians of input/output data 3103 // set endians of input/output data 3124 void G4GMocrenIO::setLittleEndianInput(bool _ 3104 void G4GMocrenIO::setLittleEndianInput(bool _little) {kLittleEndianInput = _little;} 3125 void G4GMocrenIO::setLittleEndianOutput(bool 3105 void G4GMocrenIO::setLittleEndianOutput(bool _little) {kLittleEndianOutput = _little;} 3126 3106 3127 // voxel spacing 3107 // voxel spacing 3128 void G4GMocrenIO::setVoxelSpacing(float _spac 3108 void G4GMocrenIO::setVoxelSpacing(float _spacing[3]) { 3129 for(int i = 0; i < 3; i++) kVoxelSpacing[i] 3109 for(int i = 0; i < 3; i++) kVoxelSpacing[i] = _spacing[i]; 3130 } 3110 } 3131 void G4GMocrenIO::getVoxelSpacing(float _spac 3111 void G4GMocrenIO::getVoxelSpacing(float _spacing[3]) { 3132 for(int i = 0; i < 3; i++) _spacing[i] = kV 3112 for(int i = 0; i < 3; i++) _spacing[i] = kVoxelSpacing[i]; 3133 } 3113 } 3134 3114 3135 // get & set number of events 3115 // get & set number of events 3136 int & G4GMocrenIO::getNumberOfEvents() { 3116 int & G4GMocrenIO::getNumberOfEvents() { 3137 return kNumberOfEvents; 3117 return kNumberOfEvents; 3138 } 3118 } 3139 void G4GMocrenIO::setNumberOfEvents(int & _nu 3119 void G4GMocrenIO::setNumberOfEvents(int & _numberOfEvents) { 3140 kNumberOfEvents = _numberOfEvents; 3120 kNumberOfEvents = _numberOfEvents; 3141 } 3121 } 3142 void G4GMocrenIO::addOneEvent() { 3122 void G4GMocrenIO::addOneEvent() { 3143 kNumberOfEvents++; 3123 kNumberOfEvents++; 3144 } 3124 } 3145 3125 3146 // set/get pointer the modality image data 3126 // set/get pointer the modality image data 3147 void G4GMocrenIO::setPointerToModalityData(un 3127 void G4GMocrenIO::setPointerToModalityData(unsigned int & _pointer) { 3148 kPointerToModalityData = _pointer; 3128 kPointerToModalityData = _pointer; 3149 } 3129 } 3150 unsigned int G4GMocrenIO::getPointerToModalit 3130 unsigned int G4GMocrenIO::getPointerToModalityData() { 3151 return kPointerToModalityData; 3131 return kPointerToModalityData; 3152 } 3132 } 3153 // set/get pointer the dose distribution imag 3133 // set/get pointer the dose distribution image data 3154 void G4GMocrenIO::addPointerToDoseDistData(un 3134 void G4GMocrenIO::addPointerToDoseDistData(unsigned int & _pointer) { 3155 kPointerToDoseDistData.push_back(_pointer); 3135 kPointerToDoseDistData.push_back(_pointer); 3156 } 3136 } 3157 unsigned int G4GMocrenIO::getPointerToDoseDis 3137 unsigned int G4GMocrenIO::getPointerToDoseDistData(int _elem) { 3158 if(kPointerToDoseDistData.size() == 0 || 3138 if(kPointerToDoseDistData.size() == 0 || 3159 kPointerToDoseDistData.size() < (size_t) 3139 kPointerToDoseDistData.size() < (size_t)_elem) 3160 return 0; 3140 return 0; 3161 else 3141 else 3162 return kPointerToDoseDistData[_elem]; 3142 return kPointerToDoseDistData[_elem]; 3163 } 3143 } 3164 3144 3165 // set/get pointer the ROI image data 3145 // set/get pointer the ROI image data 3166 void G4GMocrenIO::setPointerToROIData(unsigne 3146 void G4GMocrenIO::setPointerToROIData(unsigned int & _pointer) { 3167 kPointerToROIData = _pointer; 3147 kPointerToROIData = _pointer; 3168 } 3148 } 3169 unsigned int G4GMocrenIO::getPointerToROIData 3149 unsigned int G4GMocrenIO::getPointerToROIData() { 3170 return kPointerToROIData; 3150 return kPointerToROIData; 3171 } 3151 } 3172 // set/get pointer the track data 3152 // set/get pointer the track data 3173 void G4GMocrenIO::setPointerToTrackData(unsig 3153 void G4GMocrenIO::setPointerToTrackData(unsigned int & _pointer) { 3174 kPointerToTrackData = _pointer; 3154 kPointerToTrackData = _pointer; 3175 } 3155 } 3176 unsigned int G4GMocrenIO::getPointerToTrackDa 3156 unsigned int G4GMocrenIO::getPointerToTrackData() { 3177 return kPointerToTrackData; 3157 return kPointerToTrackData; 3178 } 3158 } 3179 3159 3180 // calculate pointers for version 4 3160 // calculate pointers for version 4 3181 void G4GMocrenIO::calcPointers4() { 3161 void G4GMocrenIO::calcPointers4() { 3182 3162 3183 // pointer to modality data 3163 // pointer to modality data 3184 unsigned int pointer = 1070; // up to "poin 3164 unsigned int pointer = 1070; // up to "pointer to the detector data" except for "pointer to the dose dist data" 3185 int nDoseDist = getNumDoseDist(); 3165 int nDoseDist = getNumDoseDist(); 3186 pointer += nDoseDist*4; 3166 pointer += nDoseDist*4; 3187 3167 3188 setPointerToModalityData(pointer); 3168 setPointerToModalityData(pointer); 3189 3169 3190 // pointer to dose data 3170 // pointer to dose data 3191 // ct-density map for modality data 3171 // ct-density map for modality data 3192 int msize[3]; 3172 int msize[3]; 3193 getModalityImageSize(msize); 3173 getModalityImageSize(msize); 3194 short mminmax[2]; 3174 short mminmax[2]; 3195 getModalityImageMinMax(mminmax); 3175 getModalityImageMinMax(mminmax); 3196 int pmsize = 2*msize[0]*msize[1]*msize[2]; 3176 int pmsize = 2*msize[0]*msize[1]*msize[2]; 3197 int pmmap = 4*(mminmax[1] - mminmax[0] + 1) 3177 int pmmap = 4*(mminmax[1] - mminmax[0] + 1); 3198 pointer += 32 + pmsize + pmmap; 3178 pointer += 32 + pmsize + pmmap; 3199 // 3179 // 3200 kPointerToDoseDistData.clear(); 3180 kPointerToDoseDistData.clear(); 3201 if(nDoseDist == 0) { 3181 if(nDoseDist == 0) { 3202 unsigned int pointer0 = 0; 3182 unsigned int pointer0 = 0; 3203 addPointerToDoseDistData(pointer0); 3183 addPointerToDoseDistData(pointer0); 3204 } 3184 } 3205 for(int ndose = 0; ndose < nDoseDist; ndose 3185 for(int ndose = 0; ndose < nDoseDist; ndose++) { 3206 addPointerToDoseDistData(pointer); 3186 addPointerToDoseDistData(pointer); 3207 int dsize[3]; 3187 int dsize[3]; 3208 getDoseDistSize(dsize); 3188 getDoseDistSize(dsize); 3209 pointer += 44 + dsize[0]*dsize[1]*dsize[2 3189 pointer += 44 + dsize[0]*dsize[1]*dsize[2]*2 + 80; 3210 } 3190 } 3211 3191 3212 // pointer to roi data 3192 // pointer to roi data 3213 if(!isROIEmpty()) { 3193 if(!isROIEmpty()) { 3214 setPointerToROIData(pointer); 3194 setPointerToROIData(pointer); 3215 3195 3216 int rsize[3]; 3196 int rsize[3]; 3217 getROISize(rsize); 3197 getROISize(rsize); 3218 int prsize = 2*rsize[0]*rsize[1]*rsize[2] 3198 int prsize = 2*rsize[0]*rsize[1]*rsize[2]; 3219 pointer += 20 + prsize + 12; 3199 pointer += 20 + prsize + 12; 3220 } else { 3200 } else { 3221 unsigned int pointer0 = 0; 3201 unsigned int pointer0 = 0; 3222 setPointerToROIData(pointer0); 3202 setPointerToROIData(pointer0); 3223 } 3203 } 3224 3204 3225 // pointer to track data 3205 // pointer to track data 3226 int ntrk = (int)kTracks.size(); << 3206 int ntrk = kTracks.size(); 3227 if(ntrk != 0) { 3207 if(ntrk != 0) { 3228 setPointerToTrackData(pointer); 3208 setPointerToTrackData(pointer); 3229 3209 3230 pointer += 4; // # of tracks 3210 pointer += 4; // # of tracks 3231 for(int nt = 0; nt < ntrk; nt++) { 3211 for(int nt = 0; nt < ntrk; nt++) { 3232 int nsteps = kTracks[nt].getNumberOfSte 3212 int nsteps = kTracks[nt].getNumberOfSteps(); 3233 pointer += 4 + 3 + nsteps*(4*6); // # o 3213 pointer += 4 + 3 + nsteps*(4*6); // # of steps + color + steps(float*6) 3234 } 3214 } 3235 } else { 3215 } else { 3236 unsigned int pointer0 = 0; 3216 unsigned int pointer0 = 0; 3237 setPointerToTrackData(pointer0); 3217 setPointerToTrackData(pointer0); 3238 } 3218 } 3239 if(kVerbose > 0) G4cout << " pointer to the << 3219 if(kVerbose > 0) std::cout << " pointer to the track data :" 3240 << kPointerToTrackData << G4endl; << 3220 << kPointerToTrackData << std::endl; 3241 3221 3242 // pointer to detector data 3222 // pointer to detector data 3243 int ndet = (int)kDetectors.size(); << 3223 int ndet = kDetectors.size(); 3244 if(ndet != 0) { 3224 if(ndet != 0) { 3245 kPointerToDetectorData = pointer; 3225 kPointerToDetectorData = pointer; 3246 } else { 3226 } else { 3247 kPointerToDetectorData = 0; 3227 kPointerToDetectorData = 0; 3248 } 3228 } 3249 if(kVerbose > 0) G4cout << " pointer to the << 3229 if(kVerbose > 0) std::cout << " pointer to the detector data :" 3250 << kPointerToDetectorData << G4end << 3230 << kPointerToDetectorData << std::endl; 3251 3231 3252 } 3232 } 3253 3233 3254 // calculate pointers for ver.3 3234 // calculate pointers for ver.3 3255 void G4GMocrenIO::calcPointers3() { 3235 void G4GMocrenIO::calcPointers3() { 3256 3236 3257 // pointer to modality data 3237 // pointer to modality data 3258 unsigned int pointer = 1066; // up to "poin 3238 unsigned int pointer = 1066; // up to "pointer to the track data" except for "pointer to the dose dist data" 3259 int nDoseDist = getNumDoseDist(); 3239 int nDoseDist = getNumDoseDist(); 3260 pointer += nDoseDist*4; 3240 pointer += nDoseDist*4; 3261 3241 3262 setPointerToModalityData(pointer); 3242 setPointerToModalityData(pointer); 3263 3243 3264 // pointer to dose data 3244 // pointer to dose data 3265 // ct-density map for modality data 3245 // ct-density map for modality data 3266 int msize[3]; 3246 int msize[3]; 3267 getModalityImageSize(msize); 3247 getModalityImageSize(msize); 3268 short mminmax[2]; 3248 short mminmax[2]; 3269 getModalityImageMinMax(mminmax); 3249 getModalityImageMinMax(mminmax); 3270 int pmsize = 2*msize[0]*msize[1]*msize[2]; 3250 int pmsize = 2*msize[0]*msize[1]*msize[2]; 3271 int pmmap = 4*(mminmax[1] - mminmax[0] + 1) 3251 int pmmap = 4*(mminmax[1] - mminmax[0] + 1); 3272 pointer += 32 + pmsize + pmmap; 3252 pointer += 32 + pmsize + pmmap; 3273 // 3253 // 3274 kPointerToDoseDistData.clear(); 3254 kPointerToDoseDistData.clear(); 3275 if(nDoseDist == 0) { 3255 if(nDoseDist == 0) { 3276 unsigned int pointer0 = 0; 3256 unsigned int pointer0 = 0; 3277 addPointerToDoseDistData(pointer0); 3257 addPointerToDoseDistData(pointer0); 3278 } 3258 } 3279 for(int ndose = 0; ndose < nDoseDist; ndose 3259 for(int ndose = 0; ndose < nDoseDist; ndose++) { 3280 addPointerToDoseDistData(pointer); 3260 addPointerToDoseDistData(pointer); 3281 int dsize[3]; 3261 int dsize[3]; 3282 getDoseDistSize(dsize); 3262 getDoseDistSize(dsize); 3283 pointer += 44 + dsize[0]*dsize[1]*dsize[2 3263 pointer += 44 + dsize[0]*dsize[1]*dsize[2]*2; 3284 } 3264 } 3285 3265 3286 // pointer to roi data 3266 // pointer to roi data 3287 if(!isROIEmpty()) { 3267 if(!isROIEmpty()) { 3288 setPointerToROIData(pointer); 3268 setPointerToROIData(pointer); 3289 3269 3290 int rsize[3]; 3270 int rsize[3]; 3291 getROISize(rsize); 3271 getROISize(rsize); 3292 int prsize = 2*rsize[0]*rsize[1]*rsize[2] 3272 int prsize = 2*rsize[0]*rsize[1]*rsize[2]; 3293 pointer += 20 + prsize + 12; 3273 pointer += 20 + prsize + 12; 3294 } else { 3274 } else { 3295 unsigned int pointer0 = 0; 3275 unsigned int pointer0 = 0; 3296 setPointerToROIData(pointer0); 3276 setPointerToROIData(pointer0); 3297 } 3277 } 3298 3278 3299 // 3279 // 3300 if(getNumTracks() != 0) 3280 if(getNumTracks() != 0) 3301 setPointerToTrackData(pointer); 3281 setPointerToTrackData(pointer); 3302 else { 3282 else { 3303 unsigned int pointer0 = 0; 3283 unsigned int pointer0 = 0; 3304 setPointerToTrackData(pointer0); 3284 setPointerToTrackData(pointer0); 3305 } 3285 } 3306 3286 3307 } 3287 } 3308 3288 3309 // calculate pointers for ver.2 3289 // calculate pointers for ver.2 3310 void G4GMocrenIO::calcPointers2() { 3290 void G4GMocrenIO::calcPointers2() { 3311 3291 3312 // pointer to modality data 3292 // pointer to modality data 3313 unsigned int pointer = 65; 3293 unsigned int pointer = 65; 3314 setPointerToModalityData(pointer); 3294 setPointerToModalityData(pointer); 3315 3295 3316 // pointer to dose data 3296 // pointer to dose data 3317 int msize[3]; 3297 int msize[3]; 3318 getModalityImageSize(msize); 3298 getModalityImageSize(msize); 3319 short mminmax[2]; 3299 short mminmax[2]; 3320 getModalityImageMinMax(mminmax); 3300 getModalityImageMinMax(mminmax); 3321 int pmsize = 2*msize[0]*msize[1]*msize[2]; 3301 int pmsize = 2*msize[0]*msize[1]*msize[2]; 3322 int pmmap = 4*(mminmax[1] - mminmax[0] + 1) 3302 int pmmap = 4*(mminmax[1] - mminmax[0] + 1); 3323 pointer += 20 + pmsize + pmmap; 3303 pointer += 20 + pmsize + pmmap; 3324 int dsize[3]; 3304 int dsize[3]; 3325 getDoseDistSize(dsize); 3305 getDoseDistSize(dsize); 3326 kPointerToDoseDistData.clear(); 3306 kPointerToDoseDistData.clear(); 3327 if(dsize[0] != 0) { 3307 if(dsize[0] != 0) { 3328 kPointerToDoseDistData.push_back(pointer) 3308 kPointerToDoseDistData.push_back(pointer); 3329 3309 3330 int pdsize = 2*dsize[0]*dsize[1]*dsize[2] 3310 int pdsize = 2*dsize[0]*dsize[1]*dsize[2]; 3331 pointer += 20 + pdsize + 12; 3311 pointer += 20 + pdsize + 12; 3332 } else { 3312 } else { 3333 unsigned int pointer0 = 0; 3313 unsigned int pointer0 = 0; 3334 kPointerToDoseDistData.push_back(pointer0 3314 kPointerToDoseDistData.push_back(pointer0); 3335 } 3315 } 3336 3316 3337 // pointer to roi data 3317 // pointer to roi data 3338 if(!isROIEmpty()) { 3318 if(!isROIEmpty()) { 3339 int rsize[3]; 3319 int rsize[3]; 3340 getROISize(rsize); 3320 getROISize(rsize); 3341 setPointerToROIData(pointer); 3321 setPointerToROIData(pointer); 3342 int prsize = 2*rsize[0]*rsize[1]*rsize[2] 3322 int prsize = 2*rsize[0]*rsize[1]*rsize[2]; 3343 pointer += 20 + prsize + 12; 3323 pointer += 20 + prsize + 12; 3344 3324 3345 } else { 3325 } else { 3346 unsigned int pointer0 = 0; 3326 unsigned int pointer0 = 0; 3347 setPointerToROIData(pointer0); 3327 setPointerToROIData(pointer0); 3348 } 3328 } 3349 3329 3350 // 3330 // 3351 if(getNumTracks() != 0) 3331 if(getNumTracks() != 0) 3352 setPointerToTrackData(pointer); 3332 setPointerToTrackData(pointer); 3353 else { 3333 else { 3354 unsigned int pointer0 = 0; 3334 unsigned int pointer0 = 0; 3355 setPointerToTrackData(pointer0); 3335 setPointerToTrackData(pointer0); 3356 } 3336 } 3357 3337 3358 } 3338 } 3359 3339 3360 3340 3361 //----- Modality image -----// 3341 //----- Modality image -----// 3362 void G4GMocrenIO::getModalityImageSize(int _s 3342 void G4GMocrenIO::getModalityImageSize(int _size[3]) { 3363 3343 3364 kModality.getSize(_size); 3344 kModality.getSize(_size); 3365 } 3345 } 3366 void G4GMocrenIO::setModalityImageSize(int _s 3346 void G4GMocrenIO::setModalityImageSize(int _size[3]) { 3367 3347 3368 kModality.setSize(_size); 3348 kModality.setSize(_size); 3369 } 3349 } 3370 3350 3371 // get & set the modality image size 3351 // get & set the modality image size 3372 void G4GMocrenIO::setModalityImageScale(doubl 3352 void G4GMocrenIO::setModalityImageScale(double & _scale) { 3373 3353 3374 kModality.setScale(_scale); 3354 kModality.setScale(_scale); 3375 } 3355 } 3376 double G4GMocrenIO::getModalityImageScale() { 3356 double G4GMocrenIO::getModalityImageScale() { 3377 3357 3378 return kModality.getScale(); 3358 return kModality.getScale(); 3379 } 3359 } 3380 3360 3381 // set the modality image in CT 3361 // set the modality image in CT 3382 void G4GMocrenIO::setModalityImage(short * _i 3362 void G4GMocrenIO::setModalityImage(short * _image) { 3383 3363 3384 kModality.addImage(_image); 3364 kModality.addImage(_image); 3385 } 3365 } 3386 short * G4GMocrenIO::getModalityImage(int _z) 3366 short * G4GMocrenIO::getModalityImage(int _z) { 3387 3367 3388 return kModality.getImage(_z); 3368 return kModality.getImage(_z); 3389 } 3369 } 3390 void G4GMocrenIO::clearModalityImage() { << 3391 << 3392 kModality.clearImage(); << 3393 } << 3394 // set/get the modality image density map 3370 // set/get the modality image density map 3395 void G4GMocrenIO::setModalityImageDensityMap( 3371 void G4GMocrenIO::setModalityImageDensityMap(std::vector<float> & _map) { 3396 kModalityImageDensityMap = _map; 3372 kModalityImageDensityMap = _map; 3397 } 3373 } 3398 std::vector<float> & G4GMocrenIO::getModality 3374 std::vector<float> & G4GMocrenIO::getModalityImageDensityMap() { 3399 return kModalityImageDensityMap; 3375 return kModalityImageDensityMap; 3400 } 3376 } 3401 // set the modality image min./max. 3377 // set the modality image min./max. 3402 void G4GMocrenIO::setModalityImageMinMax(shor 3378 void G4GMocrenIO::setModalityImageMinMax(short _minmax[2]) { 3403 3379 3404 kModality.setMinMax(_minmax); 3380 kModality.setMinMax(_minmax); 3405 } 3381 } 3406 // get the modality image min./max. 3382 // get the modality image min./max. 3407 void G4GMocrenIO::getModalityImageMinMax(shor 3383 void G4GMocrenIO::getModalityImageMinMax(short _minmax[2]) { 3408 3384 3409 short minmax[2]; 3385 short minmax[2]; 3410 kModality.getMinMax(minmax); 3386 kModality.getMinMax(minmax); 3411 for(int i = 0; i < 2; i++) _minmax[i] = min 3387 for(int i = 0; i < 2; i++) _minmax[i] = minmax[i]; 3412 } 3388 } 3413 short G4GMocrenIO::getModalityImageMax() { 3389 short G4GMocrenIO::getModalityImageMax() { 3414 3390 3415 short minmax[2]; 3391 short minmax[2]; 3416 kModality.getMinMax(minmax); 3392 kModality.getMinMax(minmax); 3417 return minmax[1]; 3393 return minmax[1]; 3418 } 3394 } 3419 short G4GMocrenIO::getModalityImageMin() { 3395 short G4GMocrenIO::getModalityImageMin() { 3420 3396 3421 short minmax[2]; 3397 short minmax[2]; 3422 kModality.getMinMax(minmax); 3398 kModality.getMinMax(minmax); 3423 return minmax[0]; 3399 return minmax[0]; 3424 } 3400 } 3425 // set/get position of the modality image cen 3401 // set/get position of the modality image center 3426 void G4GMocrenIO::setModalityCenterPosition(f 3402 void G4GMocrenIO::setModalityCenterPosition(float _center[3]) { 3427 3403 3428 kModality.setCenterPosition(_center); 3404 kModality.setCenterPosition(_center); 3429 } 3405 } 3430 void G4GMocrenIO::getModalityCenterPosition(f 3406 void G4GMocrenIO::getModalityCenterPosition(float _center[3]) { 3431 3407 3432 if(isROIEmpty()) 3408 if(isROIEmpty()) 3433 for(int i = 0; i < 3; i++) _center[i] = 0 3409 for(int i = 0; i < 3; i++) _center[i] = 0; 3434 else 3410 else 3435 kModality.getCenterPosition(_center); 3411 kModality.getCenterPosition(_center); 3436 } 3412 } 3437 // get & set the modality image unit 3413 // get & set the modality image unit 3438 std::string G4GMocrenIO::getModalityImageUnit 3414 std::string G4GMocrenIO::getModalityImageUnit() { 3439 return kModalityUnit; 3415 return kModalityUnit; 3440 } 3416 } 3441 void G4GMocrenIO::setModalityImageUnit(std::s 3417 void G4GMocrenIO::setModalityImageUnit(std::string & _unit) { 3442 kModalityUnit = _unit; 3418 kModalityUnit = _unit; 3443 } 3419 } 3444 // 3420 // 3445 short G4GMocrenIO::convertDensityToHU(float & 3421 short G4GMocrenIO::convertDensityToHU(float & _dens) { 3446 short rval = -1024; // default: air 3422 short rval = -1024; // default: air 3447 int nmap = (int)kModalityImageDensityMap.si 3423 int nmap = (int)kModalityImageDensityMap.size(); 3448 if(nmap != 0) { 3424 if(nmap != 0) { 3449 short minmax[2]; 3425 short minmax[2]; 3450 kModality.getMinMax(minmax); 3426 kModality.getMinMax(minmax); 3451 rval = minmax[1]; 3427 rval = minmax[1]; 3452 for(int i = 0; i < nmap; i++) { 3428 for(int i = 0; i < nmap; i++) { 3453 //G4cout << kModalityImageDensityMap[i] << 3429 //std::cout << kModalityImageDensityMap[i] << std::endl; 3454 if(_dens <= kModalityImageDensityMap[i] 3430 if(_dens <= kModalityImageDensityMap[i]) { 3455 rval = i + minmax[0]; 3431 rval = i + minmax[0]; 3456 break; 3432 break; 3457 } 3433 } 3458 } 3434 } 3459 } 3435 } 3460 return rval; 3436 return rval; 3461 } 3437 } 3462 3438 3463 3439 3464 //----- Dose distribution -----// 3440 //----- Dose distribution -----// 3465 // 3441 // 3466 void G4GMocrenIO::newDoseDist() { 3442 void G4GMocrenIO::newDoseDist() { 3467 GMocrenDataPrimitive<double> doseData; 3443 GMocrenDataPrimitive<double> doseData; 3468 kDose.push_back(doseData); 3444 kDose.push_back(doseData); 3469 } 3445 } 3470 int G4GMocrenIO::getNumDoseDist() { 3446 int G4GMocrenIO::getNumDoseDist() { 3471 return (int)kDose.size(); 3447 return (int)kDose.size(); 3472 } 3448 } 3473 3449 3474 // get & set the dose distribution unit 3450 // get & set the dose distribution unit 3475 std::string G4GMocrenIO::getDoseDistUnit(int 3451 std::string G4GMocrenIO::getDoseDistUnit(int _num) { 3476 // to avoid a warning in the compile proces 3452 // to avoid a warning in the compile process 3477 if(kDoseUnit.size() > static_cast<size_t>(_ << 3453 int dummynum; >> 3454 dummynum = _num; 3478 3455 3479 return kDoseUnit; 3456 return kDoseUnit; 3480 } 3457 } 3481 void G4GMocrenIO::setDoseDistUnit(std::string 3458 void G4GMocrenIO::setDoseDistUnit(std::string & _unit, int _num) { 3482 // to avoid a warning in the compile proces 3459 // to avoid a warning in the compile process 3483 if(_unit.size() > static_cast<size_t>(_num) << 3460 int dummynum; >> 3461 dummynum = _num; 3484 3462 3485 //char unit[13]; 3463 //char unit[13]; 3486 //std::strncpy(unit, _unit.c_str(), 12); 3464 //std::strncpy(unit, _unit.c_str(), 12); 3487 //doseUnit = unit; 3465 //doseUnit = unit; 3488 kDoseUnit = _unit; 3466 kDoseUnit = _unit; 3489 } 3467 } 3490 // 3468 // 3491 void G4GMocrenIO::getDoseDistSize(int _size[3 3469 void G4GMocrenIO::getDoseDistSize(int _size[3], int _num) { 3492 if(isDoseEmpty()) 3470 if(isDoseEmpty()) 3493 for(int i = 0; i < 3; i++) _size[i] = 0; 3471 for(int i = 0; i < 3; i++) _size[i] = 0; 3494 else 3472 else 3495 kDose[_num].getSize(_size); 3473 kDose[_num].getSize(_size); 3496 } 3474 } 3497 void G4GMocrenIO::setDoseDistSize(int _size[3 3475 void G4GMocrenIO::setDoseDistSize(int _size[3], int _num) { 3498 3476 3499 kDose[_num].setSize(_size); 3477 kDose[_num].setSize(_size); 3500 3478 3501 //resetDose(); 3479 //resetDose(); 3502 } 3480 } 3503 3481 3504 void G4GMocrenIO::setDoseDistMinMax(short _mi 3482 void G4GMocrenIO::setDoseDistMinMax(short _minmax[2], int _num) { 3505 3483 3506 double minmax[2]; 3484 double minmax[2]; 3507 double scale = kDose[_num].getScale(); 3485 double scale = kDose[_num].getScale(); 3508 for(int i = 0; i < 2; i++) minmax[i] = (dou 3486 for(int i = 0; i < 2; i++) minmax[i] = (double)_minmax[i]*scale; 3509 kDose[_num].setMinMax(minmax); 3487 kDose[_num].setMinMax(minmax); 3510 } 3488 } 3511 void G4GMocrenIO::getDoseDistMinMax(short _mi 3489 void G4GMocrenIO::getDoseDistMinMax(short _minmax[2], int _num) { 3512 3490 3513 if(isDoseEmpty()) 3491 if(isDoseEmpty()) 3514 for(int i = 0; i < 2; i++) _minmax[i] = 0 3492 for(int i = 0; i < 2; i++) _minmax[i] = 0; 3515 else { 3493 else { 3516 double minmax[2]; 3494 double minmax[2]; 3517 kDose[_num].getMinMax(minmax); 3495 kDose[_num].getMinMax(minmax); 3518 double scale = kDose[_num].getScale(); 3496 double scale = kDose[_num].getScale(); 3519 for(int i = 0; i < 2; i++) _minmax[i] = ( 3497 for(int i = 0; i < 2; i++) _minmax[i] = (short)(minmax[i]/scale+0.5); 3520 } 3498 } 3521 } 3499 } 3522 void G4GMocrenIO::setDoseDistMinMax(double _m 3500 void G4GMocrenIO::setDoseDistMinMax(double _minmax[2], int _num) { 3523 3501 3524 kDose[_num].setMinMax(_minmax); 3502 kDose[_num].setMinMax(_minmax); 3525 } 3503 } 3526 void G4GMocrenIO::getDoseDistMinMax(double _m 3504 void G4GMocrenIO::getDoseDistMinMax(double _minmax[2], int _num) { 3527 3505 3528 if(isDoseEmpty()) 3506 if(isDoseEmpty()) 3529 for(int i = 0; i < 2; i++) _minmax[i] = 0 3507 for(int i = 0; i < 2; i++) _minmax[i] = 0.; 3530 else 3508 else 3531 kDose[_num].getMinMax(_minmax); 3509 kDose[_num].getMinMax(_minmax); 3532 } 3510 } 3533 3511 3534 // get & set the dose distribution image scal 3512 // get & set the dose distribution image scale 3535 void G4GMocrenIO::setDoseDistScale(double & _ 3513 void G4GMocrenIO::setDoseDistScale(double & _scale, int _num) { 3536 3514 3537 kDose[_num].setScale(_scale); 3515 kDose[_num].setScale(_scale); 3538 } 3516 } 3539 double G4GMocrenIO::getDoseDistScale(int _num 3517 double G4GMocrenIO::getDoseDistScale(int _num) { 3540 3518 3541 if(isDoseEmpty()) 3519 if(isDoseEmpty()) 3542 return 0.; 3520 return 0.; 3543 else 3521 else 3544 return kDose[_num].getScale(); 3522 return kDose[_num].getScale(); 3545 } 3523 } 3546 3524 3547 /* 3525 /* 3548 void G4GMocrenIO::initializeShortDoseDist() 3526 void G4GMocrenIO::initializeShortDoseDist() { 3549 ; 3527 ; 3550 } 3528 } 3551 void G4GMocrenIO::finalizeShortDoseDist() { 3529 void G4GMocrenIO::finalizeShortDoseDist() { 3552 ; 3530 ; 3553 } 3531 } 3554 */ 3532 */ 3555 // set the dose distribution image 3533 // set the dose distribution image 3556 void G4GMocrenIO::setShortDoseDist(short * _i 3534 void G4GMocrenIO::setShortDoseDist(short * _image, int _num) { 3557 3535 3558 int size[3]; 3536 int size[3]; 3559 kDose[_num].getSize(size); 3537 kDose[_num].getSize(size); 3560 int dsize = size[0]*size[1]; 3538 int dsize = size[0]*size[1]; 3561 double * ddata = new double[dsize]; 3539 double * ddata = new double[dsize]; 3562 double scale = kDose[_num].getScale(); 3540 double scale = kDose[_num].getScale(); 3563 double minmax[2]; 3541 double minmax[2]; 3564 kDose[_num].getMinMax(minmax); 3542 kDose[_num].getMinMax(minmax); 3565 for(int xy = 0; xy < dsize; xy++) { 3543 for(int xy = 0; xy < dsize; xy++) { 3566 ddata[xy] = _image[xy]*scale; 3544 ddata[xy] = _image[xy]*scale; 3567 if(ddata[xy] < minmax[0]) minmax[0] = dda 3545 if(ddata[xy] < minmax[0]) minmax[0] = ddata[xy]; 3568 if(ddata[xy] > minmax[1]) minmax[1] = dda 3546 if(ddata[xy] > minmax[1]) minmax[1] = ddata[xy]; 3569 } 3547 } 3570 kDose[_num].addImage(ddata); 3548 kDose[_num].addImage(ddata); 3571 3549 3572 // set min./max. 3550 // set min./max. 3573 kDose[_num].setMinMax(minmax); 3551 kDose[_num].setMinMax(minmax); 3574 } 3552 } 3575 void G4GMocrenIO::getShortDoseDist(short * _d 3553 void G4GMocrenIO::getShortDoseDist(short * _data, int _z, int _num) { 3576 3554 3577 if(_data == NULL) { 3555 if(_data == NULL) { 3578 if (G4VisManager::GetVerbosity() >= G4Vis << 3556 std::cerr << "In G4GMocrenIO::getShortDoseDist(), " 3579 G4cout << "In G4GMocrenIO::getShortDose << 3557 << "first argument is NULL pointer. " 3580 << "first argument is NULL pointer. " << 3558 << "The argument must be allocated array." 3581 << "The argument must be allocated array. << 3559 << std::endl; 3582 << G4endl; << 3560 std::exit(-1); 3583 G4Exception("G4GMocrenIO::getShortDoseDis << 3584 "gMocren2002", FatalException << 3585 "Error."); << 3586 return; << 3587 } 3561 } 3588 3562 3589 int size[3]; 3563 int size[3]; 3590 kDose[_num].getSize(size); 3564 kDose[_num].getSize(size); 3591 //short * shdata = new short[size[0]*size[1 3565 //short * shdata = new short[size[0]*size[1]]; 3592 double * ddata = kDose[_num].getImage(_z); 3566 double * ddata = kDose[_num].getImage(_z); 3593 double scale = kDose[_num].getScale(); 3567 double scale = kDose[_num].getScale(); 3594 for(int xy = 0; xy < size[0]*size[1]; xy++) 3568 for(int xy = 0; xy < size[0]*size[1]; xy++) { 3595 _data[xy] = (short)(ddata[xy]/scale+0.5); 3569 _data[xy] = (short)(ddata[xy]/scale+0.5); //there is never negative value 3596 } 3570 } 3597 } 3571 } 3598 void G4GMocrenIO::getShortDoseDistMinMax(shor 3572 void G4GMocrenIO::getShortDoseDistMinMax(short _minmax[2], int _num) { 3599 double scale = kDose[_num].getScale(); 3573 double scale = kDose[_num].getScale(); 3600 double minmax[2]; 3574 double minmax[2]; 3601 kDose[_num].getMinMax(minmax); 3575 kDose[_num].getMinMax(minmax); 3602 for(int i = 0; i < 2; i++) 3576 for(int i = 0; i < 2; i++) 3603 _minmax[i] = (short)(minmax[i]/scale+0.5) 3577 _minmax[i] = (short)(minmax[i]/scale+0.5); 3604 } 3578 } 3605 // 3579 // 3606 void G4GMocrenIO::setDoseDist(double * _image 3580 void G4GMocrenIO::setDoseDist(double * _image, int _num) { 3607 3581 3608 kDose[_num].addImage(_image); 3582 kDose[_num].addImage(_image); 3609 } 3583 } 3610 double * G4GMocrenIO::getDoseDist(int _z, int 3584 double * G4GMocrenIO::getDoseDist(int _z, int _num) { 3611 3585 3612 double * image; 3586 double * image; 3613 if(isDoseEmpty()) { 3587 if(isDoseEmpty()) { 3614 image = 0; 3588 image = 0; 3615 } else { 3589 } else { 3616 image = kDose[_num].getImage(_z); 3590 image = kDose[_num].getImage(_z); 3617 } 3591 } 3618 return image; 3592 return image; 3619 } 3593 } 3620 /* 3594 /* 3621 void G4GMocrenIO::getDoseDist(double * & _i 3595 void G4GMocrenIO::getDoseDist(double * & _image, int _z, int _num) { 3622 3596 3623 G4cout << " <" << (void*)_image << "> "; << 3597 std::cout << " <" << (void*)_image << "> "; 3624 if(isDoseEmpty()) { 3598 if(isDoseEmpty()) { 3625 _image = 0; 3599 _image = 0; 3626 } else { 3600 } else { 3627 _image = kDose[_num].getImage(_z); 3601 _image = kDose[_num].getImage(_z); 3628 G4cout << " <" << (void*)_image << "> "; << 3602 std::cout << " <" << (void*)_image << "> "; 3629 G4cout << _image[100] << " "; << 3603 std::cout << _image[100] << " "; 3630 } 3604 } 3631 } 3605 } 3632 */ 3606 */ 3633 bool G4GMocrenIO::addDoseDist(std::vector<dou 3607 bool G4GMocrenIO::addDoseDist(std::vector<double *> & _image, int _num) { 3634 3608 3635 int size[3]; 3609 int size[3]; 3636 getDoseDistSize(size, _num); 3610 getDoseDistSize(size, _num); 3637 std::vector<double *> dosedist = kDose[_num 3611 std::vector<double *> dosedist = kDose[_num].getImage(); 3638 3612 3639 int nimg = size[0]*size[1]; 3613 int nimg = size[0]*size[1]; 3640 for(int z = 0; z < size[2]; z++) { 3614 for(int z = 0; z < size[2]; z++) { 3641 for(int xy = 0; xy < nimg; xy++) { 3615 for(int xy = 0; xy < nimg; xy++) { 3642 dosedist[z][xy] += _image[z][xy]; 3616 dosedist[z][xy] += _image[z][xy]; 3643 } 3617 } 3644 } 3618 } 3645 3619 3646 return true; 3620 return true; 3647 } 3621 } 3648 //void setDoseDistDensityMap(float * _map) {d 3622 //void setDoseDistDensityMap(float * _map) {doseImageDensityMap = _map;}; 3649 // set the dose distribution image displaceme 3623 // set the dose distribution image displacement 3650 void G4GMocrenIO::setDoseDistCenterPosition(f 3624 void G4GMocrenIO::setDoseDistCenterPosition(float _center[3], int _num) { 3651 3625 3652 kDose[_num].setCenterPosition(_center); 3626 kDose[_num].setCenterPosition(_center); 3653 } 3627 } 3654 void G4GMocrenIO::getDoseDistCenterPosition(f 3628 void G4GMocrenIO::getDoseDistCenterPosition(float _center[3], int _num) { 3655 3629 3656 if(isDoseEmpty()) 3630 if(isDoseEmpty()) 3657 for(int i = 0; i < 3; i++) _center[i] = 0 3631 for(int i = 0; i < 3; i++) _center[i] = 0; 3658 else 3632 else 3659 kDose[_num].getCenterPosition(_center); 3633 kDose[_num].getCenterPosition(_center); 3660 } 3634 } 3661 // set & get name of dose distribution 3635 // set & get name of dose distribution 3662 void G4GMocrenIO::setDoseDistName(std::string 3636 void G4GMocrenIO::setDoseDistName(std::string _name, int _num) { 3663 3637 3664 kDose[_num].setName(_name); 3638 kDose[_num].setName(_name); 3665 } 3639 } 3666 std::string G4GMocrenIO::getDoseDistName(int 3640 std::string G4GMocrenIO::getDoseDistName(int _num) { 3667 3641 3668 std::string name; 3642 std::string name; 3669 if(isDoseEmpty()) 3643 if(isDoseEmpty()) 3670 return name; 3644 return name; 3671 else 3645 else 3672 return kDose[_num].getName(); 3646 return kDose[_num].getName(); 3673 } 3647 } 3674 // copy dose distributions 3648 // copy dose distributions 3675 void G4GMocrenIO::copyDoseDist(std::vector<cl 3649 void G4GMocrenIO::copyDoseDist(std::vector<class GMocrenDataPrimitive<double> > & _dose) { 3676 std::vector<class GMocrenDataPrimitive<doub 3650 std::vector<class GMocrenDataPrimitive<double> >::iterator itr; 3677 for(itr = kDose.begin(); itr != kDose.end() 3651 for(itr = kDose.begin(); itr != kDose.end(); itr++) { 3678 _dose.push_back(*itr); 3652 _dose.push_back(*itr); 3679 } 3653 } 3680 } 3654 } 3681 // merge two dose distributions 3655 // merge two dose distributions 3682 bool G4GMocrenIO::mergeDoseDist(std::vector<c 3656 bool G4GMocrenIO::mergeDoseDist(std::vector<class GMocrenDataPrimitive<double> > & _dose) { 3683 if(kDose.size() != _dose.size()) { 3657 if(kDose.size() != _dose.size()) { 3684 if (G4VisManager::GetVerbosity() >= G4Vis << 3658 std::cerr << "G4GMocrenIO::mergeDoseDist() : Error" << std::endl; 3685 G4cout << "G4GMocrenIO::mergeDoseDist() << 3659 std::cerr << " Unable to merge the dose distributions,"<< std::endl; 3686 G4cout << " Unable to merge the dose << 3660 std::cerr << " because of different size of dose maps."<< std::endl; 3687 G4cout << " because of different size << 3688 } << 3689 return false; 3661 return false; 3690 } 3662 } 3691 3663 3692 int num = (int)kDose.size(); << 3664 int num = kDose.size(); 3693 std::vector<class GMocrenDataPrimitive<doub 3665 std::vector<class GMocrenDataPrimitive<double> >::iterator itr1 = kDose.begin(); 3694 std::vector<class GMocrenDataPrimitive<doub 3666 std::vector<class GMocrenDataPrimitive<double> >::iterator itr2 = _dose.begin(); 3695 for(int i = 0; i < num; i++, itr1++, itr2++ 3667 for(int i = 0; i < num; i++, itr1++, itr2++) { 3696 if (G4VisManager::GetVerbosity() >= G4Vis << 3668 if(kVerbose > 0) std::cerr << "merged dose distribution [" << i << "]" << std::endl; 3697 if(kVerbose > 0) << 3698 G4cout << "merged dose distribution [" << i << 3699 *itr1 += *itr2; 3669 *itr1 += *itr2; 3700 } 3670 } 3701 3671 3702 return true; 3672 return true; 3703 } 3673 } 3704 // 3674 // 3705 void G4GMocrenIO::clearDoseDistAll() { 3675 void G4GMocrenIO::clearDoseDistAll() { 3706 3676 3707 if(!isDoseEmpty()) { 3677 if(!isDoseEmpty()) { 3708 for(int i = 0; i < getNumDoseDist(); i++) 3678 for(int i = 0; i < getNumDoseDist(); i++) { 3709 kDose[i].clear(); 3679 kDose[i].clear(); 3710 } 3680 } 3711 kDose.clear(); 3681 kDose.clear(); 3712 } 3682 } 3713 } 3683 } 3714 // 3684 // 3715 bool G4GMocrenIO::isDoseEmpty() { 3685 bool G4GMocrenIO::isDoseEmpty() { 3716 if(kDose.empty()) { 3686 if(kDose.empty()) { 3717 //if (G4VisManager::GetVerbosity() >= G4V << 3687 //std::cerr << "!!! dose distribution data is empty." << std::endl; 3718 // G4cout << "!!! dose distribution data << 3719 return true; 3688 return true; 3720 } else { 3689 } else { 3721 return false; 3690 return false; 3722 } 3691 } 3723 } 3692 } 3724 3693 3725 // 3694 // 3726 void G4GMocrenIO::calcDoseDistScale() { 3695 void G4GMocrenIO::calcDoseDistScale() { 3727 3696 3728 double scale; 3697 double scale; 3729 double minmax[2]; 3698 double minmax[2]; 3730 3699 3731 for(int i = 0; i < (int)kDose.size(); i++) 3700 for(int i = 0; i < (int)kDose.size(); i++) { 3732 kDose[i].getMinMax(minmax); 3701 kDose[i].getMinMax(minmax); 3733 scale = minmax[1]/DOSERANGE; 3702 scale = minmax[1]/DOSERANGE; 3734 kDose[i].setScale(scale); 3703 kDose[i].setScale(scale); 3735 } 3704 } 3736 } 3705 } 3737 3706 3738 3707 3739 //----- RoI -----// 3708 //----- RoI -----// 3740 3709 3741 // add one RoI data 3710 // add one RoI data 3742 void G4GMocrenIO::newROI() { 3711 void G4GMocrenIO::newROI() { 3743 GMocrenDataPrimitive<short> roiData; 3712 GMocrenDataPrimitive<short> roiData; 3744 kRoi.push_back(roiData); 3713 kRoi.push_back(roiData); 3745 } 3714 } 3746 int G4GMocrenIO::getNumROI() { 3715 int G4GMocrenIO::getNumROI() { 3747 return (int)kRoi.size(); 3716 return (int)kRoi.size(); 3748 } 3717 } 3749 3718 3750 // set/get the ROI image scale 3719 // set/get the ROI image scale 3751 void G4GMocrenIO::setROIScale(double & _scale 3720 void G4GMocrenIO::setROIScale(double & _scale, int _num) { 3752 3721 3753 kRoi[_num].setScale(_scale); 3722 kRoi[_num].setScale(_scale); 3754 } 3723 } 3755 double G4GMocrenIO::getROIScale(int _num) { 3724 double G4GMocrenIO::getROIScale(int _num) { 3756 3725 3757 if(isROIEmpty()) 3726 if(isROIEmpty()) 3758 return 0.; 3727 return 0.; 3759 else 3728 else 3760 return kRoi[_num].getScale(); 3729 return kRoi[_num].getScale(); 3761 } 3730 } 3762 // set the ROI image 3731 // set the ROI image 3763 void G4GMocrenIO::setROI(short * _image, int 3732 void G4GMocrenIO::setROI(short * _image, int _num) { 3764 3733 3765 kRoi[_num].addImage(_image); 3734 kRoi[_num].addImage(_image); 3766 } 3735 } 3767 short * G4GMocrenIO::getROI(int _z, int _num) 3736 short * G4GMocrenIO::getROI(int _z, int _num) { 3768 3737 3769 if(isROIEmpty()) 3738 if(isROIEmpty()) 3770 return 0; 3739 return 0; 3771 else 3740 else 3772 return kRoi[_num].getImage(_z); 3741 return kRoi[_num].getImage(_z); 3773 } 3742 } 3774 // set/get the ROI image size 3743 // set/get the ROI image size 3775 void G4GMocrenIO::setROISize(int _size[3], in 3744 void G4GMocrenIO::setROISize(int _size[3], int _num) { 3776 3745 3777 return kRoi[_num].setSize(_size); 3746 return kRoi[_num].setSize(_size); 3778 } 3747 } 3779 void G4GMocrenIO::getROISize(int _size[3], in 3748 void G4GMocrenIO::getROISize(int _size[3], int _num) { 3780 3749 3781 if(isROIEmpty()) 3750 if(isROIEmpty()) 3782 for(int i = 0; i < 3; i++) _size[i] = 0; 3751 for(int i = 0; i < 3; i++) _size[i] = 0; 3783 else 3752 else 3784 return kRoi[_num].getSize(_size); 3753 return kRoi[_num].getSize(_size); 3785 } 3754 } 3786 // set/get the ROI image min. and max. 3755 // set/get the ROI image min. and max. 3787 void G4GMocrenIO::setROIMinMax(short _minmax[ 3756 void G4GMocrenIO::setROIMinMax(short _minmax[2], int _num) { 3788 3757 3789 kRoi[_num].setMinMax(_minmax); 3758 kRoi[_num].setMinMax(_minmax); 3790 } 3759 } 3791 void G4GMocrenIO::getROIMinMax(short _minmax[ 3760 void G4GMocrenIO::getROIMinMax(short _minmax[2], int _num) { 3792 3761 3793 if(isROIEmpty()) 3762 if(isROIEmpty()) 3794 for(int i = 0; i < 2; i++) _minmax[i] = 0 3763 for(int i = 0; i < 2; i++) _minmax[i] = 0; 3795 else 3764 else 3796 kRoi[_num].getMinMax(_minmax); 3765 kRoi[_num].getMinMax(_minmax); 3797 } 3766 } 3798 // set/get the ROI image displacement 3767 // set/get the ROI image displacement 3799 void G4GMocrenIO::setROICenterPosition(float 3768 void G4GMocrenIO::setROICenterPosition(float _center[3], int _num) { 3800 3769 3801 kRoi[_num].setCenterPosition(_center); 3770 kRoi[_num].setCenterPosition(_center); 3802 } 3771 } 3803 void G4GMocrenIO::getROICenterPosition(float 3772 void G4GMocrenIO::getROICenterPosition(float _center[3], int _num) { 3804 3773 3805 if(isROIEmpty()) 3774 if(isROIEmpty()) 3806 for(int i = 0; i < 3; i++) _center[i] = 0 3775 for(int i = 0; i < 3; i++) _center[i] = 0; 3807 else 3776 else 3808 kRoi[_num].getCenterPosition(_center); 3777 kRoi[_num].getCenterPosition(_center); 3809 } 3778 } 3810 // 3779 // 3811 void G4GMocrenIO::clearROIAll() { 3780 void G4GMocrenIO::clearROIAll() { 3812 3781 3813 if(!isROIEmpty()) { 3782 if(!isROIEmpty()) { 3814 for(int i = 0; i < getNumROI(); i++) { 3783 for(int i = 0; i < getNumROI(); i++) { 3815 kRoi[i].clear(); 3784 kRoi[i].clear(); 3816 } 3785 } 3817 kRoi.clear(); 3786 kRoi.clear(); 3818 } 3787 } 3819 } 3788 } 3820 // 3789 // 3821 bool G4GMocrenIO::isROIEmpty() { 3790 bool G4GMocrenIO::isROIEmpty() { 3822 if(kRoi.empty()) { 3791 if(kRoi.empty()) { 3823 //if (G4VisManager::GetVerbosity() >= G4V << 3792 //std::cerr << "!!! ROI data is empty." << std::endl; 3824 // G4cout << "!!! ROI data is empty." << << 3825 return true; 3793 return true; 3826 } else { 3794 } else { 3827 return false; 3795 return false; 3828 } 3796 } 3829 } 3797 } 3830 3798 3831 3799 3832 3800 3833 //----- Track information -----// 3801 //----- Track information -----// 3834 3802 3835 int G4GMocrenIO::getNumTracks() { 3803 int G4GMocrenIO::getNumTracks() { 3836 return (int)kSteps.size(); 3804 return (int)kSteps.size(); 3837 } 3805 } 3838 int G4GMocrenIO::getNumTracks4() { 3806 int G4GMocrenIO::getNumTracks4() { 3839 return (int)kTracks.size(); 3807 return (int)kTracks.size(); 3840 } 3808 } 3841 void G4GMocrenIO::addTrack(float * _tracks) { 3809 void G4GMocrenIO::addTrack(float * _tracks) { 3842 kSteps.push_back(_tracks); 3810 kSteps.push_back(_tracks); 3843 } 3811 } 3844 void G4GMocrenIO::setTracks(std::vector<float 3812 void G4GMocrenIO::setTracks(std::vector<float *> & _tracks) { 3845 kSteps = _tracks; 3813 kSteps = _tracks; 3846 } 3814 } 3847 std::vector<float *> & G4GMocrenIO::getTracks 3815 std::vector<float *> & G4GMocrenIO::getTracks() { 3848 return kSteps; 3816 return kSteps; 3849 } 3817 } 3850 void G4GMocrenIO::addTrackColor(unsigned char 3818 void G4GMocrenIO::addTrackColor(unsigned char * _colors) { 3851 kStepColors.push_back(_colors); 3819 kStepColors.push_back(_colors); 3852 } 3820 } 3853 void G4GMocrenIO::setTrackColors(std::vector< 3821 void G4GMocrenIO::setTrackColors(std::vector<unsigned char *> & _trackColors) { 3854 kStepColors = _trackColors; 3822 kStepColors = _trackColors; 3855 } 3823 } 3856 std::vector<unsigned char *> & G4GMocrenIO::g 3824 std::vector<unsigned char *> & G4GMocrenIO::getTrackColors() { 3857 return kStepColors; 3825 return kStepColors; 3858 } 3826 } 3859 void G4GMocrenIO::copyTracks(std::vector<floa 3827 void G4GMocrenIO::copyTracks(std::vector<float *> & _tracks, 3860 std::vector<unsigned char *> & _ 3828 std::vector<unsigned char *> & _colors) { 3861 std::vector<float *>::iterator titr; 3829 std::vector<float *>::iterator titr; 3862 for(titr = kSteps.begin(); titr != kSteps.e 3830 for(titr = kSteps.begin(); titr != kSteps.end(); titr++) { 3863 float * pts = new float[6]; 3831 float * pts = new float[6]; 3864 for(int i = 0; i < 6; i++) { 3832 for(int i = 0; i < 6; i++) { 3865 pts[i] = (*titr)[i]; 3833 pts[i] = (*titr)[i]; 3866 } 3834 } 3867 _tracks.push_back(pts); 3835 _tracks.push_back(pts); 3868 } 3836 } 3869 3837 3870 std::vector<unsigned char *>::iterator citr 3838 std::vector<unsigned char *>::iterator citr; 3871 for(citr = kStepColors.begin(); citr != kSt 3839 for(citr = kStepColors.begin(); citr != kStepColors.end(); citr++) { 3872 unsigned char * pts = new unsigned char[3 3840 unsigned char * pts = new unsigned char[3]; 3873 for(int i = 0; i < 3; i++) { 3841 for(int i = 0; i < 3; i++) { 3874 pts[i] = (*citr)[i]; 3842 pts[i] = (*citr)[i]; 3875 } 3843 } 3876 _colors.push_back(pts); 3844 _colors.push_back(pts); 3877 } 3845 } 3878 } 3846 } 3879 void G4GMocrenIO::mergeTracks(std::vector<flo 3847 void G4GMocrenIO::mergeTracks(std::vector<float *> & _tracks, 3880 std::vector<unsigned char *> & _color 3848 std::vector<unsigned char *> & _colors) { 3881 std::vector<float *>::iterator titr; 3849 std::vector<float *>::iterator titr; 3882 for(titr = _tracks.begin(); titr != _tracks 3850 for(titr = _tracks.begin(); titr != _tracks.end(); titr++) { 3883 addTrack(*titr); 3851 addTrack(*titr); 3884 } 3852 } 3885 3853 3886 std::vector<unsigned char *>::iterator citr 3854 std::vector<unsigned char *>::iterator citr; 3887 for(citr = _colors.begin(); citr != _colors 3855 for(citr = _colors.begin(); citr != _colors.end(); citr++) { 3888 addTrackColor(*citr); 3856 addTrackColor(*citr); 3889 } 3857 } 3890 } 3858 } 3891 void G4GMocrenIO::addTrack(std::vector<float 3859 void G4GMocrenIO::addTrack(std::vector<float *> & _steps, unsigned char _color[3]) { 3892 3860 3893 std::vector<float *>::iterator itr = _steps 3861 std::vector<float *>::iterator itr = _steps.begin(); 3894 std::vector<struct GMocrenTrack::Step> st 3862 std::vector<struct GMocrenTrack::Step> steps; 3895 for(; itr != _steps.end(); itr++) { 3863 for(; itr != _steps.end(); itr++) { 3896 struct GMocrenTrack::Step step; 3864 struct GMocrenTrack::Step step; 3897 for(int i = 0; i < 3; i++) { 3865 for(int i = 0; i < 3; i++) { 3898 step.startPoint[i] = (*itr)[i]; 3866 step.startPoint[i] = (*itr)[i]; 3899 step.endPoint[i] = (*itr)[i+3]; 3867 step.endPoint[i] = (*itr)[i+3]; 3900 } 3868 } 3901 steps.push_back(step); 3869 steps.push_back(step); 3902 } 3870 } 3903 GMocrenTrack track; 3871 GMocrenTrack track; 3904 track.setTrack(steps); 3872 track.setTrack(steps); 3905 track.setColor(_color); 3873 track.setColor(_color); 3906 kTracks.push_back(track); 3874 kTracks.push_back(track); 3907 3875 3908 } 3876 } 3909 void G4GMocrenIO::getTrack(int _num, std::vec 3877 void G4GMocrenIO::getTrack(int _num, std::vector<float *> & _steps, 3910 std::vector<unsigned char *> & _co 3878 std::vector<unsigned char *> & _color) { 3911 3879 3912 if(_num > (int)kTracks.size()) { 3880 if(_num > (int)kTracks.size()) { 3913 if (G4VisManager::GetVerbosity() >= G4Vis << 3881 std::cerr << "ERROR in getTrack() : " << std::endl; 3914 G4cout << "ERROR in getTrack() : " << G << 3882 std::exit(-1); 3915 G4Exception("G4GMocrenIO::getTrack()", << 3916 "gMocren2003", FatalException << 3917 "Error."); << 3918 } 3883 } 3919 unsigned char * color = new unsigned char[3 3884 unsigned char * color = new unsigned char[3]; 3920 kTracks[_num].getColor(color); 3885 kTracks[_num].getColor(color); 3921 _color.push_back(color); 3886 _color.push_back(color); 3922 3887 3923 // steps 3888 // steps 3924 int nsteps = kTracks[_num].getNumberOfSteps 3889 int nsteps = kTracks[_num].getNumberOfSteps(); 3925 for(int isteps = 0; isteps < nsteps; isteps << 3890 for(int ns = 0; ns < nsteps; ns++) { 3926 float * stepPoints = new float[6]; 3891 float * stepPoints = new float[6]; 3927 kTracks[_num].getStep(stepPoints[0], step 3892 kTracks[_num].getStep(stepPoints[0], stepPoints[1], stepPoints[2], 3928 stepPoints[3], stepPoints[4], stepPoi 3893 stepPoints[3], stepPoints[4], stepPoints[5], 3929 isteps); << 3894 ns); 3930 _steps.push_back(stepPoints); 3895 _steps.push_back(stepPoints); 3931 } 3896 } 3932 } 3897 } 3933 3898 3934 void G4GMocrenIO::translateTracks(std::vector 3899 void G4GMocrenIO::translateTracks(std::vector<float> & _translate) { 3935 std::vector<class GMocrenTrack>::iterator i 3900 std::vector<class GMocrenTrack>::iterator itr = kTracks.begin(); 3936 for(; itr != kTracks.end(); itr++) { 3901 for(; itr != kTracks.end(); itr++) { 3937 itr->translate(_translate); 3902 itr->translate(_translate); 3938 } 3903 } 3939 } 3904 } 3940 3905 3941 3906 3942 3907 3943 3908 3944 //----- Detector information -----// 3909 //----- Detector information -----// 3945 int G4GMocrenIO::getNumberOfDetectors() { 3910 int G4GMocrenIO::getNumberOfDetectors() { 3946 return (int)kDetectors.size(); 3911 return (int)kDetectors.size(); 3947 } 3912 } 3948 void G4GMocrenIO::addDetector(std::string & _ 3913 void G4GMocrenIO::addDetector(std::string & _name, 3949 std::vector<float *> & _det, 3914 std::vector<float *> & _det, 3950 unsigned char _color[3]) { 3915 unsigned char _color[3]) { 3951 3916 3952 std::vector<float *>::iterator itr = _det 3917 std::vector<float *>::iterator itr = _det.begin(); 3953 std::vector<struct GMocrenDetector::Edge> 3918 std::vector<struct GMocrenDetector::Edge> edges; 3954 for(; itr != _det.end(); itr++) { 3919 for(; itr != _det.end(); itr++) { 3955 struct GMocrenDetector::Edge edge; 3920 struct GMocrenDetector::Edge edge; 3956 for(int i = 0; i < 3; i++) { 3921 for(int i = 0; i < 3; i++) { 3957 edge.startPoint[i] = (*itr)[i]; 3922 edge.startPoint[i] = (*itr)[i]; 3958 edge.endPoint[i] = (*itr)[i+3]; 3923 edge.endPoint[i] = (*itr)[i+3]; 3959 } 3924 } 3960 edges.push_back(edge); 3925 edges.push_back(edge); 3961 } 3926 } 3962 GMocrenDetector detector; 3927 GMocrenDetector detector; 3963 detector.setDetector(edges); 3928 detector.setDetector(edges); 3964 detector.setColor(_color); 3929 detector.setColor(_color); 3965 detector.setName(_name); 3930 detector.setName(_name); 3966 kDetectors.push_back(detector); 3931 kDetectors.push_back(detector); 3967 3932 3968 } 3933 } 3969 3934 3970 void G4GMocrenIO::getDetector(int _num, std:: 3935 void G4GMocrenIO::getDetector(int _num, std::vector<float *> & _edges, 3971 std::vector<unsigned char *> & _color 3936 std::vector<unsigned char *> & _color, 3972 std::string & _detName) { 3937 std::string & _detName) { 3973 3938 3974 if(_num > (int)kDetectors.size()) { 3939 if(_num > (int)kDetectors.size()) { 3975 if (G4VisManager::GetVerbosity() >= G4Vis << 3940 std::cerr << "ERROR in getDetector() : " << std::endl; 3976 G4cout << "ERROR in getDetector() : " < << 3941 std::exit(-1); 3977 << 3978 G4Exception("G4GMocrenIO::getDetector()", << 3979 "gMocren2004", FatalException << 3980 "Error."); << 3981 } 3942 } 3982 3943 3983 _detName = kDetectors[_num].getName(); 3944 _detName = kDetectors[_num].getName(); 3984 3945 3985 unsigned char * color = new unsigned char[3 3946 unsigned char * color = new unsigned char[3]; 3986 kDetectors[_num].getColor(color); 3947 kDetectors[_num].getColor(color); 3987 _color.push_back(color); 3948 _color.push_back(color); 3988 3949 3989 // edges 3950 // edges 3990 int nedges = kDetectors[_num].getNumberOfEd 3951 int nedges = kDetectors[_num].getNumberOfEdges(); 3991 for(int ne = 0; ne < nedges; ne++) { 3952 for(int ne = 0; ne < nedges; ne++) { 3992 float * edgePoints = new float[6]; 3953 float * edgePoints = new float[6]; 3993 kDetectors[_num].getEdge(edgePoints[0], e 3954 kDetectors[_num].getEdge(edgePoints[0], edgePoints[1], edgePoints[2], 3994 edgePoints[3], edgePoints[4], edge 3955 edgePoints[3], edgePoints[4], edgePoints[5], 3995 ne); 3956 ne); 3996 _edges.push_back(edgePoints); 3957 _edges.push_back(edgePoints); 3997 } 3958 } 3998 } 3959 } 3999 3960 4000 void G4GMocrenIO::translateDetector(std::vect 3961 void G4GMocrenIO::translateDetector(std::vector<float> & _translate) { 4001 std::vector<class GMocrenDetector>::iterato 3962 std::vector<class GMocrenDetector>::iterator itr = kDetectors.begin(); 4002 for(; itr != kDetectors.end(); itr++) { 3963 for(; itr != kDetectors.end(); itr++) { 4003 itr->translate(_translate); 3964 itr->translate(_translate); 4004 } 3965 } 4005 } 3966 } 4006 3967 4007 // endian conversion 3968 // endian conversion 4008 template <typename T> 3969 template <typename T> 4009 void G4GMocrenIO::convertEndian(char * _val, 3970 void G4GMocrenIO::convertEndian(char * _val, T & _rval) { 4010 3971 4011 if((kLittleEndianOutput && !kLittleEndianIn 3972 if((kLittleEndianOutput && !kLittleEndianInput) || // big endian 4012 (!kLittleEndianOutput && kLittleEndianIn 3973 (!kLittleEndianOutput && kLittleEndianInput)) { // little endian 4013 3974 4014 const int SIZE = sizeof(_rval); 3975 const int SIZE = sizeof(_rval); 4015 char ctemp; 3976 char ctemp; 4016 for(int i = 0; i < SIZE/2; i++) { 3977 for(int i = 0; i < SIZE/2; i++) { 4017 ctemp = _val[i]; 3978 ctemp = _val[i]; 4018 _val[i] = _val[SIZE - 1 - i]; 3979 _val[i] = _val[SIZE - 1 - i]; 4019 _val[SIZE - 1 - i] = ctemp; 3980 _val[SIZE - 1 - i] = ctemp; 4020 } 3981 } 4021 } 3982 } 4022 _rval = *(T *)_val; 3983 _rval = *(T *)_val; 4023 } 3984 } 4024 3985 4025 // inversion of byte order 3986 // inversion of byte order 4026 template <typename T> 3987 template <typename T> 4027 void G4GMocrenIO::invertByteOrder(char * _val 3988 void G4GMocrenIO::invertByteOrder(char * _val, T & _rval) { 4028 3989 4029 const int SIZE = sizeof(_rval); 3990 const int SIZE = sizeof(_rval); 4030 //char * cval = new char[SIZE]; 3991 //char * cval = new char[SIZE]; 4031 union { 3992 union { 4032 char cu[16]; 3993 char cu[16]; 4033 T tu; 3994 T tu; 4034 } uni; 3995 } uni; 4035 for(int i = 0; i < SIZE; i++) { 3996 for(int i = 0; i < SIZE; i++) { 4036 uni.cu[i] = _val[SIZE-1-i]; 3997 uni.cu[i] = _val[SIZE-1-i]; 4037 //cval[i] = _val[SIZE-i-1]; 3998 //cval[i] = _val[SIZE-i-1]; 4038 } 3999 } 4039 //_rval = *(T *)cval; 4000 //_rval = *(T *)cval; 4040 _rval = uni.tu; 4001 _rval = uni.tu; 4041 //delete [] cval; 4002 //delete [] cval; 4042 } 4003 } 4043 4004 4044 //----- kVerbose information -----// 4005 //----- kVerbose information -----// 4045 void G4GMocrenIO::setVerboseLevel(int _level) 4006 void G4GMocrenIO::setVerboseLevel(int _level) { 4046 kVerbose = _level; 4007 kVerbose = _level; 4047 } 4008 } 4048 4009 4049 4010