Geant4  10.01.p02
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 87360 2014-12-01 16:07:16Z 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 (size_t i = 0; i < nKeptEvents; ++i) {
608  const G4Event* event = (*events)[i];
609  if (event) DrawEvent(event);
610  }
611 
612  if (!fpScene->GetRefreshAtEndOfRun()) {
613  if (verbosity >= G4VisManager::warnings) {
614  G4cout <<
615  "WARNING: Cannot refresh events accumulated over more"
616  "\n than one runs. Refreshed just the last run."
617  << G4endl;
618  }
619  }
620  }
621  }
622  }
623  }
624  visManager->SetEventRefreshing(false);
625  }
626 
627  // Refresh end-of-run model list.
628  // Allow only in Idle or GeomClosed state...
629  if (state == G4State_Idle || state == G4State_GeomClosed) {
631  }
632 
633  fMarkForClearingTransientStore = tmpMarkForClearingTransientStore;
634 }
635 
637 {
638  const std::vector<G4Scene::Model>& EOEModelList =
639  fpScene -> GetEndOfEventModelList ();
640  size_t nModels = EOEModelList.size();
641  if (nModels) {
643  pMP->SetEvent(event);
644  for (size_t i = 0; i < nModels; i++) {
645  if (EOEModelList[i].fActive) {
646  G4VModel* pModel = EOEModelList[i].fpModel;
647  pModel -> SetModelingParameters(pMP);
648  SetModel (pModel);
649  pModel -> DescribeYourselfTo (*this);
650  pModel -> SetModelingParameters(0);
651  }
652  }
653  delete pMP;
654  SetModel (0);
655  }
656 }
657 
659 {
660  const std::vector<G4Scene::Model>& EORModelList =
661  fpScene -> GetEndOfRunModelList ();
662  size_t nModels = EORModelList.size();
663  if (nModels) {
665  pMP->SetEvent(0);
666  for (size_t i = 0; i < nModels; i++) {
667  if (EORModelList[i].fActive) {
668  G4VModel* pModel = EORModelList[i].fpModel;
669  pModel -> SetModelingParameters(pMP);
670  SetModel (pModel);
671  pModel -> DescribeYourselfTo (*this);
672  pModel -> SetModelingParameters(0);
673  }
674  }
675  delete pMP;
676  SetModel (0);
677  }
678 }
679 
681 {
682  // Create modeling parameters from View Parameters...
683  if (!fpViewer) return NULL;
684 
685  const G4ViewParameters& vp = fpViewer -> GetViewParameters ();
686 
687  // Convert drawing styles...
688  G4ModelingParameters::DrawingStyle modelDrawingStyle =
690  switch (vp.GetDrawingStyle ()) {
691  default:
693  modelDrawingStyle = G4ModelingParameters::wf;
694  break;
696  modelDrawingStyle = G4ModelingParameters::hlr;
697  break;
699  modelDrawingStyle = G4ModelingParameters::hsr;
700  break;
702  modelDrawingStyle = G4ModelingParameters::hlhsr;
703  break;
704  }
705 
706  // Decide if covered daughters are really to be culled...
707  G4bool reallyCullCovered =
708  vp.IsCullingCovered() // Culling daughters depends also on...
709  && !vp.IsSection () // Sections (DCUT) not requested.
710  && !vp.IsCutaway () // Cutaways not requested.
711  ;
712 
713  G4ModelingParameters* pModelingParams = new G4ModelingParameters
715  modelDrawingStyle,
716  vp.IsCulling (),
717  vp.IsCullingInvisible (),
718  vp.IsDensityCulling (),
719  vp.GetVisibleDensity (),
720  reallyCullCovered,
721  vp.GetNoOfSides ()
722  );
723 
724  pModelingParams->SetWarning
726 
727  pModelingParams->SetExplodeFactor(vp.GetExplodeFactor());
728  pModelingParams->SetExplodeCentre(vp.GetExplodeCentre());
729 
730  pModelingParams->SetSectionSolid(CreateSectionSolid());
731  pModelingParams->SetCutawaySolid(CreateCutawaySolid());
732  // The polyhedron objects are deleted in the modeling parameters destructor.
733 
735 
736  return pModelingParams;
737 }
738 
740 {
741  G4VSolid* sectioner = 0;
743  if (vp.IsSection () ) {
745  G4double safe = radius + fpScene->GetExtent().GetExtentCentre().mag();
746  G4VSolid* sectionBox =
747  new G4Box("_sectioner", safe, safe, 1.e-5 * radius); // Thin in z-plane.
748  const G4Plane3D& sp = vp.GetSectionPlane ();
749  G4double a = sp.a();
750  G4double b = sp.b();
751  G4double c = sp.c();
752  G4double d = sp.d();
753  G4Transform3D transform = G4TranslateZ3D(-d);
754  const G4Normal3D normal(a,b,c);
755  if (normal != G4Normal3D(0,0,1)) {
756  const G4double angle = std::acos(normal.dot(G4Normal3D(0,0,1)));
757  const G4Vector3D axis = G4Normal3D(0,0,1).cross(normal);
758  transform = G4Rotate3D(angle, axis) * transform;
759  }
760  sectioner = new G4DisplacedSolid
761  ("_displaced_sectioning_box", sectionBox, transform);
762  }
763  return sectioner;
764 }
765 
767 {
768  return 0;
769 }
770 
771 void G4VSceneHandler::LoadAtts(const G4Visible& visible, G4AttHolder* holder)
772 {
773  // Load G4Atts from G4VisAttributes, if any...
774  const G4VisAttributes* va = visible.GetVisAttributes();
775  if (va) {
776  const std::map<G4String,G4AttDef>* vaDefs =
777  va->GetAttDefs();
778  if (vaDefs) {
779  holder->AddAtts(visible.GetVisAttributes()->CreateAttValues(), vaDefs);
780  }
781  }
782 
783  G4PhysicalVolumeModel* pPVModel =
784  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
785  if (pPVModel) {
786  // Load G4Atts from G4PhysicalVolumeModel...
787  const std::map<G4String,G4AttDef>* pvDefs = pPVModel->GetAttDefs();
788  if (pvDefs) {
789  holder->AddAtts(pPVModel->CreateCurrentAttValues(), pvDefs);
790  }
791  }
792 
793  G4TrajectoriesModel* trajModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
794  if (trajModel) {
795  // Load G4Atts from trajectory model...
796  const std::map<G4String,G4AttDef>* trajModelDefs = trajModel->GetAttDefs();
797  if (trajModelDefs) {
798  holder->AddAtts(trajModel->CreateCurrentAttValues(), trajModelDefs);
799  }
800  // Load G4Atts from trajectory...
801  const G4VTrajectory* traj = trajModel->GetCurrentTrajectory();
802  if (traj) {
803  const std::map<G4String,G4AttDef>* trajDefs = traj->GetAttDefs();
804  if (trajDefs) {
805  holder->AddAtts(traj->CreateAttValues(), trajDefs);
806  }
807  G4int nPoints = traj->GetPointEntries();
808  for (G4int i = 0; i < nPoints; ++i) {
809  G4VTrajectoryPoint* trajPoint = traj->GetPoint(i);
810  if (trajPoint) {
811  const std::map<G4String,G4AttDef>* pointDefs = trajPoint->GetAttDefs();
812  if (pointDefs) {
813  holder->AddAtts(trajPoint->CreateAttValues(), pointDefs);
814  }
815  }
816  }
817  }
818  }
819 
820  G4HitsModel* hitsModel = dynamic_cast<G4HitsModel*>(fpModel);
821  if (hitsModel) {
822  // Load G4Atts from hit...
823  const G4VHit* hit = hitsModel->GetCurrentHit();
824  const std::map<G4String,G4AttDef>* hitsDefs = hit->GetAttDefs();
825  if (hitsDefs) {
826  holder->AddAtts(hit->CreateAttValues(), hitsDefs);
827  }
828  }
829 }
830 
832  // Colour is determined by the applicable vis attributes.
833  const G4Colour& colour = fpViewer ->
834  GetApplicableVisAttributes (visible.GetVisAttributes ()) -> GetColour ();
835  return colour;
836 }
837 
839  const G4VisAttributes* pVA = text.GetVisAttributes ();
840  if (!pVA) {
841  pVA = fpViewer -> GetViewParameters (). GetDefaultTextVisAttributes ();
842  }
843  const G4Colour& colour = pVA -> GetColour ();
844  return colour;
845 }
846 
848 {
849  G4double lineWidth = pVisAttribs->GetLineWidth();
850  if (lineWidth < 1.) lineWidth = 1.;
851  lineWidth *= fpViewer -> GetViewParameters().GetGlobalLineWidthScale();
852  if (lineWidth < 1.) lineWidth = 1.;
853  return lineWidth;
854 }
855 
857 (const G4VisAttributes* pVisAttribs) {
858  // Drawing style is normally determined by the view parameters, but
859  // it can be overriddden by the ForceDrawingStyle flag in the vis
860  // attributes.
862  fpViewer->GetViewParameters().GetDrawingStyle();
863  if (pVisAttribs -> IsForceDrawingStyle ()) {
865  pVisAttribs -> GetForcedDrawingStyle ();
866  // This is complicated because if hidden line and surface removal
867  // has been requested we wish to preserve this sometimes.
868  switch (forcedStyle) {
869  case (G4VisAttributes::solid):
870  switch (style) {
871  case (G4ViewParameters::hlr):
872  style = G4ViewParameters::hlhsr;
873  break;
875  style = G4ViewParameters::hsr;
876  break;
878  case (G4ViewParameters::hsr):
879  default:
880  break;
881  }
882  break;
884  default:
885  // But if forced style is wireframe, do it, because one of its
886  // main uses is in displaying the consituent solids of a Boolean
887  // solid and their surfaces overlap with the resulting Booean
888  // solid, making a mess if hlr is specified.
890  break;
891  }
892  }
893  return style;
894 }
895 
897  G4bool isAuxEdgeVisible = fpViewer->GetViewParameters().IsAuxEdgeVisible ();
898  if (pVisAttribs -> IsForceAuxEdgeVisible()) isAuxEdgeVisible = true;
899  return isAuxEdgeVisible;
900 }
901 
903 (const G4VMarker& marker,
904  G4VSceneHandler::MarkerSizeType& markerSizeType)
905 {
906  G4bool userSpecified = marker.GetWorldSize() || marker.GetScreenSize();
907  const G4VMarker& defaultMarker =
908  fpViewer -> GetViewParameters().GetDefaultMarker();
909  G4double size = userSpecified ?
910  marker.GetWorldSize() : defaultMarker.GetWorldSize();
911  if (size) {
912  // Draw in world coordinates.
913  markerSizeType = world;
914  }
915  else {
916  size = userSpecified ?
917  marker.GetScreenSize() : defaultMarker.GetScreenSize();
918  // Draw in screen coordinates.
919  markerSizeType = screen;
920  }
921  size *= fpViewer -> GetViewParameters().GetGlobalMarkerScale();
922  if (markerSizeType == screen && size < 1.) size = 1.;
923  return size;
924 }
925 
927 {
928  // No. of sides (lines segments per circle) is normally determined
929  // by the view parameters, but it can be overriddden by the
930  // ForceLineSegmentsPerCircle in the vis attributes.
931  G4int lineSegmentsPerCircle = fpViewer->GetViewParameters().GetNoOfSides();
932  if (pVisAttribs) {
933  if (pVisAttribs->IsForceLineSegmentsPerCircle())
934  lineSegmentsPerCircle = pVisAttribs->GetForcedLineSegmentsPerCircle();
935  if (lineSegmentsPerCircle < pVisAttribs->GetMinLineSegmentsPerCircle()) {
936  lineSegmentsPerCircle = pVisAttribs->GetMinLineSegmentsPerCircle();
937  G4cout <<
938  "G4VSceneHandler::GetNoOfSides: attempt to set the"
939  "\nnumber of line segements per circle < " << lineSegmentsPerCircle
940  << "; forced to " << pVisAttribs->GetMinLineSegmentsPerCircle() << G4endl;
941  }
942  }
943  return lineSegmentsPerCircle;
944 }
945 
946 std::ostream& operator << (std::ostream& os, const G4VSceneHandler& sh) {
947 
948  os << "Scene handler " << sh.fName << " has "
949  << sh.fViewerList.size () << " viewer(s):";
950  for (size_t i = 0; i < sh.fViewerList.size (); i++) {
951  os << "\n " << *(sh.fViewerList [i]);
952  }
953 
954  if (sh.fpScene) {
955  os << "\n " << *sh.fpScene;
956  }
957  else {
958  os << "\n This scene handler currently has no scene.";
959  }
960 
961  return os;
962 }
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
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
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:134
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 &)