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