Geant4  10.02.p03
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 97696 2016-06-07 10:23:09Z 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();
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 
510  G4cout << "***** G4GMocrenFileSceneHandler::GFBeginModeling (called & started)" << G4endl;
511 
512  //----- Send saving command and heading comment
513  BeginSavingGdd();
514 
515  kFlagInModeling = true ;
516 
517  // These models are entrusted to user commands /vis/scene/add/psHits or hits
518  //GetScene()->AddEndOfEventModel(new G4PSHitsModel());
519  //GetScene()->AddEndOfRunModel(new G4PSHitsModel());
520  //scene->AddEndOfEventModel(new G4HitsModel());
521  if(GFDEBUG_HIT) {
522  G4Scene * scene = GetScene();
523  std::vector<G4Scene::Model> vmodel = scene->GetEndOfEventModelList();
524  std::vector<G4Scene::Model>::iterator itr = vmodel.begin();
525  for(; itr != vmodel.end(); itr++) {
526  G4cout << " IIIIII model name: " << itr->fpModel->GetGlobalTag() << G4endl;
527  }
528  }
529  }
530 }
531 
532 
533 //========== AddPrimitive() functions ==========//
534 
535 //----- Add polyline
537 {
539  G4cout << "***** AddPrimitive" << G4endl;
540 
541  if (fProcessing2D) {
542  static G4bool warned = false;
543  if (!warned) {
544  warned = true;
546  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyline&)",
547  "gMocren1001", JustWarning,
548  "2D polylines not implemented. Ignored.");
549  }
550  return;
551  }
552 
553  //----- Initialize if necessary
554  GFBeginModeling();
555 
556  static G4int numTrajectories = 0;
557  if(numTrajectories >= MAX_NUM_TRAJECTORIES) return;
558 
559  // draw trajectories
561 
562  G4TrajectoriesModel * pTrModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
563  if (!pTrModel) {
564  G4Exception
565  ("G4VSceneHandler::AddCompound(const G4Polyline&)",
566  "gMocren0002", FatalException, "Not a G4TrajectoriesModel.");
567  }
568 
569  G4ThreeVector trans;
570  G4RotationMatrix rot;
571  trans = kVolumeTrans3D.getTranslation();
573 
574  if(GFDEBUG_TRK) G4cout << " trajectory points : " << G4endl;
575  std::vector<G4float *> trajectory;
576  if(polyline.size() < 2) return;
577  G4Polyline::const_iterator preitr = polyline.begin();
578  G4Polyline::const_iterator postitr = preitr; postitr++;
579  for(; postitr != polyline.end(); preitr++, postitr++) {
580  G4ThreeVector prePts(preitr->x(), preitr->y(), preitr->z());
581  prePts -= trans;
582  prePts.transform(rot);
583  G4ThreeVector postPts(postitr->x(), postitr->y(), postitr->z());
584  postPts -= trans;
585  postPts.transform(rot);
586  G4float * stepPts = new G4float[6];
587  stepPts[0] = prePts.x();
588  stepPts[1] = prePts.y();
589  stepPts[2] = prePts.z();
590  stepPts[3] = postPts.x();
591  stepPts[4] = postPts.y();
592  stepPts[5] = postPts.z();
593  trajectory.push_back(stepPts);
594 
595  if(GFDEBUG_TRK) {
596  G4cout << " ("
597  << stepPts[0] << ", "
598  << stepPts[1] << ", "
599  << stepPts[2] << ") - ("
600  << stepPts[3] << ", "
601  << stepPts[4] << ", "
602  << stepPts[5] << ")" << G4endl;
603  }
604  }
605 
606  const G4VisAttributes * att = polyline.GetVisAttributes();
607  G4Color color = att->GetColor();
608  unsigned char trkcolor[3];
609  trkcolor[0] = (unsigned char)(color.GetRed()*255);
610  trkcolor[1] = (unsigned char)(color.GetGreen()*255);
611  trkcolor[2] = (unsigned char)(color.GetBlue()*255);
612  if(GFDEBUG_TRK) {
613  G4cout << " color : ["
614  << color.GetRed() << ", "
615  << color.GetGreen() << ", "
616  << color.GetBlue() << "]" << G4endl;
617  }
618 
619  kgMocrenIO->addTrack(trajectory, trkcolor);
620 
621  numTrajectories++;
622  }
623 
624 } // G4GMocrenFileSceneHandler::AddPrimitive (polyline)
625 
626 
627 //----- Add text
629 {
630  if (fProcessing2D) {
631  static G4bool warned = false;
632  if (!warned) {
633  warned = true;
635  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Text&)",
636  "gMocren1002", JustWarning,
637  "2D text not implemented. Ignored.");
638  }
639  return;
640  }
641 
642  // to avoid a warning in the compile process
643  G4Text dummytext = text;
644 
645  //-----
647  G4cout << "***** AddPrimitive( G4Text )" << G4endl;
648 
649  //----- Initialize IF NECESSARY
650  GFBeginModeling();
651 
652 } // G4GMocrenFileSceneHandler::AddPrimitive ( text )
653 
654 
655 //----- Add circle
657 {
658  // to avoid a warning in the compile process
659  G4Circle dummycircle = mark_circle;
660 
661  if (fProcessing2D) {
662  static G4bool warned = false;
663  if (!warned) {
664  warned = true;
666  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Circle&)",
667  "gMocren1003", JustWarning,
668  "2D circles not implemented. Ignored.");
669  }
670  return;
671  }
672 
673  //-----
675  G4cout << "***** AddPrimitive( G4Circle )" << G4endl;
676 
677  //----- Initialize IF NECESSARY
678  GFBeginModeling();
679 
680 
681 } // G4GMocrenFileSceneHandler::AddPrimitive ( mark_circle )
682 
683 
684 //----- Add square
686 {
687  // to avoid a warning in the compile process
688  G4Square dummysquare = mark_square;
689 
690  if (fProcessing2D) {
691  static G4bool warned = false;
692  if (!warned) {
693  warned = true;
695  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Square&)",
696  "gMocren1004", JustWarning,
697  "2D squares not implemented. Ignored.");
698  }
699  return;
700  }
701 
702  //-----
704  G4cout << "***** AddPrimitive( G4Square )" << G4endl;
705 
706  //----- Initialize if necessary
707  GFBeginModeling();
708 
709 } // G4GMocrenFileSceneHandler::AddPrimitive ( mark_square )
710 
711 
712 //----- Add polyhedron
714 {
715  //-----
717  G4cout << "***** AddPrimitive( G4Polyhedron )" << G4endl;
718 
719 
720  if (polyhedron.GetNoFacets() == 0) return;
721 
722  if (fProcessing2D) {
723  static G4bool warned = false;
724  if (!warned) {
725  warned = true;
727  ("G4GMocrenFileSceneHandler::AddPrimitive (const G4Polyhedron&)",
728  "gMocren1005", JustWarning,
729  "2D polyhedra not implemented. Ignored.");
730  }
731  return;
732  }
733 
734  //----- Initialize if necessary
735  GFBeginModeling();
736 
737  //---------- (3) Facet block
738  for (G4int f = polyhedron.GetNoFacets(); f; f--){
739  G4bool notLastEdge = true;
740  G4int index = -1; // initialization
741  G4int edgeFlag = 1;
742  //G4int preedgeFlag = 1;
743  //G4int work[4], i = 0;
744  G4int i = 0;
745  do {
746  //preedgeFlag = edgeFlag;
747  notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
748  //work[i++] = index;
749  i++;
750  }while (notLastEdge);
751  switch (i){
752  case 3:
753  //SendStrInt3(FR_FACET, work[0], work[1], work[2] );
754  break;
755  case 4:
756  //SendStrInt4(FR_FACET, work[0], work[1], work[2], work[3] );
757  break;
758  default:
760  G4cout <<
761  "ERROR G4GMocrenFileSceneHandler::AddPrimitive(G4Polyhedron)" << G4endl;
762  G4PhysicalVolumeModel* pPVModel =
763  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
764  if (pPVModel)
766  G4cout << "Volume " << pPVModel->GetCurrentPV()->GetName() <<
767  ", Solid " << pPVModel->GetCurrentLV()->GetSolid()->GetName() <<
768  " (" << pPVModel->GetCurrentLV()->GetSolid()->GetEntityType();
769 
771  G4cout <<
772  "\nG4Polyhedron facet with " << i << " edges" << G4endl;
773  }
774  }
775 
776 } // G4GMocrenFileSceneHandler::AddPrimitive (polyhedron)
777 
778 
779 //-----
781 {
783 
784  //-----
786  G4cout << "***** GFEndModeling (called)" << G4endl;
787 
788  if( GFIsInModeling() ) {
789 
791  G4cout << "***** GFEndModeling (started) " ;
792  G4cout << "(/EndModeling, /DrawAll, /CloseDevice)" << G4endl;
793  }
794 
795  //----- End saving data to g4.gdd
796  EndSavingGdd() ;
797 
798  //------ Reset flag
799  kFlagInModeling = false ;
800 
801  }
802 
803 }
804 
805 
806 //-----
808 {
810  G4cout << "***** BeginPrimitives " << G4endl;
811 
812  GFBeginModeling();
813 
814  G4VSceneHandler::BeginPrimitives (objectTransformation);
815 
816 }
817 
818 
819 //-----
821 {
823  G4cout << "***** EndPrimitives " << G4endl;
824 
826 }
827 
828 
829 //========== AddSolid() functions ==========//
830 
831 //----- Add box
833 {
835  G4cout << "***** AddSolid ( box )" << G4endl;
836 
837  if(GFDEBUG_DET > 0)
838  G4cout << "G4GMocrenFileSceneHandler::AddSolid(const G4Box&) : "
839  << box.GetName() << G4endl;
840 
841  //----- skip drawing invisible primitive
842  if( !IsVisible() ) { return ; }
843 
844  //----- Initialize if necessary
845  GFBeginModeling();
846 
847 
848  //--
849  if(GFDEBUG_DET > 1) {
850  G4cout << "-------" << G4endl;
851  G4cout << " " << box.GetName() << G4endl;
852  G4Polyhedron * poly = box.CreatePolyhedron();
854  //G4int nv = poly->GetNoVertices();
855  G4Point3D v1, v2;
856  G4int next;
857  //while(1) { // next flag isn't functional.
858  for(G4int i = 0; i < 12; i++) { // # of edges is 12.
859  poly->GetNextEdge(v1, v2, next);
860  if(next == 0) break;
861  G4cout << " (" << v1.x() << ", "
862  << v1.y() << ", "
863  << v1.z() << ") - ("
864  << v2.x() << ", "
865  << v2.y() << ", "
866  << v2.z() << ") [" << next << "]"
867  << G4endl;
868  }
869  delete poly;
870  }
871 
872 
873  // the volume name set by /vis/gMocren/setVolumeName
874  G4String volName = kMessenger.getVolumeName();
875 
876  if(kFlagParameterization != 2) {
878  if(pScrMan) {
879  G4ScoringBox * pScBox = dynamic_cast<G4ScoringBox*>(pScrMan->FindMesh(volName));
880  G4bool bMesh = false;
881  if(pScBox != NULL) bMesh = true;
882  if(bMesh) kFlagParameterization = 2;
883  if(GFDEBUG_DET > 0) G4cout << " G4ScoringManager::FindMesh() : "
884  << volName << " - " << bMesh << G4endl;
885  }
886  }
887 
888  const G4VModel* pv_model = GetModel();
889  if (!pv_model) { return ; }
890  G4PhysicalVolumeModel* pPVModel =
891  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
892  if (!pPVModel) { return ; }
893 
894 
895  //-- debug information
896  if(GFDEBUG_DET > 0) {
897  G4Material * mat = pPVModel->GetCurrentMaterial();
898  G4String name = mat->GetName();
899  G4double dens = mat->GetDensity()/(g/cm3);
900  G4int copyNo = pPVModel->GetCurrentPV()->GetCopyNo();
901  G4int depth = pPVModel->GetCurrentDepth();
902  G4cout << " copy no.: " << copyNo << G4endl;
903  G4cout << " depth : " << depth << G4endl;
904  G4cout << " density : " << dens << " [g/cm3]" << G4endl;
905  G4cout << " location: " << pPVModel->GetCurrentPV()->GetObjectTranslation() << G4endl;
906  G4cout << " Multiplicity : " << pPVModel->GetCurrentPV()->GetMultiplicity() << G4endl;
907  G4cout << " Is replicated? : " << pPVModel->GetCurrentPV()->IsReplicated() << G4endl;
908  G4cout << " Is parameterised? : " << pPVModel->GetCurrentPV()->IsParameterised() << G4endl;
909  G4cout << " top phys. vol. name : " << pPVModel->GetTopPhysicalVolume()->GetName() << G4endl;
910  }
911 
912  //-- check the parameterised volume
913  if(box.GetName() == volName) {
914 
916  // coordination system correction for gMocren
917  G4ThreeVector raxis(1., 0., 0.), dummy(0.,0.,0.);
918  G4RotationMatrix rot(raxis, pi*rad);
919  G4Transform3D trot(rot, dummy);
920  if(GFDEBUG_DET) {
923  G4cout << "kVolumeTrans3D: " << trans1 << G4endl << rot1 << G4endl;
924  }
926  if(GFDEBUG_DET) G4cout << " Parameterised volume : " << box.GetName() << G4endl;
927 
928 
929 
930  //
931  G4VPhysicalVolume * pv[3] = {0,0,0};
932  pv[0] = pPVModel->GetCurrentPV()->GetLogicalVolume()->GetDaughter(0);
933  if(!pv[0]) {
934  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
935  "gMocren0003", FatalException, "Unexpected volume.");
936  }
937  G4int dirAxis[3] = {-1,-1,-1};
938  G4int nDaughters[3] = {0,0,0};
939 
940  EAxis axis; G4int nReplicas; G4double width; G4double offset; G4bool consuming;
941  pv[0]->GetReplicationData(axis, nReplicas, width, offset, consuming);
942  nDaughters[0] = nReplicas;
943  switch(axis) {
944  case kXAxis: dirAxis[0] = 0; break;
945  case kYAxis: dirAxis[0] = 1; break;
946  case kZAxis: dirAxis[0] = 2; break;
947  default:
948  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
949  "gMocren0004", FatalException, "Error.");
950  }
951  kNestedVolumeNames.push_back(pv[0]->GetName());
952  if(GFDEBUG_DET)
953  G4cout << " daughter name : " << pv[0]->GetName()
954  << " # : " << nDaughters[0] << G4endl;
955 
956  //
957  if(GFDEBUG_DET) {
958  if(pv[0]->GetLogicalVolume()->GetNoDaughters()) {
959  G4cout << "# of daughters : "
960  << pv[0]->GetLogicalVolume()->GetNoDaughters() << G4endl;
961  } else {
962  //G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
963  // "gMocren0005", FatalException, "Error.");
964  }
965  }
966 
967  // check whether nested or regular parameterization
968  if(GFDEBUG_DET) G4cout << "# of daughters : "
969  << pv[0]->GetLogicalVolume()->GetNoDaughters() << G4endl;
970  if(pv[0]->GetLogicalVolume()->GetNoDaughters() == 0) {
972  //G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
973  // "gMocren0006", FatalException, "Error.");
974  }
975 
976  if(kFlagParameterization == 0) {
977 
978  pv[1] = pv[0]->GetLogicalVolume()->GetDaughter(0);
979  if(pv[1]) {
980  pv[1]->GetReplicationData(axis, nReplicas, width, offset, consuming);
981  nDaughters[1] = nReplicas;
982  switch(axis) {
983  case kXAxis: dirAxis[1] = 0; break;
984  case kYAxis: dirAxis[1] = 1; break;
985  case kZAxis: dirAxis[1] = 2; break;
986  default:
987  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
988  "gMocren0007", FatalException, "Error.");
989  }
990  kNestedVolumeNames.push_back(pv[1]->GetName());
991  if(GFDEBUG_DET)
992  G4cout << " sub-daughter name : " << pv[1]->GetName()
993  << " # : " << nDaughters[1]<< G4endl;
994 
995  //
996  pv[2] = pv[1]->GetLogicalVolume()->GetDaughter(0);
997  if(pv[2]) {
998  nDaughters[2] = pv[2]->GetMultiplicity();
999  kNestedVolumeNames.push_back(pv[2]->GetName());
1000  if(GFDEBUG_DET)
1001  G4cout << " sub-sub-daughter name : " << pv[2]->GetName()
1002  << " # : " << nDaughters[2] << G4endl;
1003 
1004  if(nDaughters[2] > 1) {
1005  G4VNestedParameterisation * nestPara
1006  = dynamic_cast<G4VNestedParameterisation*>(pv[2]->GetParameterisation());
1007  if(nestPara == NULL)
1008  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1009  "gMocren0008", FatalException, "Non-nested parameterisation");
1010 
1011  nestPara->ComputeTransformation(0, pv[2]);
1012  G4ThreeVector trans0 = pv[2]->GetObjectTranslation();
1013  nestPara->ComputeTransformation(1, pv[2]);
1014  G4ThreeVector trans1 = pv[2]->GetObjectTranslation();
1015  G4ThreeVector diff(trans0 - trans1);
1016  if(GFDEBUG_DET)
1017  G4cout << trans0 << " - " << trans1 << " - " << diff << G4endl;
1018 
1019  if(diff.x() != 0.) dirAxis[2] = 0;
1020  else if(diff.y() != 0.) dirAxis[2] = 1;
1021  else if(diff.z() != 0.) dirAxis[2] = 2;
1022  else
1023  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1024  "gMocren0009", FatalException, "Unexpected nested parameterisation");
1025  }
1026  }
1027  }
1028 
1029  for(G4int i = 0; i < 3; i++) {
1030  kNestedVolumeDimension[i] = nDaughters[i];
1031  //kNestedVolumeDimension[i] = nDaughters[dirAxis[i]];
1032  kNestedVolumeDirAxis[i] = dirAxis[i];
1033  }
1034  //G4cout << "@@@@@@@@@ "
1035  // << dirAxis[0] << ", " << dirAxis[1] << ", " << dirAxis[2] << G4endl;
1036 
1037  // get densities
1038  G4VNestedParameterisation * nestPara
1039  = dynamic_cast<G4VNestedParameterisation*>(pv[2]->GetParameterisation());
1040  if(nestPara != NULL) {
1041  G4double prexyz[3] = {0.,0.,0.}, xyz[3] = {0.,0.,0.};
1042  for(G4int n0 = 0; n0 < nDaughters[0]; n0++) {
1043  for(G4int n1 = 0; n1 < nDaughters[1]; n1++) {
1044  for(G4int n2 = 0; n2 < nDaughters[2]; n2++) {
1045 
1046  G4GMocrenTouchable * touch = new G4GMocrenTouchable(n1, n0);
1047  if(GFDEBUG_DET)
1048  G4cout << " retrieve volume : copy # : " << n0
1049  << ", " << n1 << ", " << n2 << G4endl;
1050  G4Material * mat = nestPara->ComputeMaterial(pv[2], n2, touch);
1051  delete touch;
1052  G4double dens = mat->GetDensity()/(g/cm3);
1053 
1054  if(GFDEBUG_DET)
1055  G4cout << " density :" << dens << " [g/cm3]" << G4endl;
1056 
1057  G4Box tbox(box);
1058  nestPara->ComputeDimensions(tbox, n2, pv[2]);
1059  xyz[0] = tbox.GetXHalfLength()/mm;
1060  xyz[1] = tbox.GetYHalfLength()/mm;
1061  xyz[2] = tbox.GetZHalfLength()/mm;
1062  if(n0 != 0 || n1 != 0 || n2 != 0) {
1063  for(G4int i = 0; i < 3; i++) {
1064  if(xyz[i] != prexyz[i])
1065  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1066  "gMocren0010", FatalException, "Unsupported parameterisation");
1067  }
1068  }
1069  if(GFDEBUG_DET)
1070  G4cout << " size : " << tbox.GetXHalfLength()/mm << " x "
1071  << tbox.GetYHalfLength()/mm << " x "
1072  << tbox.GetZHalfLength()/mm << " [mm3]" << G4endl;
1073 
1074  G4int idx[3];
1075  idx[dirAxis[0]] = n0;
1076  idx[dirAxis[1]] = n1;
1077  idx[dirAxis[2]] = n2;
1078  Index3D i3d(idx[0],idx[1],idx[2]);
1079  kNestedModality[i3d] = dens;
1080  if(GFDEBUG_DET)
1081  G4cout << " index: " << idx[0] << ", " << idx[1] << ", " << idx[2]
1082  << " density: " << dens << G4endl;
1083 
1084  for(G4int i = 0; i < 3; i++) prexyz[i] = xyz[i];
1085  }
1086  }
1087  }
1088 
1089  kVolumeSize.set(box.GetXHalfLength()*2/mm,
1090  box.GetYHalfLength()*2/mm,
1091  box.GetZHalfLength()*2/mm);
1092  // mesh size
1093  if(!kbSetModalityVoxelSize) {
1094  G4float spacing[3] = {static_cast<G4float>(2*xyz[0]),
1095  static_cast<G4float>(2*xyz[1]),
1096  static_cast<G4float>(2*xyz[2])};
1097  kgMocrenIO->setVoxelSpacing(spacing);
1098  kVoxelDimension.set(spacing[0], spacing[1], spacing[2]);
1099  kbSetModalityVoxelSize = true;
1100  }
1101 
1102  } else {
1103  if(GFDEBUG_DET)
1104  G4cout << pv[2]->GetName() << G4endl;
1105  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1106  "gMocren0011", FatalException, "Non-nested parameterisation");
1107  }
1108 
1109 
1110 
1111  //-- debug
1112  if(GFDEBUG_DET > 1) {
1113  if(pPVModel->GetCurrentPV()->IsParameterised()) {
1114  G4VPVParameterisation * para = pPVModel->GetCurrentPV()->GetParameterisation();
1115  G4cout << " Is nested parameterisation? : " << para->IsNested() << G4endl;
1116 
1117 
1118  G4int npvp = pPVModel->GetDrawnPVPath().size();
1119  G4cout << " physical volume node id : "
1120  << "size: " << npvp << ", PV name: ";
1121  for(G4int i = 0; i < npvp; i++) {
1122  G4cout << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetName()
1123  << " [param:"
1124  << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->IsParameterised()
1125  << ",rep:"
1126  << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->IsReplicated();
1127  if(pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()) {
1128  G4cout << ",nest:"
1129  << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetParameterisation()->IsNested();
1130  }
1131  G4cout << ",copyno:"
1132  << pPVModel->GetDrawnPVPath()[i].GetPhysicalVolume()->GetCopyNo();
1133  G4cout << "] - ";
1134  }
1135  G4cout << G4endl;
1136 
1137 
1138  pPVModel->GetCurrentPV()->GetReplicationData(axis, nReplicas, width, offset, consuming);
1139  G4cout << " # replicas : " << nReplicas << G4endl;
1140  G4double pareDims[3] = {0.,0.,0.};
1141  G4Box * pbox = dynamic_cast<G4Box *>(pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1142  if(pbox) {
1143  pareDims[0] = 2.*pbox->GetXHalfLength()*mm;
1144  pareDims[1] = 2.*pbox->GetYHalfLength()*mm;
1145  pareDims[2] = 2.*pbox->GetZHalfLength()*mm;
1146  G4cout << " mother size ["
1147  << pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName()
1148  << "] : "
1149  << pareDims[0] << " x "
1150  << pareDims[1] << " x "
1151  << pareDims[2] << " [mm3]"
1152  << G4endl;
1153  }
1154  G4double paraDims[3];
1155  G4Box * boxP = dynamic_cast<G4Box *>(pPVModel->GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetLogicalVolume()->GetSolid());
1156  if(boxP) {
1157  paraDims[0] = 2.*boxP->GetXHalfLength()*mm;
1158  paraDims[1] = 2.*boxP->GetYHalfLength()*mm;
1159  paraDims[2] = 2.*boxP->GetZHalfLength()*mm;
1160  G4cout << " parameterised volume? ["
1161  << pPVModel->GetDrawnPVPath()[npvp-1].GetPhysicalVolume()->GetName()
1162  << "] : "
1163  << paraDims[0] << " x "
1164  << paraDims[1] << " x "
1165  << paraDims[2] << " [mm3] : "
1166  << G4int(pareDims[0]/paraDims[0]) << " x "
1167  << G4int(pareDims[1]/paraDims[1]) << " x "
1168  << G4int(pareDims[2]/paraDims[2]) << G4endl;
1169  } else {
1170  G4cout << pPVModel->GetDrawnPVPath()[npvp-2].GetPhysicalVolume()->GetName()
1171  << " isn't a G4Box." << G4endl;
1172  }
1173  }
1174  }
1175 
1176 
1177  } else if(kFlagParameterization == 1) { // G4PhantomParameterisation based geom. construnction
1178 
1179  // get the dimension of the parameterized patient geometry
1180  G4PhantomParameterisation * phantomPara
1181  = dynamic_cast<G4PhantomParameterisation*>(pv[0]->GetParameterisation());
1182  if(phantomPara == NULL) {
1183  G4Exception("G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )",
1184  "gMocren0012", FatalException, "no G4PhantomParameterisation");
1185  } else {
1186  ;
1187  }
1188 
1189  kNestedVolumeDimension[0] = phantomPara->GetNoVoxelX();
1190  kNestedVolumeDimension[1] = phantomPara->GetNoVoxelY();
1191  kNestedVolumeDimension[2] = phantomPara->GetNoVoxelZ();
1192  kNestedVolumeDirAxis[0] = 0;
1193  kNestedVolumeDirAxis[1] = 1;
1194  kNestedVolumeDirAxis[2] = 2;
1195 
1196  // get densities of the parameterized patient geometry
1197  G4int nX = kNestedVolumeDimension[0];
1199 
1200  for(G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1201  for(G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1202  for(G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1203 
1204  G4int repNo = n0 + n1*nX + n2*nXY;
1205  G4Material * mat = phantomPara->ComputeMaterial(repNo, pv[0]);
1206  G4double dens = mat->GetDensity()/(g/cm3);
1207 
1208 
1209  G4int idx[3];
1210  idx[kNestedVolumeDirAxis[0]] = n0;
1211  idx[kNestedVolumeDirAxis[1]] = n1;
1212  idx[kNestedVolumeDirAxis[2]] = n2;
1213  Index3D i3d(idx[0],idx[1],idx[2]);
1214  kNestedModality[i3d] = dens;
1215 
1216  if(GFDEBUG_DET)
1217  G4cout << " index: " << idx[0] << ", " << idx[1] << ", " << idx[2]
1218  << " density: " << dens << G4endl;
1219 
1220  }
1221  }
1222  }
1223 
1224  kVolumeSize.set(box.GetXHalfLength()*2/mm,
1225  box.GetYHalfLength()*2/mm,
1226  box.GetZHalfLength()*2/mm);
1227 
1228  // mesh size
1229  if(!kbSetModalityVoxelSize) {
1230  G4float spacing[3] = {static_cast<G4float>(2*phantomPara->GetVoxelHalfX()),
1231  static_cast<G4float>(2*phantomPara->GetVoxelHalfY()),
1232  static_cast<G4float>(2*phantomPara->GetVoxelHalfZ())};
1233  kgMocrenIO->setVoxelSpacing(spacing);
1234  kVoxelDimension.set(spacing[0], spacing[1], spacing[2]);
1235  kbSetModalityVoxelSize = true;
1236  }
1237  }
1238 
1239  } // if(box.GetName() == volName)
1240 
1241 
1242  // processing geometry construction based on the interactive PS
1244 
1245 
1246  // get the dimension of the geometry defined in G4VScoringMesh
1248  if(!pScrMan) return;
1249  G4ScoringBox * scoringBox
1250  = dynamic_cast<G4ScoringBox*>(pScrMan->FindMesh(volName));
1251  if(scoringBox == NULL) return;
1252 
1253 
1254  G4int nVoxels[3];
1255  scoringBox->GetNumberOfSegments(nVoxels);
1256  // this order depends on the G4ScoringBox
1257  kNestedVolumeDimension[0] = nVoxels[2];
1258  kNestedVolumeDimension[1] = nVoxels[1];
1259  kNestedVolumeDimension[2] = nVoxels[0];
1260  kNestedVolumeDirAxis[0] = 2;
1261  kNestedVolumeDirAxis[1] = 1;
1262  kNestedVolumeDirAxis[2] = 0;
1263 
1264  // get densities of the parameterized patient geometry
1265  for(G4int n0 = 0; n0 < kNestedVolumeDimension[0]; n0++) {
1266  for(G4int n1 = 0; n1 < kNestedVolumeDimension[1]; n1++) {
1267  for(G4int n2 = 0; n2 < kNestedVolumeDimension[2]; n2++) {
1268 
1269  G4double dens = 0.*(g/cm3);
1270 
1271  G4int idx[3];
1272  idx[kNestedVolumeDirAxis[0]] = n0;
1273  idx[kNestedVolumeDirAxis[1]] = n1;
1274  idx[kNestedVolumeDirAxis[2]] = n2;
1275  Index3D i3d(idx[0],idx[1],idx[2]);
1276  kNestedModality[i3d] = dens;
1277 
1278  }
1279  }
1280  }
1281 
1282  G4ThreeVector boxSize = scoringBox->GetSize();
1283  if(GFDEBUG_DET > 1) {
1284  G4cout << "Interactive Scorer : size - "
1285  << boxSize.x()/cm << " x "
1286  << boxSize.y()/cm << " x "
1287  << boxSize.z()/cm << " [cm3]" << G4endl;
1288  G4cout << "Interactive Scorer : # voxels - "
1289  << nVoxels[0] << " x "
1290  << nVoxels[1] << " x "
1291  << nVoxels[2] << G4endl;
1292  }
1293  kVolumeSize.set(boxSize.x()*2,
1294  boxSize.y()*2,
1295  boxSize.z()*2);
1296 
1297  // mesh size
1298  if(!kbSetModalityVoxelSize) {
1299  G4float spacing[3] = {static_cast<G4float>(boxSize.x()*2/nVoxels[0]),
1300  static_cast<G4float>(boxSize.y()*2/nVoxels[1]),
1301  static_cast<G4float>(boxSize.z()*2/nVoxels[2])};
1302 
1303  kgMocrenIO->setVoxelSpacing(spacing);
1304  kVoxelDimension.set(spacing[0], spacing[1], spacing[2]);
1305  kbSetModalityVoxelSize = true;
1306 
1307  }
1308 
1309 
1311 
1312  // translation for the scoring mesh
1313  G4ThreeVector sbth = scoringBox->GetTranslation();
1314  G4Translate3D sbtranslate(sbth);
1315  kVolumeTrans3D = kVolumeTrans3D*sbtranslate;
1316 
1317  // rotation matrix for the scoring mesh
1318  G4RotationMatrix sbrm;
1319  sbrm = scoringBox->GetRotationMatrix();
1320  if(!sbrm.isIdentity()) {
1321  G4ThreeVector sbdummy(0.,0.,0.);
1322  G4Transform3D sbrotate(sbrm.inverse(), sbdummy);
1323  kVolumeTrans3D = kVolumeTrans3D*sbrotate;
1324  }
1325 
1326 
1327  // coordination system correction for gMocren
1328  G4ThreeVector raxisY(0., 1., 0.), dummyY(0.,0.,0.);
1329  G4RotationMatrix rotY(raxisY, pi*rad);
1330  G4Transform3D trotY(rotY, dummyY);
1331  G4ThreeVector raxisZ(0., 0., 1.), dummyZ(0.,0.,0.);
1332  G4RotationMatrix rotZ(raxisZ, pi*rad);
1333  G4Transform3D trotZ(rotZ, dummyZ);
1334 
1335  kVolumeTrans3D = kVolumeTrans3D*trotY*trotZ;
1336 
1337 
1338  //
1340  }
1341 
1342 
1343 
1344  //-- add detectors
1345  G4bool bAddDet = true;
1346  if(!kMessenger.getDrawVolumeGrid()) {
1347 
1348  if(kFlagParameterization == 0) { // nested parameterisation
1349 
1350  if(volName == box.GetName()) {
1351  bAddDet = false;
1352  }
1353 
1354  std::vector<G4String>::iterator itr = kNestedVolumeNames.begin();
1355  for(; itr != kNestedVolumeNames.end(); itr++) {
1356  if(*itr == box.GetName()) {
1357  bAddDet = false;
1358  break;
1359  }
1360  }
1361  } else if(kFlagParameterization == 1) { // phantom paramemterisation
1362 
1363  if(volName != box.GetName()) {
1364  bAddDet = false;
1365  }
1366 
1367  } else if(kFlagParameterization == 2) { // interactive primitive scorer
1368  ;
1369  }
1370 
1371  }
1372  if(bAddDet) AddDetector(box);
1373 
1374 
1375 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Box& box )
1376 
1377 
1378 //----- Add tubes
1379 void
1381 {
1383  G4cout << "***** AddSolid ( tubes )" << G4endl;
1384 
1385  //----- skip drawing invisible primitive
1386  if( !IsVisible() ) { return ; }
1387 
1388  //----- Initialize if necessary
1389  GFBeginModeling();
1390 
1391  //
1392  AddDetector(tubes);
1393 
1394 
1395  // for a debug
1396  if(GFDEBUG_DET > 0) {
1397  G4cout << "-------" << G4endl;
1398  G4cout << " " << tubes.GetName() << G4endl;
1399  G4Polyhedron * poly = tubes.CreatePolyhedron();
1400  G4int nv = poly->GetNoVertices();
1401  for(G4int i = 0; i < nv; i++) {
1402  G4cout << " (" << poly->GetVertex(i).x() << ", "
1403  << poly->GetVertex(i).y() << ", "
1404  << poly->GetVertex(i).z() << ")" << G4endl;
1405  }
1406  delete poly;
1407  }
1408 
1409  const G4VModel* pv_model = GetModel();
1410  if (!pv_model) { return ; }
1411  G4PhysicalVolumeModel* pPVModel =
1412  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
1413  if (!pPVModel) { return ; }
1414  G4Material * mat = pPVModel->GetCurrentMaterial();
1415  G4String name = mat->GetName();
1416 
1417 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Tubs& )
1418 
1419 
1420 
1421 //----- Add cons
1422 void
1424 {
1426  G4cout << "***** AddSolid ( cons )" << G4endl;
1427 
1428  //----- skip drawing invisible primitive
1429  if( !IsVisible() ) { return ; }
1430 
1431  //----- Initialize if necessary
1432  GFBeginModeling();
1433 
1434  //
1435  AddDetector(cons);
1436 
1437 }// G4GMocrenFileSceneHandler::AddSolid( cons )
1438 
1439 
1440 //----- Add trd
1442 {
1444  G4cout << "***** AddSolid ( trd )" << G4endl;
1445 
1446 
1447  //----- skip drawing invisible primitive
1448  if( !IsVisible() ) { return ; }
1449 
1450  //----- Initialize if necessary
1451  GFBeginModeling();
1452 
1453  //
1454  AddDetector(trd);
1455 
1456 } // G4GMocrenFileSceneHandler::AddSolid ( trd )
1457 
1458 
1459 //----- Add sphere
1461 {
1463  G4cout << "***** AddSolid ( sphere )" << G4endl;
1464 
1465  //----- skip drawing invisible primitive
1466  if( !IsVisible() ) { return ; }
1467 
1468  //----- Initialize if necessary
1469  GFBeginModeling();
1470 
1471  //
1472  AddDetector(sphere);
1473 
1474 } // G4GMocrenFileSceneHandler::AddSolid ( sphere )
1475 
1476 
1477 //----- Add para
1479 {
1481  G4cout << "***** AddSolid ( para )" << G4endl;
1482 
1483  //----- skip drawing invisible primitive
1484  if( !IsVisible() ) { return ; }
1485 
1486  //----- Initialize if necessary
1487  GFBeginModeling();
1488 
1489  //
1490  AddDetector(para);
1491 
1492 } // G4GMocrenFileSceneHandler::AddSolid ( para )
1493 
1494 
1495 //----- Add trap
1497 {
1499  G4cout << "***** AddSolid ( trap )" << G4endl;
1500 
1501  //----- skip drawing invisible primitive
1502  if( !IsVisible() ) { return ; }
1503 
1504  //----- Initialize if necessary
1505  GFBeginModeling();
1506 
1507  //
1508  AddDetector(trap);
1509 
1510 } // G4GMocrenFileSceneHandler::AddSolid (const G4Trap& trap)
1511 
1512 
1513 //----- Add torus
1514 void
1516 {
1518  G4cout << "***** AddSolid ( torus )" << G4endl;
1519 
1520  //----- skip drawing invisible primitive
1521  if( !IsVisible() ) { return ; }
1522 
1523  //----- Initialize if necessary
1524  GFBeginModeling();
1525 
1526  //
1527  AddDetector(torus);
1528 
1529 } // void G4GMocrenFileSceneHandler::AddSolid( const G4Torus& )
1530 
1531 
1532 
1533 //----- Add a shape which is not treated above
1535 {
1536  //----- skip drawing invisible primitive
1537  if( !IsVisible() ) { return ; }
1538 
1539  //----- Initialize if necessary
1540  GFBeginModeling();
1541 
1542  //
1543  AddDetector(solid);
1544 
1545  //----- Send a primitive
1546  G4VSceneHandler::AddSolid( solid ) ;
1547 
1548 } //G4GMocrenFileSceneHandler::AddSolid ( const G4VSolid& )
1549 
1550 #include "G4TrajectoriesModel.hh"
1551 #include "G4VTrajectory.hh"
1552 #include "G4VTrajectoryPoint.hh"
1553 
1554 //----- Add a trajectory
1556 
1557  kbModelingTrajectory = true;
1558 
1560 
1561  if(GFDEBUG_TRK) {
1562  G4cout << " ::AddCompound(const G4VTrajectory&) >>>>>>>>> " << G4endl;
1563  G4TrajectoriesModel * pTrModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
1564  if (!pTrModel) {
1565  G4Exception
1566  ("G4VSceneHandler::AddCompound(const G4VTrajectory&)",
1567  "gMocren0013", FatalException, "Not a G4TrajectoriesModel.");
1568  } else {
1569  traj.DrawTrajectory();
1570 
1571  const G4VTrajectory * trj = pTrModel->GetCurrentTrajectory();
1572  G4cout << "------ track" << G4endl;
1573  G4cout << " name: " << trj->GetParticleName() << G4endl;
1574  G4cout << " id: " << trj->GetTrackID() << G4endl;
1575  G4cout << " charge: " << trj->GetCharge() << G4endl;
1576  G4cout << " momentum: " << trj->GetInitialMomentum() << G4endl;
1577 
1578  G4int nPnt = trj->GetPointEntries();
1579  G4cout << " point: ";
1580  for(G4int i = 0; i < nPnt; i++) {
1581  G4cout << trj->GetPoint(i)->GetPosition() << ", ";
1582  }
1583  G4cout << G4endl;
1584  }
1585  G4cout << G4endl;
1586  }
1587 
1588  kbModelingTrajectory = false;
1589 }
1590 
1591 #include <vector>
1592 #include "G4VHit.hh"
1593 #include "G4AttValue.hh"
1594 //----- Add a hit
1596  if(GFDEBUG_HIT) G4cout << " ::AddCompound(const G4VHit&) >>>>>>>>> " << G4endl;
1597 
1599 
1600  /*
1601  const std::map<G4String, G4AttDef> * map = hit.GetAttDefs();
1602  if(!map) return;
1603  std::map<G4String, G4AttDef>::const_iterator itr = map->begin();
1604  for(; itr != map->end(); itr++) {
1605  G4cout << itr->first << " : " << itr->second.GetName()
1606  << " , " << itr->second.GetDesc() << G4endl;
1607  }
1608  */
1609 
1610  std::vector<G4String> hitNames = kMessenger.getHitNames();
1611  if(GFDEBUG_HIT) {
1612  std::vector<G4String>::iterator itr = hitNames.begin();
1613  for(; itr != hitNames.end(); itr++)
1614  G4cout << " hit name : " << *itr << G4endl;
1615  }
1616 
1617  std::vector<G4AttValue> * attval = hit.CreateAttValues();
1618  if(!attval) {G4cout << "0 empty " << G4endl;}
1619  else {
1620 
1621  G4bool bid[3] = {false, false, false};
1622  Index3D id;
1623 
1624  std::vector<G4AttValue>::iterator itr;
1625  // First, get IDs
1626  for(itr = attval->begin(); itr != attval->end(); itr++) {
1627  std::string stmp = itr->GetValue();
1628  std::istringstream sval(stmp.c_str());
1629 
1630  if(itr->GetName() == G4String("XID")) {
1631  sval >> id.x;
1632  bid[0] = true;
1633  continue;
1634  }
1635  if(itr->GetName() == G4String("YID")) {
1636  sval >> id.y;
1637  bid[1] = true;
1638  continue;
1639  }
1640  if(itr->GetName() == G4String("ZID")) {
1641  sval >> id.z;
1642  bid[2] = true;
1643  continue;
1644  }
1645  }
1646 
1647  G4int nhitname = (G4int)hitNames.size();
1648 
1649  if(bid[0] && bid[1] && bid[2]) {
1650 
1651  if(GFDEBUG_HIT)
1652  G4cout << " Hit : index(" << id.x << ", " << id.y << ", "
1653  << id.z << ")" << G4endl;
1654 
1655  // Get attributes
1656  for(itr = attval->begin(); itr != attval->end(); itr++) {
1657  for(G4int i = 0; i < nhitname; i++) {
1658  if(itr->GetName() == hitNames[i]) {
1659 
1660  std::string stmp = itr->GetValue();
1661  std::istringstream sval(stmp.c_str());
1662  G4double value;
1663  G4String unit;
1664  sval >> value >> unit;
1665 
1666  std::map<G4String, std::map<Index3D, G4double> >::iterator kNestedHitsListItr;
1667  kNestedHitsListItr = kNestedHitsList.find(hitNames[i]);
1668  if(kNestedHitsListItr != kNestedHitsList.end()) {
1669  //fTempNestedHits = &kNestedHitsListItr->second;
1670  //(*fTempNestedHits)[id] = value;
1671  kNestedHitsListItr->second[id] = value;
1672  } else {
1673  std::map<Index3D, G4double> hits;
1674  hits.insert(std::map<Index3D, G4double>::value_type(id, value));
1675  kNestedHitsList[hitNames[i]] = hits;
1676  }
1677 
1678 
1679  if(GFDEBUG_HIT)
1680  G4cout << " : " << hitNames[i] << " -> " << value
1681  << " [" << unit << "]" << G4endl;
1682  }
1683  }
1684  }
1685  } else {
1686  G4Exception("G4GMocrenFileSceneHandler::AddCompound(const G4VHit &)",
1687  "gMocren0014", FatalException, "Error");
1688  }
1689 
1690  delete attval;
1691  }
1692 
1693 }
1694 
1696  if(GFDEBUG_DIGI) G4cout << " ::AddCompound(const G4VDigi&) >>>>>>>>> " << G4endl;
1698 }
1699 
1701  if(GFDEBUG_HIT)
1702  G4cout << " ::AddCompound(const std::map<G4int, G4double*> &) >>>>>>>>> " << G4endl;
1703 
1704 
1705  std::vector<G4String> hitScorerNames = kMessenger.getHitScorerNames();
1706  G4int nhitname = (G4int)hitScorerNames.size();
1707  G4String scorername = static_cast<G4VHitsCollection>(hits).GetName();
1708 
1709  //-- --//
1710  /*
1711  std::vector<G4String> hitScorerNames = kMessenger.getHitScorerNames();
1712  if(GFDEBUG_HIT) {
1713  std::vector<G4String>::iterator itr = hitScorerNames.begin();
1714  for(; itr != hitScorerNames.end(); itr++)
1715  G4cout << " PS name : " << *itr << G4endl;
1716  }
1717  */
1718 
1719  { // Scope bracket to avoid compiler messages about shadowing (JA).
1720  //for(G4int i = 0; i < nhitname; i++) { // this selection trusts
1721  //if(scorername == hitScorerNames[i]) { // thea command /vis/scene/add/psHits hit_name.
1722 
1723  G4int idx[3];
1724  std::map<G4int, G4double*> * map = hits.GetMap();
1725  std::map<G4int, G4double*>::const_iterator itr = map->begin();
1726  for(; itr != map->end(); itr++) {
1727  GetNestedVolumeIndex(itr->first, idx);
1728  Index3D id(idx[0], idx[1], idx[2]);
1729 
1730  std::map<G4String, std::map<Index3D, G4double> >::iterator nestedHitsListItr;
1731  nestedHitsListItr = kNestedHitsList.find(scorername);
1732  if(nestedHitsListItr != kNestedHitsList.end()) {
1733  nestedHitsListItr->second[id] = *itr->second;
1734  } else {
1735  std::map<Index3D, G4double> hit;
1736  hit.insert(std::map<Index3D, G4double>::value_type(id, *itr->second));
1737  kNestedHitsList[scorername] = hit;
1738  }
1739  }
1740 
1741  //break;
1742  //}
1743  //}
1744  }
1745 
1746  if(GFDEBUG_HIT) {
1747  G4String meshname = static_cast<G4VHitsCollection>(hits).GetSDname();
1748  G4cout << " >>>>> " << meshname << " : " << scorername << G4endl;
1749 
1750  for(G4int i = 0; i < nhitname; i++)
1751  if(scorername == hitScorerNames[i])
1752  G4cout << " !!!! Hit scorer !!!! " << scorername << G4endl;
1753 
1754  G4cout << " dimension: "
1755  << kNestedVolumeDimension[0] << " x "
1756  << kNestedVolumeDimension[1] << " x "
1757  << kNestedVolumeDimension[2] << G4endl;
1758 
1759  G4int id[3];
1760  std::map<G4int, G4double*> * map = hits.GetMap();
1761  std::map<G4int, G4double*>::const_iterator itr = map->begin();
1762  for(; itr != map->end(); itr++) {
1763  GetNestedVolumeIndex(itr->first, id);
1764  G4cout << "[" << itr->first << "] "
1765  << "("<< id[0] << "," << id[1] << "," << id[2] << ")"
1766  << *itr->second << ", ";
1767  }
1768  G4cout << G4endl;
1769  }
1770 
1771 }
1772 
1773 //-----
1775 {
1776  //-----
1777  G4bool visibility = true ;
1778 
1779  const G4VisAttributes* pVisAttribs =
1781 
1782  if(pVisAttribs) {
1783  visibility = pVisAttribs->IsVisible();
1784  }
1785 
1786  return visibility ;
1787 
1788 } // G4GMocrenFileSceneHandler::IsVisible()
1789 
1790 
1791 //-----
1793 {
1794  // This is typically called after an update and before drawing hits
1795  // of the next event. To simulate the clearing of "transients"
1796  // (hits, etc.) the detector is redrawn...
1797  if (fpViewer) {
1798  fpViewer -> SetView ();
1799  fpViewer -> ClearView ();
1800  fpViewer -> DrawView ();
1801  }
1802 }
1803 
1804 //-----
1806 
1807  Detector detector;
1808 
1809  // detector name
1810  detector.name = solid.GetName();
1811  if(GFDEBUG_DET > 1)
1812  G4cout << "0 Detector name : " << detector.name << G4endl;
1813 
1814  const G4VModel* pv_model = GetModel();
1815  if (!pv_model) { return ; }
1816  G4PhysicalVolumeModel* pPVModel =
1817  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
1818  if (!pPVModel) { return ; }
1819 
1820  // edge points of the detector
1821  std::vector<G4float *> dedges;
1822  G4Polyhedron * poly = solid.CreatePolyhedron();
1823  detector.polyhedron = poly;
1825 
1826  // retrieve color
1827  unsigned char uccolor[3] = {30, 30, 30};
1828  if(pPVModel->GetCurrentLV()->GetVisAttributes()) {
1829  G4Color color = pPVModel->GetCurrentLV()->GetVisAttributes()->GetColor();
1830  uccolor[0] = (unsigned char)(color.GetRed()*255);
1831  uccolor[1] = (unsigned char)(color.GetGreen()*255);
1832  uccolor[2] = (unsigned char)(color.GetBlue()*255);
1833  //if(uccolor[0] < 2 && uccolor[1] < 2 && uccolor[2] < 2)
1834  //uccolor[0] = uccolor[1] = uccolor[2] = 30; // dark grey
1835  }
1836  for(G4int i = 0; i < 3; i++) detector.color[i] = uccolor[i];
1837  //
1838  kDetectors.push_back(detector);
1839 
1840  if(GFDEBUG_DET > 1) {
1841  G4cout << "0 color: (" << (G4int)uccolor[0] << ", "
1842  << (G4int)uccolor[1] << ", " << (G4int)uccolor[2] << ")"
1843  << G4endl;
1844  }
1845 
1846 }
1847 
1848 //-----
1850 
1851  std::vector<Detector>::iterator itr = kDetectors.begin();
1852 
1853  for(; itr != kDetectors.end(); itr++) {
1854 
1855  // detector name
1856  G4String detname = itr->name;
1857  if(GFDEBUG_DET > 1)
1858  G4cout << "Detector name : " << detname << G4endl;
1859 
1860  // edge points of the detector
1861  std::vector<G4float *> dedges;
1862  G4Polyhedron * poly = itr->polyhedron;
1863  poly->Transform(itr->transform3D);
1864  G4Transform3D invVolTrans = kVolumeTrans3D.inverse();
1865  poly->Transform(invVolTrans);
1866 
1867  G4Point3D v1, v2;
1868  G4bool bnext = true;
1869  G4int next;
1870  G4int nedges = 0;
1871  //
1872  while(bnext) {
1873  if(!(poly->GetNextEdge(v1, v2, next))) bnext =false;
1874  G4float * edge = new G4float[6];
1875  edge[0] = v1.x()/mm;
1876  edge[1] = v1.y()/mm;
1877  edge[2] = v1.z()/mm;
1878  edge[3] = v2.x()/mm;
1879  edge[4] = v2.y()/mm;
1880  edge[5] = v2.z()/mm;
1881  dedges.push_back(edge);
1882  nedges++;
1883  }
1884  //delete poly;
1885  // detector color
1886  unsigned char uccolor[3] = {itr->color[0],
1887  itr->color[1],
1888  itr->color[2]};
1889  //
1890  kgMocrenIO->addDetector(detname, dedges, uccolor);
1891  for(G4int i = 0; i < nedges; i++) { // # of edges is 12.
1892  delete [] dedges[i];
1893  }
1894  dedges.clear();
1895 
1896  if(GFDEBUG_DET > 1) {
1897  G4cout << " color: (" << (G4int)uccolor[0] << ", "
1898  << (G4int)uccolor[1] << ", " << (G4int)uccolor[2] << ")"
1899  << G4endl;
1900  }
1901  }
1902 }
1903 
1905  if(kNestedVolumeDimension[0] == 0 ||
1906  kNestedVolumeDimension[1] == 0 ||
1907  kNestedVolumeDimension[2] == 0) {
1908  for(G4int i = 0; i < 3; i++) _idx3d[i] = 0;
1909  return;
1910  }
1911 
1912 
1913  if(kFlagParameterization == 0) {
1914 
1916  G4int line = kNestedVolumeDimension[2];
1917 
1918  /*
1919  G4int idx3d[3];
1920  idx3d[0] = _idx/plane;
1921  idx3d[1] = (_idx%plane)/line;
1922  idx3d[2] = (_idx%plane)%line;
1923  _idx3d[0] = idx3d[kNestedVolumeDirAxis[0]];
1924  _idx3d[1] = idx3d[kNestedVolumeDirAxis[1]];
1925  _idx3d[2] = idx3d[kNestedVolumeDirAxis[2]];
1926  */
1927 
1928  _idx3d[kNestedVolumeDirAxis[0]] = _idx/plane;
1929  _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
1930  _idx3d[kNestedVolumeDirAxis[2]] = (_idx%plane)%line;
1931 
1932 
1933 
1934  /*
1935 
1936  G4cout << "G4GMocrenFileSceneHandler::GetNestedVolumeIndex : " << G4endl;
1937  G4cout << "(depi, depj, depk) : "
1938  << kNestedVolumeDirAxis[0] << ", "
1939  << kNestedVolumeDirAxis[1] << ", "
1940  << kNestedVolumeDirAxis[2] << G4endl;
1941  G4cout << "(ni, nj, nk) :"
1942  << kNestedVolumeDimension[0] << ", "
1943  << kNestedVolumeDimension[1] << ", "
1944  << kNestedVolumeDimension[2] << " - " << G4endl;
1945 
1946  G4cout << " _idx = " << _idx << " : plane = "
1947  << plane << " , line = " << line << G4endl;
1948  G4cout << "(idx,idy,idz) + " << _idx3d[0] << ", "
1949  << _idx3d[1] << ", " << _idx3d[2] << " + " << G4endl;
1950 
1951  */
1952 
1953 
1954 
1955  } else {
1956 
1958  G4int line = kNestedVolumeDimension[0];
1959  _idx3d[kNestedVolumeDirAxis[2]] = _idx/plane;
1960  _idx3d[kNestedVolumeDirAxis[1]] = (_idx%plane)/line;
1961  _idx3d[kNestedVolumeDirAxis[0]] = (_idx%plane)%line;
1962 
1963  }
1964 
1965 }
1966 
1967 
1968 //-- --//
1970  : polyhedron(0) {
1971  color[0] = color[1] = color[2] = 255;
1972 }
1974  if(!polyhedron) delete polyhedron;
1975 }
1977  name.clear();
1978  if(!polyhedron) delete polyhedron;
1979  color[0] = color[1] = color[2] = 255;
1981 }
1982 
1983 //-- --//
1985  : x(0), y(0), z(0) {
1986  ;
1987 }
1988 
1990  : x(_index3D.x), y(_index3D.y), z(_index3D.z) {
1991  //: x(_index3D.X()),
1992  //y(_index3D.Y()),
1993  //z(_index3D.Z()) {
1994  // : x(static_cast<Index3D>(_index3D).x),
1995  // y(static_cast<Index3D>(_index3D).y),
1996  // z(static_cast<Index3D>(_index3D).z) {
1997  ;
1998 }
1999 
2001  : x(_x), y(_y), z(_z) {
2002  ;
2003 }
2005  if(z < static_cast<Index3D>(_right).z) {
2006  return true;
2007  } else if(z == _right.z) {
2008  if(y < static_cast<Index3D>(_right).y) return true;
2009  else if(y == _right.y)
2010  if(x < static_cast<Index3D>(_right).x) return true;
2011  }
2012  return false;
2013 }
2015  if(z == _right.z && y == _right.y && x == _right.x) return true;
2016  return false;
2017 }
void set(double x, double y, double z)
TString fin
const std::vector< G4PhysicalVolumeNodeID > & GetDrawnPVPath() const
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)
bool isIdentity() const
Definition: Rotation.cc:172
G4ThreeVector GetSize() const
void GetNumberOfSegments(G4int nSegment[3])
const G4VisAttributes * GetVisAttributes() const
G4Point3D GetVertex(G4int index) const
void newDoseDist()
short convertDensityToHU(float &_dens)
void setDoseDistUnit(std::string &_unit, int _num=0)
G4bool operator<(const Index3D &_right) const
Definition: G4Para.hh:77
const std::vector< Model > & GetEndOfEventModelList() const
virtual void AddSolid(const G4Box &)
Definition: G4Text.hh:73
CLHEP::Hep3Vector getTranslation() const
virtual void BeginModeling()
G4VPhysicalVolume * GetTopPhysicalVolume() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
G4int GetNoDaughters() const
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
Int_t index
void addDetector(std::string &_name, std::vector< float *> &_det, unsigned char _color[3])
virtual G4int GetMultiplicity() const
void AddDetector(const G4VSolid &solid)
virtual void DrawTrajectory() const
virtual G4bool IsReplicated() const =0
void addTrack(float *_tracks)
G4double GetVoxelHalfY() const
Definition: G4Box.hh:64
G4VViewer * fpViewer
G4Scene * GetScene() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
G4String name
Definition: TRTMaterials.hh:40
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
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
const G4String & GetName() const
G4Polyhedron * CreatePolyhedron() const
Definition: G4Box.cc:1047
std::map< G4String, std::map< Index3D, G4double > > kNestedHitsList
virtual G4String getVolumeName()
const G4bool GFDEBUG_TRK
void setModalityImageSize(int _size[3])
size_t GetNoVoxelX() const
G4ThreeVector GetTranslation() const
G4double GetDensity() const
Definition: G4Material.hh:180
#define width
G4Transform3D fObjectTransformation
const G4int FR_MAX_FILE_NUM
G4double GetDensity(G4int &_ct) const
Definition: G4VHit.hh:48
const char DEFAULT_GDD_FILE_NAME[]
Definition: G4Trd.hh:72
G4VScoringMesh * FindMesh(G4VHitsCollection *map)
G4RotationMatrix GetRotationMatrix() const
G4double GetGreen() const
Definition: G4Colour.hh:140
G4double GetVoxelHalfZ() const
virtual G4GeometryType GetEntityType() const =0
void hits()
Definition: readHits.C:15
HepPolyhedron & Transform(const G4Transform3D &t)
virtual G4Material * ComputeMaterial(const G4int repNo, G4VPhysicalVolume *currentVol, const G4VTouchable *parentTouch=0)
G4int GetNoFacets() const
int G4int
Definition: G4Types.hh:78
const G4int GFDEBUG_DET
size_t GetNoVoxelZ() const
G4String GetName() const
void clearDetector()
Definition: G4GMocrenIO.hh:451
void translateDetector(std::vector< float > &_translate)
G4double GetRed() const
Definition: G4Colour.hh:139
Float_t mat
void setDoseDist(double *_image, int _num=0)
G4double GetXHalfLength() const
void clearROIAll()
virtual G4bool getDrawVolumeGrid()
Double_t y
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5206
G4VModel * GetModel() const
Char_t n[5]
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 GetBlue() const
Definition: G4Colour.hh:141
G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const
G4double GetZHalfLength() const
void clearDoseDistAll()
const G4VisAttributes * GetVisAttributes() const
bool G4bool
Definition: G4Types.hh:79
Double_t scale
Definition: G4Cons.hh:83
virtual G4VPVParameterisation * GetParameterisation() const =0
const char GDD_FILE_HEADER[]
virtual void ComputeTransformation(const G4int no, G4VPhysicalVolume *currentPV) const =0
static const double cm3
Definition: G4SIunits.hh:120
virtual void EndModeling()
virtual std::vector< G4AttValue > * CreateAttValues() const
Definition: G4VHit.hh:67
virtual void EndPrimitives()
void setModalityImageMinMax(short _minmax[2])
G4LogicalVolume * GetCurrentLV() const
virtual G4bool IsNested() const
Hep3Vector & transform(const HepRotation &)
Definition: ThreeVectorR.cc:24
virtual G4double GetCharge() const =0
void setModalityImage(short *_image)
void GetNestedVolumeIndex(G4int, G4int[3])
size_t GetNoVoxelY() const
void setVoxelSpacing(float _spacing[3])
G4ThreeVector GetObjectTranslation() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double x() const
static const double rad
Definition: G4SIunits.hh:148
virtual G4bool IsParameterised() const =0
const G4int MAX_NUM_TRAJECTORIES
const G4Color & GetColor() const
virtual std::vector< G4String > getHitScorerNames()
G4double GetVoxelHalfX() const
G4double GetYHalfLength() const
const G4String & GetName() const
virtual const G4ThreeVector GetPosition() const =0
const G4VisAttributes * fpVisAttribs
void clearTracks()
Definition: G4GMocrenIO.hh:439
std::vector< Detector > kDetectors
virtual void AddCompound(const G4VTrajectory &)
static const double pi
Definition: G4SIunits.hh:74
double y() const
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
Definition: G4VViewer.cc:78
EAxis
Definition: geomdefs.hh:54
const G4VTrajectory * GetCurrentTrajectory() const
virtual G4int GetCopyNo() const =0
G4Polyhedron * CreatePolyhedron() const
Definition: G4Tubs.cc:1919
double z() const
const G4bool GFDEBUG_HIT
virtual G4int GetTrackID() const =0
void translateTracks(std::vector< float > &_translateo)
static Verbosity GetVerbosity()
void AddPrimitive(const G4Polyline &line)
G4VPhysicalVolume * GetCurrentPV() const
system("rm -rf microbeam.root")
G4Material * GetCurrentMaterial() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
const G4bool GFDEBUG
#define G4endl
Definition: G4ios.hh:61
G4VPhysicalVolume * GetDaughter(const G4int i) const
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:639
static G4ScoringManager * GetScoringManager()
HepRotation inverse() const
virtual G4ThreeVector GetInitialMomentum() const =0
void setDoseDistScale(double &_scale, int _num=0)
G4bool operator==(const Index3D &_right) const
double G4double
Definition: G4Types.hh:76
const G4bool GFDEBUG_DIGI
void setDoseDistSize(int _size[3], int _num=0)
CLHEP::HepRotation getRotation() const
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
Definition: G4Material.hh:178
std::vector< G4String > kNestedVolumeNames
#define DBL_MAX
Definition: templates.hh:83
G4int GetNoVertices() const
static const double mm
Definition: G4SIunits.hh:114
G4bool IsVisible() const
G4VSolid * GetSolid() const
G4bool GetNextVertexIndex(G4int &index, G4int &edgeFlag) const
std::map< Index3D, float > kNestedModality
void setDoseDistName(std::string _name, int _num=0)
static const Transform3D Identity
Definition: Transform3D.h:197
Transform3D inverse() const
Definition: Transform3D.cc:142
G4GMocrenFileSceneHandler(G4GMocrenFile &system, G4GMocrenMessenger &messenger, const G4String &name="")
void setModalityImageDensityMap(std::vector< float > &_map)