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