100 fpGraphicsSystem (0),
104 fpStateDependent (0),
105 fEventRefreshing (false),
106 fTransientsDrawnThisRun (false),
107 fTransientsDrawnThisEvent (false),
108 fNoOfEventsDrawnThisRun (0),
110 fEventKeepingSuspended (false),
111 fDrawEventOnlyIfToBeKept (false),
112 fpRequestedEvent (0),
113 fReviewingKeptEvents (false),
114 fAbortReviewKeptEvents (false),
115 fIsDrawGroup (false),
116 fDrawGroupNestingDepth (0),
117 fIgnoreStateChanges (false)
118#ifdef G4MULTITHREADED
119, fMaxEventQueueSize (100)
120, fWaitOnEventQueueFull (true)
130 (
"Simple graded message scheme - digit or string (1st character defines):");
132 (
" 0) quiet, // Nothing is printed.");
134 (
" 1) startup, // Startup and endup messages are printed...");
136 (
" 2) errors, // ...and errors...");
138 (
" 3) warnings, // ...and warnings...");
140 (
" 4) confirmations, // ...and confirming messages...");
142 (
" 5) parameters, // ...and parameters of scenes and views...");
144 (
" 6) all // ...and everything available.");
148 (
"G4VisManager::G4VisManager",
150 "Attempt to Construct more than one VisManager");
162 <<
"Visualization Manager instantiating with verbosity \""
193 directory -> SetGuidance (
"Visualization commands.");
194 fDirectoryList.push_back (directory);
208 for (i = 0; i < fSceneList.size (); ++i) {
209 delete fSceneList[i];
211 for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
212 if (fAvailableSceneHandlers[i] != NULL) {
213 delete fAvailableSceneHandlers[i];
216 for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
217 if (fAvailableGraphicsSystems[i]) {
218 delete fAvailableGraphicsSystems[i];
223 G4cout <<
"Visualization Manager deleting..." <<
G4endl;
225 for (i = 0; i < fMessengerList.size (); ++i) {
226 delete fMessengerList[i];
228 for (i = 0; i < fDirectoryList.size (); ++i) {
229 delete fDirectoryList[i];
232 delete fpDigiFilterMgr;
233 delete fpHitFilterMgr;
234 delete fpTrajFilterMgr;
235 delete fpTrajDrawModelMgr;
241 (
"G4VisManager::GetInstance",
249 if (fInitialised && fVerbosity >=
warnings) {
250 G4cout <<
"WARNING: G4VisManager::Initialise: already initialised."
256 G4cout <<
"Visualization Manager initialising..." <<
G4endl;
261 "\nYou have instantiated your own Visualization Manager, inheriting"
262 "\n G4VisManager and implementing RegisterGraphicsSystems(), in which"
263 "\n you should, normally, instantiate drivers which do not need"
264 "\n external packages or libraries, and, optionally, drivers under"
265 "\n control of environment variables."
266 "\n Also you should implement RegisterModelFactories()."
267 "\n See visualization/management/include/G4VisExecutive.hh/icc, for example."
268 "\n In your main() you will have something like:"
269 "\n G4VisManager* visManager = new G4VisExecutive;"
270 "\n visManager -> SetVerboseLevel (Verbose);"
271 "\n visManager -> Initialize ();"
272 "\n (Don't forget to delete visManager;)"
285 "\nYou have successfully registered the following graphics systems."
295 directory -> SetGuidance (
"Modeling commands.");
296 fDirectoryList.push_back (directory);
297 directory =
new G4UIdirectory (
"/vis/modeling/trajectories/");
298 directory -> SetGuidance (
"Trajectory model commands.");
299 fDirectoryList.push_back (directory);
300 directory =
new G4UIdirectory (
"/vis/modeling/trajectories/create/");
301 directory -> SetGuidance (
"Create trajectory models and messengers.");
302 fDirectoryList.push_back (directory);
306 directory -> SetGuidance (
"Filtering commands.");
307 fDirectoryList.push_back (directory);
308 directory =
new G4UIdirectory (
"/vis/filtering/trajectories/");
309 directory -> SetGuidance (
"Trajectory filtering commands.");
310 fDirectoryList.push_back (directory);
311 directory =
new G4UIdirectory (
"/vis/filtering/trajectories/create/");
312 directory -> SetGuidance (
"Create trajectory filters and messengers.");
313 fDirectoryList.push_back (directory);
315 directory -> SetGuidance (
"Hit filtering commands.");
316 fDirectoryList.push_back (directory);
317 directory =
new G4UIdirectory (
"/vis/filtering/hits/create/");
318 directory -> SetGuidance (
"Create hit filters and messengers.");
319 fDirectoryList.push_back (directory);
321 directory -> SetGuidance (
"Digi filtering commands.");
322 fDirectoryList.push_back (directory);
323 directory =
new G4UIdirectory (
"/vis/filtering/digi/create/");
324 directory -> SetGuidance (
"Create digi filters and messengers.");
325 fDirectoryList.push_back (directory);
337 "\nYou have successfully registered the following model factories."
339 PrintAvailableModels (fVerbosity);
344 PrintAvailableUserVisActions (fVerbosity);
348 InitialiseG4ColourMap();
352 "Some /vis commands (optionally) take a string to specify colour."
353 "\n\"/vis/list\" to see available colours."
360void G4VisManager::InitialiseG4ColourMap()
const
369#define TOOLS_COLORS_STAT(name,r,g,b) \
370G4Colour::AddToMap(#name, G4Colour(r,g,b));
451#undef TOOLS_COLORS_STAT
462 directory -> SetGuidance(
"Operations on vis attributes of Geant4 geometry.");
463 fDirectoryList.push_back (directory);
468 directory -> SetGuidance(
"Set vis attributes of Geant4 geometry.");
469 fDirectoryList.push_back (directory);
481#ifdef G4MULTITHREADED
483 directory -> SetGuidance(
"Commands unique to multithreading mode.");
484 fDirectoryList.push_back (directory);
490 directory -> SetGuidance
491 (
"Set quantities for use in future commands where appropriate.");
492 fDirectoryList.push_back (directory);
504 directory -> SetGuidance (
"Operations on Geant4 scenes.");
505 fDirectoryList.push_back (directory);
516 directory -> SetGuidance (
"Add model to current scene.");
517 fDirectoryList.push_back (directory);
544 directory -> SetGuidance (
"Operations on Geant4 scene handlers.");
545 fDirectoryList.push_back (directory);
552 directory -> SetGuidance (
"Operations on touchables.");
553 fDirectoryList.push_back (directory);
557 directory -> SetGuidance (
"Set vis attributes of current touchable.");
558 fDirectoryList.push_back (directory);
562 directory -> SetGuidance (
"Operations on Geant4 viewers.");
563 fDirectoryList.push_back (directory);
590 directory -> SetGuidance(
"Set default values for future viewers.");
591 fDirectoryList.push_back (directory);
596 directory -> SetGuidance (
"Set view parameters of current viewer.");
597 fDirectoryList.push_back (directory);
619 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->
Placement()));
621 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->
Placement()));
625 (fpTrajFilterMgr, fpTrajFilterMgr->
Placement()));
627 (fpTrajFilterMgr, fpTrajFilterMgr->
Placement()));
631 (fpHitFilterMgr, fpHitFilterMgr->
Placement()));
633 (fpHitFilterMgr, fpHitFilterMgr->
Placement()));
637 (fpDigiFilterMgr, fpDigiFilterMgr->
Placement()));
639 (fpDigiFilterMgr, fpDigiFilterMgr->
Placement()));
643 if (IsValidView ()) {
646 G4cout <<
"G4VisManager::Enable: visualization enabled." <<
G4endl;
649 G4int nKeptEvents = 0;
653 "There are " << nKeptEvents <<
" kept events."
654 "\n \"/vis/reviewKeptEvents\" to review them one by one."
655 "\n \"/vis/viewer/flush\" or \"/vis/viewer/rebuild\" to see them accumulated."
662 "G4VisManager::Enable: WARNING: visualization remains disabled for"
663 "\n above reasons. Rectifying with valid vis commands will"
664 "\n automatically enable."
674 "G4VisManager::Disable: visualization disabled."
675 "\n The pointer returned by GetConcreteInstance will be zero."
676 "\n Note that it will become enabled after some valid vis commands."
680 G4int currentTrajectoryType =
682 if (currentTrajectoryType > 0) {
684 "You may wish to disable trajectory production too:"
685 "\n \"/tracking/storeTrajectory 0\""
686 "\nbut don't forget to re-enable with"
688 "\n \"/tracking/storeTrajectory " << currentTrajectoryType
689 <<
"\"\n and maybe \"/vis/viewer/rebuild\""
696 G4int nSystems = fAvailableGraphicsSystems.size ();
699 G4cout <<
"G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
700 "\n graphics system available!"
701 "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
702 "\n when you compiled/built the visualization code?"
703 "\n 2) Did you instantiate your own Visualization Manager and forget"
704 "\n to implement RegisterGraphicsSystems correctly?"
705 "\n 3) You can register your own graphics system, e.g.,"
706 "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
707 "\n after instantiating your vis manager and before"
708 "\n visManager->Initialize()."
712 return fAvailableGraphicsSystems;
718 fAvailableGraphicsSystems.push_back (pSystem);
720 G4cout <<
"G4VisManager::RegisterGraphicsSystem: "
721 << pSystem -> GetName ();
722 if (pSystem -> GetNickname () !=
"") {
723 G4cout <<
" (" << pSystem -> GetNickname () <<
")";
729 if (fVerbosity >=
errors) {
730 G4cout <<
"G4VisManager::RegisterGraphicsSystem: null pointer!"
741 assert (0 != fpTrajDrawModelMgr);
750 G4cout<<
"G4VisManager: Using G4TrajectoryDrawByCharge as fallback trajectory model."<<
G4endl;
751 G4cout<<
"See commands in /vis/modeling/trajectories/ for other options."<<
G4endl;
755 model = fpTrajDrawModelMgr->
Current();
763 fpTrajDrawModelMgr->
Register(model);
769 fpTrajDrawModelMgr->
Register(factory);
812#ifdef G4MULTITHREADED
815 fDrawGroupNestingDepth++;
816 if (fDrawGroupNestingDepth > 1) {
818 (
"G4VisManager::BeginDraw",
820 "Nesting detected. It is illegal to nest Begin/EndDraw."
824 if (IsValidView ()) {
825 ClearTransientStoreIfMarked();
826 fpSceneHandler -> BeginPrimitives (objectTransform);
833#ifdef G4MULTITHREADED
836 fDrawGroupNestingDepth--;
837 if (fDrawGroupNestingDepth != 0) {
838 if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
841 if (IsValidView ()) {
842 fpSceneHandler -> EndPrimitives ();
844 fIsDrawGroup =
false;
849#ifdef G4MULTITHREADED
852 fDrawGroupNestingDepth++;
853 if (fDrawGroupNestingDepth > 1) {
855 (
"G4VisManager::BeginDraw2D",
857 "Nesting detected. It is illegal to nest Begin/EndDraw2D."
861 if (IsValidView ()) {
862 ClearTransientStoreIfMarked();
863 fpSceneHandler -> BeginPrimitives2D (objectTransform);
870#ifdef G4MULTITHREADED
873 fDrawGroupNestingDepth--;
874 if (fDrawGroupNestingDepth != 0) {
875 if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
878 if (IsValidView ()) {
879 fpSceneHandler -> EndPrimitives2D ();
881 fIsDrawGroup =
false;
884template <
class T>
void G4VisManager::DrawT
885(
const T& graphics_primitive,
const G4Transform3D& objectTransform) {
886#ifdef G4MULTITHREADED
892 (
"G4VSceneHandler::DrawT",
894 "Different transform detected in Begin/EndDraw group.");
896 fpSceneHandler -> AddPrimitive (graphics_primitive);
898 if (IsValidView ()) {
899 ClearTransientStoreIfMarked();
900 fpSceneHandler -> BeginPrimitives (objectTransform);
901 fpSceneHandler -> AddPrimitive (graphics_primitive);
902 fpSceneHandler -> EndPrimitives ();
907template <
class T>
void G4VisManager::DrawT2D
908(
const T& graphics_primitive,
const G4Transform3D& objectTransform) {
909#ifdef G4MULTITHREADED
915 (
"G4VSceneHandler::DrawT",
917 "Different transform detected in Begin/EndDraw2D group.");
919 fpSceneHandler -> AddPrimitive (graphics_primitive);
921 if (IsValidView ()) {
922 ClearTransientStoreIfMarked();
923 fpSceneHandler -> BeginPrimitives2D (objectTransform);
924 fpSceneHandler -> AddPrimitive (graphics_primitive);
925 fpSceneHandler -> EndPrimitives2D ();
933 DrawT (circle, objectTransform);
939 DrawT (polyhedron, objectTransform);
945 DrawT (line, objectTransform);
951 DrawT (polymarker, objectTransform);
957 DrawT (scale, objectTransform);
963 DrawT (square, objectTransform);
969 DrawT (text, objectTransform);
975 DrawT2D (circle, objectTransform);
981 DrawT2D (polyhedron, objectTransform);
987 DrawT2D (line, objectTransform);
993 DrawT2D (polymarker, objectTransform);
999 DrawT2D (square, objectTransform);
1005 DrawT2D (text, objectTransform);
1009#ifdef G4MULTITHREADED
1013 fpSceneHandler -> AddCompound (hit);
1015 if (IsValidView ()) {
1016 ClearTransientStoreIfMarked();
1017 fpSceneHandler -> AddCompound (hit);
1023#ifdef G4MULTITHREADED
1027 fpSceneHandler -> AddCompound (digi);
1029 if (IsValidView ()) {
1030 ClearTransientStoreIfMarked();
1031 fpSceneHandler -> AddCompound (digi);
1037#ifdef G4MULTITHREADED
1054 fpSceneHandler -> SetModel (&trajectoriesModel);
1055 fpSceneHandler -> AddCompound (traj);
1056 fpSceneHandler -> SetModel (0);
1058 if (IsValidView ()) {
1059 ClearTransientStoreIfMarked();
1060 fpSceneHandler -> SetModel (&trajectoriesModel);
1061 fpSceneHandler -> AddCompound (traj);
1062 fpSceneHandler -> SetModel (0);
1070#ifdef G4MULTITHREADED
1075 Draw (*pSol, attribs, objectTransform);
1081#ifdef G4MULTITHREADED
1085 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
1087 fpSceneHandler -> PostAddSolid ();
1089 if (IsValidView ()) {
1090 ClearTransientStoreIfMarked();
1091 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
1093 fpSceneHandler -> PostAddSolid ();
1101#ifdef G4MULTITHREADED
1117 G4VSolid* pSol = pLV -> GetSolid ();
1118 Draw (*pSol, attribs, objectTransform);
1123 if (fpGraphicsSystem) {
1126 if (pSceneHandler) {
1127 fAvailableSceneHandlers.push_back (pSceneHandler);
1128 fpSceneHandler = pSceneHandler;
1131 if (fVerbosity >=
errors) {
1132 G4cout <<
"ERROR in G4VisManager::CreateSceneHandler during "
1133 << fpGraphicsSystem -> GetName ()
1134 <<
" scene handler creation.\n No action taken."
1139 else PrintInvalidPointers ();
1148 if (!fpSceneHandler) {
1149 PrintInvalidPointers ();
1156 if (fVerbosity >=
errors) {
1157 G4cerr <<
"ERROR in G4VisManager::CreateViewer: null pointer during "
1158 << fpGraphicsSystem -> GetName ()
1159 <<
" viewer creation.\n No action taken."
1165 if (p -> GetViewId() < 0) {
1166 if (fVerbosity >=
errors) {
1167 G4cerr <<
"ERROR in G4VisManager::CreateViewer during "
1168 << fpGraphicsSystem -> GetName ()
1169 <<
" viewer instantiation.\n No action taken."
1180 p -> SetViewParameters(initialvp);
1182 if (p -> GetViewId() < 0) {
1183 if (fVerbosity >=
errors) {
1184 G4cerr <<
"ERROR in G4VisManager::CreateViewer during "
1185 << fpGraphicsSystem -> GetName ()
1186 <<
" viewer initialisation.\n No action taken."
1193 fpSceneHandler -> AddViewerToList (fpViewer);
1196 G4cout <<
"G4VisManager::CreateViewer: new viewer created."
1206 static G4bool warned =
false;
1210 "NOTE: objects with visibility flag set to \"false\""
1211 " will not be drawn!"
1212 "\n \"/vis/viewer/set/culling global false\" to Draw such objects."
1213 "\n Also see other \"/vis/viewer/set\" commands."
1220 static G4bool warned =
false;
1224 "WARNING: covered objects in solid mode will not be rendered!"
1225 "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
1226 "\n Also see other \"/vis/viewer/set\" commands."
1236 G4cout <<
"G4VisManager::GeometryHasChanged() called." <<
G4endl;
1242 -> GetNavigatorForTracking () -> GetWorldVolume ();
1245 G4cout <<
"WARNING: There is no world volume!" <<
G4endl;
1251 G4int iScene, nScenes = sceneList.size ();
1252 for (iScene = 0; iScene < nScenes; iScene++) {
1253 G4Scene* pScene = sceneList [iScene];
1254 std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1255 if (modelList.size ()) {
1258 modelInvalid =
false;
1259 std::vector<G4Scene::Model>::iterator iterModel;
1260 for (iterModel = modelList.begin();
1261 iterModel != modelList.end();
1263 modelInvalid = !(iterModel->fpModel->Validate(fVerbosity>=
warnings));
1267 G4cout <<
"WARNING: Model \""
1268 << iterModel->fpModel->GetGlobalDescription ()
1270 "\" is no longer valid - being removed\n from scene \""
1271 << pScene -> GetName () <<
"\""
1274 modelList.erase (iterModel);
1278 }
while (modelInvalid);
1280 if (modelList.size () == 0) {
1282 G4cout <<
"WARNING: No models left in this scene \""
1283 << pScene -> GetName ()
1291 ApplyCommand (
G4String(
"/vis/scene/notifyHandlers " + pScene->
GetName()));
1297 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1299 G4cout <<
"WARNING: The current scene \""
1300 << fpScene -> GetName ()
1301 <<
"\" has no run duration models."
1302 <<
"\n Use \"/vis/scene/add/volume\" or create a new scene."
1317 G4cout <<
"G4VisManager::NotifyHandler() called." <<
G4endl;
1320 if (IsValidView()) {
1324 G4int iScene, nScenes = sceneList.size ();
1325 for (iScene = 0; iScene < nScenes; iScene++) {
1326 G4Scene* pScene = sceneList [iScene];
1327 std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1329 if (modelList.size ()) {
1332 ApplyCommand (
G4String(
"/vis/scene/notifyHandlers " + pScene->
GetName()));
1337 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1339 G4cout <<
"WARNING: The current scene \""
1340 << fpScene -> GetName ()
1341 <<
"\" has no run duration models."
1342 <<
"\n Use \"/vis/scene/add/volume\" or create a new scene."
1357 return fpTrajFilterMgr->
Accept(trajectory);
1362 return fpHitFilterMgr->
Accept(hit);
1367 return fpDigiFilterMgr->
Accept(digi);
1385 assert (0 != fpTrajDrawModelMgr);
1389 assert (0 != trajectoryModel);
1391 if (IsValidView()) {
1392 trajectoryModel->
Draw(trajectory, visible);
1401 "WARNING: SetUserAction is deprecated. Use RegisterRunDurationUserVisAction."
1411 fRunDurationUserVisActions.push_back(
UserVisAction(name,pVisAction));
1413 fUserVisActionExtents[pVisAction] = extent;
1417 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1423 <<
"Run duration user vis action \"" << name <<
"\" registered"
1432 fEndOfEventUserVisActions.push_back(
UserVisAction(name,pVisAction));
1434 fUserVisActionExtents[pVisAction] = extent;
1438 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1444 <<
"End of event user vis action \"" << name <<
"\" registered"
1453 fEndOfRunUserVisActions.push_back(
UserVisAction(name,pVisAction));
1455 fUserVisActionExtents[pVisAction] = extent;
1459 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1465 <<
"End of run user vis action \"" << name <<
"\" registered"
1471 if (pScene != fpScene) {
1480 fpGraphicsSystem = pSystem;
1482 G4cout <<
"G4VisManager::SetCurrentGraphicsSystem: system now "
1483 << pSystem -> GetName () <<
G4endl;
1488 if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
1490 G4int nSH = sceneHandlerList.size ();
1492 for (iSH = nSH - 1; iSH >= 0; iSH--) {
1493 if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem)
break;
1496 fpSceneHandler = sceneHandlerList [iSH];
1498 G4cout <<
" Scene Handler now "
1499 << fpSceneHandler -> GetName () <<
G4endl;
1501 if (fpScene != fpSceneHandler -> GetScene ()) {
1502 fpScene = fpSceneHandler -> GetScene ();
1504 G4cout <<
" Scene now \""
1505 << fpScene -> GetName () <<
"\"" <<
G4endl;
1508 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1509 if (viewerList.size ()) {
1510 fpViewer = viewerList [0];
1512 G4cout <<
" Viewer now " << fpViewer -> GetName () <<
G4endl;
1527 fpSceneHandler = pSceneHandler;
1529 G4cout <<
"G4VisManager::SetCurrentSceneHandler: scene handler now \""
1530 << pSceneHandler -> GetName () <<
"\"" <<
G4endl;
1532 if (fpScene != fpSceneHandler -> GetScene ()) {
1533 fpScene = fpSceneHandler -> GetScene ();
1535 G4cout <<
" Scene now \""
1536 << fpScene -> GetName () <<
"\"" <<
G4endl;
1539 if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
1540 fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
1542 G4cout <<
" Graphics system now \""
1543 << fpGraphicsSystem -> GetName () <<
"\"" <<
G4endl;
1546 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1547 G4int nViewers = viewerList.size ();
1550 for (iViewer = 0; iViewer < nViewers; iViewer++) {
1551 if (fpViewer == viewerList [iViewer])
break;
1553 if (iViewer >= nViewers) {
1554 fpViewer = viewerList [0];
1556 G4cout <<
" Viewer now \"" << fpViewer -> GetName () <<
"\""
1560 if (!IsValidView ()) {
1563 "WARNING: Problem setting scene handler - please report circumstances."
1572 "WARNING: No viewers for this scene handler - please create one."
1581 G4cout <<
"G4VisManager::SetCurrentViewer: viewer now "
1582 << pViewer -> GetName ()
1585 fpSceneHandler = fpViewer -> GetSceneHandler ();
1586 if (!fpSceneHandler) {
1589 "WARNING: No scene handler for this viewer - please create one."
1597 fpScene = fpSceneHandler -> GetScene ();
1598 fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1599 if (!IsValidView ()) {
1602 "WARNING: Problem setting viewer - please report circumstances."
1610 G4cout <<
"Registered graphics systems are:\n";
1611 if (fAvailableGraphicsSystems.size ()) {
1612 for (
const auto& gs: fAvailableGraphicsSystems) {
1613 const G4String& name = gs->GetName();
1614 const std::vector<G4String>& nicknames = gs->GetNicknames();
1617 G4cout <<
" " << name <<
" (";
1618 for (
size_t i = 0; i < nicknames.size(); ++i) {
1632 G4cout <<
" NONE!!! None registered - yet! Mmmmm!" <<
G4endl;
1636void G4VisManager::PrintAvailableModels (Verbosity verbosity)
const
1641 const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1645 std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1646 for (i = factoryList.begin(); i != factoryList.end(); ++i) {
1653 const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1657 std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1658 for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1659 G4cout <<
" " << i->second->Name();
1660 if (i->second == listManager->
Current())
G4cout <<
" (Current)";
1672 const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1676 std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1677 for (i = factoryList.begin(); i != factoryList.end(); ++i) {
1683 const std::vector<G4VFilter<G4VTrajectory>*>&
1687 std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1688 for (i = filterList.begin(); i != filterList.end(); ++i) {
1696void G4VisManager::PrintAvailableUserVisActions (Verbosity)
const
1699 "You have successfully registered the following user vis actions."
1701 G4cout <<
"Run Duration User Vis Actions:";
1702 if (fRunDurationUserVisActions.empty())
G4cout <<
" none" <<
G4endl;
1705 for (
size_t i = 0; i < fRunDurationUserVisActions.size(); i++) {
1706 const G4String&
name = fRunDurationUserVisActions[i].fName;
1711 G4cout <<
"End of Event User Vis Actions:";
1712 if (fEndOfEventUserVisActions.empty())
G4cout <<
" none" <<
G4endl;
1715 for (
size_t i = 0; i < fEndOfEventUserVisActions.size(); i++) {
1716 const G4String&
name = fEndOfEventUserVisActions[i].fName;
1721 G4cout <<
"End of Run User Vis Actions:";
1722 if (fEndOfRunUserVisActions.empty())
G4cout <<
" none" <<
G4endl;
1725 for (
size_t i = 0; i < fEndOfRunUserVisActions.size(); i++) {
1726 const G4String&
name = fEndOfRunUserVisActions[i].fName;
1732void G4VisManager::PrintAvailableColours (Verbosity)
const {
1734 "Some /vis commands (optionally) take a string to specify colour."
1735 "\nAvailable colours:\n ";
1737 for (std::map<G4String, G4Colour>::const_iterator i = map.begin();
1740 if (++i != map.end())
G4cout <<
", ";
1745void G4VisManager::PrintInvalidPointers ()
const {
1746 if (fVerbosity >=
errors) {
1747 G4cerr <<
"ERROR: G4VisManager::PrintInvalidPointers:";
1748 if (!fpGraphicsSystem) {
1749 G4cerr <<
"\n null graphics system pointer.";
1752 G4cerr <<
"\n Graphics system is " << fpGraphicsSystem -> GetName ()
1756 "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1757 " \"/vis/scene/create\".";
1758 if (!fpSceneHandler)
1760 "\n Null scene handler pointer. Use \"/vis/open\" or"
1761 " \"/vis/sceneHandler/create\".";
1764 "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1770#ifdef G4MULTITHREADED
1773 G4bool mtRunInProgress =
false;
1774 std::deque<const G4Event*> mtVisEventQueue;
1783 if (!pSceneHandler)
return 0;
1785 if (!pScene)
return 0;
1787 if (!pViewer)
return 0;
1802 pViewer->SwitchToVisSubThread();
1807 G4int eventQueueSize = mtVisEventQueue.size();
1811 while (eventQueueSize) {
1814 const G4Event*
event = mtVisEventQueue.front();
1834 pVisManager->ClearTransientStoreIfMarked();
1838 ++pVisManager->fNoOfEventsDrawnThisRun;
1855 mtVisEventQueue.pop_front();
1856 event->PostProcessingFinished();
1857 eventQueueSize = mtVisEventQueue.size();
1863 G4int runInProgress = mtRunInProgress;
1865 if (!runInProgress) {
1872 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1876 pViewer->DoneWithVisSubThread();
1877 pViewer->MovingToMasterThread();
1891void G4VisManager::BeginOfRun ()
1893 if (fIgnoreStateChanges)
return;
1895#ifdef G4MULTITHREADED
1905 if (nEventsToBeProcessed == 0)
return;
1908 fEventKeepingSuspended =
false;
1909 fTransientsDrawnThisRun =
false;
1911 fNoOfEventsDrawnThisRun = 0;
1919#ifdef G4MULTITHREADED
1928 if (fpViewer) fpViewer->DoneWithMasterThread();
1933 mtRunInProgress =
true;
1944 if (fpViewer) fpViewer->MovingToVisSubThread();
1949void G4VisManager::BeginOfEvent ()
1951 if (fIgnoreStateChanges)
return;
1959#ifndef G4MULTITHREADED
1961 fTransientsDrawnThisEvent =
false;
1966void G4VisManager::EndOfEvent ()
1968 if (fIgnoreStateChanges)
return;
1975 G4bool valid = fpSceneHandler && IsValidView();
1981#ifdef G4MULTITHREADED
1990 if (!currentRun)
return;
1995 if (!currentEvent)
return;
1999 if (fDrawEventOnlyIfToBeKept) {
2000 if (!currentEvent->
ToBeKept())
return;
2005#ifdef G4MULTITHREADED
2009 G4int eventQueueSize = mtVisEventQueue.size();
2013 G4bool eventQueueFull =
false;
2014 while (fMaxEventQueueSize > 0 && eventQueueSize >= fMaxEventQueueSize) {
2017 if (fWaitOnEventQueueFull) {
2018 static G4bool warned =
false;
2021 "WARNING: The number of events in the visualisation queue has exceeded"
2023 << fMaxEventQueueSize <<
2024 ".\n If, during a multithreaded run, the simulation gets ahead of the"
2025 "\n visualisation by more than this maximum, the simulation is delayed"
2026 "\n until the vis sub-thread has drawn a few more events and removed them"
2027 "\n from the queue. You may change this maximum number of events with"
2028 "\n \"/vis/multithreading/maxEventQueueSize <N>\", where N is the maximum"
2029 "\n number you wish to allow. N <= 0 means \"unlimited\"."
2030 "\n Alternatively you may choose to discard events for drawing by setting"
2031 "\n \"/vis/multithreading/actionOnEventQueueFull discard\"."
2032 "\n To avoid visualisation altogether: \"/vis/disable\"."
2033 "\n And maybe \"/tracking/storeTrajectories 0\"."
2039 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2042 static G4bool warned =
false;
2045 "WARNING: The number of events in the visualisation queue has exceeded"
2047 << fMaxEventQueueSize <<
2048 ".\n Some events have been discarded for drawing. You may change this"
2049 "\n behaviour with \"/vis/multithreading/actionOnEventQueueFull wait\"."
2050 "\n To avoid visualisation altogether: \"/vis/disable\"."
2051 "\n And maybe \"/tracking/storeTrajectories 0\"."
2055 eventQueueFull =
true;
2060 eventQueueSize = mtVisEventQueue.size();
2064 if (!eventQueueFull) {
2070 if (fNKeepRequests == 0) {
2075 mtVisEventQueue.push_back(currentEvent);
2090 G4int nEventsToBeProcessed = 0;
2091 G4int nKeptEvents = 0;
2096 const std::vector<const G4Event*>* events = currentRun->
GetEventVector();
2097 if (events) nKeptEvents = events->size();
2108 ClearTransientStoreIfMarked();
2111 fpSceneHandler->
DrawEvent(currentEvent);
2112 ++fNoOfEventsDrawnThisRun;
2117 if (eventID < nEventsToBeProcessed - 1) {
2124 if (nKeptEvents == 0) {
2142 if (maxNumberOfKeptEvents > 0 &&
2143 fNKeepRequests >= maxNumberOfKeptEvents) {
2145 fEventKeepingSuspended =
true;
2146 static G4bool warned =
false;
2150 "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
2151 "\n The number of events exceeds the maximum, "
2152 << maxNumberOfKeptEvents <<
2153 ", that may be kept by\n the vis manager."
2159 }
else if (maxNumberOfKeptEvents != 0) {
2174void G4VisManager::EndOfRun ()
2176 if (fIgnoreStateChanges)
return;
2178#ifdef G4MULTITHREADED
2189 if (nEventsToBeProcessed == 0)
return;
2192 if (!currentRun)
return;
2194#ifdef G4MULTITHREADED
2199 mtRunInProgress =
false;
2203 delete mtVisSubThread;
2204 if (fpViewer) fpViewer->SwitchToMasterThread();
2208#ifdef G4MULTITHREADED
2213 if (fpSceneHandler && IsValidView()) {
2215 if (fNoOfEventsDrawnThisRun != noOfEventsRequested) {
2216 if (!fWaitOnEventQueueFull && fVerbosity >=
warnings) {
2218 <<
"WARNING: Number of events drawn this run, "
2219 << fNoOfEventsDrawnThisRun <<
", is different to number requested, "
2220 << noOfEventsRequested <<
2221 ".\n (This is because you requested \"/vis/multithreading/actionOnEventQueueFull discard\".)"
2228 G4int nKeptEvents = 0;
2229 const std::vector<const G4Event*>* events = currentRun->
GetEventVector();
2230 if (events) nKeptEvents = events->size();
2233 if (nKeptEvents == 1)
G4cout <<
" event has";
2234 else G4cout <<
" events have";
2235 G4cout <<
" been kept for refreshing and/or reviewing." <<
G4endl;
2236 if (nKeptEvents != fNKeepRequests) {
2238 if (fNKeepRequests == 0) {
2239 G4cout <<
"No keep requests were";
2240 }
else if (fNKeepRequests == 1) {
2241 G4cout <<
"1 keep request was";
2243 G4cout << fNKeepRequests <<
" keep requests were";
2245 G4cout <<
" made by the vis manager.";
2246 if (fNKeepRequests == 0) {
2248 "\n The kept events are those you have asked to be kept in your user action(s).)";
2251 "\n The same or further events may have been kept by you in your user action(s).)";
2256 " \"/vis/reviewKeptEvents\" to review them one by one."
2257 "\n \"/vis/enable\", then \"/vis/viewer/flush\" or \"/vis/viewer/rebuild\" to see them accumulated."
2278 if (fEventKeepingSuspended && fVerbosity >=
warnings) {
2280 "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
2281 "\n The number of events in the run exceeded the maximum, "
2283 ", that may be\n kept by the vis manager." <<
2284 "\n The number of events kept by the vis manager can be changed with"
2285 "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
2286 "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
2293 G4bool valid = fpSceneHandler && IsValidView();
2317 G4cout <<
"\"/vis/viewer/update\" to close file." <<
G4endl;
2323 fEventRefreshing =
false;
2326void G4VisManager::ClearTransientStoreIfMarked(){
2342 fTransientsDrawnThisRun =
false;
2343 fTransientsDrawnThisEvent =
false;
2345 for (i = fAvailableSceneHandlers.begin();
2346 i != fAvailableSceneHandlers.end(); ++i) {
2347 (*i)->SetTransientsDrawnThisEvent(
false);
2348 (*i)->SetTransientsDrawnThisRun(
false);
2353 G4String viewerShortName (viewerName);
2354 viewerShortName = viewerShortName (0, viewerShortName.find (
' '));
2355 return viewerShortName.
strip ();
2360 size_t nHandlers = fAvailableSceneHandlers.size ();
2361 size_t iHandler, iViewer;
2364 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
2366 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
2367 for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
2368 viewer = viewerList [iViewer];
2369 if (viewerShortName == viewer -> GetShortName ()) {
2376 if (found)
return viewer;
2384 switch (verbosity) {
2385 case quiet: rs =
"quiet (0)";
break;
2386 case startup: rs =
"startup (1)";
break;
2387 case errors: rs =
"errors (2)";
break;
2388 case warnings: rs =
"warnings (3)";
break;
2390 case parameters: rs =
"parameters (5)";
break;
2391 case all: rs =
"all (6)";
break;
2400 if (ss(0) ==
'q') verbosity =
quiet;
2401 else if (ss(0) ==
's') verbosity =
startup;
2402 else if (ss(0) ==
'e') verbosity =
errors;
2403 else if (ss(0) ==
'w') verbosity =
warnings;
2405 else if (ss(0) ==
'p') verbosity =
parameters;
2406 else if (ss(0) ==
'a') verbosity =
all;
2409 std::istringstream is(ss);
2412 G4cerr <<
"ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
2413 << verbosityString <<
"\"";
2431 else if (intVerbosity >
all) verbosity =
all;
2432 else verbosity =
Verbosity(intVerbosity);
2448G4bool G4VisManager::IsValidView () {
2452 static G4bool noGSPrinting =
true;
2453 if (!fpGraphicsSystem) {
2457 noGSPrinting =
false;
2460 "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
2461 "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
2462 "\n Alternatively, to avoid this message, suppress instantiation of vis"
2463 "\n manager (G4VisExecutive) and ensure drawing code is executed only if"
2464 "\n G4VVisManager::GetConcreteInstance() is non-zero."
2471 if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
2472 if (fVerbosity >=
errors) {
2474 "ERROR: G4VisManager::IsValidView(): Current view is not valid."
2476 PrintInvalidPointers ();
2481 if (fpScene != fpSceneHandler -> GetScene ()) {
2482 if (fVerbosity >=
errors) {
2483 G4cerr <<
"ERROR: G4VisManager::IsValidView ():";
2484 if (fpSceneHandler -> GetScene ()) {
2486 "\n The current scene \""
2487 << fpScene -> GetName ()
2488 <<
"\" is not handled by"
2489 "\n the current scene handler \""
2490 << fpSceneHandler -> GetName ()
2492 "\n (it currently handles scene \""
2493 << fpSceneHandler -> GetScene () -> GetName ()
2496 "\n (a) attach it to the scene handler with"
2497 "\n /vis/sceneHandler/attach "
2498 << fpScene -> GetName ()
2500 "\n (b) create a new scene handler with "
2501 "\n /vis/sceneHandler/create <graphics-system>,"
2502 "\n in which case it should pick up the the new scene."
2506 G4cout <<
"\n Scene handler \""
2507 << fpSceneHandler -> GetName ()
2508 <<
"\" has null scene pointer."
2509 "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
2516 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
2517 if (viewerList.size () == 0) {
2518 if (fVerbosity >=
errors) {
2520 "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
2521 << fpSceneHandler -> GetName ()
2522 <<
"\" has no viewers. Do /vis/viewer/create."
2529 if (fpScene -> IsEmpty ()) {
2531 G4bool successful = fpScene -> AddWorldIfEmpty (warn);
2532 if (!successful || fpScene -> IsEmpty ()) {
2533 if (fVerbosity >=
errors) {
2534 G4cerr <<
"ERROR: G4VisManager::IsValidView ():";
2536 "\n Attempt at some drawing operation when scene is empty."
2537 "\n Maybe the geometry has not yet been defined."
2538 " Try /run/initialize."
2539 "\n Or use \"/vis/scene/add/extent\"."
2548 "WARNING: G4VisManager: the scene was empty, \"world\" has been"
2549 "\n added and the scene handlers notified.";
2561 G4cout<<
"G4VisManager: No model factories registered with G4VisManager."<<
G4endl;
2562 G4cout<<
"G4VisManager::RegisterModelFactories() should be overridden in derived"<<
G4endl;
2563 G4cout<<
"class. See G4VisExecutive for an example."<<
G4endl;
2567#ifdef G4MULTITHREADED
2568void G4VisManager::SetUpForAThread()
2576 fIgnoreStateChanges = val;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4VSceneHandler * >::const_iterator G4SceneHandlerListConstIterator
#define G4MUTEX_INITIALIZER
#define G4MUTEXLOCK(mutex)
#define G4THREADJOIN(worker)
void G4THREADCREATE(_Worker *&worker, _Func func, _Args... args)
#define G4MUTEXUNLOCK(mutex)
void * G4ThreadFunReturnType
void * G4ThreadFunArgType
#define TOOLS_COLORS_STAT(name, r, g, b)
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static void InitialiseColourMap()
static const std::map< G4String, G4Colour > & GetMap()
void KeepTheCurrentEvent()
const G4Event * GetConstCurrentEvent()
static G4EventManager * GetEventManager()
void KeepForPostProcessing() const
static pool_type * GetPool()
G4VSolid * GetSolid() const
void SetWorldVolume(G4VPhysicalVolume *pWorld)
static G4RunManager * GetMasterRunManager()
static G4RunManagerKernel * GetMasterRunManagerKernel()
static G4RunManagerKernel * GetRunManagerKernel()
G4TrackingManager * GetTrackingManager() const
G4int GetNumberOfEventsToBeProcessed() const
static G4RunManager * GetRunManager()
const G4Run * GetCurrentRun() const
const std::vector< const G4Event * > * GetEventVector() const
G4bool GetRefreshAtEndOfEvent() const
const G4String & GetName() const
G4bool GetRefreshAtEndOfRun() const
G4int GetMaxNumberOfKeptEvents() const
static pool_type * GetPool()
G4String strip(G4int strip_Type=trailing, char c=' ')
void CreateAndUseWorkspace()
G4int GetStoreTrajectory() const
void SetCurrentTrajectory(const G4VTrajectory *pTraj)
void SetEventID(G4int eventID)
void SetRunID(G4int runID)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
G4int ApplyCommand(const char *aCommand)
void SetUpForSpecialThread(G4String aPrefix)
static G4UImanager * GetUIpointer()
Functionality GetFunctionality() const
G4LogicalVolume * GetLogicalVolume() const
virtual void ClearTransientStore()
G4bool GetTransientsDrawnThisEvent() const
void SetTransientsDrawnThisRun(G4bool)
void DrawEvent(const G4Event *)
void SetMarkForClearingTransientStore(G4bool)
G4Scene * GetScene() const
void SetTransientsDrawnThisEvent(G4bool)
void DrawEndOfRunModels()
const G4Transform3D & GetObjectTransformation() const
G4bool GetTransientsDrawnThisRun() const
virtual void ClearStore()
G4bool GetMarkForClearingTransientStore() const
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const =0
virtual void Draw(const G4VTrajectory &trajectory, const G4bool &visible=true) const =0
const G4ViewParameters & GetViewParameters() const
virtual void FinishView()
virtual void ClearView()=0
static void SetVisManager(G4VisManager *pVisManager)
static G4VVisManager * GetConcreteInstance()
static void SetConcreteInstance(G4VVisManager *)
void SetXGeometryString(const G4String &)
G4bool IsCullingInvisible() const
G4bool IsAutoRefresh() const
G4bool IsCullingCovered() const
G4double GetExtentRadius() const
FilterMode::Mode GetMode() const
G4String Placement() const
const std::vector< Filter * > & FilterList() const
const std::vector< Factory * > & FactoryList() const
const std::map< G4String, T * > & Map() const
const T * Current() const
void SelectTrajectoryModel(const G4String &model)
void RegisterRunDurationUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent())
void Draw(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
virtual void RegisterGraphicsSystems()=0
void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())
void CreateSceneHandler(const G4String &name="")
void SetCurrentSceneHandler(G4VSceneHandler *)
const G4VTrajectoryModel * CurrentTrajDrawModel() const
G4bool FilterDigi(const G4VDigi &)
void SetTransientsDrawnThisEvent(G4bool)
void SetCurrentScene(G4Scene *)
static std::vector< G4String > VerbosityGuidanceStrings
static G4String VerbosityString(Verbosity)
void RegisterEndOfEventUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent())
G4String ViewerShortName(const G4String &viewerName) const
void RegisterModel(G4VTrajectoryModel *model)
void RegisterMessenger(G4UImessenger *messenger)
void SetCurrentViewer(G4VViewer *)
void SetUserAction(G4VUserVisAction *pVisAction, const G4VisExtent &=G4VisExtent())
void RegisterModelFactory(G4TrajDrawModelFactory *factory)
G4bool FilterHit(const G4VHit &)
G4VViewer * GetCurrentViewer() const
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
void PrintAvailableGraphicsSystems(Verbosity) const
virtual void RegisterModelFactories()
G4VSceneHandler * GetCurrentSceneHandler() const
static Verbosity GetVerbosity()
void RegisterMessengers()
void ResetTransientsDrawnFlags()
G4bool FilterTrajectory(const G4VTrajectory &)
void SetVerboseLevel(G4int)
void IgnoreStateChanges(G4bool)
friend class G4VisStateDependent
G4VisManager(const G4String &verbosityString="warnings")
static Verbosity GetVerbosityValue(const G4String &)
static G4VisManager * GetInstance()
void GeometryHasChanged()
const G4GraphicsSystemList & GetAvailableGraphicsSystems()
void RegisterEndOfRunUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent())
void BeginDraw(const G4Transform3D &objectTransformation=G4Transform3D())
void CreateViewer(const G4String &name="", const G4String &XGeometry="")
void DispatchToModel(const G4VTrajectory &)
G4VViewer * GetViewer(const G4String &viewerName) const
const List * ListManager() const
const Model * Current() const
void SetCurrent(const G4String &)
const std::vector< Factory * > & FactoryList() const
G4String Placement() const
const char * name(G4int ptype)
G4bool IsMultithreadedApplication()