79 #ifdef G4MULTITHREADED
96 fEventRefreshing (false),
97 fTransientsDrawnThisRun (false),
98 fTransientsDrawnThisEvent (false),
100 fEventKeepingSuspended (false),
101 fKeptLastEvent (false),
102 fpRequestedEvent (0),
103 fAbortReviewKeptEvents (false),
104 fIsDrawGroup (false),
105 fDrawGroupNestingDepth (0),
106 fIgnoreStateChanges (false)
115 (
"Simple graded message scheme - digit or string (1st character defines):");
117 (
" 0) quiet, // Nothing is printed.");
119 (
" 1) startup, // Startup and endup messages are printed...");
121 (
" 2) errors, // ...and errors...");
123 (
" 3) warnings, // ...and warnings...");
125 (
" 4) confirmations, // ...and confirming messages...");
127 (
" 5) parameters, // ...and parameters of scenes and views...");
129 (
" 6) all // ...and everything available.");
133 (
"G4VisManager::G4VisManager",
135 "Attempt to Construct more than one VisManager");
147 <<
"Visualization Manager instantiating with verbosity \""
180 directory -> SetGuidance (
"Visualization commands.");
181 fDirectoryList.push_back (directory);
195 for (i = 0; i < fSceneList.size (); ++i) {
196 delete fSceneList[i];
198 for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
199 if (fAvailableSceneHandlers[i] != NULL) {
200 delete fAvailableSceneHandlers[i];
203 for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
204 if (fAvailableGraphicsSystems[i]) {
205 delete fAvailableGraphicsSystems[i];
210 G4cout <<
"Visualization Manager deleting..." <<
G4endl;
212 for (i = 0; i < fMessengerList.size (); ++i) {
213 delete fMessengerList[i];
215 for (i = 0; i < fDirectoryList.size (); ++i) {
216 delete fDirectoryList[i];
219 delete fpDigiFilterMgr;
220 delete fpHitFilterMgr;
221 delete fpTrajFilterMgr;
222 delete fpTrajDrawModelMgr;
228 (
"G4VisManager::GetInstance",
236 if (fInitialised && fVerbosity >=
warnings) {
237 G4cout <<
"WARNING: G4VisManager::Initialise: already initialised."
243 G4cout <<
"Visualization Manager initialising..." <<
G4endl;
248 "\nYou have instantiated your own Visualization Manager, inheriting"
249 "\n G4VisManager and implementing RegisterGraphicsSystems(), in which"
250 "\n you should, normally, instantiate drivers which do not need"
251 "\n external packages or libraries, and, optionally, drivers under"
252 "\n control of environment variables."
253 "\n Also you should implement RegisterModelFactories()."
254 "\n See visualization/include/G4VisExecutive.hh/icc, for example."
255 "\n In your main() you will have something like:"
256 "\n #ifdef G4VIS_USE"
257 "\n G4VisManager* visManager = new G4VisExecutive;"
258 "\n visManager -> SetVerboseLevel (Verbose);"
259 "\n visManager -> Initialize ();"
261 "\n (Don't forget to delete visManager;)"
274 "\nYou have successfully registered the following graphics systems."
284 directory -> SetGuidance (
"Modeling commands.");
285 fDirectoryList.push_back (directory);
286 directory =
new G4UIdirectory (
"/vis/modeling/trajectories/");
287 directory -> SetGuidance (
"Trajectory model commands.");
288 fDirectoryList.push_back (directory);
289 directory =
new G4UIdirectory (
"/vis/modeling/trajectories/create/");
290 directory -> SetGuidance (
"Create trajectory models and messengers.");
291 fDirectoryList.push_back (directory);
295 directory -> SetGuidance (
"Filtering commands.");
296 fDirectoryList.push_back (directory);
297 directory =
new G4UIdirectory (
"/vis/filtering/trajectories/");
298 directory -> SetGuidance (
"Trajectory filtering commands.");
299 fDirectoryList.push_back (directory);
300 directory =
new G4UIdirectory (
"/vis/filtering/trajectories/create/");
301 directory -> SetGuidance (
"Create trajectory filters and messengers.");
302 fDirectoryList.push_back (directory);
304 directory -> SetGuidance (
"Hit filtering commands.");
305 fDirectoryList.push_back (directory);
306 directory =
new G4UIdirectory (
"/vis/filtering/hits/create/");
307 directory -> SetGuidance (
"Create hit filters and messengers.");
308 fDirectoryList.push_back (directory);
310 directory -> SetGuidance (
"Digi filtering commands.");
311 fDirectoryList.push_back (directory);
312 directory =
new G4UIdirectory (
"/vis/filtering/digi/create/");
313 directory -> SetGuidance (
"Create digi filters and messengers.");
314 fDirectoryList.push_back (directory);
326 "\nYou have successfully registered the following model factories."
328 PrintAvailableModels (fVerbosity);
333 PrintAvailableUserVisActions (fVerbosity);
338 PrintAvailableColours (fVerbosity);
371 directory -> SetGuidance(
"Operations on vis attributes of Geant4 geometry.");
372 fDirectoryList.push_back (directory);
377 directory -> SetGuidance(
"Set vis attributes of Geant4 geometry.");
378 fDirectoryList.push_back (directory);
390 directory -> SetGuidance
391 (
"Set quantities for use in future commands where appropriate.");
392 fDirectoryList.push_back (directory);
400 directory -> SetGuidance (
"Operations on Geant4 scenes.");
401 fDirectoryList.push_back (directory);
411 directory -> SetGuidance (
"Add model to current scene.");
412 fDirectoryList.push_back (directory);
436 directory -> SetGuidance (
"Operations on Geant4 scene handlers.");
437 fDirectoryList.push_back (directory);
444 directory -> SetGuidance (
"Operations on touchables.");
445 fDirectoryList.push_back (directory);
447 directory -> SetGuidance (
"Set vis attributes of current touchable.");
448 fDirectoryList.push_back (directory);
452 directory -> SetGuidance (
"Operations on Geant4 viewers.");
453 fDirectoryList.push_back (directory);
476 directory -> SetGuidance(
"Set default values for future viewers.");
477 fDirectoryList.push_back (directory);
482 directory -> SetGuidance (
"Set view parameters of current viewer.");
483 fDirectoryList.push_back (directory);
488 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->
Placement()));
490 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->
Placement()));
494 (fpTrajFilterMgr, fpTrajFilterMgr->
Placement()));
496 (fpTrajFilterMgr, fpTrajFilterMgr->
Placement()));
500 (fpHitFilterMgr, fpHitFilterMgr->
Placement()));
502 (fpHitFilterMgr, fpHitFilterMgr->
Placement()));
506 (fpDigiFilterMgr, fpDigiFilterMgr->
Placement()));
508 (fpDigiFilterMgr, fpDigiFilterMgr->
Placement()));
512 if (IsValidView ()) {
515 G4cout <<
"G4VisManager::Enable: visualization enabled." <<
G4endl;
521 "G4VisManager::Enable: WARNING: visualization remains disabled for"
522 "\n above reasons. Rectifying with valid vis commands will"
523 "\n automatically enable."
533 "G4VisManager::Disable: visualization disabled."
534 "\n The pointer returned by GetConcreteInstance will be zero."
535 "\n Note that it will become enabled after some valid vis commands."
541 G4int nSystems = fAvailableGraphicsSystems.size ();
544 G4cout <<
"G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
545 "\n graphics system available!"
546 "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
547 "\n when you compiled/built the visualization code?"
548 "\n 2) Did you instantiate your own Visualization Manager and forget"
549 "\n to implement RegisterGraphicsSystems correctly?"
550 "\n 3) You can register your own graphics system, e.g.,"
551 "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
552 "\n after instantiating your vis manager and before"
553 "\n visManager->Initialize()."
557 return fAvailableGraphicsSystems;
563 fAvailableGraphicsSystems.push_back (pSystem);
565 G4cout <<
"G4VisManager::RegisterGraphicsSystem: "
566 << pSystem -> GetName ();
567 if (pSystem -> GetNickname () !=
"") {
568 G4cout <<
" (" << pSystem -> GetNickname () <<
")";
574 if (fVerbosity >=
errors) {
575 G4cout <<
"G4VisManager::RegisterGraphicsSystem: null pointer!"
586 assert (0 != fpTrajDrawModelMgr);
596 G4cout<<
"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<
G4endl;
597 G4cout<<
"See commands in /vis/modeling/trajectories/ for other options."<<
G4endl;
601 model = fpTrajDrawModelMgr->
Current();
609 fpTrajDrawModelMgr->
Register(model);
615 fpTrajDrawModelMgr->
Register(factory);
658 #ifdef G4MULTITHREADED
661 fDrawGroupNestingDepth++;
662 if (fDrawGroupNestingDepth > 1) {
664 (
"G4VSceneHandler::BeginDraw",
666 "Nesting detected. It is illegal to nest Begin/EndDraw."
670 if (IsValidView ()) {
671 ClearTransientStoreIfMarked();
672 fpSceneHandler -> BeginPrimitives (objectTransform);
679 #ifdef G4MULTITHREADED
682 fDrawGroupNestingDepth--;
683 if (fDrawGroupNestingDepth != 0) {
684 if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
687 if (IsValidView ()) {
688 fpSceneHandler -> EndPrimitives ();
690 fIsDrawGroup =
false;
695 #ifdef G4MULTITHREADED
698 fDrawGroupNestingDepth++;
699 if (fDrawGroupNestingDepth > 1) {
701 (
"G4VSceneHandler::BeginDraw2D",
703 "Nesting detected. It is illegal to nest Begin/EndDraw2D."
707 if (IsValidView ()) {
708 ClearTransientStoreIfMarked();
709 fpSceneHandler -> BeginPrimitives2D (objectTransform);
716 #ifdef G4MULTITHREADED
719 fDrawGroupNestingDepth--;
720 if (fDrawGroupNestingDepth != 0) {
721 if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
724 if (IsValidView ()) {
725 fpSceneHandler -> EndPrimitives2D ();
727 fIsDrawGroup =
false;
730 template <
class T>
void G4VisManager::DrawT
731 (
const T& graphics_primitive,
const G4Transform3D& objectTransform) {
732 #ifdef G4MULTITHREADED
738 (
"G4VSceneHandler::DrawT",
740 "Different transform detected in Begin/EndDraw group.");
742 fpSceneHandler -> AddPrimitive (graphics_primitive);
744 if (IsValidView ()) {
745 ClearTransientStoreIfMarked();
746 fpSceneHandler -> BeginPrimitives (objectTransform);
747 fpSceneHandler -> AddPrimitive (graphics_primitive);
748 fpSceneHandler -> EndPrimitives ();
753 template <
class T>
void G4VisManager::DrawT2D
754 (
const T& graphics_primitive,
const G4Transform3D& objectTransform) {
755 #ifdef G4MULTITHREADED
761 (
"G4VSceneHandler::DrawT",
763 "Different transform detected in Begin/EndDraw2D group.");
765 fpSceneHandler -> AddPrimitive (graphics_primitive);
767 if (IsValidView ()) {
768 ClearTransientStoreIfMarked();
769 fpSceneHandler -> BeginPrimitives2D (objectTransform);
770 fpSceneHandler -> AddPrimitive (graphics_primitive);
771 fpSceneHandler -> EndPrimitives2D ();
779 DrawT (circle, objectTransform);
785 DrawT (polyhedron, objectTransform);
791 DrawT (line, objectTransform);
797 DrawT (polymarker, objectTransform);
803 DrawT (scale, objectTransform);
809 DrawT (square, objectTransform);
815 DrawT (text, objectTransform);
821 DrawT2D (circle, objectTransform);
827 DrawT2D (polyhedron, objectTransform);
833 DrawT2D (line, objectTransform);
839 DrawT2D (polymarker, objectTransform);
845 DrawT2D (square, objectTransform);
851 DrawT2D (text, objectTransform);
855 #ifdef G4MULTITHREADED
859 fpSceneHandler -> AddCompound (hit);
861 if (IsValidView ()) {
862 ClearTransientStoreIfMarked();
863 fpSceneHandler -> AddCompound (hit);
869 #ifdef G4MULTITHREADED
873 fpSceneHandler -> AddCompound (digi);
875 if (IsValidView ()) {
876 ClearTransientStoreIfMarked();
877 fpSceneHandler -> AddCompound (digi);
883 #ifdef G4MULTITHREADED
887 fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
888 fpSceneHandler -> AddCompound (traj);
890 if (IsValidView ()) {
891 ClearTransientStoreIfMarked();
892 fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
893 fpSceneHandler -> AddCompound (traj);
901 #ifdef G4MULTITHREADED
906 Draw (*pSol, attribs, objectTransform);
912 #ifdef G4MULTITHREADED
916 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
918 fpSceneHandler -> PostAddSolid ();
920 if (IsValidView ()) {
921 ClearTransientStoreIfMarked();
922 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
924 fpSceneHandler -> PostAddSolid ();
933 #ifdef G4MULTITHREADED
937 G4VSolid* pSol = pLV -> GetSolid ();
938 Draw (*pSol, attribs, objectTransform);
943 if (fpGraphicsSystem) {
947 fAvailableSceneHandlers.push_back (pSceneHandler);
948 fpSceneHandler = pSceneHandler;
951 if (fVerbosity >=
errors) {
952 G4cout <<
"ERROR in G4VisManager::CreateSceneHandler during "
953 << fpGraphicsSystem -> GetName ()
954 <<
" scene handler creation.\n No action taken."
959 else PrintInvalidPointers ();
966 if (!fInitialised) Initialise ();
968 if (!fpSceneHandler) {
969 PrintInvalidPointers ();
973 G4VViewer*
p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
976 if (fVerbosity >= errors) {
977 G4cout <<
"ERROR in G4VisManager::CreateViewer during "
978 << fpGraphicsSystem -> GetName ()
979 <<
" viewer creation.\n No action taken."
985 if (p -> GetViewId() < 0) {
986 if (fVerbosity >= errors) {
987 G4cout <<
"ERROR in G4VisManager::CreateViewer during "
988 << fpGraphicsSystem -> GetName ()
989 <<
" viewer initialisation.\n No action taken."
1000 p -> SetViewParameters(initialvp);
1004 fpSceneHandler -> AddViewerToList (fpViewer);
1005 fpSceneHandler -> SetCurrentViewer (fpViewer);
1006 if (fVerbosity >= confirmations) {
1007 G4cout <<
"G4VisManager::CreateViewer: new viewer created."
1012 if (fVerbosity >= parameters) {
1017 static G4bool warned =
false;
1018 if (fVerbosity >= confirmations) {
1021 "NOTE: objects with visibility flag set to \"false\""
1022 " will not be drawn!"
1023 "\n \"/vis/viewer/set/culling global false\" to Draw such objects."
1024 "\n Also see other \"/vis/viewer/set\" commands."
1031 static G4bool warned =
false;
1032 if (fVerbosity >= warnings) {
1035 "WARNING: covered objects in solid mode will not be rendered!"
1036 "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
1037 "\n Also see other \"/vis/viewer/set\" commands."
1047 G4cout <<
"G4VisManager::GeometryHasChanged() called." <<
G4endl;
1053 -> GetNavigatorForTracking () -> GetWorldVolume ();
1056 G4cout <<
"WARNING: There is no world volume!" <<
G4endl;
1062 G4int iScene, nScenes = sceneList.size ();
1063 for (iScene = 0; iScene < nScenes; iScene++) {
1064 G4Scene* pScene = sceneList [iScene];
1065 std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1066 if (modelList.size ()) {
1069 modelInvalid =
false;
1070 std::vector<G4Scene::Model>::iterator iterModel;
1071 for (iterModel = modelList.begin();
1072 iterModel != modelList.end();
1074 modelInvalid = !(iterModel->fpModel->Validate(fVerbosity>=
warnings));
1078 G4cout <<
"WARNING: Model \""
1079 << iterModel->fpModel->GetGlobalDescription ()
1081 "\" is no longer valid - being removed\n from scene \""
1082 << pScene -> GetName () <<
"\""
1085 modelList.erase (iterModel);
1089 }
while (modelInvalid);
1091 if (modelList.size () == 0) {
1093 G4cout <<
"WARNING: No models left in this scene \""
1094 << pScene -> GetName ()
1102 ApplyCommand (
G4String(
"/vis/scene/notifyHandlers " + pScene->
GetName()));
1108 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1110 G4cout <<
"WARNING: The current scene \""
1111 << fpScene -> GetName ()
1112 <<
"\" has no models."
1121 G4cout <<
"G4VisManager::NotifyHandler() called." <<
G4endl;
1126 G4int iScene, nScenes = sceneList.size ();
1127 for (iScene = 0; iScene < nScenes; iScene++) {
1128 G4Scene* pScene = sceneList [iScene];
1129 std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1131 if (modelList.size ()) {
1134 ApplyCommand (
G4String(
"/vis/scene/notifyHandlers " + pScene->
GetName()));
1139 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1141 G4cout <<
"WARNING: The current scene \""
1142 << fpScene -> GetName ()
1143 <<
"\" has no models."
1151 return fpTrajFilterMgr->
Accept(trajectory);
1156 return fpHitFilterMgr->
Accept(hit);
1161 return fpDigiFilterMgr->
Accept(digi);
1179 assert (0 != fpTrajDrawModelMgr);
1183 assert (0 != trajectoryModel);
1185 if (IsValidView()) {
1186 trajectoryModel->
Draw(trajectory, visible);
1194 fRunDurationUserVisActions.push_back(
UserVisAction(name,pVisAction));
1196 fUserVisActionExtents[pVisAction] = extent;
1198 if (fVerbosity >= warnings) {
1200 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1210 fEndOfEventUserVisActions.push_back(
UserVisAction(name,pVisAction));
1212 fUserVisActionExtents[pVisAction] = extent;
1214 if (fVerbosity >= warnings) {
1216 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1226 fEndOfRunUserVisActions.push_back(
UserVisAction(name,pVisAction));
1228 fUserVisActionExtents[pVisAction] = extent;
1230 if (fVerbosity >= warnings) {
1232 "WARNING: No extent set for user vis action \"" << name <<
"\"."
1239 if (pScene != fpScene) {
1248 fpGraphicsSystem = pSystem;
1250 G4cout <<
"G4VisManager::SetCurrentGraphicsSystem: system now "
1251 << pSystem -> GetName () <<
G4endl;
1256 if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
1258 G4int nSH = sceneHandlerList.size ();
1260 for (iSH = nSH - 1; iSH >= 0; iSH--) {
1261 if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem)
break;
1264 fpSceneHandler = sceneHandlerList [iSH];
1266 G4cout <<
" Scene Handler now "
1267 << fpSceneHandler -> GetName () <<
G4endl;
1269 if (fpScene != fpSceneHandler -> GetScene ()) {
1270 fpScene = fpSceneHandler -> GetScene ();
1272 G4cout <<
" Scene now \""
1273 << fpScene -> GetName () <<
"\"" <<
G4endl;
1276 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1277 if (viewerList.size ()) {
1278 fpViewer = viewerList [0];
1280 G4cout <<
" Viewer now " << fpViewer -> GetName () <<
G4endl;
1295 fpSceneHandler = pSceneHandler;
1297 G4cout <<
"G4VisManager::SetCurrentSceneHandler: scene handler now \""
1298 << pSceneHandler -> GetName () <<
"\"" <<
G4endl;
1300 if (fpScene != fpSceneHandler -> GetScene ()) {
1301 fpScene = fpSceneHandler -> GetScene ();
1303 G4cout <<
" Scene now \""
1304 << fpScene -> GetName () <<
"\"" <<
G4endl;
1307 if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
1308 fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
1310 G4cout <<
" Graphics system now \""
1311 << fpGraphicsSystem -> GetName () <<
"\"" <<
G4endl;
1314 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1315 G4int nViewers = viewerList.size ();
1318 for (iViewer = 0; iViewer < nViewers; iViewer++) {
1319 if (fpViewer == viewerList [iViewer])
break;
1321 if (iViewer >= nViewers) {
1322 fpViewer = viewerList [0];
1324 G4cout <<
" Viewer now \"" << fpViewer -> GetName () <<
"\""
1328 if (!IsValidView ()) {
1331 "WARNING: Problem setting scene handler - please report circumstances."
1340 "WARNING: No viewers for this scene handler - please create one."
1349 G4cout <<
"G4VisManager::SetCurrentViewer: viewer now "
1350 << pViewer -> GetName ()
1353 fpSceneHandler = fpViewer -> GetSceneHandler ();
1355 fpScene = fpSceneHandler -> GetScene ();
1356 fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1357 if (!IsValidView ()) {
1360 "WARNING: Problem setting viewer - please report circumstances."
1367 struct NicknameComparison {
1369 {
return lhs.length()<rhs.length();}
1374 G4int nSystems = fAvailableGraphicsSystems.size ();
1375 G4cout <<
"Current available graphics systems are:";
1380 std::map<G4String,std::set<G4String,NicknameComparison> > systemMap;
1381 for (
G4int i = 0; i < nSystems; i++) {
1386 std::map<G4String,std::set<G4String,NicknameComparison> >::const_iterator i;
1387 for (i = systemMap.begin(); i != systemMap.end(); ++i) {
1388 G4cout <<
"\n " << i->first <<
" (";
1389 const std::set<G4String,NicknameComparison>& nicknames = i->second;
1390 std::set<G4String,NicknameComparison>::const_iterator j;
1391 for (j = nicknames.begin(); j != nicknames.end(); ++j) {
1392 if (j != nicknames.begin())
G4cout <<
", ";
1399 G4cout <<
"\n NONE!!! None registered - yet! Mmmmm!";
1404 void G4VisManager::PrintAvailableModels (
Verbosity verbosity)
const
1409 const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1411 if (factoryList.empty())
G4cout <<
" None" << G4endl;
1413 std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1414 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1419 const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1421 if (!modelMap.empty()) {
1423 std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1424 for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1425 G4cout <<
" " << i->second->Name();
1426 if (i->second == listManager->
Current())
G4cout <<
" (Current)";
1438 const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1440 if (factoryList.empty())
G4cout <<
" None" << G4endl;
1442 std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1443 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1446 const std::vector<G4VFilter<G4VTrajectory>*>&
1448 if (!filterList.empty()) {
1450 std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1451 for (i = filterList.begin(); i != filterList.end(); ++i) {
1459 void G4VisManager::PrintAvailableUserVisActions (
Verbosity)
const
1462 "You have successfully registered the following user vis actions."
1464 G4cout <<
"Run Duration User Vis Actions:";
1465 if (fRunDurationUserVisActions.empty())
G4cout <<
" none" << G4endl;
1468 for (
size_t i = 0; i < fRunDurationUserVisActions.size(); i++) {
1469 const G4String& name = fRunDurationUserVisActions[i].fName;
1474 G4cout <<
"End of Event User Vis Actions:";
1475 if (fEndOfEventUserVisActions.empty())
G4cout <<
" none" << G4endl;
1478 for (
size_t i = 0; i < fEndOfEventUserVisActions.size(); i++) {
1479 const G4String& name = fEndOfEventUserVisActions[i].fName;
1484 G4cout <<
"End of Run User Vis Actions:";
1485 if (fEndOfRunUserVisActions.empty())
G4cout <<
" none" << G4endl;
1488 for (
size_t i = 0; i < fEndOfRunUserVisActions.size(); i++) {
1489 const G4String& name = fEndOfRunUserVisActions[i].fName;
1495 void G4VisManager::PrintAvailableColours (
Verbosity)
const {
1497 "Some /vis commands (optionally) take a string to specify colour."
1498 "\nAvailable colours:\n ";
1500 for (std::map<G4String, G4Colour>::const_iterator i = map.begin();
1503 if (++i != map.end())
G4cout <<
", ";
1508 void G4VisManager::PrintInvalidPointers ()
const {
1509 if (fVerbosity >=
errors) {
1510 G4cout <<
"ERROR: G4VisManager::PrintInvalidPointers:";
1511 if (!fpGraphicsSystem) {
1512 G4cout <<
"\n null graphics system pointer.";
1515 G4cout <<
"\n Graphics system is " << fpGraphicsSystem -> GetName ()
1519 "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1520 " \"/vis/scene/create\".";
1521 if (!fpSceneHandler)
1523 "\n Null scene handler pointer. Use \"/vis/open\" or"
1524 " \"/vis/sceneHandler/create\".";
1527 "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1533 #ifdef G4MULTITHREADED
1545 void G4VisManager::BeginOfRun ()
1550 fKeptLastEvent =
false;
1551 fEventKeepingSuspended =
false;
1552 fTransientsDrawnThisRun =
false;
1556 void G4VisManager::BeginOfEvent ()
1561 void G4VisManager::EndOfEvent ()
1570 G4bool valid = fpSceneHandler && IsValidView();
1575 if (!fEventKeepingSuspended) {
1590 if (maxNumberOfKeptEvents > 0 && fNKeepRequests >= maxNumberOfKeptEvents) {
1591 fEventKeepingSuspended =
true;
1592 static G4bool warned =
false;
1596 "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
1597 "\n The number of events exceeds the maximum, "
1598 << maxNumberOfKeptEvents <<
1599 ", that may be kept by \n the vis manager."
1604 }
else if (maxNumberOfKeptEvents != 0) {
1612 void G4VisManager::EndOfRun ()
1621 G4bool valid = fpSceneHandler && IsValidView();
1628 if (!currentRun)
return;
1630 const std::vector<const G4Event*>*
1632 G4int nKeptEvents = eventsFromThreads ? eventsFromThreads->size() : 0;
1635 G4cout <<
"WARNING: " << nKeptEvents;
1636 if (nKeptEvents == 1)
G4cout <<
" event has";
1637 else G4cout <<
" events have";
1638 G4cout <<
" been kept for refreshing and/or reviewing." <<
G4endl;
1639 if (nKeptEvents != fNKeepRequests) {
1641 if (fNKeepRequests == 0) {
1642 G4cout <<
"No keep requests were";
1643 }
else if (fNKeepRequests == 1) {
1644 G4cout <<
"Only 1 keep request was";
1646 G4cout <<
"Only " << fNKeepRequests <<
" keep requests were";
1650 G4cout <<
" \"/vis/reviewKeptEvents\" to review them." <<
G4endl;
1654 if (fEventKeepingSuspended && fVerbosity >=
warnings) {
1656 "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
1657 "\n The number of events in the run exceeded the maximum, "
1659 ", that may be\n kept by the vis manager." <<
1660 "\n The number of events kept by the vis manager can be changed with"
1661 "\n \"/vis/scene/endOfEventAction [accumulate|refresh] <N>\", where N"
1662 "\n is the maximum number you wish to allow. N < 0 means \"unlimited\"."
1667 std::vector<const G4Event*>::const_iterator i;
1669 for (i = eventsFromThreads->begin(); i != eventsFromThreads->end(); ++i) {
1671 G4cout <<
"Drawing event " << (*i)->GetEventID() <<
G4endl;
1686 std::vector<G4Scene::Model> tmpEoeModels = eoeModels;
1687 std::vector<G4Scene::Model>::iterator iEoe;
1688 for (iEoe = eoeModels.begin(); iEoe != eoeModels.end(); ++iEoe) {
1689 iEoe->fActive =
false;
1692 std::vector<G4Scene::Model> tmpEorModels = eorModels;
1693 std::vector<G4Scene::Model>::iterator iEor;
1694 for (iEor = eoeModels.begin(); iEor != eoeModels.end(); ++iEor) {
1695 iEor->fActive =
false;
1697 ClearTransientStoreIfMarked();
1699 eoeModels = tmpEoeModels;
1700 eorModels = tmpEorModels;
1702 fTransientsDrawnThisEvent =
false;
1727 std::vector<G4Scene::Model> tmpEoeModels = eoeModels;
1728 std::vector<G4Scene::Model>::iterator iEoe;
1729 for (iEoe = eoeModels.begin(); iEoe != eoeModels.end(); ++iEoe) {
1730 iEoe->fActive =
false;
1733 std::vector<G4Scene::Model> tmpEorModels = eorModels;
1734 std::vector<G4Scene::Model>::iterator iEor;
1735 for (iEor = eoeModels.begin(); iEor != eoeModels.end(); ++iEor) {
1736 iEor->fActive =
false;
1738 ClearTransientStoreIfMarked();
1740 eoeModels = tmpEoeModels;
1741 eorModels = tmpEorModels;
1743 fTransientsDrawnThisEvent =
false;
1745 for (i = eventsFromThreads->begin(); i != eventsFromThreads->end(); ++i) {
1747 G4cout <<
"Drawing event " << (*i)->GetEventID() <<
G4endl;
1768 void G4VisManager::BeginOfRun ()
1773 fKeptLastEvent =
false;
1774 fEventKeepingSuspended =
false;
1775 fTransientsDrawnThisRun =
false;
1779 void G4VisManager::BeginOfEvent ()
1783 fTransientsDrawnThisEvent =
false;
1787 void G4VisManager::EndOfEvent ()
1796 G4bool valid = fpSceneHandler && IsValidView();
1801 if (!currentEvent)
return;
1805 if (!currentRun)
return;
1817 ClearTransientStoreIfMarked();
1820 fpSceneHandler->
DrawEvent(currentEvent);
1822 G4int nEventsToBeProcessed = 0;
1823 G4int nKeptEvents = 0;
1828 const std::vector<const G4Event*>* events =
1830 if (events) nKeptEvents = events->size();
1836 if (eventID < nEventsToBeProcessed - 1) {
1848 fKeptLastEvent =
true;
1855 if (maxNumberOfKeptEvents > 0 && fNKeepRequests >= maxNumberOfKeptEvents) {
1856 fEventKeepingSuspended =
true;
1857 static G4bool warned =
false;
1861 "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
1862 "\n The number of events exceeds the maximum, "
1863 << maxNumberOfKeptEvents <<
1864 ", that may be kept by\n the vis manager."
1869 }
else if (maxNumberOfKeptEvents != 0) {
1880 void G4VisManager::EndOfRun ()
1888 G4int nKeptEvents = 0;
1889 const std::vector<const G4Event*>* events =
1891 if (events) nKeptEvents = events->size();
1893 if (nKeptEvents && !fKeptLastEvent) {
1895 G4cout <<
"WARNING: " << nKeptEvents;
1896 if (nKeptEvents == 1)
G4cout <<
" event has";
1897 else G4cout <<
" events have";
1898 G4cout <<
" been kept for refreshing and/or reviewing." <<
G4endl;
1899 if (nKeptEvents != fNKeepRequests) {
1901 if (fNKeepRequests == 0) {
1902 G4cout <<
"No keep requests were";
1903 }
else if (fNKeepRequests == 1) {
1904 G4cout <<
"Only 1 keep request was";
1906 G4cout <<
"Only " << fNKeepRequests <<
" keep requests were";
1910 G4cout <<
" \"/vis/reviewKeptEvents\" to review them." <<
G4endl;
1929 if (fEventKeepingSuspended && fVerbosity >=
warnings) {
1931 "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
1932 "\n The number of events in the run exceeded the maximum, "
1934 ", that may be\n kept by the vis manager." <<
1935 "\n The number of events kept by the vis manager can be changed with"
1936 "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
1937 "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
1944 G4bool valid = fpSceneHandler && IsValidView();
1962 fEventRefreshing =
false;
1965 #endif // End of sequential versions of Begin/EndOfRun/Event.
1967 void G4VisManager::ClearTransientStoreIfMarked(){
1983 fTransientsDrawnThisRun =
false;
1984 fTransientsDrawnThisEvent =
false;
1986 for (i = fAvailableSceneHandlers.begin();
1987 i != fAvailableSceneHandlers.end(); ++i) {
1988 (*i)->SetTransientsDrawnThisEvent(
false);
1989 (*i)->SetTransientsDrawnThisRun(
false);
1994 G4String viewerShortName (viewerName);
1995 viewerShortName = viewerShortName (0, viewerShortName.find (
' '));
1996 return viewerShortName.
strip ();
2001 size_t nHandlers = fAvailableSceneHandlers.size ();
2002 size_t iHandler, iViewer;
2005 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
2007 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
2008 for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
2009 viewer = viewerList [iViewer];
2010 if (viewerShortName == viewer -> GetShortName ()) {
2017 if (found)
return viewer;
2025 switch (verbosity) {
2026 case quiet: rs =
"quiet (0)";
break;
2027 case startup: rs =
"startup (1)";
break;
2028 case errors: rs =
"errors (2)";
break;
2029 case warnings: rs =
"warnings (3)";
break;
2031 case parameters: rs =
"parameters (5)";
break;
2032 case all: rs =
"all (6)";
break;
2041 if (ss(0) ==
'q') verbosity =
quiet;
2042 else if (ss(0) ==
's') verbosity =
startup;
2043 else if (ss(0) ==
'e') verbosity =
errors;
2044 else if (ss(0) ==
'w') verbosity =
warnings;
2046 else if (ss(0) ==
'p') verbosity =
parameters;
2047 else if (ss(0) ==
'a') verbosity =
all;
2050 std::istringstream is(ss);
2053 G4cout <<
"ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
2054 << verbosityString <<
"\"";
2072 else if (intVerbosity >
all) verbosity =
all;
2073 else verbosity =
Verbosity(intVerbosity);
2089 G4bool G4VisManager::IsValidView () {
2093 static G4bool noGSPrinting =
true;
2094 if (!fpGraphicsSystem) {
2098 noGSPrinting =
false;
2101 "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
2102 "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
2103 "\n Alternatively, to avoid this message, suppress instantiation of vis"
2104 "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
2105 "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()"
2113 if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
2114 if (fVerbosity >=
errors) {
2116 "ERROR: G4VisManager::IsValidView(): Current view is not valid."
2118 PrintInvalidPointers ();
2123 if (fpScene != fpSceneHandler -> GetScene ()) {
2124 if (fVerbosity >=
errors) {
2125 G4cout <<
"ERROR: G4VisManager::IsValidView ():";
2126 if (fpSceneHandler -> GetScene ()) {
2128 "\n The current scene \""
2129 << fpScene -> GetName ()
2130 <<
"\" is not handled by"
2131 "\n the current scene handler \""
2132 << fpSceneHandler -> GetName ()
2134 "\n (it currently handles scene \""
2135 << fpSceneHandler -> GetScene () -> GetName ()
2138 "\n (a) attach it to the scene handler with"
2139 "\n /vis/sceneHandler/attach "
2140 << fpScene -> GetName ()
2142 "\n (b) create a new scene handler with "
2143 "\n /vis/sceneHandler/create <graphics-system>,"
2144 "\n in which case it should pick up the the new scene."
2148 G4cout <<
"\n Scene handler \""
2149 << fpSceneHandler -> GetName ()
2150 <<
"\" has null scene pointer."
2151 "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
2158 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
2159 if (viewerList.size () == 0) {
2160 if (fVerbosity >=
errors) {
2162 "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
2163 << fpSceneHandler -> GetName ()
2164 <<
"\" has no viewers. Do /vis/viewer/create."
2171 if (fpScene -> IsEmpty ()) {
2173 G4bool successful = fpScene -> AddWorldIfEmpty (warn);
2174 if (!successful || fpScene -> IsEmpty ()) {
2175 if (fVerbosity >=
errors) {
2176 G4cout <<
"ERROR: G4VisManager::IsViewValid ():";
2178 "\n Attempt at some drawing operation when scene is empty."
2179 "\n Maybe the geometry has not yet been defined."
2180 " Try /run/initialize."
2189 "WARNING: G4VisManager: the scene was empty, \"world\" has been"
2190 "\n added and the scene handlers notified.";
2202 G4cout<<
"G4VisManager: No model factories registered with G4VisManager."<<
G4endl;
2203 G4cout<<
"G4VisManager::RegisterModelFactories() should be overridden in derived"<<
G4endl;
2204 G4cout<<
"class. See G4VisExecutive for an example."<<
G4endl;
2208 #ifdef G4MULTITHREADED
2209 void G4VisManager::SetUpForAThread()
2215 void G4VisManager::IgnoreStateChanges(
G4bool val)
G4bool FilterDigi(const G4VDigi &)
void RegisterEndOfEventUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void RegisterModelFactory(G4TrajDrawModelFactory *factory)
virtual void RegisterModelFactories()
void SetCurrentSceneHandler(G4VSceneHandler *)
static G4VVisManager * GetConcreteInstance()
G4String strip(G4int strip_Type=trailing, char c=' ')
G4bool IsCullingInvisible() const
void RegisterEndOfRunUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void SetVerboseLevel(G4int)
const G4ViewParameters & GetViewParameters() const
const Model * Current() const
void GeometryHasChanged()
const std::vector< const G4Event * > * GetEventVector() const
void SetCurrentScene(G4Scene *)
std::vector< Model > & SetEndOfRunModelList()
G4bool GetMarkForClearingTransientStore() const
G4bool GetRefreshAtEndOfEvent() const
static std::vector< G4String > VerbosityGuidanceStrings
const G4String & GetName() const
static Verbosity GetVerbosityValue(const G4String &)
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 PrintAvailableGraphicsSystems() const
void SetTransientsDrawnThisEvent(G4bool)
G4double GetExtentRadius() const
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
G4bool GetRefreshAtEndOfRun() const
void ResetTransientsDrawnFlags()
G4bool GetTransientsDrawnThisRun() const
const XML_Char XML_Content * model
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
void SetXGeometryString(const G4String &)
const T * Current() const
G4String Placement() const
void DrawEndOfRunModels()
G4bool GetTransientsDrawnThisEvent() const
G4bool IsCullingCovered() const
const G4String & GetNickname() const
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
const G4String & GetName() const
G4VisManager(const G4String &verbosityString="warnings")
G4bool FilterHit(const G4VHit &)
G4LogicalVolume * GetLogicalVolume() const
void DrawEvent(const G4Event *)
G4VViewer * GetViewer(const G4String &viewerName) const
std::vector< Model > & SetEndOfEventModelList()
void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())
static G4String VerbosityString(Verbosity)
static G4EventManager * GetEventManager()
FilterMode::Mode GetMode() const
static Verbosity GetVerbosity()
G4bool fIgnoreStateChanges
void Draw(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
static void SetVisManager(G4VisManager *)
virtual void RegisterGraphicsSystems()=0
G4int GetNumberOfEventToBeProcessed() const
void RegisterModel(G4VTrajectoryModel *model)
const std::vector< Factory * > & FactoryList() const
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
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)
const G4Event * GetConstCurrentEvent()
void CreateSceneHandler(const G4String &name="")
const G4GraphicsSystemList & GetAvailableGraphicsSystems()
G4int GetMaxNumberOfKeptEvents() const
static void SetConcreteInstance(G4VVisManager *)
void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
void SetMarkForClearingTransientStore(G4bool)
void KeepTheCurrentEvent()
G4bool IsAutoRefresh() const
G4int ApplyCommand(const char *aCommand)
G4VSolid * GetSolid() const
const std::vector< Factory * > & FactoryList() const