Geant4  10.02.p01
G4VSceneHandler.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: G4VSceneHandler.cc 91686 2015-07-31 09:40:08Z 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 "G4Tubs.hh"
60 #include "G4Trd.hh"
61 #include "G4Trap.hh"
62 #include "G4Sphere.hh"
63 #include "G4Para.hh"
64 #include "G4Torus.hh"
65 #include "G4Polycone.hh"
66 #include "G4Polyhedra.hh"
67 #include "G4DisplacedSolid.hh"
68 #include "G4LogicalVolume.hh"
69 #include "G4PhysicalVolumeModel.hh"
70 #include "G4ModelingParameters.hh"
71 #include "G4VTrajectory.hh"
72 #include "G4VTrajectoryPoint.hh"
73 #include "G4HitsModel.hh"
74 #include "G4VHit.hh"
75 #include "G4VDigi.hh"
76 #include "G4ScoringManager.hh"
78 #include "Randomize.hh"
79 #include "G4StateManager.hh"
80 #include "G4RunManager.hh"
81 #ifdef G4MULTITHREADED
82 #include "G4MTRunManager.hh"
83 #endif
84 #include "G4Run.hh"
85 #include "G4Transform3D.hh"
86 #include "G4AttHolder.hh"
87 #include "G4AttDef.hh"
88 #include "G4VVisCommand.hh"
89 #include "G4PhysicalConstants.hh"
90 
92  fSystem (system),
93  fSceneHandlerId (id),
94  fViewCount (0),
95  fpViewer (0),
96  fpScene (0),
97  fMarkForClearingTransientStore (true), // Ready for first
98  // ClearTransientStoreIfMarked(),
99  // e.g., at end of run (see
100  // G4VisManager.cc).
101  fReadyForTransients (true), // Only false while processing scene.
102  fProcessingSolid (false),
103  fProcessing2D (false),
104  fpModel (0),
105  fNestingDepth (0),
106  fpVisAttribs (0)
107 {
109  fpScene = pVMan -> GetCurrentScene ();
110  if (name == "") {
111  std::ostringstream ost;
112  ost << fSystem.GetName () << '-' << fSceneHandlerId;
113  fName = ost.str();
114  }
115  else {
116  fName = name;
117  }
120 }
121 
123  G4VViewer* last;
124  while( ! fViewerList.empty() ) {
125  last = fViewerList.back();
126  fViewerList.pop_back();
127  delete last;
128  }
129 }
130 
132 {
133  if (fpScene) {
134  return fpScene->GetExtent();
135  } else {
137  }
138 }
139 
140 void G4VSceneHandler::PreAddSolid (const G4Transform3D& objectTransformation,
141  const G4VisAttributes& visAttribs) {
142  fObjectTransformation = objectTransformation;
143  fpVisAttribs = &visAttribs;
144  fProcessingSolid = true;
145 }
146 
148  fpVisAttribs = 0;
149  fProcessingSolid = false;
150  if (fReadyForTransients) {
153  }
154 }
155 
157 (const G4Transform3D& objectTransformation) {
158  //static G4int count = 0;
159  //G4cout << "G4VSceneHandler::BeginPrimitives: " << count++ << G4endl;
160  fNestingDepth++;
161  if (fNestingDepth > 1)
163  ("G4VSceneHandler::BeginPrimitives",
164  "visman0101", FatalException,
165  "Nesting detected. It is illegal to nest Begin/EndPrimitives.");
166  fObjectTransformation = objectTransformation;
167 }
168 
170  if (fNestingDepth <= 0)
171  G4Exception("G4VSceneHandler::EndPrimitives",
172  "visman0102", FatalException, "Nesting error.");
173  fNestingDepth--;
174  if (fReadyForTransients) {
177  }
178 }
179 
181 (const G4Transform3D& objectTransformation) {
182  fNestingDepth++;
183  if (fNestingDepth > 1)
185  ("G4VSceneHandler::BeginPrimitives2D",
186  "visman0103", FatalException,
187  "Nesting detected. It is illegal to nest Begin/EndPrimitives.");
188  fObjectTransformation = objectTransformation;
189  fProcessing2D = true;
190 }
191 
193  if (fNestingDepth <= 0)
194  G4Exception("G4VSceneHandler::EndPrimitives2D",
195  "visman0104", FatalException, "Nesting error.");
196  fNestingDepth--;
197  if (fReadyForTransients) {
200  }
201  fProcessing2D = false;
202 }
203 
205 }
206 
208 {
209  fpModel = 0;
210 }
211 
213 
215 
216 void G4VSceneHandler::AddSolid (const G4Box& box) {
217  RequestPrimitives (box);
218 // If your graphics system is sophisticated enough to handle a
219 // particular solid shape as a primitive, in your derived class write a
220 // function to override this. (Note: some compilers warn that your
221 // function "hides" this one. That's OK.)
222 // Your function might look like this...
223 // void G4MyScene::AddSolid (const G4Box& box) {
224 // Get parameters of appropriate object, e.g.:
225 // G4double dx = box.GetXHalfLength ();
226 // G4double dy = box.GetYHalfLength ();
227 // G4double dz = box.GetZHalfLength ();
228 // and Draw or Store in your display List.
229 }
230 
231 void G4VSceneHandler::AddSolid (const G4Tubs& tubs) {
232  RequestPrimitives (tubs);
233 }
234 
235 void G4VSceneHandler::AddSolid (const G4Cons& cons) {
236  RequestPrimitives (cons);
237 }
238 
239 void G4VSceneHandler::AddSolid (const G4Trd& trd) {
240  RequestPrimitives (trd);
241 }
242 
243 void G4VSceneHandler::AddSolid (const G4Trap& trap) {
244  RequestPrimitives (trap);
245 }
246 
247 void G4VSceneHandler::AddSolid (const G4Sphere& sphere) {
248  RequestPrimitives (sphere );
249 }
250 
251 void G4VSceneHandler::AddSolid (const G4Para& para) {
252  RequestPrimitives (para);
253 }
254 
255 void G4VSceneHandler::AddSolid (const G4Torus& torus) {
256  RequestPrimitives (torus);
257 }
258 
259 void G4VSceneHandler::AddSolid (const G4Polycone& polycone) {
260  RequestPrimitives (polycone);
261 }
262 
263 void G4VSceneHandler::AddSolid (const G4Polyhedra& polyhedra) {
264  RequestPrimitives (polyhedra);
265 }
266 
267 void G4VSceneHandler::AddSolid (const G4VSolid& solid) {
268  RequestPrimitives (solid);
269 }
270 
272  G4TrajectoriesModel* trajectoriesModel =
273  dynamic_cast<G4TrajectoriesModel*>(fpModel);
274  if (trajectoriesModel)
275  traj.DrawTrajectory();
276  else {
278  ("G4VSceneHandler::AddCompound(const G4VTrajectory&)",
279  "visman0105", FatalException, "Not a G4TrajectoriesModel.");
280  }
281 }
282 
284  // Cast away const because Draw is non-const!!!!
285  const_cast<G4VHit&>(hit).Draw();
286 }
287 
289  // Cast away const because Draw is non-const!!!!
290  const_cast<G4VDigi&>(digi).Draw();
291 }
292 
294  //G4cout << "AddCompound: hits: " << &hits << G4endl;
295  G4bool scoreMapHits = false;
297  if (scoringManager) {
298  size_t nMeshes = scoringManager->GetNumberOfMesh();
299  for (size_t iMesh = 0; iMesh < nMeshes; ++iMesh) {
300  G4VScoringMesh* mesh = scoringManager->GetMesh(iMesh);
301  if (mesh && mesh->IsActive()) {
302  MeshScoreMap scoreMap = mesh->GetScoreMap();
303  for(MeshScoreMap::const_iterator i = scoreMap.begin();
304  i != scoreMap.end(); ++i) {
305  const G4String& scoreMapName = i->first;
306  const G4THitsMap<G4double>* foundHits = i->second;
307  if (foundHits == &hits) {
308  G4DefaultLinearColorMap colorMap("G4VSceneHandlerColorMap");
309  scoreMapHits = true;
310  mesh->DrawMesh(scoreMapName, &colorMap);
311  }
312  }
313  }
314  }
315  }
316  if (scoreMapHits) {
317  static G4bool first = true;
318  if (first) {
319  first = false;
320  G4cout <<
321  "Scoring map drawn with default parameters."
322  "\n To get gMocren file for gMocren browser:"
323  "\n /vis/open gMocrenFile"
324  "\n /vis/viewer/flush"
325  "\n Many other options available with /score/draw... commands."
326  "\n You might want to \"/vis/viewer/set/autoRefresh false\"."
327  << G4endl;
328  }
329  } else { // Not score map hits. Just call DrawAllHits.
330  // Cast away const because DrawAllHits is non-const!!!!
331  const_cast<G4THitsMap<G4double>&>(hits).DrawAllHits();
332  }
333 }
334 
336  fViewerList.push_back (pViewer);
337 }
338 
340 
341  const G4double margin(0.01);
342  // Fractional margin - ensures scale is comfortably inside viewing
343  // volume.
344  const G4double oneMinusMargin (1. - margin);
345 
346  const G4VisExtent& sceneExtent = fpScene->GetExtent();
347 
348  // Useful constants...
349  const G4double length(scale.GetLength());
350  const G4double halfLength(length / 2.);
351  const G4double tickLength(length / 20.);
352  const G4double piBy2(halfpi);
353 
354  // Get size of scene...
355  const G4double xmin = sceneExtent.GetXmin();
356  const G4double xmax = sceneExtent.GetXmax();
357  const G4double ymin = sceneExtent.GetYmin();
358  const G4double ymax = sceneExtent.GetYmax();
359  const G4double zmin = sceneExtent.GetZmin();
360  const G4double zmax = sceneExtent.GetZmax();
361 
362  // Create (empty) polylines having the same vis attributes...
363  G4Polyline scaleLine, tick11, tick12, tick21, tick22;
364  G4VisAttributes visAtts(*scale.GetVisAttributes()); // Long enough life.
365  scaleLine.SetVisAttributes(&visAtts);
366  tick11.SetVisAttributes(&visAtts);
367  tick12.SetVisAttributes(&visAtts);
368  tick21.SetVisAttributes(&visAtts);
369  tick22.SetVisAttributes(&visAtts);
370 
371  // Add points to the polylines to represent an scale parallel to the
372  // x-axis centred on the origin...
373  G4Point3D r1(G4Point3D(-halfLength, 0., 0.));
374  G4Point3D r2(G4Point3D( halfLength, 0., 0.));
375  scaleLine.push_back(r1);
376  scaleLine.push_back(r2);
377  G4Point3D ticky(0., tickLength, 0.);
378  G4Point3D tickz(0., 0., tickLength);
379  tick11.push_back(r1 + ticky);
380  tick11.push_back(r1 - ticky);
381  tick12.push_back(r1 + tickz);
382  tick12.push_back(r1 - tickz);
383  tick21.push_back(r2 + ticky);
384  tick21.push_back(r2 - ticky);
385  tick22.push_back(r2 + tickz);
386  tick22.push_back(r2 - tickz);
387  G4Point3D textPosition(0., tickLength, 0.);
388 
389  // Transform appropriately...
390 
391  G4Transform3D transformation;
392  if (scale.GetAutoPlacing()) {
393  G4Transform3D rotation;
394  switch (scale.GetDirection()) {
395  case G4Scale::x:
396  break;
397  case G4Scale::y:
398  rotation = G4RotateZ3D(piBy2);
399  break;
400  case G4Scale::z:
401  rotation = G4RotateY3D(piBy2);
402  break;
403  }
404  G4double sxmid;
405  G4double symid;
406  G4double szmid;
407  sxmid = xmin + oneMinusMargin * (xmax - xmin);
408  symid = ymin + margin * (ymax - ymin);
409  szmid = zmin + oneMinusMargin * (zmax - zmin);
410  switch (scale.GetDirection()) {
411  case G4Scale::x:
412  sxmid -= halfLength;
413  break;
414  case G4Scale::y:
415  symid += halfLength;
416  break;
417  case G4Scale::z:
418  szmid -= halfLength;
419  break;
420  }
421  G4Translate3D translation(sxmid, symid, szmid);
422  transformation = translation * rotation;
423  } else {
424  if (fpModel) transformation = fpModel->GetTransformation();
425  }
426 
427  // Draw...
428  // We would like to call BeginPrimitives(transformation) here but
429  // calling BeginPrimitives from within an AddPrimitive is not
430  // allowed! So we have to do our own transformation...
431  AddPrimitive(scaleLine.transform(transformation));
432  AddPrimitive(tick11.transform(transformation));
433  AddPrimitive(tick12.transform(transformation));
434  AddPrimitive(tick21.transform(transformation));
435  AddPrimitive(tick22.transform(transformation));
436  G4Text text(scale.GetAnnotation(),textPosition.transform(transformation));
437  text.SetScreenSize(scale.GetAnnotationSize());
438  AddPrimitive(text);
439 }
440 
441 void G4VSceneHandler::AddPrimitive (const G4Polymarker& polymarker) {
442  switch (polymarker.GetMarkerType()) {
443  default:
444  case G4Polymarker::dots:
445  {
446  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
447  G4Circle dot (polymarker);
448  dot.SetPosition (polymarker[iPoint]);
449  dot.SetWorldSize (0.);
450  dot.SetScreenSize (0.1); // Very small circle.
451  AddPrimitive (dot);
452  }
453  }
454  break;
456  {
457  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
458  G4Circle circle (polymarker);
459  circle.SetPosition (polymarker[iPoint]);
460  AddPrimitive (circle);
461  }
462  }
463  break;
465  {
466  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
467  G4Square square (polymarker);
468  square.SetPosition (polymarker[iPoint]);
469  AddPrimitive (square);
470  }
471  }
472  break;
473  }
474 }
475 
477  fViewerList.remove(pViewer);
478 }
479 
481  fpScene = pScene;
482  // Notify all viewers that a kernel visit is required.
484  for (i = fViewerList.begin(); i != fViewerList.end(); i++) {
485  (*i) -> SetNeedKernelVisit (true);
486  }
487 }
488 
491  G4Polyhedron::SetNumberOfRotationSteps (GetNoOfSides (fpVisAttribs));
492  G4Polyhedron* pPolyhedron = solid.GetPolyhedron ();
493  G4Polyhedron::ResetNumberOfRotationSteps ();
494  if (pPolyhedron) {
495  pPolyhedron -> SetVisAttributes (fpVisAttribs);
496  AddPrimitive (*pPolyhedron);
497  }
498  else {
500  if (verbosity >= G4VisManager::errors) {
501  G4cerr <<
502  "ERROR: G4VSceneHandler::RequestPrimitives"
503  "\n Polyhedron not available for " << solid.GetName () <<
504  ".\n This means it cannot be visualized on most systems."
505  "\n Contact the Visualization Coordinator." << G4endl;
506  }
507  }
508  EndPrimitives ();
509 }
510 
512 
513  // Assumes graphics database store has already been cleared if
514  // relevant for the particular scene handler.
515 
516  if (!fpScene) return;
517 
518  G4VisManager* visManager = G4VisManager::GetInstance();
519 
520  if (!visManager->GetConcreteInstance()) return;
521 
522  G4VisManager::Verbosity verbosity = visManager->GetVerbosity();
523 
524  fReadyForTransients = false;
525 
526  // Reset fMarkForClearingTransientStore. (Leaving
527  // fMarkForClearingTransientStore true causes problems with
528  // recomputing transients below.) Restore it again at end...
529  G4bool tmpMarkForClearingTransientStore = fMarkForClearingTransientStore;
531 
532  // Traverse geometry tree and send drawing primitives to window(s).
533 
534  const std::vector<G4Scene::Model>& runDurationModelList =
535  fpScene -> GetRunDurationModelList ();
536 
537  if (runDurationModelList.size ()) {
538  if (verbosity >= G4VisManager::confirmations) {
539  G4cout << "Traversing scene data..." << G4endl;
540  }
541 
542  BeginModeling ();
543 
544  // Create modeling parameters from view parameters...
546 
547  for (size_t i = 0; i < runDurationModelList.size (); i++) {
548  if (runDurationModelList[i].fActive) {
549  G4VModel* pModel = runDurationModelList[i].fpModel;
550  // Note: this is not the place to take action on
551  // pModel->GetTransformation(). The model must take care of
552  // this in pModel->DescribeYourselfTo(*this). See, for example,
553  // G4PhysicalVolumeModel and /vis/scene/add/logo.
554  pModel -> SetModelingParameters (pMP);
555  SetModel (pModel); // Store for use by derived class.
556  pModel -> DescribeYourselfTo (*this);
557  pModel -> SetModelingParameters (0);
558  }
559  }
560 
561  delete pMP;
562  EndModeling ();
563  }
564 
565  fReadyForTransients = true;
566 
567  // Refresh event from end-of-event model list.
568  // Allow only in Idle or GeomClosed state...
570  G4ApplicationState state = stateManager->GetCurrentState();
571  if (state == G4State_Idle || state == G4State_GeomClosed) {
572 
573  visManager->SetEventRefreshing(true);
574 
575  if (visManager->GetRequestedEvent()) {
576  DrawEvent(visManager->GetRequestedEvent());
577 
578  } else {
579 
581 #ifdef G4MULTITHREADED
583  { runManager = G4MTRunManager::GetMasterRunManager(); }
584 #endif
585  if (runManager) {
586  const G4Run* run = runManager->GetCurrentRun();
587  const std::vector<const G4Event*>* events =
588  run? run->GetEventVector(): 0;
589  size_t nKeptEvents = 0;
590  if (events) nKeptEvents = events->size();
591  if (nKeptEvents) {
592 
594 
595  if (verbosity >= G4VisManager::confirmations) {
596  G4cout << "Refreshing event..." << G4endl;
597  }
598  const G4Event* event = 0;
599  if (events && events->size()) event = events->back();
600  if (event) DrawEvent(event);
601 
602  } else { // Accumulating events.
603 
604  if (verbosity >= G4VisManager::confirmations) {
605  G4cout << "Refreshing events in run..." << G4endl;
606  }
607  for (auto&& event: *events) {
608  if (event) DrawEvent(event);
609  }
610 
611  if (!fpScene->GetRefreshAtEndOfRun()) {
612  if (verbosity >= G4VisManager::warnings) {
613  G4cout <<
614  "WARNING: Cannot refresh events accumulated over more"
615  "\n than one runs. Refreshed just the last run."
616  << G4endl;
617  }
618  }
619  }
620  }
621  }
622  }
623  visManager->SetEventRefreshing(false);
624  }
625 
626  // Refresh end-of-run model list.
627  // Allow only in Idle or GeomClosed state...
628  if (state == G4State_Idle || state == G4State_GeomClosed) {
630  }
631 
632  fMarkForClearingTransientStore = tmpMarkForClearingTransientStore;
633 }
634 
636 {
637  const std::vector<G4Scene::Model>& EOEModelList =
638  fpScene -> GetEndOfEventModelList ();
639  size_t nModels = EOEModelList.size();
640  if (nModels) {
642  pMP->SetEvent(event);
643  for (size_t i = 0; i < nModels; i++) {
644  if (EOEModelList[i].fActive) {
645  G4VModel* pModel = EOEModelList[i].fpModel;
646  pModel -> SetModelingParameters(pMP);
647  SetModel (pModel);
648  pModel -> DescribeYourselfTo (*this);
649  pModel -> SetModelingParameters(0);
650  }
651  }
652  delete pMP;
653  SetModel (0);
654  }
655 }
656 
658 {
659  const std::vector<G4Scene::Model>& EORModelList =
660  fpScene -> GetEndOfRunModelList ();
661  size_t nModels = EORModelList.size();
662  if (nModels) {
664  pMP->SetEvent(0);
665  for (size_t i = 0; i < nModels; i++) {
666  if (EORModelList[i].fActive) {
667  G4VModel* pModel = EORModelList[i].fpModel;
668  pModel -> SetModelingParameters(pMP);
669  SetModel (pModel);
670  pModel -> DescribeYourselfTo (*this);
671  pModel -> SetModelingParameters(0);
672  }
673  }
674  delete pMP;
675  SetModel (0);
676  }
677 }
678 
680 {
681  // Create modeling parameters from View Parameters...
682  if (!fpViewer) return NULL;
683 
684  const G4ViewParameters& vp = fpViewer -> GetViewParameters ();
685 
686  // Convert drawing styles...
687  G4ModelingParameters::DrawingStyle modelDrawingStyle =
689  switch (vp.GetDrawingStyle ()) {
690  default:
692  modelDrawingStyle = G4ModelingParameters::wf;
693  break;
695  modelDrawingStyle = G4ModelingParameters::hlr;
696  break;
698  modelDrawingStyle = G4ModelingParameters::hsr;
699  break;
701  modelDrawingStyle = G4ModelingParameters::hlhsr;
702  break;
703  }
704 
705  // Decide if covered daughters are really to be culled...
706  G4bool reallyCullCovered =
707  vp.IsCullingCovered() // Culling daughters depends also on...
708  && !vp.IsSection () // Sections (DCUT) not requested.
709  && !vp.IsCutaway () // Cutaways not requested.
710  ;
711 
712  G4ModelingParameters* pModelingParams = new G4ModelingParameters
714  modelDrawingStyle,
715  vp.IsCulling (),
716  vp.IsCullingInvisible (),
717  vp.IsDensityCulling (),
718  vp.GetVisibleDensity (),
719  reallyCullCovered,
720  vp.GetNoOfSides ()
721  );
722 
723  pModelingParams->SetWarning
725 
726  pModelingParams->SetExplodeFactor(vp.GetExplodeFactor());
727  pModelingParams->SetExplodeCentre(vp.GetExplodeCentre());
728 
729  pModelingParams->SetSectionSolid(CreateSectionSolid());
730  pModelingParams->SetCutawaySolid(CreateCutawaySolid());
731  // The polyhedron objects are deleted in the modeling parameters destructor.
732 
734 
735  return pModelingParams;
736 }
737 
739 {
740  G4VSolid* sectioner = 0;
742  if (vp.IsSection () ) {
744  G4double safe = radius + fpScene->GetExtent().GetExtentCentre().mag();
745  G4VSolid* sectionBox =
746  new G4Box("_sectioner", safe, safe, 1.e-5 * radius); // Thin in z-plane.
747  const G4Plane3D& sp = vp.GetSectionPlane ();
748  G4double a = sp.a();
749  G4double b = sp.b();
750  G4double c = sp.c();
751  G4double d = sp.d();
752  G4Transform3D transform = G4TranslateZ3D(-d);
753  const G4Normal3D normal(a,b,c);
754  if (normal != G4Normal3D(0,0,1)) {
755  const G4double angle = std::acos(normal.dot(G4Normal3D(0,0,1)));
756  const G4Vector3D axis = G4Normal3D(0,0,1).cross(normal);
757  transform = G4Rotate3D(angle, axis) * transform;
758  }
759  sectioner = new G4DisplacedSolid
760  ("_displaced_sectioning_box", sectionBox, transform);
761  }
762  return sectioner;
763 }
764 
766 {
767  return 0;
768 }
769 
770 void G4VSceneHandler::LoadAtts(const G4Visible& visible, G4AttHolder* holder)
771 {
772  // Load G4Atts from G4VisAttributes, if any...
773  const G4VisAttributes* va = visible.GetVisAttributes();
774  if (va) {
775  const std::map<G4String,G4AttDef>* vaDefs =
776  va->GetAttDefs();
777  if (vaDefs) {
778  holder->AddAtts(visible.GetVisAttributes()->CreateAttValues(), vaDefs);
779  }
780  }
781 
782  G4PhysicalVolumeModel* pPVModel =
783  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
784  if (pPVModel) {
785  // Load G4Atts from G4PhysicalVolumeModel...
786  const std::map<G4String,G4AttDef>* pvDefs = pPVModel->GetAttDefs();
787  if (pvDefs) {
788  holder->AddAtts(pPVModel->CreateCurrentAttValues(), pvDefs);
789  }
790  }
791 
792  G4TrajectoriesModel* trajModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
793  if (trajModel) {
794  // Load G4Atts from trajectory model...
795  const std::map<G4String,G4AttDef>* trajModelDefs = trajModel->GetAttDefs();
796  if (trajModelDefs) {
797  holder->AddAtts(trajModel->CreateCurrentAttValues(), trajModelDefs);
798  }
799  // Load G4Atts from trajectory...
800  const G4VTrajectory* traj = trajModel->GetCurrentTrajectory();
801  if (traj) {
802  const std::map<G4String,G4AttDef>* trajDefs = traj->GetAttDefs();
803  if (trajDefs) {
804  holder->AddAtts(traj->CreateAttValues(), trajDefs);
805  }
806  G4int nPoints = traj->GetPointEntries();
807  for (G4int i = 0; i < nPoints; ++i) {
808  G4VTrajectoryPoint* trajPoint = traj->GetPoint(i);
809  if (trajPoint) {
810  const std::map<G4String,G4AttDef>* pointDefs = trajPoint->GetAttDefs();
811  if (pointDefs) {
812  holder->AddAtts(trajPoint->CreateAttValues(), pointDefs);
813  }
814  }
815  }
816  }
817  }
818 
819  G4HitsModel* hitsModel = dynamic_cast<G4HitsModel*>(fpModel);
820  if (hitsModel) {
821  // Load G4Atts from hit...
822  const G4VHit* hit = hitsModel->GetCurrentHit();
823  const std::map<G4String,G4AttDef>* hitsDefs = hit->GetAttDefs();
824  if (hitsDefs) {
825  holder->AddAtts(hit->CreateAttValues(), hitsDefs);
826  }
827  }
828 }
829 
831  // Colour is determined by the applicable vis attributes.
832  const G4Colour& colour = fpViewer ->
833  GetApplicableVisAttributes (visible.GetVisAttributes ()) -> GetColour ();
834  return colour;
835 }
836 
838  const G4VisAttributes* pVA = text.GetVisAttributes ();
839  if (!pVA) {
840  pVA = fpViewer -> GetViewParameters (). GetDefaultTextVisAttributes ();
841  }
842  const G4Colour& colour = pVA -> GetColour ();
843  return colour;
844 }
845 
847 {
848  G4double lineWidth = pVisAttribs->GetLineWidth();
849  if (lineWidth < 1.) lineWidth = 1.;
850  lineWidth *= fpViewer -> GetViewParameters().GetGlobalLineWidthScale();
851  if (lineWidth < 1.) lineWidth = 1.;
852  return lineWidth;
853 }
854 
856 (const G4VisAttributes* pVisAttribs) {
857  // Drawing style is normally determined by the view parameters, but
858  // it can be overriddden by the ForceDrawingStyle flag in the vis
859  // attributes.
861  fpViewer->GetViewParameters().GetDrawingStyle();
862  if (pVisAttribs -> IsForceDrawingStyle ()) {
864  pVisAttribs -> GetForcedDrawingStyle ();
865  // This is complicated because if hidden line and surface removal
866  // has been requested we wish to preserve this sometimes.
867  switch (forcedStyle) {
868  case (G4VisAttributes::solid):
869  switch (style) {
870  case (G4ViewParameters::hlr):
871  style = G4ViewParameters::hlhsr;
872  break;
874  style = G4ViewParameters::hsr;
875  break;
877  case (G4ViewParameters::hsr):
878  default:
879  break;
880  }
881  break;
883  default:
884  // But if forced style is wireframe, do it, because one of its
885  // main uses is in displaying the consituent solids of a Boolean
886  // solid and their surfaces overlap with the resulting Booean
887  // solid, making a mess if hlr is specified.
889  break;
890  }
891  }
892  return style;
893 }
894 
896  G4bool isAuxEdgeVisible = fpViewer->GetViewParameters().IsAuxEdgeVisible ();
897  if (pVisAttribs -> IsForceAuxEdgeVisible()) isAuxEdgeVisible = true;
898  return isAuxEdgeVisible;
899 }
900 
902 (const G4VMarker& marker,
903  G4VSceneHandler::MarkerSizeType& markerSizeType)
904 {
905  G4bool userSpecified = marker.GetWorldSize() || marker.GetScreenSize();
906  const G4VMarker& defaultMarker =
907  fpViewer -> GetViewParameters().GetDefaultMarker();
908  G4double size = userSpecified ?
909  marker.GetWorldSize() : defaultMarker.GetWorldSize();
910  if (size) {
911  // Draw in world coordinates.
912  markerSizeType = world;
913  }
914  else {
915  size = userSpecified ?
916  marker.GetScreenSize() : defaultMarker.GetScreenSize();
917  // Draw in screen coordinates.
918  markerSizeType = screen;
919  }
920  size *= fpViewer -> GetViewParameters().GetGlobalMarkerScale();
921  if (markerSizeType == screen && size < 1.) size = 1.;
922  return size;
923 }
924 
926 {
927  // No. of sides (lines segments per circle) is normally determined
928  // by the view parameters, but it can be overriddden by the
929  // ForceLineSegmentsPerCircle in the vis attributes.
930  G4int lineSegmentsPerCircle = fpViewer->GetViewParameters().GetNoOfSides();
931  if (pVisAttribs) {
932  if (pVisAttribs->IsForceLineSegmentsPerCircle())
933  lineSegmentsPerCircle = pVisAttribs->GetForcedLineSegmentsPerCircle();
934  if (lineSegmentsPerCircle < pVisAttribs->GetMinLineSegmentsPerCircle()) {
935  lineSegmentsPerCircle = pVisAttribs->GetMinLineSegmentsPerCircle();
936  G4cout <<
937  "G4VSceneHandler::GetNoOfSides: attempt to set the"
938  "\nnumber of line segements per circle < " << lineSegmentsPerCircle
939  << "; forced to " << pVisAttribs->GetMinLineSegmentsPerCircle() << G4endl;
940  }
941  }
942  return lineSegmentsPerCircle;
943 }
944 
945 std::ostream& operator << (std::ostream& os, const G4VSceneHandler& sh) {
946 
947  os << "Scene handler " << sh.fName << " has "
948  << sh.fViewerList.size () << " viewer(s):";
949  for (size_t i = 0; i < sh.fViewerList.size (); i++) {
950  os << "\n " << *(sh.fViewerList [i]);
951  }
952 
953  if (sh.fpScene) {
954  os << "\n " << *sh.fpScene;
955  }
956  else {
957  os << "\n This scene handler currently has no scene.";
958  }
959 
960  return os;
961 }
virtual G4Polyhedron * GetPolyhedron() const
Definition: G4VSolid.cc:644
G4bool GetTransientsDrawnThisRun() const
Direction GetDirection() const
G4String GetName() const
void SetWorldSize(G4double)
virtual void ClearStore()
virtual ~G4VSceneHandler()
void AddAtts(const std::vector< G4AttValue > *values, const std::map< G4String, G4AttDef > *defs)
Definition: G4AttHolder.hh:65
Definition: G4Para.hh:77
void DrawMesh(const G4String &psName, G4VScoreColorMap *colorMap, G4int axflg=111)
virtual void AddSolid(const G4Box &)
Definition: G4Text.hh:73
static const G4VisExtent NullExtent
Definition: G4VisExtent.hh:80
static const double halfpi
Definition: G4SIunits.hh:76
virtual G4VSolid * CreateSectionSolid()
MarkerType GetMarkerType() const
G4bool GetAutoPlacing() const
HepGeom::RotateY3D G4RotateY3D
G4double GetXmin() const
Definition: G4VisExtent.hh:89
const std::map< G4String, G4AttDef > * GetAttDefs() const
G4double GetVisibleDensity() const
virtual void BeginModeling()
G4ModelingParameters * CreateModelingParameters()
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
std::map< G4String, G4THitsMap< G4double > * > MeshScoreMap
static G4VVisManager * GetConcreteInstance()
G4double GetWorldSize() const
G4double GetLineWidth() const
const G4Point3D & GetExplodeCentre() const
G4int first(char) const
std::vector< G4AttValue > * CreateCurrentAttValues() const
void SetEventRefreshing(G4bool)
void LoadAtts(const G4Visible &, G4AttHolder *)
const std::map< G4String, G4AttDef > * GetAttDefs() const
G4bool IsCullingInvisible() const
Definition: G4Box.hh:64
G4VViewer * fpViewer
G4double GetExplodeFactor() const
G4String name
Definition: TRTMaterials.hh:40
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
Definition: G4Tubs.hh:85
void RemoveViewerFromList(G4VViewer *pView)
virtual void PostAddSolid()
const G4ViewParameters & GetViewParameters() const
G4double GetXmax() const
Definition: G4VisExtent.hh:90
const G4Transform3D & GetTransformation() const
G4bool IsDensityCulling() const
static G4double angle[DIM]
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:115
G4Transform3D fObjectTransformation
const G4Point3D & GetExtentCentre() const
Definition: G4VisExtent.cc:63
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
Definition: G4VHit.hh:48
G4double a
Definition: TRTMaterials.hh:39
Definition: G4Trd.hh:72
const G4VisAttributes * GetVisAttributes() const
G4int GetNoOfSides(const G4VisAttributes *)
virtual const G4VisExtent & GetExtent() const
G4bool GetRefreshAtEndOfEvent() const
int G4int
Definition: G4Types.hh:78
virtual void AddPrimitive(const G4Polyline &)=0
HepGeom::RotateZ3D G4RotateZ3D
const G4Run * GetCurrentRun() const
virtual G4VSolid * CreateCutawaySolid()
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4double GetScreenSize() const
G4VSceneHandler(G4VGraphicsSystem &system, G4int id, const G4String &name="")
virtual void DrawTrajectory() const
virtual std::vector< G4AttValue > * CreateAttValues() const
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:77
void remove(G4VViewer *)
Definition: G4ViewerList.cc:31
void SetCutawaySolid(G4VSolid *pCutawaySolid)
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
static G4StateManager * GetStateManager()
G4double GetLineWidth(const G4VisAttributes *)
virtual int GetPointEntries() const =0
const G4int fSceneHandlerId
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
void AddViewerToList(G4VViewer *pView)
G4GLOB_DLL std::ostream G4cout
G4bool IsAuxEdgeVisible() const
static G4ScoringManager * GetScoringManagerIfExist()
const G4VisExtent & GetExtent() const
static G4int GetMinLineSegmentsPerCircle()
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4double GetYmax() const
Definition: G4VisExtent.hh:92
void SetEvent(const G4Event *pEvent)
bool G4bool
Definition: G4Types.hh:79
static G4MTRunManager * GetMasterRunManager()
Definition: G4Cons.hh:83
G4bool GetRefreshAtEndOfRun() const
static G4VisManager * GetInstance()
const G4VHit * GetCurrentHit() const
Definition: G4HitsModel.hh:58
Definition: G4Run.hh:46
G4ViewerList fViewerList
virtual void EndModeling()
virtual void EndPrimitives()
HepGeom::Transform3D G4Transform3D
G4double GetZmax() const
Definition: G4VisExtent.hh:94
G4bool IsCullingCovered() const
G4ApplicationState GetCurrentState() const
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:136
std::ostream & operator<<(std::ostream &os, const G4VSceneHandler &sh)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation)
G4bool GetTransientsDrawnThisEvent() const
virtual void SetScene(G4Scene *)
G4int GetForcedLineSegmentsPerCircle() const
void SetSectionSolid(G4VSolid *pSectionSolid)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4bool IsSection() const
void SetVisAttributesModifiers(const std::vector< VisAttributesModifier > &)
G4bool IsCutaway() const
HepGeom::Rotate3D G4Rotate3D
const G4VisAttributes * fpVisAttribs
const G4String & GetName() const
G4bool fMarkForClearingTransientStore
virtual void AddCompound(const G4VTrajectory &)
const G4VTrajectory * GetCurrentTrajectory() const
virtual std::vector< G4AttValue > * CreateAttValues() const
void SetPosition(const G4Point3D &)
std::vector< G4AttValue > * CreateCurrentAttValues() const
const std::vector< G4AttValue > * CreateAttValues() const
void DrawEvent(const G4Event *)
G4double GetAnnotationSize() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
Definition: G4VHit.hh:60
G4int GetNoOfSides() const
virtual void ProcessScene()
G4bool fTransientsDrawnThisEvent
const std::map< G4String, G4AttDef > * GetAttDefs() const
G4double GetLength() const
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
void SetWarning(G4bool)
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
G4double GetZmin() const
Definition: G4VisExtent.hh:93
static Verbosity GetVerbosity()
const G4Event * GetRequestedEvent() const
G4bool GetAuxEdgeVisible(const G4VisAttributes *)
HepGeom::Translate3D G4Translate3D
MeshScoreMap GetScoreMap() const
DrawingStyle GetDrawingStyle() const
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
G4double GetYmin() const
Definition: G4VisExtent.hh:91
virtual std::vector< G4AttValue > * CreateAttValues() const
Definition: G4VHit.hh:67
void SetExplodeFactor(G4double explodeFactor)
HepGeom::Plane3D< G4double > G4Plane3D
Definition: G4Plane3D.hh:37
#define G4endl
Definition: G4ios.hh:61
const G4Colour & GetColour(const G4Visible &)
const G4Plane3D & GetSectionPlane() const
virtual void RequestPrimitives(const G4VSolid &solid)
std::vector< G4VViewer * >::iterator G4ViewerListIterator
Definition: G4ViewerList.hh:43
void SetModel(G4VModel *)
G4bool IsActive() const
size_t GetNumberOfMesh() const
const G4VisAttributes * GetDefaultVisAttributes() const
double G4double
Definition: G4Types.hh:76
virtual void ClearTransientStore()
G4bool fTransientsDrawnThisRun
void SetExplodeCentre(const G4Point3D &explodeCentre)
G4VGraphicsSystem & fSystem
G4bool IsForceLineSegmentsPerCircle() const
const G4String & GetAnnotation() const
G4VScoringMesh * GetMesh(G4int i) const
G4bool IsCulling() const
G4Polyline & transform(const G4Transform3D &)
Definition: G4Polyline.cc:38
G4ApplicationState
virtual void EndPrimitives2D()
G4GLOB_DLL std::ostream G4cerr
HepGeom::TranslateZ3D G4TranslateZ3D
void SetScreenSize(G4double)
HepGeom::Normal3D< G4double > G4Normal3D
Definition: G4Normal3D.hh:35
const G4Colour & GetTextColour(const G4Text &)