Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4VSceneHandler.cc
이 파일의 문서화 페이지로 가기
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: G4VSceneHandler.cc 109510 2018-04-26 07:15:57Z gcosmo $
28 //
29 //
30 // John Allison 19th July 1996
31 // Abstract interface class for graphics scenes.
32 
33 #include "G4VSceneHandler.hh"
34 
35 #include "G4ios.hh"
36 #include <sstream>
37 
38 #include "G4VisManager.hh"
39 #include "G4VGraphicsSystem.hh"
40 #include "G4VViewer.hh"
41 #include "G4VSolid.hh"
42 #include "G4RotationMatrix.hh"
43 #include "G4ThreeVector.hh"
44 #include "G4VPhysicalVolume.hh"
45 #include "G4Material.hh"
46 #include "G4Polyline.hh"
47 #include "G4Scale.hh"
48 #include "G4Text.hh"
49 #include "G4Circle.hh"
50 #include "G4Square.hh"
51 #include "G4Polymarker.hh"
52 #include "G4Polyhedron.hh"
53 #include "G4Visible.hh"
54 #include "G4VisAttributes.hh"
55 #include "G4VModel.hh"
56 #include "G4TrajectoriesModel.hh"
57 #include "G4Box.hh"
58 #include "G4Cons.hh"
59 #include "G4Orb.hh"
60 #include "G4Para.hh"
61 #include "G4Sphere.hh"
62 #include "G4Torus.hh"
63 #include "G4Trap.hh"
64 #include "G4Trd.hh"
65 #include "G4Tubs.hh"
66 #include "G4Ellipsoid.hh"
67 #include "G4Polycone.hh"
68 #include "G4Polyhedra.hh"
69 #include "G4DisplacedSolid.hh"
70 #include "G4LogicalVolume.hh"
71 #include "G4PhysicalVolumeModel.hh"
72 #include "G4ModelingParameters.hh"
73 #include "G4VTrajectory.hh"
74 #include "G4VTrajectoryPoint.hh"
75 #include "G4HitsModel.hh"
76 #include "G4VHit.hh"
77 #include "G4VDigi.hh"
78 #include "G4ScoringManager.hh"
80 #include "Randomize.hh"
81 #include "G4StateManager.hh"
82 #include "G4RunManager.hh"
83 #ifdef G4MULTITHREADED
84 #include "G4MTRunManager.hh"
85 #endif
86 #include "G4Run.hh"
87 #include "G4Transform3D.hh"
88 #include "G4AttHolder.hh"
89 #include "G4AttDef.hh"
90 #include "G4VVisCommand.hh"
91 #include "G4PhysicalConstants.hh"
92 #include "G4SystemOfUnits.hh"
93 
95  fSystem (system),
96  fSceneHandlerId (id),
97  fViewCount (0),
98  fpViewer (0),
99  fpScene (0),
100  fMarkForClearingTransientStore (true), // Ready for first
101  // ClearTransientStoreIfMarked(),
102  // e.g., at end of run (see
103  // G4VisManager.cc).
104  fReadyForTransients (true), // Only false while processing scene.
105  fProcessingSolid (false),
106  fProcessing2D (false),
107  fpModel (0),
108  fNestingDepth (0),
109  fpVisAttribs (0)
110 {
112  fpScene = pVMan -> GetCurrentScene ();
113  if (name == "") {
114  std::ostringstream ost;
115  ost << fSystem.GetName () << '-' << fSceneHandlerId;
116  fName = ost.str();
117  }
118  else {
119  fName = name;
120  }
123 }
124 
126  G4VViewer* last;
127  while( ! fViewerList.empty() ) {
128  last = fViewerList.back();
129  fViewerList.pop_back();
130  delete last;
131  }
132 }
133 
135 {
136  if (fpScene) {
137  return fpScene->GetExtent();
138  } else {
139  static const G4VisExtent defaultExtent = G4VisExtent();
140  return defaultExtent;
141  }
142 }
143 
144 void G4VSceneHandler::PreAddSolid (const G4Transform3D& objectTransformation,
145  const G4VisAttributes& visAttribs) {
146  fObjectTransformation = objectTransformation;
147  fpVisAttribs = &visAttribs;
148  fProcessingSolid = true;
149 }
150 
152  fpVisAttribs = 0;
153  fProcessingSolid = false;
154  if (fReadyForTransients) {
157  }
158 }
159 
161 (const G4Transform3D& objectTransformation) {
162  //static G4int count = 0;
163  //G4cout << "G4VSceneHandler::BeginPrimitives: " << count++ << G4endl;
164  fNestingDepth++;
165  if (fNestingDepth > 1)
167  ("G4VSceneHandler::BeginPrimitives",
168  "visman0101", FatalException,
169  "Nesting detected. It is illegal to nest Begin/EndPrimitives.");
170  fObjectTransformation = objectTransformation;
171 }
172 
174  if (fNestingDepth <= 0)
175  G4Exception("G4VSceneHandler::EndPrimitives",
176  "visman0102", FatalException, "Nesting error.");
177  fNestingDepth--;
178  if (fReadyForTransients) {
181  }
182 }
183 
185 (const G4Transform3D& objectTransformation) {
186  fNestingDepth++;
187  if (fNestingDepth > 1)
189  ("G4VSceneHandler::BeginPrimitives2D",
190  "visman0103", FatalException,
191  "Nesting detected. It is illegal to nest Begin/EndPrimitives.");
192  fObjectTransformation = objectTransformation;
193  fProcessing2D = true;
194 }
195 
197  if (fNestingDepth <= 0)
198  G4Exception("G4VSceneHandler::EndPrimitives2D",
199  "visman0104", FatalException, "Nesting error.");
200  fNestingDepth--;
201  if (fReadyForTransients) {
204  }
205  fProcessing2D = false;
206 }
207 
209 }
210 
212 {
213  fpModel = 0;
214 }
215 
217 
219 
220 template <class T> void G4VSceneHandler::AddSolidT
221 (const T& solid)
222 {
223  // Get and check applicable vis attributes.
224  fpVisAttribs = fpViewer->GetApplicableVisAttributes(fpVisAttribs);
225  RequestPrimitives (solid);
226 }
227 
228 template <class T> void G4VSceneHandler::AddSolidWithAuxiliaryEdges
229 (const T& solid)
230 {
231  // Get and check applicable vis attributes.
232  fpVisAttribs = fpViewer->GetApplicableVisAttributes(fpVisAttribs);
233  // Draw with auxiliary edges unless otherwise specified.
234  if (!fpVisAttribs->IsForceAuxEdgeVisible()) {
235  // Create a vis atts object for the modified vis atts.
236  // It is static so that we may return a reliable pointer to it.
237  static G4VisAttributes visAttsWithAuxEdges;
238  // Initialise it with the current vis atts and reset the pointer.
239  visAttsWithAuxEdges = *fpVisAttribs;
240  // Force auxiliary edges visible.
241  visAttsWithAuxEdges.SetForceAuxEdgeVisible();
242  fpVisAttribs = &visAttsWithAuxEdges;
243  }
244  RequestPrimitives (solid);
245 }
246 
247 void G4VSceneHandler::AddSolid (const G4Box& box) {
248  AddSolidT (box);
249  // If your graphics system is sophisticated enough to handle a
250  // particular solid shape as a primitive, in your derived class write a
251  // function to override this.
252  // Your function might look like this...
253  // void G4MySceneHandler::AddSolid (const G4Box& box) {
254  // Get and check applicable vis attributes.
255  // fpVisAttribs = fpViewer->GetApplicableVisAttributes(fpVisAttribs);
256  // Do not draw if not visible.
257  // if (fpVisAttribs->IsVisible()) {
258  // Get parameters of appropriate object, e.g.:
259  // G4double dx = box.GetXHalfLength ();
260  // G4double dy = box.GetYHalfLength ();
261  // G4double dz = box.GetZHalfLength ();
262  // ...
263  // and Draw or Store in your display List.
264 }
265 
266 void G4VSceneHandler::AddSolid (const G4Cons& cons) {
267  AddSolidT (cons);
268 }
269 
270 void G4VSceneHandler::AddSolid (const G4Orb& orb) {
272 }
273 
274 void G4VSceneHandler::AddSolid (const G4Para& para) {
275  AddSolidT (para);
276 }
277 
278 void G4VSceneHandler::AddSolid (const G4Sphere& sphere) {
280 }
281 
282 void G4VSceneHandler::AddSolid (const G4Torus& torus) {
284 }
285 
286 void G4VSceneHandler::AddSolid (const G4Trap& trap) {
287  AddSolidT (trap);
288 }
289 
290 void G4VSceneHandler::AddSolid (const G4Trd& trd) {
291  AddSolidT (trd);
292 }
293 
294 void G4VSceneHandler::AddSolid (const G4Tubs& tubs) {
295  AddSolidT (tubs);
296 }
297 
298 void G4VSceneHandler::AddSolid (const G4Ellipsoid& ellipsoid) {
299  AddSolidWithAuxiliaryEdges (ellipsoid);
300 }
301 
302 void G4VSceneHandler::AddSolid (const G4Polycone& polycone) {
303  AddSolidT (polycone);
304 }
305 
306 void G4VSceneHandler::AddSolid (const G4Polyhedra& polyhedra) {
307  AddSolidT (polyhedra);
308 }
309 
310 void G4VSceneHandler::AddSolid (const G4VSolid& solid) {
311  AddSolidT (solid);
312 }
313 
315  G4TrajectoriesModel* trajectoriesModel =
316  dynamic_cast<G4TrajectoriesModel*>(fpModel);
317  if (trajectoriesModel)
318  traj.DrawTrajectory();
319  else {
321  ("G4VSceneHandler::AddCompound(const G4VTrajectory&)",
322  "visman0105", FatalException, "Not a G4TrajectoriesModel.");
323  }
324 }
325 
327  // Cast away const because Draw is non-const!!!!
328  const_cast<G4VHit&>(hit).Draw();
329 }
330 
332  // Cast away const because Draw is non-const!!!!
333  const_cast<G4VDigi&>(digi).Draw();
334 }
335 
337  //G4cout << "AddCompound: hits: " << &hits << G4endl;
338  G4bool scoreMapHits = false;
340  if (scoringManager) {
341  size_t nMeshes = scoringManager->GetNumberOfMesh();
342  for (size_t iMesh = 0; iMesh < nMeshes; ++iMesh) {
343  G4VScoringMesh* mesh = scoringManager->GetMesh(iMesh);
344  if (mesh && mesh->IsActive()) {
345  MeshScoreMap scoreMap = mesh->GetScoreMap();
346  const G4String& mapNam = const_cast<G4THitsMap<G4double>&>(hits).GetName();
347  for(MeshScoreMap::const_iterator i = scoreMap.begin();
348  i != scoreMap.end(); ++i) {
349  const G4String& scoreMapName = i->first;
350  if (scoreMapName == mapNam) {
351  G4DefaultLinearColorMap colorMap("G4VSceneHandlerColorMap");
352  scoreMapHits = true;
353  mesh->DrawMesh(scoreMapName, &colorMap);
354  }
355  }
356  }
357  }
358  }
359  if (scoreMapHits) {
360  static G4bool first = true;
361  if (first) {
362  first = false;
363  G4cout <<
364  "Scoring map drawn with default parameters."
365  "\n To get gMocren file for gMocren browser:"
366  "\n /vis/open gMocrenFile"
367  "\n /vis/viewer/flush"
368  "\n Many other options available with /score/draw... commands."
369  "\n You might want to \"/vis/viewer/set/autoRefresh false\"."
370  << G4endl;
371  }
372  } else { // Not score map hits. Just call DrawAllHits.
373  // Cast away const because DrawAllHits is non-const!!!!
374  const_cast<G4THitsMap<G4double>&>(hits).DrawAllHits();
375  }
376 }
377 
379  //G4cout << "AddCompound: hits: " << &hits << G4endl;
380  G4bool scoreMapHits = false;
382  if (scoringManager) {
383  size_t nMeshes = scoringManager->GetNumberOfMesh();
384  for (size_t iMesh = 0; iMesh < nMeshes; ++iMesh) {
385  G4VScoringMesh* mesh = scoringManager->GetMesh(iMesh);
386  if (mesh && mesh->IsActive()) {
387  MeshScoreMap scoreMap = mesh->GetScoreMap();
388  for(MeshScoreMap::const_iterator i = scoreMap.begin();
389  i != scoreMap.end(); ++i) {
390  const G4String& scoreMapName = i->first;
391  const G4THitsMap<G4StatDouble>* foundHits = i->second;
392  if (foundHits == &hits) {
393  G4DefaultLinearColorMap colorMap("G4VSceneHandlerColorMap");
394  scoreMapHits = true;
395  mesh->DrawMesh(scoreMapName, &colorMap);
396  }
397  }
398  }
399  }
400  }
401  if (scoreMapHits) {
402  static G4bool first = true;
403  if (first) {
404  first = false;
405  G4cout <<
406  "Scoring map drawn with default parameters."
407  "\n To get gMocren file for gMocren browser:"
408  "\n /vis/open gMocrenFile"
409  "\n /vis/viewer/flush"
410  "\n Many other options available with /score/draw... commands."
411  "\n You might want to \"/vis/viewer/set/autoRefresh false\"."
412  << G4endl;
413  }
414  } else { // Not score map hits. Just call DrawAllHits.
415  // Cast away const because DrawAllHits is non-const!!!!
416  const_cast<G4THitsMap<G4StatDouble>&>(hits).DrawAllHits();
417  }
418 }
419 
421  fViewerList.push_back (pViewer);
422 }
423 
425 
426  const G4double margin(0.01);
427  // Fractional margin - ensures scale is comfortably inside viewing
428  // volume.
429  const G4double oneMinusMargin (1. - margin);
430 
431  const G4VisExtent& sceneExtent = fpScene->GetExtent();
432 
433  // Useful constants...
434  const G4double length(scale.GetLength());
435  const G4double halfLength(length / 2.);
436  const G4double tickLength(length / 20.);
437  const G4double piBy2(halfpi);
438 
439  // Get size of scene...
440  const G4double xmin = sceneExtent.GetXmin();
441  const G4double xmax = sceneExtent.GetXmax();
442  const G4double ymin = sceneExtent.GetYmin();
443  const G4double ymax = sceneExtent.GetYmax();
444  const G4double zmin = sceneExtent.GetZmin();
445  const G4double zmax = sceneExtent.GetZmax();
446 
447  // Create (empty) polylines having the same vis attributes...
448  G4Polyline scaleLine, tick11, tick12, tick21, tick22;
449  G4VisAttributes visAtts(*scale.GetVisAttributes()); // Long enough life.
450  scaleLine.SetVisAttributes(&visAtts);
451  tick11.SetVisAttributes(&visAtts);
452  tick12.SetVisAttributes(&visAtts);
453  tick21.SetVisAttributes(&visAtts);
454  tick22.SetVisAttributes(&visAtts);
455 
456  // Add points to the polylines to represent an scale parallel to the
457  // x-axis centred on the origin...
458  G4Point3D r1(G4Point3D(-halfLength, 0., 0.));
459  G4Point3D r2(G4Point3D( halfLength, 0., 0.));
460  scaleLine.push_back(r1);
461  scaleLine.push_back(r2);
462  G4Point3D ticky(0., tickLength, 0.);
463  G4Point3D tickz(0., 0., tickLength);
464  tick11.push_back(r1 + ticky);
465  tick11.push_back(r1 - ticky);
466  tick12.push_back(r1 + tickz);
467  tick12.push_back(r1 - tickz);
468  tick21.push_back(r2 + ticky);
469  tick21.push_back(r2 - ticky);
470  tick22.push_back(r2 + tickz);
471  tick22.push_back(r2 - tickz);
472  G4Point3D textPosition(0., tickLength, 0.);
473 
474  // Transform appropriately...
475 
476  G4Transform3D transformation;
477  if (scale.GetAutoPlacing()) {
478  G4Transform3D rotation;
479  switch (scale.GetDirection()) {
480  case G4Scale::x:
481  break;
482  case G4Scale::y:
483  rotation = G4RotateZ3D(piBy2);
484  break;
485  case G4Scale::z:
486  rotation = G4RotateY3D(piBy2);
487  break;
488  }
489  G4double sxmid;
490  G4double symid;
491  G4double szmid;
492  sxmid = xmin + oneMinusMargin * (xmax - xmin);
493  symid = ymin + margin * (ymax - ymin);
494  szmid = zmin + oneMinusMargin * (zmax - zmin);
495  switch (scale.GetDirection()) {
496  case G4Scale::x:
497  sxmid -= halfLength;
498  break;
499  case G4Scale::y:
500  symid += halfLength;
501  break;
502  case G4Scale::z:
503  szmid -= halfLength;
504  break;
505  }
506  G4Translate3D translation(sxmid, symid, szmid);
507  transformation = translation * rotation;
508  } else {
509  if (fpModel) transformation = fpModel->GetTransformation();
510  }
511 
512  // Draw...
513  // We would like to call BeginPrimitives(transformation) here but
514  // calling BeginPrimitives from within an AddPrimitive is not
515  // allowed! So we have to do our own transformation...
516  AddPrimitive(scaleLine.transform(transformation));
517  AddPrimitive(tick11.transform(transformation));
518  AddPrimitive(tick12.transform(transformation));
519  AddPrimitive(tick21.transform(transformation));
520  AddPrimitive(tick22.transform(transformation));
521  G4Text text(scale.GetAnnotation(),textPosition.transform(transformation));
523  text.SetVisAttributes(va);
524  text.SetScreenSize(scale.GetAnnotationSize());
525  AddPrimitive(text);
526 }
527 
528 void G4VSceneHandler::AddPrimitive (const G4Polymarker& polymarker) {
529  switch (polymarker.GetMarkerType()) {
530  default:
531  case G4Polymarker::dots:
532  {
533  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
534  G4Circle dot (polymarker);
535  dot.SetPosition (polymarker[iPoint]);
536  dot.SetWorldSize (0.);
537  dot.SetScreenSize (0.1); // Very small circle.
538  AddPrimitive (dot);
539  }
540  }
541  break;
543  {
544  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
545  G4Circle circle (polymarker);
546  circle.SetPosition (polymarker[iPoint]);
547  AddPrimitive (circle);
548  }
549  }
550  break;
552  {
553  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
554  G4Square square (polymarker);
555  square.SetPosition (polymarker[iPoint]);
556  AddPrimitive (square);
557  }
558  }
559  break;
560  }
561 }
562 
564  fViewerList.remove(pViewer);
565 }
566 
568  fpScene = pScene;
569  // Notify all viewers that a kernel visit is required.
571  for (i = fViewerList.begin(); i != fViewerList.end(); i++) {
572  (*i) -> SetNeedKernelVisit (true);
573  }
574 }
575 
578  G4Polyhedron* pPolyhedron = solid.GetPolyhedron ();
580  if (pPolyhedron) {
581  pPolyhedron -> SetVisAttributes (fpVisAttribs);
583  AddPrimitive (*pPolyhedron);
584  EndPrimitives ();
585  }
586  else {
588  if (verbosity >= G4VisManager::errors) {
589  G4cerr <<
590  "ERROR: G4VSceneHandler::RequestPrimitives"
591  "\n Polyhedron not available for " << solid.GetName () <<
592  "\n Touchable path: ";
593  G4PhysicalVolumeModel* pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
594  if (pPVModel) {
595  G4cerr << pPVModel->GetFullPVPath();
596  }
597  static G4bool explanation = false;
598  if (!explanation) {
599  explanation = true;
600  G4cerr <<
601  "\n This means it cannot be visualized on most systems (try RayTracer)."
602  "\n 1) The solid may not have implemented the CreatePolyhedron method."
603  "\n 2) For Boolean solids, the BooleanProcessor, which attempts to create"
604  "\n the resultant polyhedron, may have failed.";
605  }
606  G4cerr << G4endl;
607  }
608  }
609 }
610 
612 
613  // Assumes graphics database store has already been cleared if
614  // relevant for the particular scene handler.
615 
616  if (!fpScene) return;
617 
618  G4VisManager* visManager = G4VisManager::GetInstance();
619 
620  if (!visManager->GetConcreteInstance()) return;
621 
622  G4VisManager::Verbosity verbosity = visManager->GetVerbosity();
623 
624  fReadyForTransients = false;
625 
626  // Reset fMarkForClearingTransientStore. (Leaving
627  // fMarkForClearingTransientStore true causes problems with
628  // recomputing transients below.) Restore it again at end...
629  G4bool tmpMarkForClearingTransientStore = fMarkForClearingTransientStore;
631 
632  // Traverse geometry tree and send drawing primitives to window(s).
633 
634  const std::vector<G4Scene::Model>& runDurationModelList =
635  fpScene -> GetRunDurationModelList ();
636 
637  if (runDurationModelList.size ()) {
638  if (verbosity >= G4VisManager::confirmations) {
639  G4cout << "Traversing scene data..." << G4endl;
640  }
641 
642  BeginModeling ();
643 
644  // Create modeling parameters from view parameters...
646 
647  for (size_t i = 0; i < runDurationModelList.size (); i++) {
648  if (runDurationModelList[i].fActive) {
649  G4VModel* pModel = runDurationModelList[i].fpModel;
650  // Note: this is not the place to take action on
651  // pModel->GetTransformation(). The model must take care of
652  // this in pModel->DescribeYourselfTo(*this). See, for example,
653  // G4PhysicalVolumeModel and /vis/scene/add/logo.
654  pModel -> SetModelingParameters (pMP);
655  SetModel (pModel); // Store for use by derived class.
656  pModel -> DescribeYourselfTo (*this);
657  pModel -> SetModelingParameters (0);
658  }
659  }
660 
661  delete pMP;
662  EndModeling ();
663  }
664 
665  fReadyForTransients = true;
666 
667  // Refresh event from end-of-event model list.
668  // Allow only in Idle or GeomClosed state...
670  G4ApplicationState state = stateManager->GetCurrentState();
671  if (state == G4State_Idle || state == G4State_GeomClosed) {
672 
673  visManager->SetEventRefreshing(true);
674 
675  if (visManager->GetRequestedEvent()) {
676  DrawEvent(visManager->GetRequestedEvent());
677 
678  } else {
679 
681 #ifdef G4MULTITHREADED
683  { runManager = G4MTRunManager::GetMasterRunManager(); }
684 #endif
685  if (runManager) {
686  const G4Run* run = runManager->GetCurrentRun();
687  const std::vector<const G4Event*>* events =
688  run? run->GetEventVector(): 0;
689  size_t nKeptEvents = 0;
690  if (events) nKeptEvents = events->size();
691  if (nKeptEvents) {
692 
694 
695  if (verbosity >= G4VisManager::confirmations) {
696  G4cout << "Refreshing event..." << G4endl;
697  }
698  const G4Event* event = 0;
699  if (events && events->size()) event = events->back();
700  if (event) DrawEvent(event);
701 
702  } else { // Accumulating events.
703 
704  if (verbosity >= G4VisManager::confirmations) {
705  G4cout << "Refreshing events in run..." << G4endl;
706  }
707  for (const auto& event: *events) {
708  if (event) DrawEvent(event);
709  }
710 
711  if (!fpScene->GetRefreshAtEndOfRun()) {
712  if (verbosity >= G4VisManager::warnings) {
713  G4cout <<
714  "WARNING: Cannot refresh events accumulated over more"
715  "\n than one runs. Refreshed just the last run."
716  << G4endl;
717  }
718  }
719  }
720  }
721  }
722  }
723  visManager->SetEventRefreshing(false);
724  }
725 
726  // Refresh end-of-run model list.
727  // Allow only in Idle or GeomClosed state...
728  if (state == G4State_Idle || state == G4State_GeomClosed) {
730  }
731 
732  fMarkForClearingTransientStore = tmpMarkForClearingTransientStore;
733 }
734 
736 {
737  const std::vector<G4Scene::Model>& EOEModelList =
738  fpScene -> GetEndOfEventModelList ();
739  size_t nModels = EOEModelList.size();
740  if (nModels) {
742  pMP->SetEvent(event);
743  for (size_t i = 0; i < nModels; i++) {
744  if (EOEModelList[i].fActive) {
745  G4VModel* pModel = EOEModelList[i].fpModel;
746  pModel -> SetModelingParameters(pMP);
747  SetModel (pModel);
748  pModel -> DescribeYourselfTo (*this);
749  pModel -> SetModelingParameters(0);
750  }
751  }
752  delete pMP;
753  SetModel (0);
754  }
755 }
756 
758 {
759  const std::vector<G4Scene::Model>& EORModelList =
760  fpScene -> GetEndOfRunModelList ();
761  size_t nModels = EORModelList.size();
762  if (nModels) {
764  pMP->SetEvent(0);
765  for (size_t i = 0; i < nModels; i++) {
766  if (EORModelList[i].fActive) {
767  G4VModel* pModel = EORModelList[i].fpModel;
768  pModel -> SetModelingParameters(pMP);
769  SetModel (pModel);
770  pModel -> DescribeYourselfTo (*this);
771  pModel -> SetModelingParameters(0);
772  }
773  }
774  delete pMP;
775  SetModel (0);
776  }
777 }
778 
780 {
781  // Create modeling parameters from View Parameters...
782  if (!fpViewer) return NULL;
783 
784  const G4ViewParameters& vp = fpViewer -> GetViewParameters ();
785 
786  // Convert drawing styles...
787  G4ModelingParameters::DrawingStyle modelDrawingStyle =
789  switch (vp.GetDrawingStyle ()) {
790  default:
792  modelDrawingStyle = G4ModelingParameters::wf;
793  break;
795  modelDrawingStyle = G4ModelingParameters::hlr;
796  break;
798  modelDrawingStyle = G4ModelingParameters::hsr;
799  break;
801  modelDrawingStyle = G4ModelingParameters::hlhsr;
802  break;
803  }
804 
805  // Decide if covered daughters are really to be culled...
806  G4bool reallyCullCovered =
807  vp.IsCullingCovered() // Culling daughters depends also on...
808  && !vp.IsSection () // Sections (DCUT) not requested.
809  && !vp.IsCutaway () // Cutaways not requested.
810  ;
811 
812  G4ModelingParameters* pModelingParams = new G4ModelingParameters
814  modelDrawingStyle,
815  vp.IsCulling (),
816  vp.IsCullingInvisible (),
817  vp.IsDensityCulling (),
818  vp.GetVisibleDensity (),
819  reallyCullCovered,
820  vp.GetNoOfSides ()
821  );
822 
823  pModelingParams->SetWarning
825 
826  pModelingParams->SetCBDAlgorithmNumber(vp.GetCBDAlgorithmNumber());
827  pModelingParams->SetCBDParameters(vp.GetCBDParameters());
828 
829  pModelingParams->SetExplodeFactor(vp.GetExplodeFactor());
830  pModelingParams->SetExplodeCentre(vp.GetExplodeCentre());
831 
832  pModelingParams->SetSectionSolid(CreateSectionSolid());
833  pModelingParams->SetCutawaySolid(CreateCutawaySolid());
834  // The polyhedron objects are deleted in the modeling parameters destructor.
835 
837 
838  return pModelingParams;
839 }
840 
842 {
843  G4VSolid* sectioner = 0;
845  if (vp.IsSection () ) {
847  G4double safe = radius + fpScene->GetExtent().GetExtentCentre().mag();
848  G4VSolid* sectionBox =
849  new G4Box("_sectioner", safe, safe, 1.e-5 * radius); // Thin in z-plane.
850  const G4Plane3D& sp = vp.GetSectionPlane ();
851  G4double a = sp.a();
852  G4double b = sp.b();
853  G4double c = sp.c();
854  G4double d = sp.d();
855  G4Transform3D transform = G4TranslateZ3D(-d);
856  const G4Normal3D normal(a,b,c);
857  if (normal != G4Normal3D(0,0,1)) {
858  const G4double angle = std::acos(normal.dot(G4Normal3D(0,0,1)));
859  const G4Vector3D axis = G4Normal3D(0,0,1).cross(normal);
860  transform = G4Rotate3D(angle, axis) * transform;
861  }
862  sectioner = new G4DisplacedSolid
863  ("_displaced_sectioning_box", sectionBox, transform);
864  }
865  return sectioner;
866 }
867 
869 {
870  // To be reviewed.
871  return 0;
872  /*** An alternative way of getting a cutaway is to use
873  Command /vis/scene/add/volume
874  Guidance :
875  Adds a physical volume to current scene, with optional clipping volume.
876  If physical-volume-name is "world" (the default), the top of the
877  main geometry tree (material world) is added. If "worlds", the
878  top of all worlds - material world and parallel worlds, if any - are
879  added. Otherwise a search of all worlds is made, taking the first
880  matching occurence only. To see a representation of the geometry
881  hierarchy of the worlds, try "/vis/drawTree [worlds]" or one of the
882  driver/browser combinations that have the required functionality, e.g., HepRep.
883  If clip-volume-type is specified, the subsequent parameters are used to
884  to define a clipping volume. For example,
885  "/vis/scene/add/volume ! ! ! -box km 0 1 0 1 0 1" will draw the world
886  with the positive octant cut away. (If the Boolean Processor issues
887  warnings try replacing 0 by 0.000000001 or something.)
888  If clip-volume-type is prepended with '-', the clip-volume is subtracted
889  (cutaway). (This is the default if there is no prepended character.)
890  If '*' is prepended, the intersection of the physical-volume and the
891  clip-volume is made. (You can make a section/DCUT with a thin box, for
892  example).
893  For "box", the parameters are xmin,xmax,ymin,ymax,zmin,zmax.
894  Only "box" is programmed at present.
895  ***/
896 }
897 
898 void G4VSceneHandler::LoadAtts(const G4Visible& visible, G4AttHolder* holder)
899 {
900  // Load G4Atts from G4VisAttributes, if any...
901  const G4VisAttributes* va = visible.GetVisAttributes();
902  if (va) {
903  const std::map<G4String,G4AttDef>* vaDefs =
904  va->GetAttDefs();
905  if (vaDefs) {
906  holder->AddAtts(visible.GetVisAttributes()->CreateAttValues(), vaDefs);
907  }
908  }
909 
910  G4PhysicalVolumeModel* pPVModel =
911  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
912  if (pPVModel) {
913  // Load G4Atts from G4PhysicalVolumeModel...
914  const std::map<G4String,G4AttDef>* pvDefs = pPVModel->GetAttDefs();
915  if (pvDefs) {
916  holder->AddAtts(pPVModel->CreateCurrentAttValues(), pvDefs);
917  }
918  }
919 
920  G4TrajectoriesModel* trajModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
921  if (trajModel) {
922  // Load G4Atts from trajectory model...
923  const std::map<G4String,G4AttDef>* trajModelDefs = trajModel->GetAttDefs();
924  if (trajModelDefs) {
925  holder->AddAtts(trajModel->CreateCurrentAttValues(), trajModelDefs);
926  }
927  // Load G4Atts from trajectory...
928  const G4VTrajectory* traj = trajModel->GetCurrentTrajectory();
929  if (traj) {
930  const std::map<G4String,G4AttDef>* trajDefs = traj->GetAttDefs();
931  if (trajDefs) {
932  holder->AddAtts(traj->CreateAttValues(), trajDefs);
933  }
934  G4int nPoints = traj->GetPointEntries();
935  for (G4int i = 0; i < nPoints; ++i) {
936  G4VTrajectoryPoint* trajPoint = traj->GetPoint(i);
937  if (trajPoint) {
938  const std::map<G4String,G4AttDef>* pointDefs = trajPoint->GetAttDefs();
939  if (pointDefs) {
940  holder->AddAtts(trajPoint->CreateAttValues(), pointDefs);
941  }
942  }
943  }
944  }
945  }
946 
947  G4HitsModel* hitsModel = dynamic_cast<G4HitsModel*>(fpModel);
948  if (hitsModel) {
949  // Load G4Atts from hit...
950  const G4VHit* hit = hitsModel->GetCurrentHit();
951  const std::map<G4String,G4AttDef>* hitsDefs = hit->GetAttDefs();
952  if (hitsDefs) {
953  holder->AddAtts(hit->CreateAttValues(), hitsDefs);
954  }
955  }
956 }
957 
959  const G4VisAttributes* pVA = text.GetVisAttributes ();
960  if (!pVA) {
962  }
963  const G4Colour& colour = pVA -> GetColour ();
964  return colour;
965 }
966 
968 {
969  G4double lineWidth = pVisAttribs->GetLineWidth();
970  if (lineWidth < 1.) lineWidth = 1.;
971  lineWidth *= fpViewer -> GetViewParameters().GetGlobalLineWidthScale();
972  if (lineWidth < 1.) lineWidth = 1.;
973  return lineWidth;
974 }
975 
977 (const G4VisAttributes* pVisAttribs) {
978  // Drawing style is normally determined by the view parameters, but
979  // it can be overriddden by the ForceDrawingStyle flag in the vis
980  // attributes.
982  fpViewer->GetViewParameters().GetDrawingStyle();
983  if (pVisAttribs -> IsForceDrawingStyle ()) {
985  pVisAttribs -> GetForcedDrawingStyle ();
986  // This is complicated because if hidden line and surface removal
987  // has been requested we wish to preserve this sometimes.
988  switch (forcedStyle) {
989  case (G4VisAttributes::solid):
990  switch (style) {
991  case (G4ViewParameters::hlr):
992  style = G4ViewParameters::hlhsr;
993  break;
995  style = G4ViewParameters::hsr;
996  break;
998  case (G4ViewParameters::hsr):
999  default:
1000  break;
1001  }
1002  break;
1004  default:
1005  // But if forced style is wireframe, do it, because one of its
1006  // main uses is in displaying the consituent solids of a Boolean
1007  // solid and their surfaces overlap with the resulting Booean
1008  // solid, making a mess if hlr is specified.
1010  break;
1011  }
1012  }
1013  return style;
1014 }
1015 
1017  G4bool isAuxEdgeVisible = fpViewer->GetViewParameters().IsAuxEdgeVisible ();
1018  if (pVisAttribs -> IsForceAuxEdgeVisible()) {
1019  isAuxEdgeVisible = pVisAttribs->IsForcedAuxEdgeVisible();
1020  }
1021  return isAuxEdgeVisible;
1022 }
1023 
1025 (const G4VMarker& marker,
1026  G4VSceneHandler::MarkerSizeType& markerSizeType)
1027 {
1028  G4bool userSpecified = marker.GetWorldSize() || marker.GetScreenSize();
1029  const G4VMarker& defaultMarker =
1030  fpViewer -> GetViewParameters().GetDefaultMarker();
1031  G4double size = userSpecified ?
1032  marker.GetWorldSize() : defaultMarker.GetWorldSize();
1033  if (size) {
1034  // Draw in world coordinates.
1035  markerSizeType = world;
1036  }
1037  else {
1038  size = userSpecified ?
1039  marker.GetScreenSize() : defaultMarker.GetScreenSize();
1040  // Draw in screen coordinates.
1041  markerSizeType = screen;
1042  }
1043  size *= fpViewer -> GetViewParameters().GetGlobalMarkerScale();
1044  if (markerSizeType == screen && size < 1.) size = 1.;
1045  return size;
1046 }
1047 
1049 {
1050  // No. of sides (lines segments per circle) is normally determined
1051  // by the view parameters, but it can be overriddden by the
1052  // ForceLineSegmentsPerCircle in the vis attributes.
1053  G4int lineSegmentsPerCircle = fpViewer->GetViewParameters().GetNoOfSides();
1054  if (pVisAttribs) {
1055  if (pVisAttribs->IsForceLineSegmentsPerCircle())
1056  lineSegmentsPerCircle = pVisAttribs->GetForcedLineSegmentsPerCircle();
1057  if (lineSegmentsPerCircle < pVisAttribs->GetMinLineSegmentsPerCircle()) {
1058  lineSegmentsPerCircle = pVisAttribs->GetMinLineSegmentsPerCircle();
1059  G4cout <<
1060  "G4VSceneHandler::GetNoOfSides: attempt to set the"
1061  "\nnumber of line segements per circle < " << lineSegmentsPerCircle
1062  << "; forced to " << pVisAttribs->GetMinLineSegmentsPerCircle() << G4endl;
1063  }
1064  }
1065  return lineSegmentsPerCircle;
1066 }
1067 
1068 std::ostream& operator << (std::ostream& os, const G4VSceneHandler& sh) {
1069 
1070  os << "Scene handler " << sh.fName << " has "
1071  << sh.fViewerList.size () << " viewer(s):";
1072  for (size_t i = 0; i < sh.fViewerList.size (); i++) {
1073  os << "\n " << *(sh.fViewerList [i]);
1074  }
1075 
1076  if (sh.fpScene) {
1077  os << "\n " << *sh.fpScene;
1078  }
1079  else {
1080  os << "\n This scene handler currently has no scene.";
1081  }
1082 
1083  return os;
1084 }
const G4String & GetName() const
void SetPosition(const G4Point3D &)
HepGeom::RotateY3D G4RotateY3D
MeshScoreMap GetScoreMap() const
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
virtual const G4VisExtent & GetExtent() const
static G4MTRunManager * GetMasterRunManager()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
const G4Run * GetCurrentRun() const
G4double GetExplodeFactor() const
G4VSceneHandler(G4VGraphicsSystem &system, G4int id, const G4String &name="")
T d() const
Definition: Plane3D.h:86
const XML_Char * name
Definition: expat.h:151
G4bool GetAutoPlacing() const
const std::map< G4String, G4AttDef > * GetAttDefs() const
T a() const
Definition: Plane3D.h:77
void SetForceAuxEdgeVisible(G4bool=true)
G4Transform3D fObjectTransformation
virtual std::vector< G4AttValue > * CreateAttValues() const
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
system("rm -rf microbeam.root")
const G4Colour & GetColour()
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
void AddSolidT(const T &solid)
size_t GetNumberOfMesh() const
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
void AddAtts(const std::vector< G4AttValue > *values, const std::map< G4String, G4AttDef > *defs)
Definition: G4AttHolder.hh:65
T c() const
Definition: Plane3D.h:83
G4bool GetTransientsDrawnThisRun() const
void SetExplodeCentre(const G4Point3D &explodeCentre)
virtual G4Polyhedron * GetPolyhedron() const
Definition: G4VSolid.cc:665
virtual void ClearStore()
G4bool IsDensityCulling() const
G4double GetZmax() const
Definition: G4VisExtent.hh:93
Definition: G4Tubs.hh:85
G4double GetYmax() const
Definition: G4VisExtent.hh:91
static void ResetNumberOfRotationSteps()
const G4Plane3D & GetSectionPlane() const
G4double GetScreenSize() const
G4ViewerList fViewerList
const G4Event * GetRequestedEvent() const
const G4VisAttributes * GetVisAttributes() const
#define G4endl
Definition: G4ios.hh:61
hist1 Draw("HIST")
G4VViewer * fpViewer
HepGeom::TranslateZ3D G4TranslateZ3D
Definition: G4VHit.hh:48
virtual G4VSolid * CreateSectionSolid()
const G4VTrajectory * GetCurrentTrajectory() const
void SetCBDParameters(const std::vector< G4double > &)
virtual std::vector< G4AttValue > * CreateAttValues() const
Definition: G4VHit.hh:67
static G4VisManager * GetInstance()
G4bool IsAuxEdgeVisible() const
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:77
virtual void ClearTransientStore()
void SetWorldSize(G4double)
G4ModelingParameters * CreateModelingParameters()
void SetModel(G4VModel *)
void SetEvent(const G4Event *pEvent)
const G4ViewParameters & GetViewParameters() const
G4bool fMarkForClearingTransientStore
const G4Point3D & GetExtentCentre() const
Definition: G4VisExtent.cc:61
G4Polyline & transform(const G4Transform3D &)
Definition: G4Polyline.cc:38
const G4Point3D & GetExplodeCentre() const
void DrawMesh(const G4String &psName, G4VScoreColorMap *colorMap, G4int axflg=111)
G4double GetZmin() const
Definition: G4VisExtent.hh:92
const G4Colour & GetTextColour(const G4Text &)
const std::vector< G4PhysicalVolumeNodeID > & GetFullPVPath() const
G4bool IsForceLineSegmentsPerCircle() const
static void SetNumberOfRotationSteps(G4int n)
void LoadAtts(const G4Visible &, G4AttHolder *)
G4VGraphicsSystem & fSystem
virtual void ProcessScene()
const std::vector< G4double > & GetCBDParameters() const
G4bool IsCulling() const
void remove(G4VViewer *)
Definition: G4ViewerList.cc:31
static G4VVisManager * GetConcreteInstance()
void SetSectionSolid(G4VSolid *pSectionSolid)
virtual std::vector< G4AttValue > * CreateAttValues() const
G4int GetNoOfSides(const G4VisAttributes *)
void RemoveViewerFromList(G4VViewer *pView)
void SetExplodeFactor(G4double explodeFactor)
static G4int GetMinLineSegmentsPerCircle()
G4bool IsForcedAuxEdgeVisible() const
void SetScreenSize(G4double)
Direction GetDirection() const
virtual void AddCompound(const G4VTrajectory &)
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
Double_t scale
void hits()
Definition: readHits.C:15
const std::vector< G4AttValue > * CreateAttValues() const
G4bool GetRefreshAtEndOfEvent() const
Definition: G4Text.hh:73
Definition: G4Cons.hh:83
const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual void PostAddSolid()
G4int GetCBDAlgorithmNumber() const
static G4ScoringManager * GetScoringManagerIfExist()
virtual int GetPointEntries() const =0
virtual void BeginModeling()
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation)
Definition: G4Box.hh:64
void DrawEvent(const G4Event *)
HepGeom::Normal3D< G4double > G4Normal3D
Definition: G4Normal3D.hh:35
G4double GetLineWidth() const
G4bool IsCutaway() const
Float_t d
G4double GetWorldSize() const
const G4VisAttributes * GetDefaultVisAttributes() const
G4double GetXmin() const
Definition: G4VisExtent.hh:88
static constexpr double halfpi
Definition: G4SIunits.hh:77
virtual void SetScene(G4Scene *)
T dot(const BasicVector3D< T > &v) const
G4int GetNoOfSides() const
static Verbosity GetVerbosity()
G4double GetLength() const
const std::map< G4String, G4AttDef > * GetAttDefs() const
Definition: G4Orb.hh:62
Double_t radius
G4bool IsCullingInvisible() const
G4double GetAnnotationSize() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual void EndModeling()
G4GLOB_DLL std::ostream G4cerr
void SetVisAttributesModifiers(const std::vector< VisAttributesModifier > &)
Definition: G4Run.hh:46
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
const G4VisAttributes * fpVisAttribs
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
G4bool GetRefreshAtEndOfRun() const
virtual void AddSolid(const G4Box &)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
DrawingStyle GetDrawingStyle() const
G4bool GetAuxEdgeVisible(const G4VisAttributes *)
G4bool fTransientsDrawnThisRun
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:136
void AddSolidWithAuxiliaryEdges(const T &solid)
int G4int
Definition: G4Types.hh:78
void SetEventRefreshing(G4bool)
G4bool GetTransientsDrawnThisEvent() const
G4ApplicationState GetCurrentState() const
G4String GetName() const
virtual void AddPrimitive(const G4Polyline &)=0
virtual void DrawTrajectory() const
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:71
Definition: G4Trd.hh:72
static const G4Colour & GetCurrentTextColour()
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:115
void AddViewerToList(G4VViewer *pView)
G4GLOB_DLL std::ostream G4cout
std::vector< G4AttValue > * CreateCurrentAttValues() const
G4bool IsActive() const
G4ApplicationState
const G4VisExtent & GetExtent() const
void SetWarning(G4bool)
G4VScoringMesh * GetMesh(G4int i) const
void SetCutawaySolid(G4VSolid *pCutawaySolid)
G4double GetYmin() const
Definition: G4VisExtent.hh:90
G4bool fTransientsDrawnThisEvent
const G4String & GetName() const
void SetCBDAlgorithmNumber(G4int)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
Definition: G4VHit.hh:60
G4int first(char) const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4bool IsCullingCovered() const
HepGeom::Rotate3D G4Rotate3D
G4double GetVisibleDensity() const
virtual G4VSolid * CreateCutawaySolid()
G4double GetXmax() const
Definition: G4VisExtent.hh:89
Definition: G4Para.hh:86
T b() const
Definition: Plane3D.h:80
std::vector< G4VViewer * >::iterator G4ViewerListIterator
Definition: G4ViewerList.hh:43
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
G4double GetLineWidth(const G4VisAttributes *)
G4int GetForcedLineSegmentsPerCircle() const
MarkerType GetMarkerType() const
virtual void EndPrimitives2D()
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
const G4VHit * GetCurrentHit() const
Definition: G4HitsModel.hh:58
std::vector< G4AttValue > * CreateCurrentAttValues() const
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
virtual ~G4VSceneHandler()
virtual void EndPrimitives()
const G4int fSceneHandlerId
virtual void RequestPrimitives(const G4VSolid &solid)
const G4Transform3D & GetTransformation() const
static G4StateManager * GetStateManager()
std::map< G4String, RunScore * > MeshScoreMap
HepGeom::RotateZ3D G4RotateZ3D
G4bool IsSection() const
const G4String & GetAnnotation() const