Geant4  10.02.p01
G4GMocrenFileSceneHandler.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4GMocrenFileSceneHandler.cc 88772 2015-03-09 12:42:03Z gcosmo $
28 //
29 //
30 // Created: Mar. 31, 2009 Akinori Kimura
31 // Sep. 22, 2009 Akinori Kimura : modify and fix code to support
32 // PrimitiveScorers and clean up
33 //
34 // GMocrenFile scene handler
35 
36 
37 //----- header files
38 #include <fstream>
39 #include <cstdlib>
40 #include <cstring>
41 #include <sstream>
42 
43 #include "globals.hh"
44 #include "G4PhysicalConstants.hh"
45 #include "G4SystemOfUnits.hh"
46 #include "G4VisManager.hh"
47 
48 #include "G4GMocrenFile.hh"
50 #include "G4GMocrenFileViewer.hh"
51 #include "G4Point3D.hh"
52 #include "G4VisAttributes.hh"
53 #include "G4Scene.hh"
54 #include "G4Transform3D.hh"
55 #include "G4Polyhedron.hh"
56 #include "G4Box.hh"
57 #include "G4Cons.hh"
58 #include "G4Polyline.hh"
59 #include "G4Trd.hh"
60 #include "G4Tubs.hh"
61 #include "G4Trap.hh"
62 #include "G4Torus.hh"
63 #include "G4Sphere.hh"
64 #include "G4Para.hh"
65 #include "G4Text.hh"
66 #include "G4Circle.hh"
67 #include "G4Square.hh"
68 #include "G4VPhysicalVolume.hh"
69 #include "G4PhysicalVolumeModel.hh"
70 #include "G4LogicalVolume.hh"
71 #include "G4Material.hh"
72 
73 #include "G4VPVParameterisation.hh"
75 #include "G4VisTrajContext.hh"
76 #include "G4TrajectoriesModel.hh"
77 #include "G4VTrajectoryModel.hh"
79 #include "G4HitsModel.hh"
80 #include "G4GMocrenMessenger.hh"
81 //#include "G4PSHitsModel.hh"
82 #include "G4GMocrenIO.hh"
84 #include "G4GMocrenTouchable.hh"
87 
88 #include "G4ScoringManager.hh"
89 #include "G4ScoringBox.hh"
90 
91 //----- constants
92 const char GDD_FILE_HEADER [] = "g4_";
93 const char DEFAULT_GDD_FILE_NAME[] = "g4_00.gdd";
94 
95 const G4int FR_MAX_FILE_NUM = 100 ;
96 const G4int MAX_NUM_TRAJECTORIES = 100000;
97 
98 //-- for a debugging
99 const G4bool GFDEBUG = false;
100 const G4bool GFDEBUG_TRK = false;//true;
101 const G4bool GFDEBUG_HIT = false;//true;
102 const G4bool GFDEBUG_DIGI = false;//true;
103 const G4int GFDEBUG_DET = 0; // 0: false
104 
106 // static variables //
108 
109 //----- static variables
111 
113 // Driver-dependent part //
115 
116 
117 //----- G4GMocrenFileSceneHandler, constructor
119  G4GMocrenMessenger & messenger,
120  const G4String& name)
121  : G4VSceneHandler(system, kSceneIdCount++, name),
122  kSystem(system),
123  kMessenger(messenger),
124  kgMocrenIO(new G4GMocrenIO()),
125  kbSetModalityVoxelSize(false),
126  kbModelingTrajectory(false),
127 // kGddDest(0),
128  kFlagInModeling(false),
129  kFlagSaving_g4_gdd(false),
130  kFlagParameterization(0),
131  kFlagProcessedInteractiveScorer(false) {
132 
133  // g4.gdd filename and its directory
134  if(std::getenv("G4GMocrenFile_DEST_DIR") == NULL) {
135  kGddDestDir[0] = '\0';
136  //std::strcpy(kGddDestDir , ""); // output dir
137  //std::strcpy(kGddFileName, DEFAULT_GDD_FILE_NAME); // filename
138  std::strncpy(kGddFileName, DEFAULT_GDD_FILE_NAME,
139  std::strlen(DEFAULT_GDD_FILE_NAME)+1); // filename
140  } else {
141  const char * env = std::getenv("G4GMocrenFile_DEST_DIR");
142  int len = std::strlen(env);
143  if(len > 256) {
144  G4Exception("G4GMocrenFileSceneHandler::G4GMocrenFileSceneHandler(*)",
145  "gMocren1000", FatalException,
146  "Invalid length of string set in G4GMocrenFile_DEST_DIR");
147  }
148  std::strncpy(kGddDestDir, env, len+1); // output dir
149  std::strncpy(kGddFileName, DEFAULT_GDD_FILE_NAME,
150  std::strlen(DEFAULT_GDD_FILE_NAME)+1); // filename
151  }
152 
153  // maximum number of g4.gdd files in the dest directory
154  kMaxFileNum = FR_MAX_FILE_NUM ; // initialization
155  if ( std::getenv( "G4GMocrenFile_MAX_FILE_NUM" ) != NULL ) {
156  char * pcFileNum = getenv("G4GMocrenFile_MAX_FILE_NUM");
157  char c10FileNum[10];
158  std::strncpy(c10FileNum, pcFileNum, 10);
159  kMaxFileNum = std::atoi(c10FileNum);
160 
161  } else {
163  }
164  if( kMaxFileNum < 1 ) { kMaxFileNum = 1 ; }
165 
167 
168 }
169 
170 
171 //----- G4GMocrenFileSceneHandler, destructor
173 {
175  G4cout << "***** ~G4GMocrenFileSceneHandler" << G4endl;
176 
177  if(kGddDest) {
178  //----- End of modeling
179  // close g4.gdd
180  GFEndModeling();
181  }
182  if(kgMocrenIO != NULL) delete kgMocrenIO;
183 
184 }
185 
186 //----- initialize all parameters
188 
189  kbSetModalityVoxelSize = false;
190 
191  for(G4int i = 0; i < 3; i++) {
192  kModalitySize[i] = 0;
193  kNestedVolumeDimension[i] = 0;
194  kNestedVolumeDirAxis[i] = -1;
195  }
196 
197  // delete kgMocrenIO;
198 
199 }
200 
201 //-----
203 {
204  // g4_00.gdd, g4_01.gdd, ..., g4_MAX_FILE_INDEX.gdd
205  const G4int MAX_FILE_INDEX = kMaxFileNum - 1 ;
206 
207  // dest directory (null if no environmental variables is set)
208  std::strncpy(kGddFileName, kGddDestDir, std::strlen(kGddDestDir)+1);
209 
210  // create full path name (default)
211  std::strncat ( kGddFileName, DEFAULT_GDD_FILE_NAME, std::strlen(DEFAULT_GDD_FILE_NAME));
212 
213  // Automatic updation of file names
214  static G4int currentNumber = 0;
215  for( G4int i = currentNumber ; i < kMaxFileNum ; i++) {
216 
217  // Message in the final execution
218  if( i == MAX_FILE_INDEX )
219  {
221  G4cout << "===========================================" << G4endl;
222  G4cout << "WARNING MESSAGE from GMocrenFile driver: " << G4endl;
223  G4cout << " This file name is the final one in the " << G4endl;
224  G4cout << " automatic updation of the output file name." << G4endl;
225  G4cout << " You may overwrite existing files, i.e. " << G4endl;
226  G4cout << " g4_XX.gdd." << G4endl;
227  G4cout << "===========================================" << G4endl;
228  }
229  }
230 
231  // re-determine file name as G4GMocrenFile_DEST_DIR/g4_XX.gdd
232  if( i >= 0 && i <= 9 ) {
233  std::sprintf( kGddFileName, "%s%s%s%d.gdd" , kGddDestDir, GDD_FILE_HEADER, "0", i );
234  } else {
235  std::sprintf( kGddFileName, "%s%s%d.gdd" , kGddDestDir, GDD_FILE_HEADER, i );
236  }
237 
238  // check validity of the file name
239  std::ifstream fin(kGddFileName);
240  if(GFDEBUG)
241  G4cout << "FILEOPEN: " << i << " : " << kGddFileName << fin.fail()
242  << G4endl;
243  if(!fin) {
244  // new file
245  fin.close();
246  currentNumber = i+1;
247  break;
248  } else {
249  // already exists (try next)
250  fin.close();
251  }
252 
253  } // for
254 
255  G4cout << "======================================================================" << G4endl;
256  G4cout << "Output file: " << kGddFileName << G4endl;
257  G4cout << "Destination directory (current dir if NULL): " << kGddDestDir << G4endl;
258  G4cout << "Maximum number of files in the destination directory: " << kMaxFileNum << G4endl;
259  G4cout << "Note:" << G4endl;
260  G4cout << " * The maximum number is customizable as: " << G4endl;
261  G4cout << " % setenv G4GMocrenFile_MAX_FILE_NUM number " << G4endl;
262  G4cout << " * The destination directory is customizable as:" << G4endl;
263  G4cout << " % setenv G4GMocrenFile_DEST_DIR dir_name/ " << G4endl;
264  G4cout << " ** Do not forget \"/\" at the end of the dir_name, e.g. \"./tmp/\"." << G4endl;
265  //G4cout << " dir_name, e.g. \"./tmp/\"." << G4endl;
266  G4cout << G4endl;
267  G4cout << "Maximum number of trajectories is set to " << MAX_NUM_TRAJECTORIES << "."<< G4endl;
268  G4cout << "======================================================================" << G4endl;
269 
270 } // G4GMocrenFileSceneHandler::SetGddFileName()
271 
272 
273 //-----
275 {
277  G4cout << "***** BeginSavingGdd (called)" << G4endl;
278 
279  if( !IsSavingGdd() ) {
280 
282  G4cout << "***** (started) " ;
283  G4cout << "(open g4.gdd, ##)" << G4endl;
284  }
285 
286  SetGddFileName() ; // result set to kGddFileName
287  kFlagSaving_g4_gdd = true;
288 
289 
291  short minmax[2];
292  minmax[0] = ctdens.GetMinCT();
293  minmax[1] = ctdens.GetMaxCT();
295  std::vector<G4float> map;
296  G4float dens;
297  for(G4int i = minmax[0]; i <= minmax[1]; i++) {
298  dens = ctdens.GetDensity(i);
299  map.push_back(dens);
300  }
302 
303  /*
304  G4String fname = "modality-map.dat";
305  std::ifstream ifile(fname);
306  if(ifile) {
307  short minmax[2];
308  ifile >> minmax[0] >> minmax[1];
309  kgMocrenIO->setModalityImageMinMax(minmax);
310  std::vector<G4float> map;
311  G4float dens;
312  for(G4int i = minmax[0]; i <= minmax[1]; i++) {
313  ifile >> dens;
314  map.push_back(dens);
315  }
316  kgMocrenIO->setModalityImageDensityMap(map);
317 
318  } else {
319  G4cout << "cann't open the file : " << fname << G4endl;
320  }
321  */
322 
323  // mesh size
324  //kMessenger.getNoVoxels(kModalitySize[0], kModalitySize[1], kModalitySize[2]);
325  //kgMocrenIO->setModalityImageSize(kModalitySize);
326 
327  // initializations
328  //kgMocrenIO->clearModalityImage();
333  std::vector<Detector>::iterator itr = kDetectors.begin();
334  for(; itr != kDetectors.end(); itr++) {
335  itr->clear();
336  }
337  kDetectors.clear();
338 
339  kNestedHitsList.clear();
340  kNestedVolumeNames.clear();
341 
342  }
343 }
344 
346 {
348  G4cout << "***** EndSavingGdd (called)" << G4endl;
349 
350  if(IsSavingGdd()) {
352  G4cout << "***** (started) (close "
353  << kGddFileName << ")" << G4endl;
354 
355  if(kGddDest) kGddDest.close();
356  kFlagSaving_g4_gdd = false;
357 
358  std::map<Index3D, G4float>::iterator itr = kNestedModality.begin();
359  G4int xmax=0, ymax=0, zmax=0;
360  for(; itr != kNestedModality.end(); itr++) {
361  if(itr->first.x > xmax) xmax = itr->first.x;
362  if(itr->first.y > ymax) ymax = itr->first.y;
363  if(itr->first.z > zmax) zmax = itr->first.z;
364  }
365  // mesh size
366  kModalitySize[0] = xmax+1;
367  kModalitySize[1] = ymax+1;
368  kModalitySize[2] = zmax+1;
370  if(GFDEBUG) G4cout << "gMocren-file driver : modality size : "
371  << kModalitySize[0] << " x "
372  << kModalitySize[1] << " x "
373  << kModalitySize[2] << G4endl;
374 
375  G4int nxy = kModalitySize[0]*kModalitySize[1];
376  //std::map<G4int, G4float>::iterator itr;
377  for(G4int z = 0; z < kModalitySize[2]; z++) {
378  short * modality = new short[nxy];
379  for(G4int y = 0; y < kModalitySize[1]; y++) {
380  for(G4int x = 0; x < kModalitySize[0]; x++) {
381  //for(G4int x = kModalitySize[0]-1; x >= 0 ; x--) {
382  //G4int ixy = x + (kModalitySize[1]-y-1)*kModalitySize[0];
383 
384  G4int ixy = x + y*kModalitySize[0];
385  Index3D idx(x,y,z);
386  itr = kNestedModality.find(idx);
387  if(itr != kNestedModality.end()) {
388 
389  modality[ixy] = kgMocrenIO->convertDensityToHU(itr->second);
390  } else {
391  modality[ixy] = -1024;
392  }
393 
394  }
395  }
396  kgMocrenIO->setModalityImage(modality);
397  }
398 
399  //-- dose
400  size_t nhits = kNestedHitsList.size();
401  if(GFDEBUG) G4cout << "gMocren-file driver : # hits = " << nhits << G4endl;
402 
403  std::map<Index3D, G4double>::iterator hitsItr;
404  std::map<G4String, std::map<Index3D, G4double> >::iterator hitsListItr = kNestedHitsList.begin();
405 
406  for(G4int n = 0; hitsListItr != kNestedHitsList.end(); hitsListItr++, n++) {
407 
409  kgMocrenIO->setDoseDistName(hitsListItr->first, n);
410  kgMocrenIO->setDoseDistSize(kModalitySize, n);
411 
412  G4double minmax[2] = {DBL_MAX, -DBL_MAX};
413  for(G4int z = 0 ; z < kModalitySize[2]; z++) {
414  G4double * values = new G4double[nxy];
415  for(G4int y = 0; y < kModalitySize[1]; y++) {
416  for(G4int x = 0; x < kModalitySize[0]; x++) {
417 
418  G4int ixy = x + y*kModalitySize[0];
419  Index3D idx(x,y,z);
420  hitsItr = hitsListItr->second.find(idx);
421  if(hitsItr != hitsListItr->second.end()) {
422 
423  values[ixy] = hitsItr->second;
424  } else {
425  values[ixy] = 0.;
426  }
427  if(values[ixy] < minmax[0]) minmax[0] = values[ixy];
428  if(values[ixy] > minmax[1]) minmax[1] = values[ixy];
429  }
430  }
431  kgMocrenIO->setDoseDist(values, n);
432  }
433  kgMocrenIO->setDoseDistMinMax(minmax, n);
434  G4double lower = 0.;
435  if(minmax[0] < 0) lower = minmax[0];
436  G4double scale = (minmax[1]-lower)/25000.;
437  kgMocrenIO->setDoseDistScale(scale, n);
438  G4String sunit("unit?"); //temporarily
439  kgMocrenIO->setDoseDistUnit(sunit, n);
440  }
441 
442 
443  //-- draw axes
444  if(false) {//true,false
445  G4ThreeVector trans;
446  G4RotationMatrix rot;
447  trans = kVolumeTrans3D.getTranslation();
448  rot = kVolumeTrans3D.getRotation().inverse();
449  // x
450  std::vector<G4float *> tracks;
451  unsigned char colors[3];
452  G4float * trk = new G4float[6];
453  tracks.push_back(trk);
454 
455  G4ThreeVector orig(0.,0.,0), xa(2000.,0.,0.), ya(0.,2000.,0.), za(0.,0.,2000.);
456  orig -= trans;
457  orig.transform(rot);
458  xa -= trans;
459  xa.transform(rot);
460  ya -= trans;
461  ya.transform(rot);
462  za -= trans;
463  za.transform(rot);
464  for(G4int i = 0; i < 3; i++) trk[i] = orig[i];
465  for(G4int i = 0; i < 3; i++) trk[i+3] = xa[i];
466  colors[0] = 255; colors[1] = 0; colors[2] = 0;
467  kgMocrenIO->addTrack(tracks, colors);
468  // y
469  for(G4int i = 0; i < 3; i++) trk[i+3] = ya[i];
470  colors[0] = 0; colors[1] = 255; colors[2] = 0;
471  kgMocrenIO->addTrack(tracks, colors);
472  // z
473  for(G4int i = 0; i < 3; i++) trk[i+3] = za[i];
474  colors[0] = 0; colors[1] = 0; colors[2] = 255;
475  kgMocrenIO->addTrack(tracks, colors);
476  }
477 
478  //-- detector
479  ExtractDetector();
480 
481 
482  if(GFDEBUG_DET) G4cout << ">>>>>>>>>>>>>>>>>>>>>> (";
483  std::vector<G4float> transformObjects;
484  for(G4int i = 0; i < 3; i++) {
485  // need to check!!
486  transformObjects.push_back((kVolumeSize[i]/2. - kVoxelDimension[i]/2.));
487  if(GFDEBUG_DET) G4cout << transformObjects[i] << ", ";
488  }
489  if(GFDEBUG_DET) G4cout << ")" << G4endl;
490 
491 
492  kgMocrenIO->translateTracks(transformObjects);
493  kgMocrenIO->translateDetector(transformObjects);
494 
495  // store
497  }
498 
499 }
500 
501 
502 //-----
504 {
506 
507  if( !GFIsInModeling() ) {
508 
509 
511  G4cout << "***** G4GMocrenFileSceneHandler::GFBeginModeling (called & started)" << G4endl;
512 
513  //----- Send saving command and heading comment
514  BeginSavingGdd();
515 
516  kFlagInModeling = true ;
517 
518  // These models are entrusted to user commands /vis/scene/add/psHits or hits
519  //GetScene()->AddEndOfEventModel(new G4PSHitsModel());
520  //GetScene()->AddEndOfRunModel(new G4PSHitsModel());
521  //scene->AddEndOfEventModel(new G4HitsModel());
522  if(GFDEBUG_HIT) {
523  G4Scene * scene = GetScene();
524  std::vector<G4Scene::Model> vmodel = scene->GetEndOfEventModelList();
525  std::vector<G4Scene::Model>::iterator itr = vmodel.begin();
526  for(; itr != vmodel.end(); itr++) {
527  G4cout << " IIIIII model name: " << itr->fpModel->GetGlobalTag() << G4endl;
528  }
529  }
530 
531  } // if
532 }
533 
534 
535 //========== AddPrimitive() functions ==========//
536 
537 //----- Add polyline
539 {
541  G4cout << "***** AddPrimitive" << G4endl;
542 
543  if (fProcessing2D) {
544  static G4bool warned = false;
545  if (!warned) {
546  warned = true;
548  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyline&)",
549  "gMocren1001", JustWarning,
550  "2D polylines not implemented. Ignored.");
551  }
552  return;
553  }
554 
555  //----- Initialize if necessary
556  GFBeginModeling();
557 
558  static G4int numTrajectories = 0;
559  if(numTrajectories >= MAX_NUM_TRAJECTORIES) return;
560 
561  // draw trajectories
563 
564  G4TrajectoriesModel * pTrModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
565  if (!pTrModel) {
566  G4Exception
567  ("G4VSceneHandler::AddCompound(const G4Polyline&)",
568  "gMocren0002", FatalException, "Not a G4TrajectoriesModel.");
569  }
570 
571  G4ThreeVector trans;
572  G4RotationMatrix rot;
573  trans = kVolumeTrans3D.getTranslation();
574  rot = kVolumeTrans3D.getRotation().inverse();
575 
576  if(GFDEBUG_TRK) G4cout << " trajectory points : " << G4endl;
577  std::vector<G4float *> trajectory;
578  if(polyline.size() < 2) return;
579  G4Polyline::const_iterator preitr = polyline.begin();
580  G4Polyline::const_iterator postitr = preitr; postitr++;
581  for(; postitr != polyline.end(); preitr++, postitr++) {
582  G4ThreeVector prePts(preitr->x(), preitr->y(), preitr->z());
583  prePts -= trans;
584  prePts.transform(rot);
585  G4ThreeVector postPts(postitr->x(), postitr->y(), postitr->z());
586  postPts -= trans;
587  postPts.transform(rot);
588  G4float * stepPts = new G4float[6];
589  stepPts[0] = prePts.x();
590  stepPts[1] = prePts.y();
591  stepPts[2] = prePts.z();
592  stepPts[3] = postPts.x();
593  stepPts[4] = postPts.y();
594  stepPts[5] = postPts.z();
595  trajectory.push_back(stepPts);
596 
597  if(GFDEBUG_TRK) {
598  G4cout << " ("
599  << stepPts[0] << ", "
600  << stepPts[1] << ", "
601  << stepPts[2] << ") - ("
602  << stepPts[3] << ", "
603  << stepPts[4] << ", "
604  << stepPts[5] << ")" << G4endl;
605  }
606  }
607 
608  const G4VisAttributes * att = polyline.GetVisAttributes();
609  G4Color color = att->GetColor();
610  unsigned char trkcolor[3];
611  trkcolor[0] = (unsigned char)(color.GetRed()*255);
612  trkcolor[1] = (unsigned char)(color.GetGreen()*255);
613  trkcolor[2] = (unsigned char)(color.GetBlue()*255);
614  if(GFDEBUG_TRK) {
615  G4cout << " color : ["
616  << color.GetRed() << ", "
617  << color.GetGreen() << ", "
618  << color.GetBlue() << "]" << G4endl;
619  }
620 
621  kgMocrenIO->addTrack(trajectory, trkcolor);
622 
623  numTrajectories++;
624  }
625 
626 } // G4GMocrenFileSceneHandler::AddPrimitive (polyline)
627 
628 
629 //----- Add text
631 {
632  if (fProcessing2D) {
633  static G4bool warned = false;
634  if (!warned) {
635  warned = true;
637  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Text&)",
638  "gMocren1002", JustWarning,
639  "2D text not implemented. Ignored.");
640  }
641  return;
642  }
643 
644  // to avoid a warning in the compile process
645  G4Text dummytext = text;
646 
647  //-----
649  G4cout << "***** AddPrimitive( G4Text )" << G4endl;
650 
651  //----- Initialize IF NECESSARY
652  GFBeginModeling();
653 
654 } // G4GMocrenFileSceneHandler::AddPrimitive ( text )
655 
656 
657 //----- Add circle
659 {
660  // to avoid a warning in the compile process
661  G4Circle dummycircle = mark_circle;
662 
663  if (fProcessing2D) {
664  static G4bool warned = false;
665  if (!warned) {
666  warned = true;
668  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Circle&)",
669  "gMocren1003", JustWarning,
670  "2D circles not implemented. Ignored.");
671  }
672  return;
673  }
674 
675  //-----
677  G4cout << "***** AddPrimitive( G4Circle )" << G4endl;
678 
679  //----- Initialize IF NECESSARY
680  GFBeginModeling();
681 
682 
683 } // G4GMocrenFileSceneHandler::AddPrimitive ( mark_circle )
684 
685 
686 //----- Add square
688 {
689  // to avoid a warning in the compile process
690  G4Square dummysquare = mark_square;
691 
692  if (fProcessing2D) {
693  static G4bool warned = false;
694  if (!warned) {
695  warned = true;
697  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Square&)",
698  "gMocren1004", JustWarning,
699  "2D squares not implemented. Ignored.");
700  }
701  return;
702  }
703 
704  //-----
706  G4cout << "***** AddPrimitive( G4Square )" << G4endl;
707 
708  //----- Initialize if necessary
709  GFBeginModeling();
710 
711 } // G4GMocrenFileSceneHandler::AddPrimitive ( mark_square )
712 
713 
714 //----- Add polyhedron
716 {
717  //-----
719  G4cout << "***** AddPrimitive( G4Polyhedron )" << G4endl;
720 
721 
722  if (polyhedron.GetNoFacets() == 0) return;
723 
724  if (fProcessing2D) {
725  static G4bool warned = false;
726  if (!warned) {
727  warned = true;
729  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyhedron&)",
730  "gMocren1005", JustWarning,
731  "2D polyhedra not implemented. Ignored.");
732  }
733  return;
734  }
735 
736  //----- Initialize if necessary
737  GFBeginModeling();
738 
739  //---------- (3) Facet block
740  for (G4int f = polyhedron.GetNoFacets(); f; f--){
741  G4bool notLastEdge = true;
742  G4int index = -1; // initialization
743  G4int edgeFlag = 1;
744  //G4int preedgeFlag = 1;
745  //G4int work[4], i = 0;
746  G4int i = 0;
747  do {
748  //preedgeFlag = edgeFlag;
749  notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
750  //work[i++] = index;
751  i++;
752  }while (notLastEdge);
753  switch (i){
754  case 3:
755  //SendStrInt3(FR_FACET, work[0], work[1], work[2] );
756  break;
757  case 4:
758  //SendStrInt4(FR_FACET, work[0], work[1], work[2], work[3] );
759  break;
760  default:
762  G4cout <<
763  "ERROR G4GMocrenFileSceneHandler::AddPrimitive(G4Polyhedron)" << G4endl;
764  G4PhysicalVolumeModel* pPVModel =
765  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
766  if (pPVModel)
768  G4cout << "Volume " << pPVModel->GetCurrentPV()->GetName() <<
769  ", Solid " << pPVModel->GetCurrentLV()->GetSolid()->GetName() <<
770  " (" << pPVModel->GetCurrentLV()->GetSolid()->GetEntityType();
771 
773  G4cout <<
774  "\nG4Polyhedron facet with " << i << " edges" << G4endl;
775  }
776  }
777 
778 } // G4GMocrenFileSceneHandler::AddPrimitive (polyhedron)
779 
780 
781 //-----
783 {
785 
786  //-----
788  G4cout << "***** GFEndModeling (called)" << G4endl;
789 
790  if( GFIsInModeling() ) {
791 
793  G4cout << "***** GFEndModeling (started) " ;
794  G4cout << "(/EndModeling, /DrawAll, /CloseDevice)" << G4endl;
795  }
796 
797  //----- End saving data to g4.gdd
798  EndSavingGdd() ;
799 
800  //------ Reset flag
801  kFlagInModeling = false ;
802 
803  }
804 
805 }
806 
807 
808 //-----
810 {
812  G4cout << "***** BeginPrimitives " << G4endl;
813 
814  GFBeginModeling();
815 
816  G4VSceneHandler::BeginPrimitives (objectTransformation);
817 
818 }
819 
820 
821 //-----
823 {
825  G4cout << "***** EndPrimitives " << G4endl;
826 
828 }
829 
830 
831 //========== AddSolid() functions ==========//
832 
833 //----- Add box
835 {
837  G4cout << "***** AddSolid ( box )" << G4endl;
838 
839  if(GFDEBUG_DET > 0)
840  G4cout << "G4GMocrenFileSceneHandler::AddSolid(const G4Box&) : "
841  << box.GetName() << G4endl;
842 
843  //----- skip drawing invisible primitive
844  if( !IsVisible() ) { return ; }
845 
846  //----- Initialize if necessary
847  GFBeginModeling();
848 
849 
850  //--
851  if(GFDEBUG_DET > 1) {
852  G4cout << "-------" << G4endl;
853  G4cout << " " << box.GetName() << G4endl;
854  G4Polyhedron * poly = box.CreatePolyhedron();
855  poly->Transform(fObjectTransformation);
856  //G4int nv = poly->GetNoVertices();
857  G4Point3D v1, v2;
858  G4int next;
859  //while(1) { // next flag isn't functional.
860  for(G4int i = 0; i < 12; i++) { // # of edges is 12.
861  poly->GetNextEdge(v1, v2, next);
862  if(next == 0) break;
863  G4cout << " (" << v1.x() << ", "
864  << v1.y() << ", "
865  << v1.z() << ") - ("
866  << v2.x() << ", "
867  << v2.y() << ", "
868  << v2.z() << ") [" << next << "]"
869  << G4endl;
870  }
871  delete poly;
872  }
873 
874 
875  // the volume name set by /vis/gMocren/setVolumeName
876  G4String volName = kMessenger.getVolumeName();
877 
878  if(kFlagParameterization != 2) {
880  if(pScrMan) {
881  G4ScoringBox * pScBox = dynamic_cast<G4ScoringBox*>(pScrMan->FindMesh(volName));
882  G4bool bMesh = false;
883  if(pScBox != NULL) bMesh = true;
884  if(bMesh) kFlagParameterization = 2;
885  if(GFDEBUG_DET > 0) G4cout << " G4ScoringManager::FindMesh() : "
886  << volName << " - " << bMesh << G4endl;
887  }
888  }
889 
890  const G4VModel* pv_model = GetModel();
891  if (!pv_model) { return ; }
892  G4PhysicalVolumeModel* pPVModel =
893  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
894  if (!pPVModel) { return ; }
895 
896 
897  //-- debug information
898  if(GFDEBUG_DET > 0) {
899  G4Material * mat = pPVModel->GetCurrentMaterial();
900  G4String name = mat->GetName();
901  G4double dens = mat->GetDensity()/(g/cm3);
902  G4int copyNo = pPVModel->GetCurrentPV()->GetCopyNo();
903  G4int depth = pPVModel->GetCurrentDepth();
904  G4cout << " copy no.: " << copyNo << G4endl;
905  G4cout << " depth : " << depth << G4endl;
906  G4cout << " density : " << dens << " [g/cm3]" << G4endl;
907  G4cout << " location: " << pPVModel->GetCurrentPV()->GetObjectTranslation() << G4endl;
908  G4cout << " Multiplicity : " << pPVModel->GetCurrentPV()->GetMultiplicity() << G4endl;
909  G4cout << " Is replicated? : " << pPVModel->GetCurrentPV()->IsReplicated() << G4endl;
910  G4cout << " Is parameterised? : " << pPVModel->GetCurrentPV()->IsParameterised() << G4endl;
911  G4cout << " top phys. vol. name : " << pPVModel->GetTopPhysicalVolume()->GetName() << G4endl;
912  }
913 
914  //-- check the parameterised volume
915  if(box.GetName() == volName) {
916 
918  // coordination system correction for gMocren
919  G4ThreeVector raxis(1., 0., 0.), dummy(0.,0.,0.);
920  G4RotationMatrix rot(raxis, pi*rad);
921  G4Transform3D trot(rot, dummy);
922  if(GFDEBUG_DET) {
923  G4ThreeVector trans1 = kVolumeTrans3D.getTranslation();
924  G4RotationMatrix rot1 = kVolumeTrans3D.getRotation().inverse();
925  G4cout << "kVolumeTrans3D: " << trans1 << G4endl << rot1 << G4endl;
926  }
928  if(GFDEBUG_DET) G4cout << " Parameterised volume : " << box.GetName() << G4endl;
929 
930 
931 
932  //
933  G4VPhysicalVolume * pv[3] = {0,0,0};
934  pv[0] = pPVModel->GetCurrentPV()->GetLogicalVolume()->GetDaughter(0);
935  if(!pv[0]) {
936  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
937  "gMocren0003", FatalException, "Unexpected volume.");
938  }
939  G4int dirAxis[3] = {-1,-1,-1};
940  G4int nDaughters[3] = {0,0,0};
941 
942  EAxis axis; G4int nReplicas; G4double width; G4double offset; G4bool consuming;
943  pv[0]->GetReplicationData(axis, nReplicas, width, offset, consuming);
944  nDaughters[0] = nReplicas;
945  switch(axis) {
946  case kXAxis: dirAxis[0] = 0; break;
947  case kYAxis: dirAxis[0] = 1; break;
948  case kZAxis: dirAxis[0] = 2; break;
949  default:
950  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
951  "gMocren0004", FatalException, "Error.");
952  }
953  kNestedVolumeNames.push_back(pv[0]->GetName());
954  if(GFDEBUG_DET)
955  G4cout << " daughter name : " << pv[0]->GetName()
956  << " # : " << nDaughters[0] << G4endl;
957 
958  //
959  if(GFDEBUG_DET) {
960  if(pv[0]->GetLogicalVolume()->GetNoDaughters()) {
961  G4cout << "# of daughters : "
962  << pv[0]->GetLogicalVolume()->GetNoDaughters() << G4endl;
963  } else {
964  //G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
965  // "gMocren0005", FatalException, "Error.");
966  }
967  }
968 
969  // check whether nested or regular parameterization
970  if(GFDEBUG_DET) G4cout << "# of daughters : "
971  << pv[0]->GetLogicalVolume()->GetNoDaughters() << G4endl;
972  if(pv[0]->GetLogicalVolume()->GetNoDaughters() == 0) {
974  //G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
975  // "gMocren0006", FatalException, "Error.");
976  }
977 
978  if(kFlagParameterization == 0) {
979 
980  pv[1] = pv[0]->GetLogicalVolume()->GetDaughter(0);
981  if(pv[1]) {
982  pv[1]->GetReplicationData(axis, nReplicas, width, offset, consuming);
983  nDaughters[1] = nReplicas;
984  switch(axis) {
985  case kXAxis: dirAxis[1] = 0; break;
986  case kYAxis: dirAxis[1] = 1; break;
987  case kZAxis: dirAxis[1] = 2; break;
988  default:
989  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
990  "gMocren0007", FatalException, "Error.");
991  }
992  kNestedVolumeNames.push_back(pv[1]->GetName());
993  if(GFDEBUG_DET)
994  G4cout << " sub-daughter name : " << pv[1]->GetName()
995  << " # : " << nDaughters[1]<< G4endl;
996 
997  //
998  pv[2] = pv[1]->GetLogicalVolume()->GetDaughter(0);
999  if(pv[2]) {
1000  nDaughters[2] = pv[2]->GetMultiplicity();
1001  kNestedVolumeNames.push_back(pv[2]->GetName());
1002  if(GFDEBUG_DET)
1003  G4cout << " sub-sub-daughter name : " << pv[2]->GetName()
1004  << " # : " << nDaughters[2] << G4endl;
1005 
1006  if(nDaughters[2] > 1) {
1007  G4VNestedParameterisation * nestPara
1008  = dynamic_cast<G4VNestedParameterisation*>(pv[2]->GetParameterisation());
1009  if(nestPara == NULL)
1010  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1011  "gMocren0008", FatalException, "Non-nested parameterisation");
1012 
1013  nestPara->ComputeTransformation(0, pv[2]);
1014  G4ThreeVector trans0 = pv[2]->GetObjectTranslation();
1015  nestPara->ComputeTransformation(1, pv[2]);
1016  G4ThreeVector trans1 = pv[2]->GetObjectTranslation();
1017  G4ThreeVector diff(trans0 - trans1);
1018  if(GFDEBUG_DET)
1019  G4cout << trans0 << " - " << trans1 << " - " << diff << G4endl;
1020 
1021  if(diff.x() != 0.) dirAxis[2] = 0;
1022  else if(diff.y() != 0.) dirAxis[2] = 1;
1023  else if(diff.z() != 0.) dirAxis[2] = 2;
1024  else
1025  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1026  "gMocren0009", FatalException, "Unexpected nested parameterisation");
1027  }
1028  }
1029  }
1030 
1031  for(G4int i = 0; i < 3; i++) {
1032  kNestedVolumeDimension[i] = nDaughters[i];
1033  //kNestedVolumeDimension[i] = nDaughters[dirAxis[i]];
1034  kNestedVolumeDirAxis[i] = dirAxis[i];
1035  }
1036  //G4cout << "@@@@@@@@@ "
1037  // << dirAxis[0] << ", " << dirAxis[1] << ", " << dirAxis[2] << G4endl;
1038 
1039  // get densities
1040  G4VNestedParameterisation * nestPara
1041  = dynamic_cast<G4VNestedParameterisation*>(pv[2]->GetParameterisation());
1042  if(nestPara != NULL) {
1043  G4double prexyz[3] = {0.,0.,0.}, xyz[3] = {0.,0.,0.};
1044  for(G4int n0 = 0; n0 < nDaughters[0]; n0++) {
1045  for(G4int n1 = 0; n1 < nDaughters[1]; n1++) {
1046  for(G4int n2 = 0; n2 < nDaughters[2]; n2++) {
1047 
1048  G4GMocrenTouchable * touch = new G4GMocrenTouchable(n1, n0);
1049  if(GFDEBUG_DET)
1050  G4cout << " retrieve volume : copy # : " << n0
1051  << ", " << n1 << ", " << n2 << G4endl;
1052  G4Material * mat = nestPara->ComputeMaterial(pv[2], n2, touch);
1053  delete touch;
1054  G4double dens = mat->GetDensity()/(g/cm3);
1055 
1056  if(GFDEBUG_DET)
1057  G4cout << " density :" << dens << " [g/cm3]" << G4endl;
1058 
1059  G4Box tbox(box);
1060  nestPara->ComputeDimensions(tbox, n2, pv[2]);
1061  xyz[0] = tbox.GetXHalfLength()/mm;
1062  xyz[1] = tbox.GetYHalfLength()/mm;
1063  xyz[2] = tbox.GetZHalfLength()/mm;
1064  if(n0 != 0 || n1 != 0 || n2 != 0) {
1065  for(G4int i = 0; i < 3; i++) {
1066  if(xyz[i] != prexyz[i])
1067  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1068  "gMocren0010", FatalException, "Unsupported parameterisation");
1069  }
1070  }
1071  if(GFDEBUG_DET)
1072  G4cout << " size : " << tbox.GetXHalfLength()/mm << " x "
1073  << tbox.GetYHalfLength()/mm << " x "
1074  << tbox.GetZHalfLength()/mm << " [mm3]" << G4endl;
1075 
1076  G4int idx[3];
1077  idx[dirAxis[0]] = n0;
1078  idx[dirAxis[1]] = n1;
1079  idx[dirAxis[2]] = n2;
1080  Index3D i3d(idx[0],idx[1],idx[2]);
1081  kNestedModality[i3d] = dens;
1082  if(GFDEBUG_DET)
1083  G4cout << " index: " << idx[0] << ", " << idx[1] << ", " << idx[2]
1084  << " density: " << dens << G4endl;
1085 
1086  for(G4int i = 0; i < 3; i++) prexyz[i] = xyz[i];
1087  }
1088  }
1089  }
1090 
1091  kVolumeSize.set(box.GetXHalfLength()*2/mm,
1092  box.GetYHalfLength()*2/mm,
1093  box.GetZHalfLength()*2/mm);
1094  // mesh size
1095  if(!kbSetModalityVoxelSize) {
1096  G4float spacing[3] = {static_cast<G4float>(2*xyz[0]),
1097  static_cast<G4float>(2*xyz[1]),
1098  static_cast<G4float>(2*xyz[2])};
1099  kgMocrenIO->setVoxelSpacing(spacing);
1100  kVoxelDimension.set(spacing[0], spacing[1], spacing[2]);
1101  kbSetModalityVoxelSize = true;
1102  }
1103 
1104  } else {
1105  if(GFDEBUG_DET)
1106  G4cout << pv[2]->GetName() << G4endl;
1107  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1108  "gMocren0011", FatalException, "Non-nested parameterisation");
1109  }
1110 
1111 
1112 
1113  //-- debug
1114  if(GFDEBUG_DET > 1) {
1115  if(pPVModel->GetCurrentPV()->IsParameterised()) {
1116  G4VPVParameterisation * para = pPVModel->GetCurrentPV()->GetParameterisation();
1117  G4cout << " Is nested parameterisation? : " << para->IsNested() << G4endl;
1118 
1119 
1120  G4int npvp = pPVModel->GetDrawnPVPath().size();
1121  G4cout << " physical volume node id : "
1122  << "size: " << npvp << ", PV name: ";
1123  for(G4int i = 0; i < npvp; i++) {
1124  G4cout << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetName()
1125  << " [param:"
1126  << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->IsParameterised()
1127  << ",rep:"
1128  << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->IsReplicated();
1129  if(pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()) {
1130  G4cout << ",nest:"
1131  << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()->IsNested();
1132  }
1133  G4cout << ",copyno:"
1134  << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetCopyNo();
1135  G4cout << "] - ";
1136  }
1137  G4cout << G4endl;
1138 
1139 
1140  pPVModel->GetCurrentPV()->GetReplicationData(axis, nReplicas, width, offset, consuming);
1141  G4cout << " # replicas : " << nReplicas << G4endl;
1142  G4double pareDims[3] = {0.,0.,0.};
1143  G4Box * pbox = dynamic_cast<G4Box *>(pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1144  if(pbox) {
1145  pareDims[0] = 2.*pbox->GetXHalfLength()*mm;
1146  pareDims[1] = 2.*pbox->GetYHalfLength()*mm;
1147  pareDims[2] = 2.*pbox->GetZHalfLength()*mm;
1148  G4cout << " mother size ["
1149  << pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName()
1150  << "] : "
1151  << pareDims[0] << " x "
1152  << pareDims[1] << " x "
1153  << pareDims[2] << " [mm3]"
1154  << G4endl;
1155  }
1156  G4double paraDims[3];
1157  G4Box * boxP = dynamic_cast<G4Box *>(pPVModel->GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1158  if(boxP) {
1159  paraDims[0] = 2.*boxP->GetXHalfLength()*mm;
1160  paraDims[1] = 2.*boxP->GetYHalfLength()*mm;
1161  paraDims[2] = 2.*boxP->GetZHalfLength()*mm;
1162  G4cout << " parameterised volume? ["
1163  << pPVModel->GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetName()
1164  << "] : "
1165  << paraDims[0] << " x "
1166  << paraDims[1] << " x "
1167  << paraDims[2] << " [mm3] : "
1168  << G4int(pareDims[0]/paraDims[0]) << " x "
1169  << G4int(pareDims[1]/paraDims[1]) << " x "
1170  << G4int(pareDims[2]/paraDims[2]) << G4endl;
1171  } else {
1172  G4cout << pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName()
1173  << " isn't a G4Box." << G4endl;
1174  }
1175  }
1176  }
1177 
1178 
1179  } else if(kFlagParameterization == 1) { // G4PhantomParameterisation based geom. construnction
1180 
1181  // get the dimension of the parameterized patient geometry
1182  G4PhantomParameterisation * phantomPara
1183  = dynamic_cast<G4PhantomParameterisation*>(pv[0]->GetParameterisation());
1184  if(phantomPara == NULL) {
1185  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1186  "gMocren0012", FatalException, "no G4PhantomParameterisation");
1187  } else {
1188  ;
1189  }
1190 
1191  kNestedVolumeDimension[0] = phantomPara->GetNoVoxelX();
1192  kNestedVolumeDimension[1] = phantomPara->GetNoVoxelY();
1193  kNestedVolumeDimension[2] = phantomPara->GetNoVoxelZ();
1194  kNestedVolumeDirAxis[0] = 0;
1195  kNestedVolumeDirAxis[1] = 1;
1196  kNestedVolumeDirAxis[2] = 2;
1197 
1198  // get densities of the parameterized patient geometry
1199  G4int nX = kNestedVolumeDimension[0];
1201 
1202  for(G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1203  for(G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1204  for(G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1205 
1206  G4int repNo = n0 + n1*nX + n2*nXY;
1207  G4Material * mat = phantomPara->ComputeMaterial(repNo, pv[0]);
1208  G4double dens = mat->GetDensity()/(g/cm3);
1209 
1210 
1211  G4int idx[3];
1212  idx[kNestedVolumeDirAxis[0]] = n0;
1213  idx[kNestedVolumeDirAxis[1]] = n1;
1214  idx[kNestedVolumeDirAxis[2]] = n2;
1215  Index3D i3d(idx[0],idx[1],idx[2]);
1216  kNestedModality[i3d] = dens;
1217 
1218  if(GFDEBUG_DET)
1219  G4cout << " index: " << idx[0] << ", " << idx[1] << ", " << idx[2]
1220  << " density: " << dens << G4endl;
1221 
1222  }
1223  }
1224  }
1225 
1226  kVolumeSize.set(box.GetXHalfLength()*2/mm,
1227  box.GetYHalfLength()*2/mm,
1228  box.GetZHalfLength()*2/mm);
1229 
1230  // mesh size
1231  if(!kbSetModalityVoxelSize) {
1232  G4float spacing[3] = {static_cast<G4float>(2*phantomPara->GetVoxelHalfX()),
1233  static_cast<G4float>(2*phantomPara->GetVoxelHalfY()),
1234  static_cast<G4float>(2*phantomPara->GetVoxelHalfZ())};
1235  kgMocrenIO->setVoxelSpacing(spacing);
1236  kVoxelDimension.set(spacing[0], spacing[1], spacing[2]);
1237  kbSetModalityVoxelSize = true;
1238  }
1239  }
1240 
1241  } // if(box.GetName() == volName)
1242 
1243 
1244  // processing geometry construction based on the interactive PS
1246 
1247 
1248  // get the dimension of the geometry defined in G4VScoringMesh
1250  if(!pScrMan) return;
1251  G4ScoringBox * scoringBox
1252  = dynamic_cast<G4ScoringBox*>(pScrMan->FindMesh(volName));
1253  if(scoringBox == NULL) return;
1254 
1255 
1256  G4int nVoxels[3];
1257  scoringBox->GetNumberOfSegments(nVoxels);
1258  // this order depends on the G4ScoringBox
1259  kNestedVolumeDimension[0] = nVoxels[2];
1260  kNestedVolumeDimension[1] = nVoxels[1];
1261  kNestedVolumeDimension[2] = nVoxels[0];
1262  kNestedVolumeDirAxis[0] = 2;
1263  kNestedVolumeDirAxis[1] = 1;
1264  kNestedVolumeDirAxis[2] = 0;
1265 
1266  // get densities of the parameterized patient geometry
1267  for(G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1268  for(G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1269  for(G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1270 
1271  G4double dens = 0.*(g/cm3);
1272 
1273  G4int idx[3];
1274  idx[kNestedVolumeDirAxis[0]] = n0;
1275  idx[kNestedVolumeDirAxis[1]] = n1;
1276  idx[kNestedVolumeDirAxis[2]] = n2;
1277  Index3D i3d(idx[0],idx[1],idx[2]);
1278  kNestedModality[i3d] = dens;
1279 
1280  }
1281  }
1282  }
1283 
1284  G4ThreeVector boxSize = scoringBox->GetSize();
1285  if(GFDEBUG_DET > 1) {
1286  G4cout << "Interactive Scorer : size - "
1287  << boxSize.x()/cm << " x "
1288  << boxSize.y()/cm << " x "
1289  << boxSize.z()/cm << " [cm3]" << G4endl;
1290  G4cout << "Interactive Scorer : # voxels - "
1291  << nVoxels[0] << " x "
1292  << nVoxels[1] << " x "
1293  << nVoxels[2] << G4endl;
1294  }
1295  kVolumeSize.set(boxSize.x()*2,
1296  boxSize.y()*2,
1297  boxSize.z()*2);
1298 
1299  // mesh size
1300  if(!kbSetModalityVoxelSize) {
1301  G4float spacing[3] = {static_cast<G4float>(boxSize.x()*2/nVoxels[0]),
1302  static_cast<G4float>(boxSize.y()*2/nVoxels[1]),
1303  static_cast<G4float>(boxSize.z()*2/nVoxels[2])};
1304 
1305  kgMocrenIO->setVoxelSpacing(spacing);
1306  kVoxelDimension.set(spacing[0], spacing[1], spacing[2]);
1307  kbSetModalityVoxelSize = true;
1308 
1309  }
1310 
1311 
1313 
1314  // translation for the scoring mesh
1315  G4ThreeVector sbth = scoringBox->GetTranslation();
1316  G4Translate3D sbtranslate(sbth);
1317  kVolumeTrans3D = kVolumeTrans3D*sbtranslate;
1318 
1319  // rotation matrix for the scoring mesh
1320  G4RotationMatrix sbrm;
1321  sbrm = scoringBox->GetRotationMatrix();
1322  if(!sbrm.isIdentity()) {
1323  G4ThreeVector sbdummy(0.,0.,0.);
1324  G4Transform3D sbrotate(sbrm.inverse(), sbdummy);
1325  kVolumeTrans3D = kVolumeTrans3D*sbrotate;
1326  }
1327 
1328 
1329  // coordination system correction for gMocren
1330  G4ThreeVector raxisY(0., 1., 0.), dummyY(0.,0.,0.);
1331  G4RotationMatrix rotY(raxisY, pi*rad);
1332  G4Transform3D trotY(rotY, dummyY);
1333  G4ThreeVector raxisZ(0., 0., 1.), dummyZ(0.,0.,0.);
1334  G4RotationMatrix rotZ(raxisZ, pi*rad);
1335  G4Transform3D trotZ(rotZ, dummyZ);
1336 
1337  kVolumeTrans3D = kVolumeTrans3D*trotY*trotZ;
1338 
1339 
1340  //
1342  }
1343 
1344 
1345 
1346  //-- add detectors
1347  G4bool bAddDet = true;
1348  if(!kMessenger.getDrawVolumeGrid()) {
1349 
1350  if(kFlagParameterization == 0) { // nested parameterisation
1351 
1352  if(volName == box.GetName()) {
1353  bAddDet = false;
1354  }
1355 
1356  std::vector<G4String>::iterator itr = kNestedVolumeNames.begin();
1357  for(; itr != kNestedVolumeNames.end(); itr++) {
1358  if(*itr == box.GetName()) {
1359  bAddDet = false;
1360  break;
1361  }
1362  }
1363  } else if(kFlagParameterization == 1) { // phantom paramemterisation
1364 
1365  if(volName != box.GetName()) {
1366  bAddDet = false;
1367  }
1368 
1369  } else if(kFlagParameterization == 2) { // interactive primitive scorer
1370  ;
1371  }
1372 
1373  }
1374  if(bAddDet) AddDetector(box);
1375 
1376 
1377 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )
1378 
1379 
1380 //----- Add tubes
1381 void
1383 {
1385  G4cout << "***** AddSolid ( tubes )" << G4endl;
1386 
1387  //----- skip drawing invisible primitive
1388  if( !IsVisible() ) { return ; }
1389 
1390  //----- Initialize if necessary
1391  GFBeginModeling();
1392 
1393  //
1394  AddDetector(tubes);
1395 
1396 
1397  // for a debug
1398  if(GFDEBUG_DET > 0) {
1399  G4cout << "-------" << G4endl;
1400  G4cout << " " << tubes.GetName() << G4endl;
1401  G4Polyhedron * poly = tubes.CreatePolyhedron();
1402  G4int nv = poly->GetNoVertices();
1403  for(G4int i = 0; i < nv; i++) {
1404  G4cout << " (" << poly->GetVertex(i).x() << ", "
1405  << poly->GetVertex(i).y() << ", "
1406  << poly->GetVertex(i).z() << ")" << G4endl;
1407  }
1408  delete poly;
1409  }
1410 
1411  const G4VModel* pv_model = GetModel();
1412  if (!pv_model) { return ; }
1413  G4PhysicalVolumeModel* pPVModel =
1414  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
1415  if (!pPVModel) { return ; }
1416  G4Material * mat = pPVModel->GetCurrentMaterial();
1417  G4String name = mat->GetName();
1418 
1419 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Tubs& )
1420 
1421 
1422 
1423 //----- Add cons
1424 void
1426 {
1428  G4cout << "***** AddSolid ( cons )" << G4endl;
1429 
1430  //----- skip drawing invisible primitive
1431  if( !IsVisible() ) { return ; }
1432 
1433  //----- Initialize if necessary
1434  GFBeginModeling();
1435 
1436  //
1437  AddDetector(cons);
1438 
1439 }// G4GMocrenFileSceneHandler::AddSolid( cons )
1440 
1441 
1442 //----- Add trd
1444 {
1446  G4cout << "***** AddSolid ( trd )" << G4endl;
1447 
1448 
1449  //----- skip drawing invisible primitive
1450  if( !IsVisible() ) { return ; }
1451 
1452  //----- Initialize if necessary
1453  GFBeginModeling();
1454 
1455  //
1456  AddDetector(trd);
1457 
1458 } // G4GMocrenFileSceneHandler::AddSolid ( trd )
1459 
1460 
1461 //----- Add sphere
1463 {
1465  G4cout << "***** AddSolid ( sphere )" << G4endl;
1466 
1467  //----- skip drawing invisible primitive
1468  if( !IsVisible() ) { return ; }
1469 
1470  //----- Initialize if necessary
1471  GFBeginModeling();
1472 
1473  //
1474  AddDetector(sphere);
1475 
1476 } // G4GMocrenFileSceneHandler::AddSolid ( sphere )
1477 
1478 
1479 //----- Add para
1481 {
1483  G4cout << "***** AddSolid ( para )" << G4endl;
1484 
1485  //----- skip drawing invisible primitive
1486  if( !IsVisible() ) { return ; }
1487 
1488  //----- Initialize if necessary
1489  GFBeginModeling();
1490 
1491  //
1492  AddDetector(para);
1493 
1494 } // G4GMocrenFileSceneHandler::AddSolid ( para )
1495 
1496 
1497 //----- Add trap
1499 {
1501  G4cout << "***** AddSolid ( trap )" << G4endl;
1502 
1503  //----- skip drawing invisible primitive
1504  if( !IsVisible() ) { return ; }
1505 
1506  //----- Initialize if necessary
1507  GFBeginModeling();
1508 
1509  //
1510  AddDetector(trap);
1511 
1512 } // G4GMocrenFileSceneHandler::AddSolid (const G4Trap& trap)
1513 
1514 
1515 //----- Add torus
1516 void
1518 {
1520  G4cout << "***** AddSolid ( torus )" << G4endl;
1521 
1522  //----- skip drawing invisible primitive
1523  if( !IsVisible() ) { return ; }
1524 
1525  //----- Initialize if necessary
1526  GFBeginModeling();
1527 
1528  //
1529  AddDetector(torus);
1530 
1531 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Torus& )
1532 
1533 
1534 
1535 //----- Add a shape which is not treated above
1537 {
1538  //----- skip drawing invisible primitive
1539  if( !IsVisible() ) { return ; }
1540 
1541  //----- Initialize if necessary
1542  GFBeginModeling();
1543 
1544  //
1545  AddDetector(solid);
1546 
1547  //----- Send a primitive
1548  G4VSceneHandler::AddSolid( solid ) ;
1549 
1550 } //G4GMocrenFileSceneHandler::AddSolid ( const G4VSolid& )
1551 
1552 #include "G4TrajectoriesModel.hh"
1553 #include "G4VTrajectory.hh"
1554 #include "G4VTrajectoryPoint.hh"
1555 
1556 //----- Add a trajectory
1558 
1559  kbModelingTrajectory = true;
1560 
1562 
1563  if(GFDEBUG_TRK) {
1564  G4cout << " ::AddCompound(const G4VTrajectory&) >>>>>>>>> " << G4endl;
1565  G4TrajectoriesModel * pTrModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
1566  if (!pTrModel) {
1567  G4Exception
1568  ("G4VSceneHandler::AddCompound(const G4VTrajectory&)",
1569  "gMocren0013", FatalException, "Not a G4TrajectoriesModel.");
1570  } else {
1571  traj.DrawTrajectory();
1572 
1573  const G4VTrajectory * trj = pTrModel->GetCurrentTrajectory();
1574  G4cout << "------ track" << G4endl;
1575  G4cout << " name: " << trj->GetParticleName() << G4endl;
1576  G4cout << " id: " << trj->GetTrackID() << G4endl;
1577  G4cout << " charge: " << trj->GetCharge() << G4endl;
1578  G4cout << " momentum: " << trj->GetInitialMomentum() << G4endl;
1579 
1580  G4int nPnt = trj->GetPointEntries();
1581  G4cout << " point: ";
1582  for(G4int i = 0; i < nPnt; i++) {
1583  G4cout << trj->GetPoint(i)->GetPosition() << ", ";
1584  }
1585  G4cout << G4endl;
1586  }
1587  G4cout << G4endl;
1588  }
1589 
1590  kbModelingTrajectory = false;
1591 }
1592 
1593 #include <vector>
1594 #include "G4VHit.hh"
1595 #include "G4AttValue.hh"
1596 //----- Add a hit
1598  if(GFDEBUG_HIT) G4cout << " ::AddCompound(const G4VHit&) >>>>>>>>> " << G4endl;
1599 
1601 
1602  /*
1603  const std::map<G4String, G4AttDef> * map = hit.GetAttDefs();
1604  if(!map) return;
1605  std::map<G4String, G4AttDef>::const_iterator itr = map->begin();
1606  for(; itr != map->end(); itr++) {
1607  G4cout << itr->first << " : " << itr->second.GetName()
1608  << " , " << itr->second.GetDesc() << G4endl;
1609  }
1610  */
1611 
1612  std::vector<G4String> hitNames = kMessenger.getHitNames();
1613  if(GFDEBUG_HIT) {
1614  std::vector<G4String>::iterator itr = hitNames.begin();
1615  for(; itr != hitNames.end(); itr++)
1616  G4cout << " hit name : " << *itr << G4endl;
1617  }
1618 
1619  std::vector<G4AttValue> * attval = hit.CreateAttValues();
1620  if(!attval) {G4cout << "0 empty " << (unsigned long)attval << G4endl;}
1621  else {
1622 
1623  G4bool bid[3] = {false, false, false};
1624  Index3D id;
1625 
1626  std::vector<G4AttValue>::iterator itr;
1627  // First, get IDs
1628  for(itr = attval->begin(); itr != attval->end(); itr++) {
1629  std::string stmp = itr->GetValue();
1630  std::istringstream sval(stmp.c_str());
1631 
1632  if(itr->GetName() == G4String("XID")) {
1633  sval >> id.x;
1634  bid[0] = true;
1635  continue;
1636  }
1637  if(itr->GetName() == G4String("YID")) {
1638  sval >> id.y;
1639  bid[1] = true;
1640  continue;
1641  }
1642  if(itr->GetName() == G4String("ZID")) {
1643  sval >> id.z;
1644  bid[2] = true;
1645  continue;
1646  }
1647  }
1648 
1649  G4int nhitname = (G4int)hitNames.size();
1650 
1651  if(bid[0] && bid[1] && bid[2]) {
1652 
1653  if(GFDEBUG_HIT)
1654  G4cout << " Hit : index(" << id.x << ", " << id.y << ", "
1655  << id.z << ")" << G4endl;
1656 
1657  // Get attributes
1658  for(itr = attval->begin(); itr != attval->end(); itr++) {
1659  for(G4int i = 0; i < nhitname; i++) {
1660  if(itr->GetName() == hitNames[i]) {
1661 
1662  std::string stmp = itr->GetValue();
1663  std::istringstream sval(stmp.c_str());
1664  G4double value;
1665  G4String unit;
1666  sval >> value >> unit;
1667 
1668  std::map<G4String, std::map<Index3D, G4double> >::iterator kNestedHitsListItr;
1669  kNestedHitsListItr = kNestedHitsList.find(hitNames[i]);
1670  if(kNestedHitsListItr != kNestedHitsList.end()) {
1671  //fTempNestedHits = &kNestedHitsListItr->second;
1672  //(*fTempNestedHits)[id] = value;
1673  kNestedHitsListItr->second[id] = value;
1674  } else {
1675  std::map<Index3D, G4double> hits;
1676  hits.insert(std::map<Index3D, G4double>::value_type(id, value));
1677  kNestedHitsList[hitNames[i]] = hits;
1678  }
1679 
1680 
1681  if(GFDEBUG_HIT)
1682  G4cout << " : " << hitNames[i] << " -> " << value
1683  << " [" << unit << "]" << G4endl;
1684  }
1685  }
1686  }
1687  } else {
1688  G4Exception("G4GMocrenFileSceneHandler::AddCompound(const G4VHit &)",
1689  "gMocren0014", FatalException, "Error");
1690  }
1691 
1692  delete attval;
1693  }
1694 
1695 }
1696 
1698  if(GFDEBUG_DIGI) G4cout << " ::AddCompound(const G4VDigi&) >>>>>>>>> " << G4endl;
1700 }
1701 
1703  if(GFDEBUG_HIT)
1704  G4cout << " ::AddCompound(const std::map<G4int, G4double*> &) >>>>>>>>> " << G4endl;
1705 
1706 
1707  std::vector<G4String> hitScorerNames = kMessenger.getHitScorerNames();
1708  G4int nhitname = (G4int)hitScorerNames.size();
1709  G4String scorername = static_cast<G4VHitsCollection>(hits).GetName();
1710 
1711  //-- --//
1712  /*
1713  std::vector<G4String> hitScorerNames = kMessenger.getHitScorerNames();
1714  if(GFDEBUG_HIT) {
1715  std::vector<G4String>::iterator itr = hitScorerNames.begin();
1716  for(; itr != hitScorerNames.end(); itr++)
1717  G4cout << " PS name : " << *itr << G4endl;
1718  }
1719  */
1720 
1721  { // Scope bracket to avoid compiler messages about shadowing (JA).
1722  //for(G4int i = 0; i < nhitname; i++) { // this selection trusts
1723  //if(scorername == hitScorerNames[i]) { // thea command /vis/scene/add/psHits hit_name.
1724 
1725  G4int idx[3];
1726  std::map<G4int, G4double*> * map = hits.GetMap();
1727  std::map<G4int, G4double*>::const_iterator itr = map->begin();
1728  for(; itr != map->end(); itr++) {
1729  GetNestedVolumeIndex(itr->first, idx);
1730  Index3D id(idx[0], idx[1], idx[2]);
1731 
1732  std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1733  nestedHitsListItr = kNestedHitsList.find(scorername);
1734  if(nestedHitsListItr != kNestedHitsList.end()) {
1735  nestedHitsListItr->second[id] = *itr->second;
1736  } else {
1737  std::map<Index3D, G4double> hit;
1738  hit.insert(std::map<Index3D, G4double>::value_type(id, *itr->second));
1739  kNestedHitsList[scorername] = hit;
1740  }
1741  }
1742 
1743  //break;
1744  //}
1745  //}
1746  }
1747 
1748  if(GFDEBUG_HIT) {
1749  G4String meshname = static_cast<G4VHitsCollection>(hits).GetSDname();
1750  G4cout << " >>>>> " << meshname << " : " << scorername << G4endl;
1751 
1752  for(G4int i = 0; i < nhitname; i++)
1753  if(scorername == hitScorerNames[i])
1754  G4cout << " !!!! Hit scorer !!!! " << scorername << G4endl;
1755 
1756  G4cout << " dimension: "
1757  << kNestedVolumeDimension[0] << " x "
1758  << kNestedVolumeDimension[1] << " x "
1759  << kNestedVolumeDimension[2] << G4endl;
1760 
1761  G4int id[3];
1762  std::map<G4int, G4double*> * map = hits.GetMap();
1763  std::map<G4int, G4double*>::const_iterator itr = map->begin();
1764  for(; itr != map->end(); itr++) {
1765  GetNestedVolumeIndex(itr->first, id);
1766  G4cout << "[" << itr->first << "] "
1767  << "("<< id[0] << "," << id[1] << "," << id[2] << ")"
1768  << *itr->second << ", ";
1769  }
1770  G4cout << G4endl;
1771  }
1772 
1773 }
1774 
1775 //-----
1777 {
1778  //-----
1779  G4bool visibility = true ;
1780 
1781  const G4VisAttributes* pVisAttribs =
1783 
1784  if(pVisAttribs) {
1785  visibility = pVisAttribs->IsVisible();
1786  }
1787 
1788  return visibility ;
1789 
1790 } // G4GMocrenFileSceneHandler::IsVisible()
1791 
1792 
1793 //-----
1795 {
1796  // This is typically called after an update and before drawing hits
1797  // of the next event. To simulate the clearing of "transients"
1798  // (hits, etc.) the detector is redrawn...
1799  if (fpViewer) {
1800  fpViewer -> SetView ();
1801  fpViewer -> ClearView ();
1802  fpViewer -> DrawView ();
1803  }
1804 }
1805 
1806 //-----
1808 
1809  Detector detector;
1810 
1811  // detector name
1812  detector.name = solid.GetName();
1813  if(GFDEBUG_DET > 1)
1814  G4cout << "0 Detector name : " << detector.name << G4endl;
1815 
1816  const G4VModel* pv_model = GetModel();
1817  if (!pv_model) { return ; }
1818  G4PhysicalVolumeModel* pPVModel =
1819  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
1820  if (!pPVModel) { return ; }
1821 
1822  // edge points of the detector
1823  std::vector<G4float *> dedges;
1824  G4Polyhedron * poly = solid.CreatePolyhedron();
1825  detector.polyhedron = poly;
1827 
1828  // retrieve color
1829  unsigned char uccolor[3] = {30, 30, 30};
1830  if(pPVModel->GetCurrentLV()->GetVisAttributes()) {
1831  G4Color color = pPVModel->GetCurrentLV()->GetVisAttributes()->GetColor();
1832  uccolor[0] = (unsigned char)(color.GetRed()*255);
1833  uccolor[1] = (unsigned char)(color.GetGreen()*255);
1834  uccolor[2] = (unsigned char)(color.GetBlue()*255);
1835  //if(uccolor[0] < 2 && uccolor[1] < 2 && uccolor[2] < 2)
1836  //uccolor[0] = uccolor[1] = uccolor[2] = 30; // dark grey
1837  }
1838  for(G4int i = 0; i < 3; i++) detector.color[i] = uccolor[i];
1839  //
1840  kDetectors.push_back(detector);
1841 
1842  if(GFDEBUG_DET > 1) {
1843  G4cout << "0 color: (" << (G4int)uccolor[0] << ", "
1844  << (G4int)uccolor[1] << ", " << (G4int)uccolor[2] << ")"
1845  << G4endl;
1846  }
1847 
1848 }
1849 
1850 //-----
1852 
1853  std::vector<Detector>::iterator itr = kDetectors.begin();
1854 
1855  for(; itr != kDetectors.end(); itr++) {
1856 
1857  // detector name
1858  G4String detname = itr->name;
1859  if(GFDEBUG_DET > 1)
1860  G4cout << "Detector name : " << detname << G4endl;
1861 
1862  // edge points of the detector
1863  std::vector<G4float *> dedges;
1864  G4Polyhedron * poly = itr->polyhedron;
1865  poly->Transform(itr->transform3D);
1866  G4Transform3D invVolTrans = kVolumeTrans3D.inverse();
1867  poly->Transform(invVolTrans);
1868 
1869  G4Point3D v1, v2;
1870  G4bool bnext = true;
1871  G4int next;
1872  G4int nedges = 0;
1873  //
1874  while(bnext) {
1875  if(!(poly->GetNextEdge(v1, v2, next))) bnext =false;
1876  G4float * edge = new G4float[6];
1877  edge[0] = v1.x()/mm;
1878  edge[1] = v1.y()/mm;
1879  edge[2] = v1.z()/mm;
1880  edge[3] = v2.x()/mm;
1881  edge[4] = v2.y()/mm;
1882  edge[5] = v2.z()/mm;
1883  dedges.push_back(edge);
1884  nedges++;
1885  }
1886  //delete poly;
1887  // detector color
1888  unsigned char uccolor[3] = {itr->color[0],
1889  itr->color[1],
1890  itr->color[2]};
1891  //
1892  kgMocrenIO->addDetector(detname, dedges, uccolor);
1893  for(G4int i = 0; i < nedges; i++) { // # of edges is 12.
1894  delete [] dedges[i];
1895  }
1896  dedges.clear();
1897 
1898  if(GFDEBUG_DET > 1) {
1899  G4cout << " color: (" << (G4int)uccolor[0] << ", "
1900  << (G4int)uccolor[1] << ", " << (G4int)uccolor[2] << ")"
1901  << G4endl;
1902  }
1903  }
1904 }
1905 
1907  if(kNestedVolumeDimension[0] == 0 ||
1908  kNestedVolumeDimension[1] == 0 ||
1909  kNestedVolumeDimension[2] == 0) {
1910  for(G4int i = 0; i < 3; i++) _idx3d[i] = 0;
1911  return;
1912  }
1913 
1914 
1915  if(kFlagParameterization == 0) {
1916 
1918  G4int line = kNestedVolumeDimension[2];
1919 
1920  /*
1921  G4int idx3d[3];
1922  idx3d[0] = _idx/plane;
1923  idx3d[1] = (_idx%plane)/line;
1924  idx3d[2] = (_idx%plane)%line;
1925  _idx3d[0] = idx3d[kNestedVolumeDirAxis[0]];
1926  _idx3d[1] = idx3d[kNestedVolumeDirAxis[1]];
1927  _idx3d[2] = idx3d[kNestedVolumeDirAxis[2]];
1928  */
1929 
1930  _idx3d[kNestedVolumeDirAxis[0]] = _idx/plane;
1931  _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
1932  _idx3d[kNestedVolumeDirAxis[2]] = (_idx%plane)%line;
1933 
1934 
1935 
1936  /*
1937 
1938  G4cout << "G4GMocrenFileSceneHandler::GetNestedVolumeIndex : " << G4endl;
1939  G4cout << "(depi, depj, depk) : "
1940  << kNestedVolumeDirAxis[0] << ", "
1941  << kNestedVolumeDirAxis[1] << ", "
1942  << kNestedVolumeDirAxis[2] << G4endl;
1943  G4cout << "(ni, nj, nk) :"
1944  << kNestedVolumeDimension[0] << ", "
1945  << kNestedVolumeDimension[1] << ", "
1946  << kNestedVolumeDimension[2] << " - " << G4endl;
1947 
1948  G4cout << " _idx = " << _idx << " : plane = "
1949  << plane << " , line = " << line << G4endl;
1950  G4cout << "(idx,idy,idz) + " << _idx3d[0] << ", "
1951  << _idx3d[1] << ", " << _idx3d[2] << " + " << G4endl;
1952 
1953  */
1954 
1955 
1956 
1957  } else {
1958 
1960  G4int line = kNestedVolumeDimension[0];
1961  _idx3d[kNestedVolumeDirAxis[2]] = _idx/plane;
1962  _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
1963  _idx3d[kNestedVolumeDirAxis[0]] = (_idx%plane)%line;
1964 
1965  }
1966 
1967 }
1968 
1969 
1970 //-- --//
1972  : polyhedron(0) {
1973  color[0] = color[1] = color[2] = 255;
1974 }
1976  if(!polyhedron) delete polyhedron;
1977 }
1979  name.clear();
1980  if(!polyhedron) delete polyhedron;
1981  color[0] = color[1] = color[2] = 255;
1982  transform3D = G4Transform3D::Identity;
1983 }
1984 
1985 //-- --//
1987  : x(0), y(0), z(0) {
1988  ;
1989 }
1990 
1992  : x(_index3D.x), y(_index3D.y), z(_index3D.z) {
1993  //: x(_index3D.X()),
1994  //y(_index3D.Y()),
1995  //z(_index3D.Z()) {
1996  // : x(static_cast<Index3D>(_index3D).x),
1997  // y(static_cast<Index3D>(_index3D).y),
1998  // z(static_cast<Index3D>(_index3D).z) {
1999  ;
2000 }
2001 
2003  : x(_x), y(_y), z(_z) {
2004  ;
2005 }
2007  if(z < static_cast<Index3D>(_right).z) {
2008  return true;
2009  } else if(z == _right.z) {
2010  if(y < static_cast<Index3D>(_right).y) return true;
2011  else if(y == _right.y)
2012  if(x < static_cast<Index3D>(_right).x) return true;
2013  }
2014  return false;
2015 }
2017  if(z == _right.z && y == _right.y && x == _right.x) return true;
2018  return false;
2019 }
static const double cm
Definition: G4SIunits.hh:118
virtual G4Material * ComputeMaterial(G4VPhysicalVolume *currentVol, const G4int repNo, const G4VTouchable *parentTouch=0)=0
void AddCompound(const G4VTrajectory &traj)
G4VModel * GetModel() const
G4String GetName() const
void GetNumberOfSegments(G4int nSegment[3])
void newDoseDist()
short convertDensityToHU(float &_dens)
G4double GetXHalfLength() const
G4RotationMatrix GetRotationMatrix() const
void setDoseDistUnit(std::string &_unit, int _num=0)
Definition: G4Para.hh:77
virtual void AddSolid(const G4Box &)
Definition: G4Text.hh:73
const std::vector< Model > & GetEndOfEventModelList() const
virtual G4bool IsNested() const
virtual void BeginModeling()
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
CLHEP::Hep3Vector G4ThreeVector
void AddDetector(const G4VSolid &solid)
CLHEP::HepRotation G4RotationMatrix
virtual G4bool IsReplicated() const =0
void addTrack(float *_tracks)
G4double z
Definition: TRTMaterials.hh:39
Definition: G4Box.hh:64
G4VViewer * fpViewer
G4bool operator==(const Index3D &_right) const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
G4bool operator<(const Index3D &_right) const
G4String name
Definition: TRTMaterials.hh:40
const G4String & GetName() const
Definition: G4Material.hh:178
float G4float
Definition: G4Types.hh:77
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
void setDoseDistMinMax(short _minmax[2], int _num=0)
Definition: G4Tubs.hh:85
G4Material * GetCurrentMaterial() const
std::map< G4String, std::map< Index3D, G4double > > kNestedHitsList
G4double GetDensity() const
Definition: G4Material.hh:180
G4bool IsVisible() const
virtual G4String getVolumeName()
G4VPhysicalVolume * GetDaughter(const G4int i) const
const G4bool GFDEBUG_TRK
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
void setModalityImageSize(int _size[3])
const G4String & GetName() const
#define width
G4Transform3D fObjectTransformation
const G4int FR_MAX_FILE_NUM
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
Definition: G4VHit.hh:48
G4double GetBlue() const
Definition: G4Colour.hh:141
const char DEFAULT_GDD_FILE_NAME[]
Definition: G4Trd.hh:72
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
Definition: G4VViewer.cc:78
const G4VisAttributes * GetVisAttributes() const
virtual G4GeometryType GetEntityType() const =0
const std::vector< G4PhysicalVolumeNodeID > & GetDrawnPVPath() const
G4ThreeVector GetSize() const
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=0)
int G4int
Definition: G4Types.hh:78
const G4int GFDEBUG_DET
G4double GetZHalfLength() const
G4Polyhedron * CreatePolyhedron() const
Definition: G4Box.cc:1047
size_t GetNoVoxelZ() const
void clearDetector()
Definition: G4GMocrenIO.hh:451
void translateDetector(std::vector< float > &_translate)
virtual void DrawTrajectory() const
void setDoseDist(double *_image, int _num=0)
void clearROIAll()
virtual G4bool getDrawVolumeGrid()
virtual int GetPointEntries() const =0
bool storeData(char *_filename)
Definition: G4GMocrenIO.cc:458
G4GLOB_DLL std::ostream G4cout
virtual std::vector< G4String > getHitNames()
virtual G4String GetParticleName() const =0
G4double GetRed() const
Definition: G4Colour.hh:139
const G4String & GetName() const
void clearDoseDistAll()
G4Polyhedron * CreatePolyhedron() const
Definition: G4Tubs.cc:1919
bool G4bool
Definition: G4Types.hh:79
G4double GetGreen() const
Definition: G4Colour.hh:140
G4double GetDensity(G4int &_ct) const
G4ThreeVector GetTranslation() const
Definition: G4Cons.hh:83
virtual G4VPVParameterisation * GetParameterisation() const =0
const char GDD_FILE_HEADER[]
virtual void ComputeTransformation(const G4int no, G4VPhysicalVolume *currentPV) const =0
const G4VisAttributes * GetVisAttributes() const
static const double cm3
Definition: G4SIunits.hh:120
virtual void EndModeling()
virtual void EndPrimitives()
G4double GetYHalfLength() const
HepGeom::Transform3D G4Transform3D
G4VScoringMesh * FindMesh(const G4String &)
void setModalityImageMinMax(short _minmax[2])
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:639
const G4int n
G4double GetVoxelHalfY() const
virtual G4double GetCharge() const =0
void setModalityImage(short *_image)
void GetNestedVolumeIndex(G4int, G4int[3])
G4int GetNoDaughters() const
void setVoxelSpacing(float _spacing[3])
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static const double rad
Definition: G4SIunits.hh:148
G4VPhysicalVolume * GetTopPhysicalVolume() const
virtual G4bool IsParameterised() const =0
const G4int MAX_NUM_TRAJECTORIES
virtual std::vector< G4String > getHitScorerNames()
const G4Color & GetColor() const
size_t GetNoVoxelY() const
virtual const G4ThreeVector GetPosition() const =0
const G4VisAttributes * fpVisAttribs
G4Scene * GetScene() const
void clearTracks()
Definition: G4GMocrenIO.hh:439
std::vector< Detector > kDetectors
virtual void AddCompound(const G4VTrajectory &)
G4LogicalVolume * GetLogicalVolume() const
const G4VTrajectory * GetCurrentTrajectory() const
static const double pi
Definition: G4SIunits.hh:74
G4double GetVoxelHalfX() const
static const double g
Definition: G4SIunits.hh:180
EAxis
Definition: geomdefs.hh:54
virtual G4int GetCopyNo() const =0
const G4double x[NPOINTSGL]
const G4bool GFDEBUG_HIT
virtual G4int GetTrackID() const =0
void translateTracks(std::vector< float > &_translateo)
virtual G4int GetMultiplicity() const
static Verbosity GetVerbosity()
HepGeom::Translate3D G4Translate3D
void AddPrimitive(const G4Polyline &line)
virtual std::vector< G4AttValue > * CreateAttValues() const
Definition: G4VHit.hh:67
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
const G4bool GFDEBUG
#define G4endl
Definition: G4ios.hh:61
G4double GetVoxelHalfZ() const
size_t GetNoVoxelX() const
static G4ScoringManager * GetScoringManager()
G4ThreeVector GetObjectTranslation() const
virtual G4ThreeVector GetInitialMomentum() const =0
void setDoseDistScale(double &_scale, int _num=0)
void addDetector(std::string &_name, std::vector< float * > &_det, unsigned char _color[3])
double G4double
Definition: G4Types.hh:76
const G4bool GFDEBUG_DIGI
void setDoseDistSize(int _size[3], int _num=0)
G4LogicalVolume * GetCurrentLV() const
G4VPhysicalVolume * GetCurrentPV() const
std::vector< G4String > kNestedVolumeNames
#define DBL_MAX
Definition: templates.hh:83
static const double mm
Definition: G4SIunits.hh:114
G4Polyline & transform(const G4Transform3D &)
Definition: G4Polyline.cc:38
std::map< Index3D, float > kNestedModality
void setDoseDistName(std::string _name, int _num=0)
G4VSolid * GetSolid() const
G4GMocrenFileSceneHandler(G4GMocrenFile &system, G4GMocrenMessenger &messenger, const G4String &name="")
void setModalityImageDensityMap(std::vector< float > &_map)