81 #ifdef G4MULTITHREADED
89 #ifdef G4VIS_USE_STD11
101 fInitialised (false),
102 fpGraphicsSystem (0),
106 fpStateDependent (0),
107 fEventRefreshing (false),
108 fTransientsDrawnThisRun (false),
109 fTransientsDrawnThisEvent (false),
110 fNoOfEventsDrawnThisRun (0),
112 fEventKeepingSuspended (false),
113 fKeptLastEvent (false),
114 fpRequestedEvent (0),
115 fAbortReviewKeptEvents (false),
116 fIsDrawGroup (false),
117 fDrawGroupNestingDepth (0),
118 fIgnoreStateChanges (false)
119 #ifdef G4MULTITHREADED
120 , fMaxEventQueueSize (100)
121 , fWaitOnEventQueueFull (true)
131 (
"Simple graded message scheme - digit or string (1st character defines):");
133 (
" 0) quiet, // Nothing is printed.");
135 (
" 1) startup, // Startup and endup messages are printed...");
137 (
" 2) errors, // ...and errors...");
139 (
" 3) warnings, // ...and warnings...");
141 (
" 4) confirmations, // ...and confirming messages...");
143 (
" 5) parameters, // ...and parameters of scenes and views...");
145 (
" 6) all // ...and everything available.");
149 (
"G4VisManager::G4VisManager",
151 "Attempt to Construct more than one VisManager");
163 <<
"Visualization Manager instantiating with verbosity \""
196 directory -> SetGuidance (
"Visualization commands.");
197 fDirectoryList.push_back (directory);
211 for (i = 0; i < fSceneList.size (); ++i) {
212 delete fSceneList[i];
214 for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
215 if (fAvailableSceneHandlers[i] != NULL) {
216 delete fAvailableSceneHandlers[i];
219 for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
220 if (fAvailableGraphicsSystems[i]) {
221 delete fAvailableGraphicsSystems[i];
226 G4cout <<
"Visualization Manager deleting..." <<
G4endl;
228 for (i = 0; i < fMessengerList.size (); ++i) {
229 delete fMessengerList[i];
231 for (i = 0; i < fDirectoryList.size (); ++i) {
232 delete fDirectoryList[i];
235 delete fpDigiFilterMgr;
236 delete fpHitFilterMgr;
237 delete fpTrajFilterMgr;
238 delete fpTrajDrawModelMgr;
244 (
"G4VisManager::GetInstance",
252 if (fInitialised && fVerbosity >=
warnings) {
253 G4cout <<
"WARNING: G4VisManager::Initialise: already initialised."
259 G4cout <<
"Visualization Manager initialising..." <<
G4endl;
264 "\nYou have instantiated your own Visualization Manager, inheriting"
265 "\n G4VisManager and implementing RegisterGraphicsSystems(), in which"
266 "\n you should, normally, instantiate drivers which do not need"
267 "\n external packages or libraries, and, optionally, drivers under"
268 "\n control of environment variables."
269 "\n Also you should implement RegisterModelFactories()."
270 "\n See visualization/management/include/G4VisExecutive.hh/icc, for example."
271 "\n In your main() you will have something like:"
272 "\n #ifdef G4VIS_USE"
273 "\n G4VisManager* visManager = new G4VisExecutive;"
274 "\n visManager -> SetVerboseLevel (Verbose);"
275 "\n visManager -> Initialize ();"
277 "\n (Don't forget to delete visManager;)"
290 "\nYou have successfully registered the following graphics systems."
300 directory -> SetGuidance (
"Modeling commands.");
301 fDirectoryList.push_back (directory);
302 directory =
new G4UIdirectory (
"/vis/modeling/trajectories/");
303 directory -> SetGuidance (
"Trajectory model commands.");
304 fDirectoryList.push_back (directory);
305 directory =
new G4UIdirectory (
"/vis/modeling/trajectories/create/");
306 directory -> SetGuidance (
"Create trajectory models and messengers.");
307 fDirectoryList.push_back (directory);
311 directory -> SetGuidance (
"Filtering commands.");
312 fDirectoryList.push_back (directory);
313 directory =
new G4UIdirectory (
"/vis/filtering/trajectories/");
314 directory -> SetGuidance (
"Trajectory filtering commands.");
315 fDirectoryList.push_back (directory);
316 directory =
new G4UIdirectory (
"/vis/filtering/trajectories/create/");
317 directory -> SetGuidance (
"Create trajectory filters and messengers.");
318 fDirectoryList.push_back (directory);
320 directory -> SetGuidance (
"Hit filtering commands.");
321 fDirectoryList.push_back (directory);
322 directory =
new G4UIdirectory (
"/vis/filtering/hits/create/");
323 directory -> SetGuidance (
"Create hit filters and messengers.");
324 fDirectoryList.push_back (directory);
326 directory -> SetGuidance (
"Digi filtering commands.");
327 fDirectoryList.push_back (directory);
328 directory =
new G4UIdirectory (
"/vis/filtering/digi/create/");
329 directory -> SetGuidance (
"Create digi filters and messengers.");
330 fDirectoryList.push_back (directory);
342 "\nYou have successfully registered the following model factories."
344 PrintAvailableModels (fVerbosity);
349 PrintAvailableUserVisActions (fVerbosity);
354 PrintAvailableColours (fVerbosity);
387 directory -> SetGuidance(
"Operations on vis attributes of Geant4 geometry.");
388 fDirectoryList.push_back (directory);
393 directory -> SetGuidance(
"Set vis attributes of Geant4 geometry.");
394 fDirectoryList.push_back (directory);
405 #ifdef G4MULTITHREADED
407 directory -> SetGuidance(
"Commands unique to multithreading mode.");
408 fDirectoryList.push_back (directory);
414 directory -> SetGuidance
415 (
"Set quantities for use in future commands where appropriate.");
416 fDirectoryList.push_back (directory);
425 directory -> SetGuidance (
"Operations on Geant4 scenes.");
426 fDirectoryList.push_back (directory);
436 directory -> SetGuidance (
"Add model to current scene.");
437 fDirectoryList.push_back (directory);
462 directory -> SetGuidance (
"Operations on Geant4 scene handlers.");
463 fDirectoryList.push_back (directory);
470 directory -> SetGuidance (
"Operations on touchables.");
471 fDirectoryList.push_back (directory);
475 directory -> SetGuidance (
"Set vis attributes of current touchable.");
476 fDirectoryList.push_back (directory);
480 directory -> SetGuidance (
"Operations on Geant4 viewers.");
481 fDirectoryList.push_back (directory);
506 directory -> SetGuidance(
"Set default values for future viewers.");
507 fDirectoryList.push_back (directory);
512 directory -> SetGuidance (
"Set view parameters of current viewer.");
513 fDirectoryList.push_back (directory);
518 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->
Placement()));
520 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->
Placement()));
524 (fpTrajFilterMgr, fpTrajFilterMgr->
Placement()));
526 (fpTrajFilterMgr, fpTrajFilterMgr->
Placement()));
530 (fpHitFilterMgr, fpHitFilterMgr->
Placement()));
532 (fpHitFilterMgr, fpHitFilterMgr->
Placement()));
536 (fpDigiFilterMgr, fpDigiFilterMgr->
Placement()));
538 (fpDigiFilterMgr, fpDigiFilterMgr->
Placement()));
542 if (IsValidView ()) {
545 G4cout <<
"G4VisManager::Enable: visualization enabled." <<
G4endl;
551 "There are " << nKeptEvents <<
" kept events."
552 "\n \"/vis/reviewKeptEvents\" to review them one by one."
553 "\n \"/vis/viewer/flush\" or \"/vis/viewer/rebuild\" to see them accumulated."
560 "G4VisManager::Enable: WARNING: visualization remains disabled for"
561 "\n above reasons. Rectifying with valid vis commands will"
562 "\n automatically enable."
572 "G4VisManager::Disable: visualization disabled."
573 "\n The pointer returned by GetConcreteInstance will be zero."
574 "\n Note that it will become enabled after some valid vis commands."
578 G4int currentTrajectoryType =
580 if (currentTrajectoryType > 0) {
582 "You may wish to disable trajectory production too:"
583 "\n \"/tracking/storeTrajectory 0\""
584 "\nbut don't forget to re-enable with"
586 "\n \"/tracking/storeTrajectory " << currentTrajectoryType <<
"\" (for your case)."
593 G4int nSystems = fAvailableGraphicsSystems.size ();
596 G4cout <<
"G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
597 "\n graphics system available!"
598 "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
599 "\n when you compiled/built the visualization code?"
600 "\n 2) Did you instantiate your own Visualization Manager and forget"
601 "\n to implement RegisterGraphicsSystems correctly?"
602 "\n 3) You can register your own graphics system, e.g.,"
603 "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
604 "\n after instantiating your vis manager and before"
605 "\n visManager->Initialize()."
609 return fAvailableGraphicsSystems;
615 fAvailableGraphicsSystems.push_back (pSystem);
617 G4cout <<
"G4VisManager::RegisterGraphicsSystem: "
618 << pSystem -> GetName ();
619 if (pSystem -> GetNickname () !=
"") {
620 G4cout <<
" (" << pSystem -> GetNickname () <<
")";
626 if (fVerbosity >=
errors) {
627 G4cout <<
"G4VisManager::RegisterGraphicsSystem: null pointer!"
638 assert (0 != fpTrajDrawModelMgr);
647 G4cout<<
"G4VisManager: Using G4TrajectoryDrawByCharge as fallback trajectory model."<<
G4endl;
648 G4cout<<
"See commands in /vis/modeling/trajectories/ for other options."<<
G4endl;
652 model = fpTrajDrawModelMgr->
Current();
660 fpTrajDrawModelMgr->
Register(model);
666 fpTrajDrawModelMgr->
Register(factory);
709 #ifdef G4MULTITHREADED
712 fDrawGroupNestingDepth++;
713 if (fDrawGroupNestingDepth > 1) {
715 (
"G4VisManager::BeginDraw",
717 "Nesting detected. It is illegal to nest Begin/EndDraw."
721 if (IsValidView ()) {
722 ClearTransientStoreIfMarked();
723 fpSceneHandler -> BeginPrimitives (objectTransform);
730 #ifdef G4MULTITHREADED
733 fDrawGroupNestingDepth--;
734 if (fDrawGroupNestingDepth != 0) {
735 if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
738 if (IsValidView ()) {
739 fpSceneHandler -> EndPrimitives ();
741 fIsDrawGroup =
false;
746 #ifdef G4MULTITHREADED
749 fDrawGroupNestingDepth++;
750 if (fDrawGroupNestingDepth > 1) {
752 (
"G4VisManager::BeginDraw2D",
754 "Nesting detected. It is illegal to nest Begin/EndDraw2D."
758 if (IsValidView ()) {
759 ClearTransientStoreIfMarked();
760 fpSceneHandler -> BeginPrimitives2D (objectTransform);
767 #ifdef G4MULTITHREADED
770 fDrawGroupNestingDepth--;
771 if (fDrawGroupNestingDepth != 0) {
772 if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
775 if (IsValidView ()) {
776 fpSceneHandler -> EndPrimitives2D ();
778 fIsDrawGroup =
false;
781 template <
class T>
void G4VisManager::DrawT
782 (
const T& graphics_primitive,
const G4Transform3D& objectTransform) {
783 #ifdef G4MULTITHREADED
789 (
"G4VSceneHandler::DrawT",
791 "Different transform detected in Begin/EndDraw group.");
793 fpSceneHandler -> AddPrimitive (graphics_primitive);
795 if (IsValidView ()) {
796 ClearTransientStoreIfMarked();
797 fpSceneHandler -> BeginPrimitives (objectTransform);
798 fpSceneHandler -> AddPrimitive (graphics_primitive);
799 fpSceneHandler -> EndPrimitives ();
804 template <
class T>
void G4VisManager::DrawT2D
805 (
const T& graphics_primitive,
const G4Transform3D& objectTransform) {
806 #ifdef G4MULTITHREADED
812 (
"G4VSceneHandler::DrawT",
814 "Different transform detected in Begin/EndDraw2D group.");
816 fpSceneHandler -> AddPrimitive (graphics_primitive);
818 if (IsValidView ()) {
819 ClearTransientStoreIfMarked();
820 fpSceneHandler -> BeginPrimitives2D (objectTransform);
821 fpSceneHandler -> AddPrimitive (graphics_primitive);
822 fpSceneHandler -> EndPrimitives2D ();
830 DrawT (circle, objectTransform);
836 DrawT (polyhedron, objectTransform);
842 DrawT (line, objectTransform);
848 DrawT (polymarker, objectTransform);
854 DrawT (scale, objectTransform);
860 DrawT (square, objectTransform);
866 DrawT (text, objectTransform);
872 DrawT2D (circle, objectTransform);
878 DrawT2D (polyhedron, objectTransform);
884 DrawT2D (line, objectTransform);
890 DrawT2D (polymarker, objectTransform);
896 DrawT2D (square, objectTransform);
902 DrawT2D (text, objectTransform);
906 #ifdef G4MULTITHREADED
910 fpSceneHandler -> AddCompound (hit);
912 if (IsValidView ()) {
913 ClearTransientStoreIfMarked();
914 fpSceneHandler -> AddCompound (hit);
920 #ifdef G4MULTITHREADED
924 fpSceneHandler -> AddCompound (digi);
926 if (IsValidView ()) {
927 ClearTransientStoreIfMarked();
928 fpSceneHandler -> AddCompound (digi);
934 #ifdef G4MULTITHREADED
941 #ifdef G4MULTITHREADED
956 fpSceneHandler -> SetModel (&trajectoriesModel);
957 fpSceneHandler -> AddCompound (traj);
958 fpSceneHandler -> SetModel (0);
960 if (IsValidView ()) {
961 ClearTransientStoreIfMarked();
962 fpSceneHandler -> SetModel (&trajectoriesModel);
963 fpSceneHandler -> AddCompound (traj);
964 fpSceneHandler -> SetModel (0);
972 #ifdef G4MULTITHREADED
977 Draw (*pSol, attribs, objectTransform);
983 #ifdef G4MULTITHREADED
987 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
989 fpSceneHandler -> PostAddSolid ();
991 if (IsValidView ()) {
992 ClearTransientStoreIfMarked();
993 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
995 fpSceneHandler -> PostAddSolid ();
1003 #ifdef G4MULTITHREADED
1019 G4VSolid* pSol = pLV -> GetSolid ();
1020 Draw (*pSol, attribs, objectTransform);
1025 if (fpGraphicsSystem) {
1028 if (pSceneHandler) {
1029 fAvailableSceneHandlers.push_back (pSceneHandler);
1030 fpSceneHandler = pSceneHandler;
1033 if (fVerbosity >=
errors) {
1034 G4cout <<
"ERROR in G4VisManager::CreateSceneHandler during "
1035 << fpGraphicsSystem -> GetName ()
1036 <<
" scene handler creation.\n No action taken."
1041 else PrintInvalidPointers ();
1048 if (!fInitialised) Initialise ();
1050 if (!fpSceneHandler) {
1051 PrintInvalidPointers ();
1055 G4VViewer*
p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
1058 if (fVerbosity >= errors) {
1059 G4cerr <<
"ERROR in G4VisManager::CreateViewer during "
1060 << fpGraphicsSystem -> GetName ()
1061 <<
" viewer creation.\n No action taken."
1067 if (p -> GetViewId() < 0) {
1068 if (fVerbosity >= errors) {
1069 G4cerr <<
"ERROR in G4VisManager::CreateViewer during "
1070 << fpGraphicsSystem -> GetName ()
1071 <<
" viewer initialisation.\n No action taken."
1082 p -> SetViewParameters(initialvp);
1086 fpSceneHandler -> AddViewerToList (fpViewer);
1087 fpSceneHandler -> SetCurrentViewer (fpViewer);
1088 if (fVerbosity >= confirmations) {
1089 G4cout <<
"G4VisManager::CreateViewer: new viewer created."
1094 if (fVerbosity >= parameters) {
1099 static G4bool warned =
false;
1100 if (fVerbosity >= confirmations) {
1103 "NOTE: objects with visibility flag set to \"false\""
1104 " will not be drawn!"
1105 "\n \"/vis/viewer/set/culling global false\" to Draw such objects."
1106 "\n Also see other \"/vis/viewer/set\" commands."
1113 static G4bool warned =
false;
1114 if (fVerbosity >= warnings) {
1117 "WARNING: covered objects in solid mode will not be rendered!"
1118 "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
1119 "\n Also see other \"/vis/viewer/set\" commands."
1129 G4cout <<
"G4VisManager::GeometryHasChanged() called." <<
G4endl;
1135 -> GetNavigatorForTracking () -> GetWorldVolume ();
1138 G4cout <<
"WARNING: There is no world volume!" <<
G4endl;
1144 G4int iScene, nScenes = sceneList.size ();
1145 for (iScene = 0; iScene < nScenes; iScene++) {
1146 G4Scene* pScene = sceneList [iScene];
1147 std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1148 if (modelList.size ()) {
1151 modelInvalid =
false;
1152 std::vector<G4Scene::Model>::iterator iterModel;
1153 for (iterModel = modelList.begin();
1154 iterModel != modelList.end();
1156 modelInvalid = !(iterModel->fpModel->Validate(fVerbosity>=
warnings));
1160 G4cout <<
"WARNING: Model \""
1161 << iterModel->fpModel->GetGlobalDescription ()
1163 "\" is no longer valid - being removed\n from scene \""
1164 << pScene -> GetName () <<
"\""
1167 modelList.erase (iterModel);
1171 }
while (modelInvalid);
1173 if (modelList.size () == 0) {
1175 G4cout <<
"WARNING: No models left in this scene \""
1176 << pScene -> GetName ()
1184 ApplyCommand (
G4String(
"/vis/scene/notifyHandlers " + pScene->
GetName()));
1190 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1192 G4cout <<
"WARNING: The current scene \""
1193 << fpScene -> GetName ()
1194 <<
"\" has no models."
1203 G4cout <<
"G4VisManager::NotifyHandler() called." <<
G4endl;
1208 G4int iScene, nScenes = sceneList.size ();
1209 for (iScene = 0; iScene < nScenes; iScene++) {
1210 G4Scene* pScene = sceneList [iScene];
1211 std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1213 if (modelList.size ()) {
1216 ApplyCommand (
G4String(
"/vis/scene/notifyHandlers " + pScene->
GetName()));
1221 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1223 G4cout <<
"WARNING: The current scene \""
1224 << fpScene -> GetName ()
1225 <<
"\" has no models."
1233 return fpTrajFilterMgr->
Accept(trajectory);
1238 return fpHitFilterMgr->
Accept(hit);
1243 return fpDigiFilterMgr->
Accept(digi);
1261 assert (0 != fpTrajDrawModelMgr);
1265 assert (0 != trajectoryModel);
1267 if (IsValidView()) {
1268 trajectoryModel->
Draw(trajectory, visible);
1276 fRunDurationUserVisActions.push_back(
UserVisAction(name,pVisAction));
1278 fUserVisActionExtents[pVisAction] = extent;
1280 if (fVerbosity >= warnings) {
1282 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1292 fEndOfEventUserVisActions.push_back(
UserVisAction(name,pVisAction));
1294 fUserVisActionExtents[pVisAction] = extent;
1296 if (fVerbosity >= warnings) {
1298 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1308 fEndOfRunUserVisActions.push_back(
UserVisAction(name,pVisAction));
1310 fUserVisActionExtents[pVisAction] = extent;
1312 if (fVerbosity >= warnings) {
1314 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1321 if (pScene != fpScene) {
1330 fpGraphicsSystem = pSystem;
1332 G4cout <<
"G4VisManager::SetCurrentGraphicsSystem: system now "
1333 << pSystem -> GetName () <<
G4endl;
1338 if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
1340 G4int nSH = sceneHandlerList.size ();
1342 for (iSH = nSH - 1; iSH >= 0; iSH--) {
1343 if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem)
break;
1346 fpSceneHandler = sceneHandlerList [iSH];
1348 G4cout <<
" Scene Handler now "
1349 << fpSceneHandler -> GetName () <<
G4endl;
1351 if (fpScene != fpSceneHandler -> GetScene ()) {
1352 fpScene = fpSceneHandler -> GetScene ();
1354 G4cout <<
" Scene now \""
1355 << fpScene -> GetName () <<
"\"" <<
G4endl;
1358 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1359 if (viewerList.size ()) {
1360 fpViewer = viewerList [0];
1362 G4cout <<
" Viewer now " << fpViewer -> GetName () <<
G4endl;
1377 fpSceneHandler = pSceneHandler;
1379 G4cout <<
"G4VisManager::SetCurrentSceneHandler: scene handler now \""
1380 << pSceneHandler -> GetName () <<
"\"" <<
G4endl;
1382 if (fpScene != fpSceneHandler -> GetScene ()) {
1383 fpScene = fpSceneHandler -> GetScene ();
1385 G4cout <<
" Scene now \""
1386 << fpScene -> GetName () <<
"\"" <<
G4endl;
1389 if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
1390 fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
1392 G4cout <<
" Graphics system now \""
1393 << fpGraphicsSystem -> GetName () <<
"\"" <<
G4endl;
1396 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1397 G4int nViewers = viewerList.size ();
1400 for (iViewer = 0; iViewer < nViewers; iViewer++) {
1401 if (fpViewer == viewerList [iViewer])
break;
1403 if (iViewer >= nViewers) {
1404 fpViewer = viewerList [0];
1406 G4cout <<
" Viewer now \"" << fpViewer -> GetName () <<
"\""
1410 if (!IsValidView ()) {
1413 "WARNING: Problem setting scene handler - please report circumstances."
1422 "WARNING: No viewers for this scene handler - please create one."
1431 G4cout <<
"G4VisManager::SetCurrentViewer: viewer now "
1432 << pViewer -> GetName ()
1435 fpSceneHandler = fpViewer -> GetSceneHandler ();
1436 if (!fpSceneHandler) {
1439 "WARNING: No scene handler for this viewer - please create one."
1446 fpScene = fpSceneHandler -> GetScene ();
1447 fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1448 if (!IsValidView ()) {
1451 "WARNING: Problem setting viewer - please report circumstances."
1459 G4cout <<
"Current available graphics systems are:\n";
1460 if (fAvailableGraphicsSystems.size ()) {
1461 for (
const auto& gs: fAvailableGraphicsSystems) {
1462 const G4String& name = gs->GetName();
1463 const std::vector<G4String>& nicknames = gs->GetNicknames();
1467 for (
size_t i = 0; i < nicknames.size(); ++i) {
1481 G4cout <<
"\n NONE!!! None registered - yet! Mmmmm!" <<
G4endl;
1485 void G4VisManager::PrintAvailableModels (
Verbosity verbosity)
const
1490 const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1492 if (factoryList.empty())
G4cout <<
" None" << G4endl;
1494 std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1495 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1500 const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1502 if (!modelMap.empty()) {
1504 std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1505 for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1506 G4cout <<
" " << i->second->Name();
1507 if (i->second == listManager->
Current())
G4cout <<
" (Current)";
1519 const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1521 if (factoryList.empty())
G4cout <<
" None" << G4endl;
1523 std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1524 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1527 const std::vector<G4VFilter<G4VTrajectory>*>&
1529 if (!filterList.empty()) {
1531 std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1532 for (i = filterList.begin(); i != filterList.end(); ++i) {
1540 void G4VisManager::PrintAvailableUserVisActions (
Verbosity)
const
1543 "You have successfully registered the following user vis actions."
1545 G4cout <<
"Run Duration User Vis Actions:";
1546 if (fRunDurationUserVisActions.empty())
G4cout <<
" none" << G4endl;
1549 for (
size_t i = 0; i < fRunDurationUserVisActions.size(); i++) {
1550 const G4String& name = fRunDurationUserVisActions[i].fName;
1555 G4cout <<
"End of Event User Vis Actions:";
1556 if (fEndOfEventUserVisActions.empty())
G4cout <<
" none" << G4endl;
1559 for (
size_t i = 0; i < fEndOfEventUserVisActions.size(); i++) {
1560 const G4String& name = fEndOfEventUserVisActions[i].fName;
1565 G4cout <<
"End of Run User Vis Actions:";
1566 if (fEndOfRunUserVisActions.empty())
G4cout <<
" none" << G4endl;
1569 for (
size_t i = 0; i < fEndOfRunUserVisActions.size(); i++) {
1570 const G4String& name = fEndOfRunUserVisActions[i].fName;
1576 void G4VisManager::PrintAvailableColours (
Verbosity)
const {
1578 "Some /vis commands (optionally) take a string to specify colour."
1579 "\nAvailable colours:\n ";
1581 for (std::map<G4String, G4Colour>::const_iterator i = map.begin();
1584 if (++i != map.end())
G4cout <<
", ";
1589 void G4VisManager::PrintInvalidPointers ()
const {
1590 if (fVerbosity >=
errors) {
1591 G4cerr <<
"ERROR: G4VisManager::PrintInvalidPointers:";
1592 if (!fpGraphicsSystem) {
1593 G4cerr <<
"\n null graphics system pointer.";
1596 G4cerr <<
"\n Graphics system is " << fpGraphicsSystem -> GetName ()
1600 "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1601 " \"/vis/scene/create\".";
1602 if (!fpSceneHandler)
1604 "\n Null scene handler pointer. Use \"/vis/open\" or"
1605 " \"/vis/sceneHandler/create\".";
1608 "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1614 #ifdef G4MULTITHREADED
1617 G4bool mtRunInProgress =
false;
1618 std::deque<const G4Event*> mtVisEventQueue;
1627 if (!pSceneHandler)
return 0;
1629 if (!pScene)
return 0;
1631 if (!pViewer)
return 0;
1646 pViewer->SwitchToVisSubThread();
1651 G4int eventQueueSize = mtVisEventQueue.size();
1655 while (eventQueueSize) {
1658 const G4Event*
event = mtVisEventQueue.front();
1677 pVisManager->ClearTransientStoreIfMarked();
1681 ++pVisManager->fNoOfEventsDrawnThisRun;
1698 mtVisEventQueue.pop_front();
1699 event->PostProcessingFinished();
1700 eventQueueSize = mtVisEventQueue.size();
1706 G4int runInProgress = mtRunInProgress;
1708 if (!runInProgress) {
1715 #ifdef G4VIS_USE_STD11
1716 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1723 pViewer->DoneWithVisSubThread();
1724 pViewer->MovingToMasterThread();
1738 void G4VisManager::BeginOfRun ()
1740 if (fIgnoreStateChanges)
return;
1744 #ifdef G4MULTITHREADED
1751 #ifdef G4MULTITHREADED
1759 if (nEventsToBeProcessed == 0)
return;
1762 fKeptLastEvent =
false;
1763 fEventKeepingSuspended =
false;
1764 fTransientsDrawnThisRun =
false;
1766 fNoOfEventsDrawnThisRun = 0;
1768 #ifdef G4MULTITHREADED
1777 if (fpViewer) fpViewer->DoneWithMasterThread();
1782 mtRunInProgress =
true;
1793 if (fpViewer) fpViewer->MovingToVisSubThread();
1798 void G4VisManager::BeginOfEvent ()
1800 if (fIgnoreStateChanges)
return;
1808 #ifndef G4MULTITHREADED
1810 fTransientsDrawnThisEvent =
false;
1815 void G4VisManager::EndOfEvent ()
1817 if (fIgnoreStateChanges)
return;
1824 G4bool valid = fpSceneHandler && IsValidView();
1830 #ifdef G4MULTITHREADED
1837 #ifdef G4MULTITHREADED
1844 if (!currentRun)
return;
1849 if (!currentEvent)
return;
1853 #ifdef G4MULTITHREADED
1857 G4int eventQueueSize = mtVisEventQueue.size();
1861 G4bool eventQueueFull =
false;
1862 while (fMaxEventQueueSize > 0 && eventQueueSize >= fMaxEventQueueSize) {
1865 if (fWaitOnEventQueueFull) {
1866 static G4bool warned =
false;
1869 "WARNING: The number of events in the visualisation queue has exceeded"
1871 << fMaxEventQueueSize <<
1872 ".\n If, during a multithreaded run, the simulation gets ahead of the"
1873 "\n visualisation by more than this maximum, the simulation is delayed"
1874 "\n until the vis sub-thread has drawn a few more events and removed them"
1875 "\n from the queue. You may change this maximum number of events with"
1876 "\n \"/vis/multithreading/maxEventQueueSize <N>\", where N is the maximum"
1877 "\n number you wish to allow. N <= 0 means \"unlimited\"."
1878 "\n Alternatively you may choose to discard events for drawing by setting"
1879 "\n \"/vis/multithreading/actionOnEventQueueFull discard\"."
1880 "\n To avoid visualisation altogether: \"/vis/disable\"."
1881 "\n And maybe \"/tracking/storeTrajectories 0\"."
1887 #ifdef G4VIS_USE_STD11
1888 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1894 static G4bool warned =
false;
1897 "WARNING: The number of events in the visualisation queue has exceeded"
1899 << fMaxEventQueueSize <<
1900 ".\n Some events have been discarded for drawing. You may change this"
1901 "\n behaviour with \"/vis/multithreading/actionOnEventQueueFull wait\"."
1902 "\n To avoid visualisation altogether: \"/vis/disable\"."
1903 "\n And maybe \"/tracking/storeTrajectories 0\"."
1907 eventQueueFull =
true;
1912 eventQueueSize = mtVisEventQueue.size();
1916 if (!eventQueueFull) {
1920 mtVisEventQueue.push_back(currentEvent);
1935 G4int nEventsToBeProcessed = 0;
1936 G4int nKeptEvents = 0;
1941 const std::vector<const G4Event*>* events = currentRun->
GetEventVector();
1942 if (events) nKeptEvents = events->size();
1953 ClearTransientStoreIfMarked();
1956 fpSceneHandler->
DrawEvent(currentEvent);
1957 ++fNoOfEventsDrawnThisRun;
1962 if (eventID < nEventsToBeProcessed - 1) {
1969 if (nKeptEvents == 0) {
1972 fKeptLastEvent =
true;
1988 if (maxNumberOfKeptEvents > 0 &&
1989 fNKeepRequests >= maxNumberOfKeptEvents) {
1991 fEventKeepingSuspended =
true;
1992 static G4bool warned =
false;
1996 "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
1997 "\n The number of events exceeds the maximum, "
1998 << maxNumberOfKeptEvents <<
1999 ", that may be kept by\n the vis manager."
2005 }
else if (maxNumberOfKeptEvents != 0) {
2020 void G4VisManager::EndOfRun ()
2022 if (fIgnoreStateChanges)
return;
2026 #ifdef G4MULTITHREADED
2034 #ifdef G4MULTITHREADED
2042 if (nEventsToBeProcessed == 0)
return;
2045 if (!currentRun)
return;
2047 #ifdef G4MULTITHREADED
2052 mtRunInProgress =
false;
2056 delete mtVisSubThread;
2057 if (fpViewer) fpViewer->SwitchToMasterThread();
2061 #ifdef G4MULTITHREADED
2066 if (fpSceneHandler && IsValidView()) {
2068 if (fNoOfEventsDrawnThisRun != noOfEventsRequested) {
2069 if (!fWaitOnEventQueueFull && fVerbosity >=
warnings) {
2071 <<
"WARNING: Number of events drawn this run, "
2072 << fNoOfEventsDrawnThisRun <<
", is different to number requested, "
2073 << noOfEventsRequested <<
2074 ".\n (This is because you requested \"/vis/multithreading/actionOnEventQueueFull discard\".)"
2081 G4int nKeptEvents = 0;
2082 const std::vector<const G4Event*>* events = currentRun->
GetEventVector();
2083 if (events) nKeptEvents = events->size();
2084 if (nKeptEvents && !fKeptLastEvent) {
2086 G4cout <<
"WARNING: " << nKeptEvents;
2087 if (nKeptEvents == 1)
G4cout <<
" event has";
2088 else G4cout <<
" events have";
2089 G4cout <<
" been kept for refreshing and/or reviewing." <<
G4endl;
2090 if (nKeptEvents != fNKeepRequests) {
2092 if (fNKeepRequests == 0) {
2093 G4cout <<
"No keep requests were";
2094 }
else if (fNKeepRequests == 1) {
2095 G4cout <<
"Only 1 keep request was";
2097 G4cout <<
"Only " << fNKeepRequests <<
" keep requests were";
2102 "\n \"/vis/reviewKeptEvents\" to review them one by one."
2103 "\n \"/vis/viewer/flush\" or \"/vis/viewer/rebuild\" to see them accumulated."
2124 if (fEventKeepingSuspended && fVerbosity >=
warnings) {
2126 "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
2127 "\n The number of events in the run exceeded the maximum, "
2129 ", that may be\n kept by the vis manager." <<
2130 "\n The number of events kept by the vis manager can be changed with"
2131 "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
2132 "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
2139 G4bool valid = fpSceneHandler && IsValidView();
2163 G4cout <<
"\"/vis/viewer/update\" to close file." <<
G4endl;
2169 fEventRefreshing =
false;
2172 void G4VisManager::ClearTransientStoreIfMarked(){
2188 fTransientsDrawnThisRun =
false;
2189 fTransientsDrawnThisEvent =
false;
2191 for (i = fAvailableSceneHandlers.begin();
2192 i != fAvailableSceneHandlers.end(); ++i) {
2193 (*i)->SetTransientsDrawnThisEvent(
false);
2194 (*i)->SetTransientsDrawnThisRun(
false);
2199 G4String viewerShortName (viewerName);
2200 viewerShortName = viewerShortName (0, viewerShortName.find (
' '));
2201 return viewerShortName.
strip ();
2206 size_t nHandlers = fAvailableSceneHandlers.size ();
2207 size_t iHandler, iViewer;
2210 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
2212 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
2213 for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
2214 viewer = viewerList [iViewer];
2215 if (viewerShortName == viewer -> GetShortName ()) {
2222 if (found)
return viewer;
2230 switch (verbosity) {
2231 case quiet: rs =
"quiet (0)";
break;
2232 case startup: rs =
"startup (1)";
break;
2233 case errors: rs =
"errors (2)";
break;
2234 case warnings: rs =
"warnings (3)";
break;
2236 case parameters: rs =
"parameters (5)";
break;
2237 case all: rs =
"all (6)";
break;
2246 if (ss(0) ==
'q') verbosity =
quiet;
2247 else if (ss(0) ==
's') verbosity =
startup;
2248 else if (ss(0) ==
'e') verbosity =
errors;
2249 else if (ss(0) ==
'w') verbosity =
warnings;
2251 else if (ss(0) ==
'p') verbosity =
parameters;
2252 else if (ss(0) ==
'a') verbosity =
all;
2255 std::istringstream is(ss);
2258 G4cerr <<
"ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
2259 << verbosityString <<
"\"";
2277 else if (intVerbosity >
all) verbosity =
all;
2278 else verbosity =
Verbosity(intVerbosity);
2294 G4bool G4VisManager::IsValidView () {
2298 static G4bool noGSPrinting =
true;
2299 if (!fpGraphicsSystem) {
2303 noGSPrinting =
false;
2306 "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
2307 "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
2308 "\n Alternatively, to avoid this message, suppress instantiation of vis"
2309 "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
2310 "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()"
2318 if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
2319 if (fVerbosity >=
errors) {
2321 "ERROR: G4VisManager::IsValidView(): Current view is not valid."
2323 PrintInvalidPointers ();
2328 if (fpScene != fpSceneHandler -> GetScene ()) {
2329 if (fVerbosity >=
errors) {
2330 G4cerr <<
"ERROR: G4VisManager::IsValidView ():";
2331 if (fpSceneHandler -> GetScene ()) {
2333 "\n The current scene \""
2334 << fpScene -> GetName ()
2335 <<
"\" is not handled by"
2336 "\n the current scene handler \""
2337 << fpSceneHandler -> GetName ()
2339 "\n (it currently handles scene \""
2340 << fpSceneHandler -> GetScene () -> GetName ()
2343 "\n (a) attach it to the scene handler with"
2344 "\n /vis/sceneHandler/attach "
2345 << fpScene -> GetName ()
2347 "\n (b) create a new scene handler with "
2348 "\n /vis/sceneHandler/create <graphics-system>,"
2349 "\n in which case it should pick up the the new scene."
2353 G4cout <<
"\n Scene handler \""
2354 << fpSceneHandler -> GetName ()
2355 <<
"\" has null scene pointer."
2356 "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
2363 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
2364 if (viewerList.size () == 0) {
2365 if (fVerbosity >=
errors) {
2367 "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
2368 << fpSceneHandler -> GetName ()
2369 <<
"\" has no viewers. Do /vis/viewer/create."
2376 if (fpScene -> IsEmpty ()) {
2378 G4bool successful = fpScene -> AddWorldIfEmpty (warn);
2379 if (!successful || fpScene -> IsEmpty ()) {
2380 if (fVerbosity >=
errors) {
2381 G4cerr <<
"ERROR: G4VisManager::IsValidView ():";
2383 "\n Attempt at some drawing operation when scene is empty."
2384 "\n Maybe the geometry has not yet been defined."
2385 " Try /run/initialize."
2386 "\n Or use \"/vis/scene/add/extent\"."
2395 "WARNING: G4VisManager: the scene was empty, \"world\" has been"
2396 "\n added and the scene handlers notified.";
2408 G4cout<<
"G4VisManager: No model factories registered with G4VisManager."<<
G4endl;
2409 G4cout<<
"G4VisManager::RegisterModelFactories() should be overridden in derived"<<
G4endl;
2410 G4cout<<
"class. See G4VisExecutive for an example."<<
G4endl;
2414 #ifdef G4MULTITHREADED
2415 void G4VisManager::SetUpForAThread()
2423 fIgnoreStateChanges = val;
G4bool FilterDigi(const G4VDigi &)
#define G4THREADJOIN(worker)
void RegisterEndOfEventUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void RegisterModelFactory(G4TrajDrawModelFactory *factory)
virtual void RegisterModelFactories()
void SetCurrentSceneHandler(G4VSceneHandler *)
static G4VVisManager * GetConcreteInstance()
void PrintAvailableGraphicsSystems(Verbosity) const
void SetEventID(G4int eventID)
G4String strip(G4int strip_Type=trailing, char c=' ')
G4bool IsCullingInvisible() const
void RegisterEndOfRunUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void SetVerboseLevel(G4int)
G4TrackingManager * GetTrackingManager() const
void SetRunID(G4int runID)
static G4SolidsWorkspacePool * GetInstance()
const G4ViewParameters & GetViewParameters() const
G4Navigator * GetNavigatorForTracking() const
const Model * Current() const
G4VSolid * GetSolid() const
void GeometryHasChanged()
const std::vector< const G4Event * > * GetEventVector() const
void SetCurrentScene(G4Scene *)
G4bool GetMarkForClearingTransientStore() const
G4bool GetRefreshAtEndOfEvent() const
static std::vector< G4String > VerbosityGuidanceStrings
const G4String & GetName() const
static Verbosity GetVerbosityValue(const G4String &)
static G4RunManagerKernel * GetRunManagerKernel()
const G4Run * GetCurrentRun() const
#define G4MUTEX_INITIALIZER
void BeginDraw(const G4Transform3D &objectTransformation=G4Transform3D())
const G4VTrajectoryModel * CurrentTrajDrawModel() const
const std::vector< Filter * > & FilterList() const
static G4UImanager * GetUIpointer()
void RegisterMessengers()
std::vector< G4VSceneHandler * >::const_iterator G4SceneHandlerListConstIterator
const G4Transform3D & GetObjectTransformation() const
G4String Placement() const
void RegisterMessenger(G4UImessenger *messenger)
void SelectTrajectoryModel(const G4String &model)
void SetCurrentTrajectory(const G4VTrajectory *pTraj)
void SetTransientsDrawnThisEvent(G4bool)
#define G4THREADCREATE(worker, func, arg)
static G4RunManagerKernel * GetMasterRunManagerKernel()
G4double GetExtentRadius() const
void IgnoreStateChanges(G4bool)
G4String ViewerShortName(const G4String &viewerName) const
friend class G4VisStateDependent
G4GLOB_DLL std::ostream G4cout
const List * ListManager() const
const std::map< G4String, T * > & Map() const
void SetCurrent(const G4String &)
G4bool FilterTrajectory(const G4VTrajectory &)
virtual void Draw(const G4VTrajectory &trajectory, const G4bool &visible=true) const =0
static G4MTRunManager * GetMasterRunManager()
G4bool GetRefreshAtEndOfRun() const
void ResetTransientsDrawnFlags()
G4bool GetTransientsDrawnThisRun() const
static G4VisManager * GetInstance()
void KeepForPostProcessing() const
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
void SetXGeometryString(const G4String &)
G4int GetNumberOfEventsToBeProcessed() const
const T * Current() const
G4String Placement() const
void DrawEndOfRunModels()
G4bool GetTransientsDrawnThisEvent() const
G4bool IsCullingCovered() const
G4bool IsMultithreadedApplication()
void CreateAndUseWorkspace()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static G4TransportationManager * GetTransportationManager()
void RegisterRunDurationUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void SetCurrentViewer(G4VViewer *)
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const =0
static G4RunManager * GetRunManager()
G4Scene * GetScene() const
void SetTransientsDrawnThisEvent(G4bool)
G4VisManager(const G4String &verbosityString="warnings")
G4bool FilterHit(const G4VHit &)
#define G4THREADSLEEP(tick)
G4LogicalVolume * GetLogicalVolume() const
void DrawEvent(const G4Event *)
G4VViewer * GetViewer(const G4String &viewerName) const
void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())
static G4String VerbosityString(Verbosity)
G4VSceneHandler * GetCurrentSceneHandler() const
void SetWorldVolume(G4VPhysicalVolume *pWorld)
static G4EventManager * GetEventManager()
G4int GetStoreTrajectory() const
FilterMode::Mode GetMode() const
static Verbosity GetVerbosity()
void Draw(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
static void SetVisManager(G4VisManager *)
virtual void RegisterGraphicsSystems()=0
static G4GeometryWorkspacePool * GetInstance()
void RegisterModel(G4VTrajectoryModel *model)
const std::vector< Factory * > & FactoryList() const
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
void CreateAndUseWorkspace()
G4VViewer * GetCurrentViewer() const
void DispatchToModel(const G4VTrajectory &)
static const std::map< G4String, G4Colour > & GetMap()
void CreateViewer(const G4String &name="", const G4String &XGeometry="")
virtual void ClearTransientStore()
void SetTransientsDrawnThisRun(G4bool)
void SetUpForSpecialThread(G4String aPrefix)
const G4Event * GetConstCurrentEvent()
void CreateSceneHandler(const G4String &name="")
Functionality GetFunctionality() const
const G4GraphicsSystemList & GetAvailableGraphicsSystems()
const XML_Char XML_Content * model
G4int GetMaxNumberOfKeptEvents() const
static void SetConcreteInstance(G4VVisManager *)
void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
void * G4ThreadFunArgType
void SetMarkForClearingTransientStore(G4bool)
void KeepTheCurrentEvent()
G4bool IsAutoRefresh() const
G4int ApplyCommand(const char *aCommand)
G4GLOB_DLL std::ostream G4cerr
void * G4ThreadFunReturnType
const std::vector< Factory * > & FactoryList() const