Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VisManager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28// GEANT4 Visualization Manager - John Allison 02/Jan/1996.
29// Michael Kelsey 31 Jan 2019 -- Add new command for electric field
30
31#include "G4VisManager.hh"
32
33#include "G4VisCommands.hh"
38#include "G4VisCommandsSet.hh"
39#include "G4VisCommandsScene.hh"
48#include "G4UImanager.hh"
50#include "G4UIdirectory.hh"
51#include "G4VGraphicsSystem.hh"
52#include "G4VSceneHandler.hh"
53#include "G4VViewer.hh"
54#include "G4VPhysicalVolume.hh"
55#include "G4LogicalVolume.hh"
56#include "G4VSolid.hh"
57#include "G4Vector3D.hh"
58#include "G4Point3D.hh"
59#include "G4RotationMatrix.hh"
60#include "G4Polyline.hh"
61#include "G4Polyhedron.hh"
62#include "G4NullModel.hh"
67#include "G4VisModelManager.hh"
68#include "G4VModelFactory.hh"
69#include "G4VisFilterManager.hh"
70#include "G4VTrajectoryModel.hh"
72#include "Randomize.hh"
73#include "G4RunManager.hh"
75#include "G4EventManager.hh"
76#include "G4Run.hh"
77#include "G4Event.hh"
78#include <map>
79#include <set>
80#include <vector>
81#include <sstream>
82
83#ifdef G4MULTITHREADED
84# include "G4Threading.hh"
85# include "G4AutoLock.hh"
86# include "G4GeometryWorkspace.hh" // no_geant4_module_check(!G4MULTITHREADED)
87# include "G4SolidsWorkspace.hh"
88# include <deque>
89# include <typeinfo>
90# include <chrono>
91# include <thread>
92#endif
93
94#define G4warn G4cout
95
96G4VisManager* G4VisManager::fpInstance = 0;
97
98G4VisManager::Verbosity G4VisManager::fVerbosity = G4VisManager::warnings;
99
100G4VisManager::G4VisManager (const G4String& verbosityString)
101: fVerbose (1)
102, fInitialised (false)
103, fpGraphicsSystem (0)
104, fpScene (0)
105, fpSceneHandler (0)
106, fpViewer (0)
107, fpStateDependent (0)
108, fEventRefreshing (false)
109, fTransientsDrawnThisRun (false)
110, fTransientsDrawnThisEvent (false)
111, fNoOfEventsDrawnThisRun (0)
112, fNKeepRequests (0)
113, fEventKeepingSuspended (false)
114, fDrawEventOnlyIfToBeKept (false)
115, fpRequestedEvent (0)
116, fReviewingKeptEvents (false)
117, fAbortReviewKeptEvents (false)
118, fReviewingPlots (false)
119, fAbortReviewPlots (false)
120, fIsDrawGroup (false)
121, fDrawGroupNestingDepth (0)
122, fIgnoreStateChanges (false)
123#ifdef G4MULTITHREADED
124, fMaxEventQueueSize (100)
125, fWaitOnEventQueueFull (true)
126#endif
127// All other objects use default constructors.
128{
129 fpTrajDrawModelMgr = new G4VisModelManager<G4VTrajectoryModel>("/vis/modeling/trajectories");
130 fpTrajFilterMgr = new G4VisFilterManager<G4VTrajectory>("/vis/filtering/trajectories");
131 fpHitFilterMgr = new G4VisFilterManager<G4VHit>("/vis/filtering/hits");
132 fpDigiFilterMgr = new G4VisFilterManager<G4VDigi>("/vis/filtering/digi");
133
135 ("Simple graded message scheme - digit or string (1st character defines):");
137 (" 0) quiet, // Nothing is printed.");
139 (" 1) startup, // Startup and endup messages are printed...");
141 (" 2) errors, // ...and errors...");
143 (" 3) warnings, // ...and warnings...");
145 (" 4) confirmations, // ...and confirming messages...");
147 (" 5) parameters, // ...and parameters of scenes and views...");
149 (" 6) all // ...and everything available.");
150
151 if (fpInstance) {
153 ("G4VisManager::G4VisManager",
154 "visman0001", FatalException,
155 "Attempt to Construct more than one VisManager");
156 }
157
158 fpInstance = this;
160
161 fpStateDependent = new G4VisStateDependent (this);
162 // No need to delete this; G4StateManager does this.
163
164 fVerbosity = GetVerbosityValue(verbosityString);
165 if (fVerbosity >= startup) {
166 G4cout
167 << "Visualization Manager instantiating with verbosity \""
168 << VerbosityString(fVerbosity)
169 << "\"..." << G4endl;
170 }
171
172 // Note: The specific graphics systems must be instantiated in a
173 // higher level library to avoid circular dependencies. Also,
174 // some specifically need additional external libararies that the
175 // user must supply. Therefore we ask the user to implement
176 // RegisterGraphicsSystems() and RegisterModelFactories()
177 // in a subclass. We have to wait for the subclass to instantiate
178 // so RegisterGraphicsSystems() cannot be called from this
179 // constructor; it is called from Initialise(). So we ask the
180 // user:
181 // (a) to write a subclass and implement RegisterGraphicsSystems()
182 // and RegisterModelFactories(). See
183 // visualization/include/G4VisExecutive.hh/icc as an example.
184 // (b) instantiate the subclass.
185 // (c) invoke the Initialise() method of the subclass.
186 // For example:
187 // ...
188 // // Instantiate and initialise Visualization Manager.
189 // G4VisManager* visManager = new G4VisExecutive;
190 // visManager -> SetVerboseLevel (Verbose);
191 // visManager -> Initialise ();
192 // // (Don't forget to delete visManager;)
193 // ...
194
195 // Make top level command directory...
196 // vis commands should *not* be broadcast to workers
197 G4bool propagateToWorkers;
198 auto directory = new G4UIdirectory ("/vis/",propagateToWorkers=false);
199 directory -> SetGuidance ("Visualization commands.");
200 // Request commands in name order
201 directory -> Sort(); // Ordering propagates to sub-directories
202 fDirectoryList.push_back (directory);
203
204 // Instantiate *basic* top level commands so that they can be used
205 // immediately after instantiation of the vis manager. Other top
206 // level and lower level commands are instantiated later in
207 // RegisterMessengers.
208 G4VVisCommand::SetVisManager (this); // Sets shared pointer
211}
212
214{
216 UImanager->SetCoutDestination(nullptr);
217 std::size_t i;
218 for (i = 0; i < fSceneList.size (); ++i) {
219 delete fSceneList[i];
220 }
221 for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
222 if (fAvailableSceneHandlers[i] != NULL) {
223 delete fAvailableSceneHandlers[i];
224 }
225 }
226 for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
227 if (fAvailableGraphicsSystems[i]) {
228 delete fAvailableGraphicsSystems[i];
229 }
230 }
231 if (fVerbosity >= startup) {
232 G4cout << "Graphics systems deleted." << G4endl;
233 G4cout << "Visualization Manager deleting..." << G4endl;
234 }
235 for (i = 0; i < fMessengerList.size (); ++i) {
236 delete fMessengerList[i];
237 }
238 for (i = 0; i < fDirectoryList.size (); ++i) {
239 delete fDirectoryList[i];
240 }
241
242 delete fpDigiFilterMgr;
243 delete fpHitFilterMgr;
244 delete fpTrajFilterMgr;
245 delete fpTrajDrawModelMgr;
246 fpInstance = 0;
247}
248
250 if (!fpInstance) {
252 ("G4VisManager::GetInstance",
253 "visman0002", FatalException, "VisManager not yet instantiated");
254 }
255 return fpInstance;
256}
257
259
260 if (fInitialised && fVerbosity >= warnings) {
261 G4warn << "WARNING: G4VisManager::Initialise: already initialised."
262 << G4endl;
263 return;
264 }
265
266 if (fVerbosity >= startup) {
267 G4cout << "Visualization Manager initialising..." << G4endl;
268 }
269
270 if (fVerbosity >= parameters) {
271 G4cout <<
272 "\nYou have instantiated your own Visualization Manager, inheriting"
273 "\n G4VisManager and implementing RegisterGraphicsSystems(), in which"
274 "\n you should, normally, instantiate drivers which do not need"
275 "\n external packages or libraries, and, optionally, drivers under"
276 "\n control of environment variables."
277 "\n Also you should implement RegisterModelFactories()."
278 "\n See visualization/management/include/G4VisExecutive.hh/icc, for example."
279 "\n In your main() you will have something like:"
280 "\n G4VisManager* visManager = new G4VisExecutive;"
281 "\n visManager -> SetVerboseLevel (Verbose);"
282 "\n visManager -> Initialize ();"
283 "\n (Don't forget to delete visManager;)"
284 "\n"
285 << G4endl;
286 }
287
288 if (fVerbosity >= startup) {
289 G4cout << "Registering graphics systems..." << G4endl;
290 }
291
293
294 if (fVerbosity >= startup) {
295 G4cout <<
296 "\nYou have successfully registered the following graphics systems."
297 << G4endl;
299 G4cout << G4endl;
300 }
301
302 // Make command directories for commands instantiated in the
303 // modeling subcategory...
304 G4UIcommand* directory;
305 directory = new G4UIdirectory ("/vis/modeling/");
306 directory -> SetGuidance ("Modeling commands.");
307 fDirectoryList.push_back (directory);
308 directory = new G4UIdirectory ("/vis/modeling/trajectories/");
309 directory -> SetGuidance ("Trajectory model commands.");
310 fDirectoryList.push_back (directory);
311 directory = new G4UIdirectory ("/vis/modeling/trajectories/create/");
312 directory -> SetGuidance ("Create trajectory models and messengers.");
313 fDirectoryList.push_back (directory);
314
315 // Filtering command directory
316 directory = new G4UIdirectory ("/vis/filtering/");
317 directory -> SetGuidance ("Filtering commands.");
318 fDirectoryList.push_back (directory);
319 directory = new G4UIdirectory ("/vis/filtering/trajectories/");
320 directory -> SetGuidance ("Trajectory filtering commands.");
321 fDirectoryList.push_back (directory);
322 directory = new G4UIdirectory ("/vis/filtering/trajectories/create/");
323 directory -> SetGuidance ("Create trajectory filters and messengers.");
324 fDirectoryList.push_back (directory);
325 directory = new G4UIdirectory ("/vis/filtering/hits/");
326 directory -> SetGuidance ("Hit filtering commands.");
327 fDirectoryList.push_back (directory);
328 directory = new G4UIdirectory ("/vis/filtering/hits/create/");
329 directory -> SetGuidance ("Create hit filters and messengers.");
330 fDirectoryList.push_back (directory);
331 directory = new G4UIdirectory ("/vis/filtering/digi/");
332 directory -> SetGuidance ("Digi filtering commands.");
333 fDirectoryList.push_back (directory);
334 directory = new G4UIdirectory ("/vis/filtering/digi/create/");
335 directory -> SetGuidance ("Create digi filters and messengers.");
336 fDirectoryList.push_back (directory);
337
339
340 if (fVerbosity >= startup) {
341 G4cout << "Registering model factories..." << G4endl;
342 }
343
345
346 if (fVerbosity >= startup) {
347 G4cout <<
348 "\nYou have successfully registered the following model factories."
349 << G4endl;
350 PrintAvailableModels (fVerbosity);
351 G4cout << G4endl;
352 }
353
354 if (fVerbosity >= startup) {
355 PrintAvailableUserVisActions (fVerbosity);
356 G4cout << G4endl;
357 }
358
359 InitialiseG4ColourMap();
360
361 if (fVerbosity >= startup) {
362 G4cout <<
363 "Some /vis commands (optionally) take a string to specify colour."
364 "\n\"/vis/list\" to see available colours."
365 << G4endl;
366 }
367
368 fInitialised = true;
369}
370
371void G4VisManager::InitialiseG4ColourMap() const
372{
373 G4Colour::InitialiseColourMap(); // Initialises (if not already initialised)
374
375 // our forever 65 named colors taken long time ago from X11.
376 // Extracted from g4tools/include/tools/colors
377 // Copyright (C) 2010, Guy Barrand. All rights reserved.
378 // See the file tools.license for terms.
379
380#define TOOLS_COLORS_STAT(name,r,g,b) \
381G4Colour::AddToMap(#name, G4Colour(r,g,b));
382
383 //0-9
384 TOOLS_COLORS_STAT(aquamarine,0.496101F,0.996109F,0.828138F)
385 TOOLS_COLORS_STAT(mediumaquamarine,0.398444F,0.800793F,0.664073F)
386 // TOOLS_COLORS_STAT(black,0,0,0) (already defined)
387 // TOOLS_COLORS_STAT(blue,0,0,1) (already defined)
388 TOOLS_COLORS_STAT(cadetblue,0.371099F,0.617197F,0.62501F)
389 TOOLS_COLORS_STAT(cornflowerblue,0.390631F,0.58204F,0.925795F)
390 TOOLS_COLORS_STAT(darkslateblue,0.281254F,0.238285F,0.542977F)
391 TOOLS_COLORS_STAT(lightblue,0.675792F,0.843763F,0.898451F)
392 TOOLS_COLORS_STAT(lightsteelblue,0.68751F,0.765637F,0.867201F)
393 TOOLS_COLORS_STAT(mediumblue,0,0,0.800793F)
394
395 //10-19
396 TOOLS_COLORS_STAT(mediumslateblue,0.480476F,0.406256F,0.929702F)
397 TOOLS_COLORS_STAT(midnightblue,0.0976577F,0.0976577F,0.437507F)
398 TOOLS_COLORS_STAT(navyblue,0,0,0.500008F)
399 TOOLS_COLORS_STAT(navy,0,0,0.500008F)
400 TOOLS_COLORS_STAT(skyblue,0.527352F,0.8047F,0.917983F)
401 TOOLS_COLORS_STAT(slateblue,0.414069F,0.351568F,0.800793F)
402 TOOLS_COLORS_STAT(steelblue,0.273442F,0.50782F,0.703136F)
403 TOOLS_COLORS_STAT(coral,0.996109F,0.496101F,0.312505F)
404 // TOOLS_COLORS_STAT(cyan,0,1,1) (already defined)
405 TOOLS_COLORS_STAT(firebrick,0.695323F,0.132815F,0.132815F)
406
407 //20-29
408 // TOOLS_COLORS_STAT(brown,0.644541F,0.164065F,0.164065F) (already defined)
409 TOOLS_COLORS_STAT(gold,0.996109F,0.839857F,0)
410 TOOLS_COLORS_STAT(goldenrod,0.851575F,0.644541F,0.125002F)
411 // TOOLS_COLORS_STAT(green,0,1,0) (already defined)
412 TOOLS_COLORS_STAT(darkgreen,0,0.390631F,0)
413 TOOLS_COLORS_STAT(darkolivegreen,0.332036F,0.417975F,0.183597F)
414 TOOLS_COLORS_STAT(forestgreen,0.132815F,0.542977F,0.132815F)
415 TOOLS_COLORS_STAT(limegreen,0.195315F,0.800793F,0.195315F)
416 TOOLS_COLORS_STAT(mediumseagreen,0.234379F,0.699229F,0.441413F)
417 TOOLS_COLORS_STAT(mediumspringgreen,0,0.976577F,0.601572F)
418
419 //30-39
420 TOOLS_COLORS_STAT(palegreen,0.593759F,0.980484F,0.593759F)
421 TOOLS_COLORS_STAT(seagreen,0.17969F,0.542977F,0.339849F)
422 TOOLS_COLORS_STAT(springgreen,0,0.996109F,0.496101F)
423 TOOLS_COLORS_STAT(yellowgreen,0.601572F,0.800793F,0.195315F)
424 TOOLS_COLORS_STAT(darkslategrey,0.183597F,0.308598F,0.308598F)
425 TOOLS_COLORS_STAT(dimgrey,0.410163F,0.410163F,0.410163F)
426 TOOLS_COLORS_STAT(lightgrey,0.824231F,0.824231F,0.824231F)
427 // TOOLS_COLORS_STAT(grey,0.750011F,0.750011F,0.750011F) (already defined)
428 TOOLS_COLORS_STAT(khaki,0.937514F,0.898451F,0.546883F)
429 // TOOLS_COLORS_STAT(magenta,1,0,1) (already defined)
430
431 //40-49
432 TOOLS_COLORS_STAT(maroon,0.68751F,0.187503F,0.375006F)
433 TOOLS_COLORS_STAT(orange,0.996109F,0.644541F,0)
434 TOOLS_COLORS_STAT(orchid,0.851575F,0.437507F,0.83595F)
435 TOOLS_COLORS_STAT(darkorchid,0.597665F,0.195315F,0.796887F)
436 TOOLS_COLORS_STAT(mediumorchid,0.726574F,0.332036F,0.824231F)
437 TOOLS_COLORS_STAT(pink,0.996109F,0.750011F,0.792981F)
438 TOOLS_COLORS_STAT(plum,0.863294F,0.62501F,0.863294F)
439 // TOOLS_COLORS_STAT(red,1,0,0) (already defined)
440 TOOLS_COLORS_STAT(indianred,0.800793F,0.35938F,0.35938F)
441 TOOLS_COLORS_STAT(mediumvioletred,0.777356F,0.0820325F,0.519539F)
442
443 //50-59
444 TOOLS_COLORS_STAT(orangered,0.996109F,0.269535F,0)
445 TOOLS_COLORS_STAT(violetred,0.812512F,0.125002F,0.562509F)
446 TOOLS_COLORS_STAT(salmon,0.976577F,0.500008F,0.445319F)
447 TOOLS_COLORS_STAT(sienna,0.62501F,0.320317F,0.175784F)
448 TOOLS_COLORS_STAT(tan,0.820325F,0.703136F,0.546883F)
449 TOOLS_COLORS_STAT(thistle,0.843763F,0.746105F,0.843763F)
450 TOOLS_COLORS_STAT(turquoise,0.250004F,0.875013F,0.812512F)
451 TOOLS_COLORS_STAT(darkturquoise,0,0.8047F,0.816419F)
452 TOOLS_COLORS_STAT(mediumturquoise,0.281254F,0.816419F,0.796887F)
453 TOOLS_COLORS_STAT(violet,0.929702F,0.50782F,0.929702F)
454
455 //60-64
456 TOOLS_COLORS_STAT(blueviolet,0.539071F,0.167971F,0.882826F)
457 TOOLS_COLORS_STAT(wheat,0.957046F,0.867201F,0.699229F)
458 // TOOLS_COLORS_STAT(white,1,1,1) (already defined)
459 // TOOLS_COLORS_STAT(yellow,1,1,0) (already defined)
460 TOOLS_COLORS_STAT(greenyellow,0.675792F,0.996109F,0.18359F)
461
462#undef TOOLS_COLORS_STAT
463}
464
466
467 // Instantiate individual messengers/commands (often - but not
468 // always - one command per messenger).
469
470 G4UIcommand* directory;
471
472 directory = new G4UIdirectory ("/vis/geometry/");
473 directory -> SetGuidance("Operations on vis attributes of Geant4 geometry.");
474 fDirectoryList.push_back (directory);
477
478 directory = new G4UIdirectory ("/vis/geometry/set/");
479 directory -> SetGuidance("Set vis attributes of Geant4 geometry.");
480 fDirectoryList.push_back (directory);
491
492#ifdef G4MULTITHREADED
493 directory = new G4UIdirectory ("/vis/multithreading/");
494 directory -> SetGuidance("Commands unique to multithreading mode.");
495 fDirectoryList.push_back (directory);
496 RegisterMessenger(new G4VisCommandMultithreadingActionOnEventQueueFull);
497 RegisterMessenger(new G4VisCommandMultithreadingMaxEventQueueSize);
498#endif
499
500 directory = new G4UIdirectory ("/vis/set/");
501 directory -> SetGuidance
502 ("Set quantities for use in future commands where appropriate.");
503 fDirectoryList.push_back (directory);
513
514 directory = new G4UIdirectory ("/vis/scene/");
515 directory -> SetGuidance ("Operations on Geant4 scenes.");
516 fDirectoryList.push_back (directory);
526
527 directory = new G4UIdirectory ("/vis/scene/add/");
528 directory -> SetGuidance ("Add model to current scene.");
529 fDirectoryList.push_back (directory);
556
557 RegisterMessenger(new G4VisCommandPlotterCreate);
558 RegisterMessenger(new G4VisCommandPlotterSetLayout);
559 RegisterMessenger(new G4VisCommandPlotterAddStyle);
560 RegisterMessenger(new G4VisCommandPlotterAddRegionStyle);
561 RegisterMessenger(new G4VisCommandPlotterAddRegionParameter);
562 RegisterMessenger(new G4VisCommandPlotterClear);
563 RegisterMessenger(new G4VisCommandPlotterClearRegion);
564 RegisterMessenger(new G4VisCommandPlotterList);
565 RegisterMessenger(new G4VisCommandPlotterAddRegionH1);
566 RegisterMessenger(new G4VisCommandPlotterAddRegionH2);
567
568 directory = new G4UIdirectory ("/vis/sceneHandler/");
569 directory -> SetGuidance ("Operations on Geant4 scene handlers.");
570 fDirectoryList.push_back (directory);
575
576 directory = new G4UIdirectory ("/vis/touchable/");
577 directory -> SetGuidance ("Operations on touchables.");
578 fDirectoryList.push_back (directory);
580
581 directory = new G4UIdirectory ("/vis/touchable/set/");
582 directory -> SetGuidance ("Set vis attributes of current touchable.");
583 fDirectoryList.push_back (directory);
585
586 directory = new G4UIdirectory ("/vis/viewer/");
587 directory -> SetGuidance ("Operations on Geant4 viewers.");
588 fDirectoryList.push_back (directory);
614
615 directory = new G4UIdirectory ("/vis/viewer/default/");
616 directory -> SetGuidance("Set default values for future viewers.");
617 fDirectoryList.push_back (directory);
620
621 directory = new G4UIdirectory ("/vis/viewer/set/");
622 directory -> SetGuidance ("Set view parameters of current viewer.");
623 fDirectoryList.push_back (directory);
625
626 // *Basic* top level commands were instantiated in the constructor
627 // so that they can be used immediately after instantiation of the
628 // vis manager. Other top level commands, including "compound commands"
629 // (i.e., commands that invoke other commands) are instantiated here.
630
645
646 // List manager commands
648 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
650 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
651
652 // Trajectory filter manager commands
654 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
656 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
657
658 // Hit filter manager commands
660 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
662 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
663
664 // Digi filter manager commands
666 (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
668 (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
669}
670
671#include <tools/histo/h1d>
672#include <tools/histo/h2d>
673
674namespace {
675 template <typename HT> // tools::histo::h1d, etc
676 G4bool PrintListOfHnPlots(const G4String& plotType) { // h1, etc.
677 auto ui = G4UImanager::GetUIpointer();
678 G4bool thereArePlots = false;
679 auto keepControlVerbose = ui->GetVerboseLevel();
680 ui->SetVerboseLevel(0);
681 auto status = ui->ApplyCommand("/analysis/" + plotType + "/getVector");
682 ui->SetVerboseLevel(keepControlVerbose);
684 G4String hexString = ui->GetCurrentValues(G4String("/analysis/" + plotType + "/getVector"));
685 if(hexString.size()) {
686 void* ptr;
687 std::istringstream is(hexString);
688 is >> ptr;
689 auto _v = (const std::vector<HT*>*)ptr;
690 auto _n = _v->size();
691 if (_n > 0) {
692 thereArePlots = true;
693 G4String isare("are"),plural("s");
694 if (_n == 1) {isare = "is"; plural = "";}
695 G4cout <<
696 "There " << isare << ' ' << _n << ' ' << plotType << " histogram" << plural
697 << G4endl;
698 if (_n <= 5) {
699 for (std::size_t i = 0; i < _n; ++i) {
700 const auto& _h = (*_v)[i];
701 G4cout
702 << std::setw(3) << i
703 << " with " << std::setw(6) << _h->entries() << " entries: "
704 << _h->get_title() << G4endl;
705 }
706 }
707 }
708 }
709 }
710 return thereArePlots;
711 }
712 void PrintListOfPlots() {
713 G4bool thereArePlots = false;
714 if (PrintListOfHnPlots<tools::histo::h1d>("h1")) thereArePlots = true;
715 if (PrintListOfHnPlots<tools::histo::h2d>("h2")) thereArePlots = true;
716 if (thereArePlots) {
717 G4cout <<
718 "List them with \"/analysis/list\"."
719 "\nView them with \"/vis/plot\" or \"/vis/reviewPlots\"."
720 << G4endl;
721 }
722 }
723}
724
726 if (IsValidView ()) {
728 if (fVerbosity >= confirmations) {
729 G4cout << "G4VisManager::Enable: visualization enabled." << G4endl;
730 }
731 if (fVerbosity >= warnings) {
732 std::size_t nKeptEvents = 0;
734 if (run) nKeptEvents = run->GetEventVector()->size();
735 G4String isare("are"),plural("s");
736 if (nKeptEvents == 1) {isare = "is"; plural = "";}
737 G4cout <<
738 "There " << isare << ' ' << nKeptEvents << " kept event" << plural << '.'
739 << G4endl;
740 if (nKeptEvents > 0) {
741 G4cout <<
742 " \"/vis/reviewKeptEvents\" to review one by one."
743 "\n To see accumulated, \"/vis/enable\", then \"/vis/viewer/flush\" or \"/vis/viewer/rebuild\"."
744 << G4endl;
745 }
746 PrintListOfPlots();
747 }
748 }
749 else {
750 if (fVerbosity >= warnings) {
751 G4warn <<
752 "G4VisManager::Enable: WARNING: visualization remains disabled for"
753 "\n above reasons. Rectifying with valid vis commands will"
754 "\n automatically enable."
755 << G4endl;
756 }
757 }
758}
759
762 if (fVerbosity >= confirmations) {
763 G4cout <<
764 "G4VisManager::Disable: visualization disabled."
765 "\n The pointer returned by GetConcreteInstance will be zero."
766 "\n Note that it will become enabled after some valid vis commands."
767 << G4endl;
768 }
769 if (fVerbosity >= warnings) {
770 G4int currentTrajectoryType =
772 if (currentTrajectoryType > 0) {
773 G4warn <<
774 "You may wish to disable trajectory production too:"
775 "\n \"/tracking/storeTrajectory 0\""
776 "\nbut don't forget to re-enable with"
777 "\n \"/vis/enable\""
778 "\n \"/tracking/storeTrajectory " << currentTrajectoryType
779 << "\"\n and maybe \"/vis/viewer/rebuild\""
780 << G4endl;
781 }
782 }
783}
784
786 std::size_t nSystems = fAvailableGraphicsSystems.size ();
787 if (nSystems == 0) {
788 if (fVerbosity >= warnings) {
789 G4warn << "G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
790 "\n graphics system available!"
791 "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
792 "\n when you compiled/built the visualization code?"
793 "\n 2) Did you instantiate your own Visualization Manager and forget"
794 "\n to implement RegisterGraphicsSystems correctly?"
795 "\n 3) You can register your own graphics system, e.g.,"
796 "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
797 "\n after instantiating your vis manager and before"
798 "\n visManager->Initialize()."
799 << G4endl;
800 }
801 }
802 return fAvailableGraphicsSystems;
803}
804
806 G4bool happy = true;
807 if (pSystem) {
808 fAvailableGraphicsSystems.push_back (pSystem);
809 if (fVerbosity >= confirmations) {
810 G4cout << "G4VisManager::RegisterGraphicsSystem: "
811 << pSystem -> GetName ();
812 if (pSystem -> GetNickname () != "") {
813 G4cout << " (" << pSystem -> GetNickname () << ")";
814 }
815 G4cout << " registered." << G4endl;
816 }
817 }
818 else {
819 if (fVerbosity >= errors) {
820 G4warn << "G4VisManager::RegisterGraphicsSystem: null pointer!"
821 << G4endl;
822 }
823 happy=false;
824 }
825 return happy;
826}
827
830{
831 assert (0 != fpTrajDrawModelMgr);
832
833 const G4VTrajectoryModel* model = fpTrajDrawModelMgr->Current();
834
835 if (0 == model) {
836 // No model was registered with the trajectory model manager.
837 // Use G4TrajectoryDrawByCharge as a fallback.
838 fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("DefaultModel"));
839 if (fVerbosity >= warnings) {
840 G4warn<<"G4VisManager: Using G4TrajectoryDrawByCharge as fallback trajectory model."<<G4endl;
841 G4warn<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl;
842 }
843 }
844
845 model = fpTrajDrawModelMgr->Current();
846 assert (0 != model); // Should definitely exist now
847
848 return model;
849}
850
852{
853 fpTrajDrawModelMgr->Register(model);
854}
855
856void
858{
859 fpTrajDrawModelMgr->Register(factory);
860}
861
863{
864 fpTrajFilterMgr->Register(model);
865}
866
867void
869{
870 fpTrajFilterMgr->Register(factory);
871}
872
874{
875 fpHitFilterMgr->Register(model);
876}
877
878void
880{
881 fpHitFilterMgr->Register(factory);
882}
883
885{
886 fpDigiFilterMgr->Register(model);
887}
888
889void
891{
892 fpDigiFilterMgr->Register(factory);
893}
894
896{
897 fpTrajDrawModelMgr->SetCurrent(model);
898}
899
900void G4VisManager::BeginDraw (const G4Transform3D& objectTransform)
901{
902#ifdef G4MULTITHREADED
903 if (G4Threading::IsWorkerThread()) return;
904#endif
905 fDrawGroupNestingDepth++;
906 if (fDrawGroupNestingDepth > 1) {
908 ("G4VisManager::BeginDraw",
909 "visman0008", JustWarning,
910 "Nesting detected. It is illegal to nest Begin/EndDraw."
911 "\n Ignored");
912 return;
913 }
914 if (IsValidView ()) {
915 ClearTransientStoreIfMarked();
916 fpSceneHandler -> BeginPrimitives (objectTransform);
917 fIsDrawGroup = true;
918 }
919}
920
922{
923#ifdef G4MULTITHREADED
924 if (G4Threading::IsWorkerThread()) return;
925#endif
926 fDrawGroupNestingDepth--;
927 if (fDrawGroupNestingDepth != 0) {
928 if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
929 return;
930 }
931 if (IsValidView ()) {
932 fpSceneHandler -> EndPrimitives ();
933 }
934 fIsDrawGroup = false;
935}
936
937void G4VisManager::BeginDraw2D (const G4Transform3D& objectTransform)
938{
939#ifdef G4MULTITHREADED
940 if (G4Threading::IsWorkerThread()) return;
941#endif
942 fDrawGroupNestingDepth++;
943 if (fDrawGroupNestingDepth > 1) {
945 ("G4VisManager::BeginDraw2D",
946 "visman0009", JustWarning,
947 "Nesting detected. It is illegal to nest Begin/EndDraw2D."
948 "\n Ignored");
949 return;
950 }
951 if (IsValidView ()) {
952 ClearTransientStoreIfMarked();
953 fpSceneHandler -> BeginPrimitives2D (objectTransform);
954 fIsDrawGroup = true;
955 }
956}
957
959{
960#ifdef G4MULTITHREADED
961 if (G4Threading::IsWorkerThread()) return;
962#endif
963 fDrawGroupNestingDepth--;
964 if (fDrawGroupNestingDepth != 0) {
965 if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
966 return;
967 }
968 if (IsValidView ()) {
969 fpSceneHandler -> EndPrimitives2D ();
970 }
971 fIsDrawGroup = false;
972}
973
974template <class T> void G4VisManager::DrawT
975(const T& graphics_primitive, const G4Transform3D& objectTransform) {
976#ifdef G4MULTITHREADED
977 if (G4Threading::IsWorkerThread()) return;
978#endif
979 if (fIsDrawGroup) {
980 if (objectTransform != fpSceneHandler->GetObjectTransformation()) {
982 ("G4VSceneHandler::DrawT",
983 "visman0010", FatalException,
984 "Different transform detected in Begin/EndDraw group.");
985 }
986 fpSceneHandler -> AddPrimitive (graphics_primitive);
987 } else {
988 if (IsValidView ()) {
989 ClearTransientStoreIfMarked();
990 fpSceneHandler -> BeginPrimitives (objectTransform);
991 fpSceneHandler -> AddPrimitive (graphics_primitive);
992 fpSceneHandler -> EndPrimitives ();
993 }
994 }
995}
996
997template <class T> void G4VisManager::DrawT2D
998(const T& graphics_primitive, const G4Transform3D& objectTransform) {
999#ifdef G4MULTITHREADED
1000 if (G4Threading::IsWorkerThread()) return;
1001#endif
1002 if (fIsDrawGroup) {
1003 if (objectTransform != fpSceneHandler->GetObjectTransformation()) {
1005 ("G4VSceneHandler::DrawT",
1006 "visman0011", FatalException,
1007 "Different transform detected in Begin/EndDraw2D group.");
1008 }
1009 fpSceneHandler -> AddPrimitive (graphics_primitive);
1010 } else {
1011 if (IsValidView ()) {
1012 ClearTransientStoreIfMarked();
1013 fpSceneHandler -> BeginPrimitives2D (objectTransform);
1014 fpSceneHandler -> AddPrimitive (graphics_primitive);
1015 fpSceneHandler -> EndPrimitives2D ();
1016 }
1017 }
1018}
1019
1020void G4VisManager::Draw (const G4Circle& circle,
1021 const G4Transform3D& objectTransform)
1022{
1023 DrawT (circle, objectTransform);
1024}
1025
1026void G4VisManager::Draw (const G4Polyhedron& polyhedron,
1027 const G4Transform3D& objectTransform)
1028{
1029 DrawT (polyhedron, objectTransform);
1030}
1031
1033 const G4Transform3D& objectTransform)
1034{
1035 DrawT (line, objectTransform);
1036}
1037
1038void G4VisManager::Draw (const G4Polymarker& polymarker,
1039 const G4Transform3D& objectTransform)
1040{
1041 DrawT (polymarker, objectTransform);
1042}
1043
1044void G4VisManager::Draw (const G4Square& square,
1045 const G4Transform3D& objectTransform)
1046{
1047 DrawT (square, objectTransform);
1048}
1049
1050void G4VisManager::Draw (const G4Text& text,
1051 const G4Transform3D& objectTransform)
1052{
1053 DrawT (text, objectTransform);
1054}
1055
1056void G4VisManager::Draw2D (const G4Circle& circle,
1057 const G4Transform3D& objectTransform)
1058{
1059 DrawT2D (circle, objectTransform);
1060}
1061
1062void G4VisManager::Draw2D (const G4Polyhedron& polyhedron,
1063 const G4Transform3D& objectTransform)
1064{
1065 DrawT2D (polyhedron, objectTransform);
1066}
1067
1069 const G4Transform3D& objectTransform)
1070{
1071 DrawT2D (line, objectTransform);
1072}
1073
1074void G4VisManager::Draw2D (const G4Polymarker& polymarker,
1075 const G4Transform3D& objectTransform)
1076{
1077 DrawT2D (polymarker, objectTransform);
1078}
1079
1080void G4VisManager::Draw2D (const G4Square& square,
1081 const G4Transform3D& objectTransform)
1082{
1083 DrawT2D (square, objectTransform);
1084}
1085
1087 const G4Transform3D& objectTransform)
1088{
1089 DrawT2D (text, objectTransform);
1090}
1091
1092void G4VisManager::Draw (const G4VHit& hit) {
1093#ifdef G4MULTITHREADED
1094 if (G4Threading::IsWorkerThread()) return;
1095#endif
1096 if (fIsDrawGroup) {
1097 fpSceneHandler -> AddCompound (hit);
1098 } else {
1099 if (IsValidView ()) {
1100 ClearTransientStoreIfMarked();
1101 fpSceneHandler -> AddCompound (hit);
1102 }
1103 }
1104}
1105
1106void G4VisManager::Draw (const G4VDigi& digi) {
1107#ifdef G4MULTITHREADED
1108 if (G4Threading::IsWorkerThread()) return;
1109#endif
1110 if (fIsDrawGroup) {
1111 fpSceneHandler -> AddCompound (digi);
1112 } else {
1113 if (IsValidView ()) {
1114 ClearTransientStoreIfMarked();
1115 fpSceneHandler -> AddCompound (digi);
1116 }
1117 }
1118}
1119
1121#ifdef G4MULTITHREADED
1122 if (G4Threading::IsWorkerThread()) return;
1123#endif
1124 // A trajectory needs a trajectories model to provide G4Atts, etc.
1125 static G4TrajectoriesModel trajectoriesModel;
1126 trajectoriesModel.SetCurrentTrajectory(&traj);
1128 const G4Run* currentRun = runManager->GetCurrentRun();
1129 if (currentRun) {
1130 trajectoriesModel.SetRunID(currentRun->GetRunID());
1131 }
1132 const G4Event* currentEvent =
1134 if (currentEvent) {
1135 trajectoriesModel.SetEventID(currentEvent->GetEventID());
1136 }
1137 if (fIsDrawGroup) {
1138 fpSceneHandler -> SetModel (&trajectoriesModel);
1139 fpSceneHandler -> AddCompound (traj);
1140 fpSceneHandler -> SetModel (0);
1141 } else {
1142 if (IsValidView ()) {
1143 ClearTransientStoreIfMarked();
1144 fpSceneHandler -> SetModel (&trajectoriesModel);
1145 fpSceneHandler -> AddCompound (traj);
1146 fpSceneHandler -> SetModel (0);
1147 }
1148 }
1149}
1150
1151void G4VisManager::Draw (const G4LogicalVolume& logicalVol,
1152 const G4VisAttributes& attribs,
1153 const G4Transform3D& objectTransform) {
1154#ifdef G4MULTITHREADED
1155 if (G4Threading::IsWorkerThread()) return;
1156#endif
1157 // Find corresponding solid.
1158 G4VSolid* pSol = logicalVol.GetSolid ();
1159 Draw (*pSol, attribs, objectTransform);
1160}
1161
1162void G4VisManager::Draw (const G4VSolid& solid,
1163 const G4VisAttributes& attribs,
1164 const G4Transform3D& objectTransform) {
1165#ifdef G4MULTITHREADED
1166 if (G4Threading::IsWorkerThread()) return;
1167#endif
1168 if (fIsDrawGroup) {
1169 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
1170 solid.DescribeYourselfTo (*fpSceneHandler);
1171 fpSceneHandler -> PostAddSolid ();
1172 } else {
1173 if (IsValidView ()) {
1174 ClearTransientStoreIfMarked();
1175 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
1176 solid.DescribeYourselfTo (*fpSceneHandler);
1177 fpSceneHandler -> PostAddSolid ();
1178 }
1179 }
1180}
1181
1182void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol,
1183 const G4VisAttributes& attribs,
1184 const G4Transform3D& objectTransform) {
1185#ifdef G4MULTITHREADED
1186 if (G4Threading::IsWorkerThread()) return;
1187#endif
1188 // Note: It is tempting to use a temporary model here, as for
1189 // trajectories, in order to get at the G4Atts of the physical
1190 // volume. I tried it (JA). But it's not easy to pass the
1191 // vis attributes. Also other aspects of the model seem not to
1192 // be properly set up. So, the idea has been abandoned for the time
1193 // being. The model pointer will be null. So when picking there
1194 // will be no G4Atts from this physical volume.
1195 //
1196 // If this is called from DrawHit, for example, the user may G4Atts to the
1197 // hit and these will be available with "/vis/scene/add/hits".
1198 //
1199 // Find corresponding logical volume and solid.
1200 G4LogicalVolume* pLV = physicalVol.GetLogicalVolume ();
1201 G4VSolid* pSol = pLV -> GetSolid ();
1202 Draw (*pSol, attribs, objectTransform);
1203}
1204
1206(G4VPhysicalVolume* v, const G4Transform3D& t)
1207// Draws a geometry tree starting at the specified physical volume.
1208{
1209 auto modelingParameters = fpSceneHandler->CreateModelingParameters();
1211 const G4bool useFullExtent = true;
1212 G4PhysicalVolumeModel aPVModel(v,depth,t,modelingParameters,useFullExtent);
1213 aPVModel.DescribeYourselfTo(*fpSceneHandler);
1214 delete modelingParameters;
1215}
1216
1218 if (!fInitialised) Initialise ();
1219 if (fpGraphicsSystem) {
1220 G4VSceneHandler* pSceneHandler =
1221 fpGraphicsSystem -> CreateSceneHandler (name);
1222 if (pSceneHandler) {
1223 fAvailableSceneHandlers.push_back (pSceneHandler);
1224 fpSceneHandler = pSceneHandler; // Make current.
1225 }
1226 else {
1227 if (fVerbosity >= errors) {
1228 G4warn << "ERROR in G4VisManager::CreateSceneHandler during "
1229 << fpGraphicsSystem -> GetName ()
1230 << " scene handler creation.\n No action taken."
1231 << G4endl;
1232 }
1233 }
1234 }
1235 else PrintInvalidPointers ();
1236}
1237
1239(const G4String& name, const G4String& XGeometry)
1240{
1241
1242 if (!fInitialised) Initialise ();
1243
1244 if (!fpSceneHandler) {
1245 PrintInvalidPointers ();
1246 return;
1247 }
1248
1249 G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
1250
1251 if (!p) {
1252 if (fVerbosity >= errors) {
1253 G4warn << "ERROR in G4VisManager::CreateViewer: null pointer during "
1254 << fpGraphicsSystem -> GetName ()
1255 << " viewer creation.\n No action taken."
1256 << G4endl;
1257 }
1258 return;
1259 }
1260
1261 if (p -> GetViewId() < 0) {
1262 if (fVerbosity >= errors) {
1263 G4warn << "ERROR in G4VisManager::CreateViewer during "
1264 << fpGraphicsSystem -> GetName ()
1265 << " viewer instantiation.\n No action taken."
1266 << G4endl;
1267 }
1268 return;
1269 }
1270
1271 // Viewer is created, now we can set geometry parameters
1272 // Before 12/2008, it was done in G4VViewer.cc but it did not have to be there!
1273
1274 G4ViewParameters initialvp = p -> GetViewParameters();
1275 initialvp.SetXGeometryString(XGeometry); //parse string and store parameters
1276 p -> SetViewParameters(initialvp);
1277 p -> Initialise (); // (Viewer itself may change view parameters further.)
1278 if (p -> GetViewId() < 0) {
1279 if (fVerbosity >= errors) {
1280 G4warn << "ERROR in G4VisManager::CreateViewer during "
1281 << fpGraphicsSystem -> GetName ()
1282 << " viewer initialisation.\n No action taken."
1283 << G4endl;
1284 }
1285 return;
1286 }
1287
1288 fpViewer = p; // Make current.
1289 fpSceneHandler -> AddViewerToList (fpViewer);
1290 fpSceneHandler -> SetCurrentViewer (fpViewer);
1291 if (fVerbosity >= confirmations) {
1292 G4cout << "G4VisManager::CreateViewer: new viewer created."
1293 << G4endl;
1294 }
1295
1296 const G4ViewParameters& vp = fpViewer->GetViewParameters();
1297 if (fVerbosity >= parameters) {
1298 G4cout << " view parameters are:\n " << vp << G4endl;
1299 }
1300
1301 if (vp.IsCulling () && vp.IsCullingInvisible ()) {
1302 static G4bool warned = false;
1303 if (fVerbosity >= confirmations) {
1304 if (!warned) {
1305 G4cout <<
1306 "NOTE: objects with visibility flag set to \"false\""
1307 " will not be drawn!"
1308 "\n \"/vis/viewer/set/culling global false\" to Draw such objects."
1309 "\n Also see other \"/vis/viewer/set\" commands."
1310 << G4endl;
1311 warned = true;
1312 }
1313 }
1314 }
1315 if (vp.IsCullingCovered ()) {
1316 static G4bool warned = false;
1317 if (fVerbosity >= warnings) {
1318 if (!warned) {
1319 G4warn <<
1320 "WARNING: covered objects in solid mode will not be rendered!"
1321 "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
1322 "\n Also see other \"/vis/viewer/set\" commands."
1323 << G4endl;
1324 warned = true;
1325 }
1326 }
1327 }
1328}
1329
1331 if (fVerbosity >= confirmations) {
1332 G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl;
1333 }
1334
1335 // Change the world...
1336 G4VPhysicalVolume* pWorld =
1338 -> GetNavigatorForTracking () -> GetWorldVolume ();
1339 if (!pWorld) {
1340 if (fVerbosity >= warnings) {
1341 G4warn << "WARNING: There is no world volume!" << G4endl;
1342 }
1343 }
1344
1345 // Check scenes.
1346 G4SceneList& sceneList = fSceneList;
1347 std::size_t iScene, nScenes = sceneList.size ();
1348 for (iScene = 0; iScene < nScenes; ++iScene) {
1349 G4Scene* pScene = sceneList [iScene];
1350 std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1351 if (modelList.size ()) {
1352 G4bool modelInvalid;
1353 do { // Remove, if required, one at a time.
1354 modelInvalid = false;
1355 std::vector<G4Scene::Model>::iterator iterModel;
1356 for (iterModel = modelList.begin();
1357 iterModel != modelList.end();
1358 ++iterModel) {
1359 modelInvalid = !(iterModel->fpModel->Validate(fVerbosity>=warnings));
1360 if (modelInvalid) {
1361 // Model invalid - remove and break.
1362 if (fVerbosity >= warnings) {
1363 G4warn << "WARNING: Model \""
1364 << iterModel->fpModel->GetGlobalDescription ()
1365 <<
1366 "\" is no longer valid - being removed\n from scene \""
1367 << pScene -> GetName () << "\""
1368 << G4endl;
1369 }
1370 modelList.erase (iterModel);
1371 break;
1372 }
1373 }
1374 } while (modelInvalid);
1375
1376 if (modelList.size () == 0) {
1377 if (fVerbosity >= warnings) {
1378 G4warn << "WARNING: No run-duration models left in this scene \""
1379 << pScene -> GetName ()
1380 << "\"."
1381 << G4endl;
1382 }
1383 if (pWorld) {
1384 if (fVerbosity >= warnings) {
1385 G4warn << " Adding current world to \""
1386 << pScene -> GetName ()
1387 << "\"."
1388 << G4endl;
1389 }
1390 pScene->AddRunDurationModel(new G4PhysicalVolumeModel(pWorld),fVerbosity>=warnings);
1391 // (The above includes a re-calculation of the extent.)
1393 ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
1394 }
1395 }
1396 else {
1397 pScene->CalculateExtent(); // Recalculate extent
1399 ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
1400 }
1401 }
1402 }
1403
1404 // Check the manager's current scene...
1405 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1406 if (fVerbosity >= warnings) {
1407 G4warn << "WARNING: The current scene \""
1408 << fpScene -> GetName ()
1409 << "\" has no run duration models."
1410 << "\n Use \"/vis/scene/add/volume\" or create a new scene."
1411 << G4endl;
1412 }
1413 // Clean up
1414 if (fpSceneHandler) {
1415 fpSceneHandler->ClearTransientStore();
1416 fpSceneHandler->ClearStore();
1417 if (fpViewer) {
1418 fpViewer->NeedKernelVisit();
1419 fpViewer->SetView();
1420 fpViewer->ClearView();
1421 fpViewer->FinishView();
1422 }
1423 }
1424 }
1425}
1426
1428
1429 if (fVerbosity >= confirmations) {
1430 G4cout << "G4VisManager::NotifyHandler() called." << G4endl;
1431 }
1432
1433 if (IsValidView()) {
1434
1435 // Check scenes.
1436 G4SceneList& sceneList = fSceneList;
1437 std::size_t iScene, nScenes = sceneList.size ();
1438 for (iScene = 0; iScene < nScenes; ++iScene) {
1439 G4Scene* pScene = sceneList [iScene];
1440 std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1441
1442 if (modelList.size ()) {
1443 pScene->CalculateExtent();
1445 ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
1446 }
1447 }
1448
1449 // Check the manager's current scene...
1450 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1451 if (fVerbosity >= warnings) {
1452 G4warn << "WARNING: The current scene \""
1453 << fpScene -> GetName ()
1454 << "\" has no run duration models."
1455 << "\n Use \"/vis/scene/add/volume\" or create a new scene."
1456 << G4endl;
1457 }
1458 fpSceneHandler->ClearTransientStore();
1459 fpSceneHandler->ClearStore();
1460 fpViewer->NeedKernelVisit();
1461 fpViewer->SetView();
1462 fpViewer->ClearView();
1463 fpViewer->FinishView();
1464 }
1465 }
1466}
1467
1469{
1470 return fpTrajFilterMgr->Accept(trajectory);
1471}
1472
1474{
1475 return fpHitFilterMgr->Accept(hit);
1476}
1477
1479{
1480 return fpDigiFilterMgr->Accept(digi);
1481}
1482
1484{
1485 G4bool visible(true);
1486
1487 // See if trajectory passes filter
1488 G4bool passed = FilterTrajectory(trajectory);
1489
1490 if (!passed) {
1491 // Draw invisible trajectory if trajectory failed filter and
1492 // are filtering in soft mode
1493 if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
1494 else {return;}
1495 }
1496
1497 // Go on to draw trajectory
1498 assert (0 != fpTrajDrawModelMgr);
1499
1500 const G4VTrajectoryModel* trajectoryModel = CurrentTrajDrawModel();
1501
1502 assert (0 != trajectoryModel); // Should exist
1503
1504 if (IsValidView()) {
1505 trajectoryModel->Draw(trajectory, visible);
1506 }
1507}
1508
1510(const G4String& name,
1511 G4VUserVisAction* pVisAction,
1512 const G4VisExtent& extent) {
1513 fRunDurationUserVisActions.push_back(UserVisAction(name,pVisAction));
1514 if (extent.GetExtentRadius() > 0.) {
1515 fUserVisActionExtents[pVisAction] = extent;
1516 } else {
1517 if (fVerbosity >= warnings) {
1518 G4warn <<
1519 "WARNING: No extent set for user vis action \"" << name << "\"."
1520 << G4endl;
1521 }
1522 }
1523 if (fVerbosity >= confirmations) {
1524 G4cout
1525 << "Run duration user vis action \"" << name << "\" registered"
1526 << G4endl;
1527 }
1528}
1529
1531(const G4String& name,
1532 G4VUserVisAction* pVisAction,
1533 const G4VisExtent& extent) {
1534 fEndOfEventUserVisActions.push_back(UserVisAction(name,pVisAction));
1535 if (extent.GetExtentRadius() > 0.) {
1536 fUserVisActionExtents[pVisAction] = extent;
1537 } else {
1538 if (fVerbosity >= warnings) {
1539 G4warn <<
1540 "WARNING: No extent set for user vis action \"" << name << "\"."
1541 << G4endl;
1542 }
1543 }
1544 if (fVerbosity >= confirmations) {
1545 G4cout
1546 << "End of event user vis action \"" << name << "\" registered"
1547 << G4endl;
1548 }
1549}
1550
1552(const G4String& name,
1553 G4VUserVisAction* pVisAction,
1554 const G4VisExtent& extent) {
1555 fEndOfRunUserVisActions.push_back(UserVisAction(name,pVisAction));
1556 if (extent.GetExtentRadius() > 0.) {
1557 fUserVisActionExtents[pVisAction] = extent;
1558 } else {
1559 if (fVerbosity >= warnings) {
1560 G4warn <<
1561 "WARNING: No extent set for user vis action \"" << name << "\"."
1562 << G4endl;
1563 }
1564 }
1565 if (fVerbosity >= confirmations) {
1566 G4cout
1567 << "End of run user vis action \"" << name << "\" registered"
1568 << G4endl;
1569 }
1570}
1571
1573 if (pScene != fpScene) {
1574 // A change of scene. Therefore reset transients drawn flags. All
1575 // memory of previous transient proceessing thereby erased...
1577 }
1578 fpScene = pScene;
1579}
1580
1582 fpGraphicsSystem = pSystem;
1583 if (fVerbosity >= confirmations) {
1584 G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now "
1585 << pSystem -> GetName () << G4endl;
1586 }
1587 // If current scene handler is of same graphics system, leave unchanged.
1588 // Else find the most recent scene handler of same graphics system.
1589 // Or clear pointers.
1590 if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
1591 const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers;
1592 G4int nSH = (G4int)sceneHandlerList.size (); // No. of scene handlers.
1593 G4int iSH;
1594 for (iSH = nSH - 1; iSH >= 0; iSH--) {
1595 if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break;
1596 }
1597 if (iSH >= 0) {
1598 fpSceneHandler = sceneHandlerList [iSH];
1599 if (fVerbosity >= confirmations) {
1600 G4cout << " Scene Handler now "
1601 << fpSceneHandler -> GetName () << G4endl;
1602 }
1603 if (fpScene != fpSceneHandler -> GetScene ()) {
1604 fpScene = fpSceneHandler -> GetScene ();
1605 if (fVerbosity >= confirmations) {
1606 G4cout << " Scene now \""
1607 << fpScene -> GetName () << "\"" << G4endl;
1608 }
1609 }
1610 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1611 if (viewerList.size ()) {
1612 fpViewer = viewerList [0];
1613 if (fVerbosity >= confirmations) {
1614 G4cout << " Viewer now " << fpViewer -> GetName () << G4endl;
1615 }
1616 }
1617 else {
1618 fpViewer = 0;
1619 }
1620 }
1621 else {
1622 fpSceneHandler = 0;
1623 fpViewer = 0;
1624 }
1625 }
1626}
1627
1629 fpSceneHandler = pSceneHandler;
1630 if (fVerbosity >= confirmations) {
1631 G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \""
1632 << pSceneHandler -> GetName () << "\"" << G4endl;
1633 }
1634 if (fpScene != fpSceneHandler -> GetScene ()) {
1635 fpScene = fpSceneHandler -> GetScene ();
1636 if (fVerbosity >= confirmations) {
1637 G4cout << " Scene now \""
1638 << fpScene -> GetName () << "\"" << G4endl;
1639 }
1640 }
1641 if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
1642 fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
1643 if (fVerbosity >= confirmations) {
1644 G4cout << " Graphics system now \""
1645 << fpGraphicsSystem -> GetName () << "\"" << G4endl;
1646 }
1647 }
1648 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1649 std::size_t nViewers = viewerList.size ();
1650 if (nViewers) {
1651 std::size_t iViewer;
1652 for (iViewer = 0; iViewer < nViewers; ++iViewer) {
1653 if (fpViewer == viewerList [iViewer]) break;
1654 }
1655 if (iViewer >= nViewers) {
1656 fpViewer = viewerList [0];
1657 if (fVerbosity >= confirmations) {
1658 G4cout << " Viewer now \"" << fpViewer -> GetName () << "\""
1659 << G4endl;
1660 }
1661 }
1662 if (!IsValidView ()) {
1663 if (fVerbosity >= warnings) {
1664 G4warn <<
1665 "WARNING: Problem setting scene handler - please report circumstances."
1666 << G4endl;
1667 }
1668 }
1669 }
1670 else {
1671 fpViewer = 0;
1672 if (fVerbosity >= warnings) {
1673 G4warn <<
1674 "WARNING: No viewers for this scene handler - please create one."
1675 << G4endl;
1676 }
1677 }
1678}
1679
1681 fpViewer = pViewer;
1682 if (fpViewer == nullptr) {
1683 if (fVerbosity >= confirmations) {
1684 G4cout << "G4VisManager::SetCurrentViewer: current viewer pointer zeroed "
1685 << G4endl;
1686 }
1687 return;
1688 }
1689 if (fVerbosity >= confirmations) {
1690 G4cout << "G4VisManager::SetCurrentViewer: viewer now "
1691 << pViewer -> GetName ()
1692 << G4endl;
1693 }
1694 fpSceneHandler = fpViewer -> GetSceneHandler ();
1695 if (!fpSceneHandler) {
1696 if (fVerbosity >= warnings) {
1697 G4warn <<
1698 "WARNING: No scene handler for this viewer - please create one."
1699 << G4endl;
1700 }
1701 return;
1702 }
1703 // JA: I don't think we need this. Setview will be called when needed.
1704 // fpViewer->SetView();
1705 fpSceneHandler -> SetCurrentViewer (pViewer);
1706 fpScene = fpSceneHandler -> GetScene ();
1707 fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1708 if (!IsValidView ()) {
1709 if (fVerbosity >= warnings) {
1710 G4warn <<
1711 "WARNING: Problem setting viewer - please report circumstances."
1712 << G4endl;
1713 }
1714 }
1715}
1716
1718(Verbosity verbosity, std::ostream& out) const
1719{
1720 out << "Registered graphics systems are:\n";
1721 if (fAvailableGraphicsSystems.size ()) {
1722 for (const auto& gs: fAvailableGraphicsSystems) {
1723 const G4String& name = gs->GetName();
1724 const std::vector<G4String>& nicknames = gs->GetNicknames();
1725 if (verbosity <= warnings) {
1726 // Brief output
1727 out << " " << name << " (";
1728 for (std::size_t i = 0; i < nicknames.size(); ++i) {
1729 if (i != 0) {
1730 out << ", ";
1731 }
1732 out << nicknames[i];
1733 }
1734 out << ')';
1735 } else {
1736 // Full output
1737 out << *gs;
1738 }
1739 out << G4endl;
1740 }
1741 } else {
1742 out << " NONE!!! None registered - yet! Mmmmm!" << G4endl;
1743 }
1744}
1745
1746void G4VisManager::PrintAvailableModels (Verbosity verbosity) const
1747{
1748 {
1749 //fpTrajDrawModelMgr->Print(G4cout);
1750 G4cout << "Registered model factories:" << G4endl;
1751 const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1752 fpTrajDrawModelMgr->FactoryList();
1753 if (factoryList.empty()) G4cout << " None" << G4endl;
1754 else {
1755 std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1756 for (i = factoryList.begin(); i != factoryList.end(); ++i) {
1757 (*i)->Print(G4cout);
1758 }
1759 }
1760 G4cout << "\nRegistered models:" << G4endl;
1761 const G4VisListManager<G4VTrajectoryModel>* listManager =
1762 fpTrajDrawModelMgr->ListManager();
1763 const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1764 listManager->Map();
1765 if (modelMap.empty()) G4cout << " None" << G4endl;
1766 else {
1767 std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1768 for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1769 G4cout << " " << i->second->Name();
1770 if (i->second == listManager->Current()) G4cout << " (Current)";
1771 G4cout << G4endl;
1772 if (verbosity >= parameters) i->second->Print(G4cout);
1773 }
1774 }
1775 }
1776
1777 G4cout << G4endl;
1778
1779 {
1780 //fpTrajFilterMgr->Print(G4cout);
1781 G4cout << "Registered filter factories:" << G4endl;
1782 const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1783 factoryList = fpTrajFilterMgr->FactoryList();
1784 if (factoryList.empty()) G4cout << " None" << G4endl;
1785 else {
1786 std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1787 for (i = factoryList.begin(); i != factoryList.end(); ++i) {
1788 (*i)->Print(G4cout);
1789 }
1790 }
1791
1792 G4cout << "\nRegistered filters:" << G4endl;
1793 const std::vector<G4VFilter<G4VTrajectory>*>&
1794 filterList = fpTrajFilterMgr->FilterList();
1795 if (filterList.empty()) G4cout << " None" << G4endl;
1796 else {
1797 std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1798 for (i = filterList.begin(); i != filterList.end(); ++i) {
1799 G4cout << " " << (*i)->GetName() << G4endl;
1800 if (verbosity >= parameters) (*i)->PrintAll(G4cout);
1801 }
1802 }
1803 }
1804}
1805
1806void G4VisManager::PrintAvailableUserVisActions (Verbosity) const
1807{
1808 G4cout <<
1809 "You have successfully registered the following user vis actions."
1810 << G4endl;
1811 G4cout << "Run Duration User Vis Actions:";
1812 if (fRunDurationUserVisActions.empty()) G4cout << " none" << G4endl;
1813 else {
1814 G4cout << G4endl;
1815 for (std::size_t i = 0; i < fRunDurationUserVisActions.size(); ++i) {
1816 const G4String& name = fRunDurationUserVisActions[i].fName;
1817 G4cout << " " << name << G4endl;
1818 }
1819 }
1820
1821 G4cout << "End of Event User Vis Actions:";
1822 if (fEndOfEventUserVisActions.empty()) G4cout << " none" << G4endl;
1823 else {
1824 G4cout << G4endl;
1825 for (std::size_t i = 0; i < fEndOfEventUserVisActions.size(); ++i) {
1826 const G4String& name = fEndOfEventUserVisActions[i].fName;
1827 G4cout << " " << name << G4endl;
1828 }
1829 }
1830
1831 G4cout << "End of Run User Vis Actions:";
1832 if (fEndOfRunUserVisActions.empty()) G4cout << " none" << G4endl;
1833 else {
1834 G4cout << G4endl;
1835 for (std::size_t i = 0; i < fEndOfRunUserVisActions.size(); ++i) {
1836 const G4String& name = fEndOfRunUserVisActions[i].fName;
1837 G4cout << " " << name << G4endl;
1838 }
1839 }
1840}
1841
1842void G4VisManager::PrintAvailableColours (Verbosity) const {
1843 G4cout <<
1844 "Some /vis commands (optionally) take a string to specify colour."
1845 "\nAvailable colours:\n ";
1846 const std::map<G4String, G4Colour>& map = G4Colour::GetMap();
1847 for (std::map<G4String, G4Colour>::const_iterator i = map.begin();
1848 i != map.end();) {
1849 G4cout << i->first;
1850 if (++i != map.end()) G4cout << ", ";
1851 }
1852 G4cout << G4endl;
1853}
1854
1855void G4VisManager::PrintInvalidPointers () const {
1856 if (fVerbosity >= errors) {
1857 G4warn << "ERROR: G4VisManager::PrintInvalidPointers:";
1858 if (!fpGraphicsSystem) {
1859 G4warn << "\n null graphics system pointer.";
1860 }
1861 else {
1862 G4warn << "\n Graphics system is " << fpGraphicsSystem -> GetName ()
1863 << " but:";
1864 if (!fpScene)
1865 G4warn <<
1866 "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1867 " \"/vis/scene/create\".";
1868 if (!fpSceneHandler)
1869 G4warn <<
1870 "\n Null scene handler pointer. Use \"/vis/open\" or"
1871 " \"/vis/sceneHandler/create\".";
1872 if (!fpViewer )
1873 G4warn <<
1874 "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1875 }
1876 G4warn << G4endl;
1877 }
1878}
1879
1880#ifdef G4MULTITHREADED
1881
1882namespace {
1883 G4bool mtRunInProgress = false;
1884 std::deque<const G4Event*> mtVisEventQueue;
1885 G4Thread* mtVisSubThread = 0;
1886 G4Mutex mtVisSubThreadMutex = G4MUTEX_INITIALIZER;
1887}
1888
1889G4ThreadFunReturnType G4VisManager::G4VisSubThread(G4ThreadFunArgType p)
1890{
1891 G4VisManager* pVisManager = (G4VisManager*)p;
1892 G4VSceneHandler* pSceneHandler = pVisManager->GetCurrentSceneHandler();
1893 if (!pSceneHandler) return 0;
1894 G4Scene* pScene = pSceneHandler->GetScene();
1895 if (!pScene) return 0;
1896 G4VViewer* pViewer = pVisManager->GetCurrentViewer();
1897 if (!pViewer) return 0;
1898
1900
1901 // G4cout << "G4VisManager::G4VisSubThread: thread: "
1902 // << G4Threading::G4GetThreadId() << std::endl;
1903
1904 // Set up geometry and navigation for a thread
1909 navigator->SetWorldVolume(
1911
1912 pViewer->SwitchToVisSubThread();
1913
1914 while (true) {
1915
1916 G4MUTEXLOCK(&mtVisSubThreadMutex);
1917 std::size_t eventQueueSize = mtVisEventQueue.size();
1918 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
1919 // G4cout << "Event queue size (A): " << eventQueueSize << G4endl;
1920
1921 while (eventQueueSize) {
1922
1923 G4MUTEXLOCK(&mtVisSubThreadMutex);
1924 const G4Event* event = mtVisEventQueue.front();
1925 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
1926 // G4int eventID = event->GetEventID();
1927 // G4cout
1928 // << "G4VisManager::G4VisSubThread: Vis sub-thread: Dealing with event:
1929 // "
1930 // << eventID << G4endl;
1931
1932 // Here comes the event drawing
1933 pVisManager->SetTransientsDrawnThisEvent(false);
1934 pSceneHandler->SetTransientsDrawnThisEvent(false);
1935
1936 // We are about to draw the event (trajectories, etc.), but first we
1937 // have to clear the previous event(s) if necessary. If this event
1938 // needs to be drawn afresh, e.g., the first event or any event when
1939 // "accumulate" is not requested, the old event has to be cleared.
1940 // We have postponed this so that, for normal viewers like OGL, the
1941 // previous event(s) stay on screen until this new event comes
1942 // along. For a file-writing viewer the geometry has to be drawn.
1943 // See, for example, G4HepRepFileSceneHandler::ClearTransientStore.
1944 pVisManager->ClearTransientStoreIfMarked();
1945
1946 // Now draw the event...
1947 pSceneHandler->DrawEvent(event);
1948 ++pVisManager->fNoOfEventsDrawnThisRun;
1949
1950 if (pScene->GetRefreshAtEndOfEvent()) {
1951
1952 // ShowView guarantees the view is flushed to the screen. It also
1953 // triggers other features such picking (if enabled) and allows
1954 // file-writing viewers to close the file.
1955 pViewer->ShowView();
1956 pSceneHandler->SetMarkForClearingTransientStore(true);
1957
1958 }
1959
1960 // Testing.
1961 // std::this_thread::sleep_for(std::chrono::seconds(5));
1962
1963 // Then pop and release event
1964 G4MUTEXLOCK(&mtVisSubThreadMutex);
1965 mtVisEventQueue.pop_front();
1966 event->PostProcessingFinished();
1967 eventQueueSize = mtVisEventQueue.size();
1968 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
1969 // G4cout << "Event queue size (B): " << eventQueueSize << G4endl;
1970 }
1971
1972 G4MUTEXLOCK(&mtVisSubThreadMutex);
1973 G4int runInProgress = mtRunInProgress;
1974 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
1975 if (!runInProgress) {
1976 // EndOfRun on master thread has signalled end of run. There is
1977 // nothing to draw so...
1978 break;
1979 }
1980
1981 // Run still in progress but nothing to draw, so wait a while.
1982 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1983 }
1984
1985 // Inform viewer that we have finished all sub-thread drawing
1986 pViewer->DoneWithVisSubThread();
1987 pViewer->MovingToMasterThread();
1988 // G4cout << "G4VisManager::G4VisSubThread: Vis sub-thread: ending" << G4endl;
1989 return nullptr;
1990}
1991
1992namespace {
1993 // G4Mutex visBeginOfRunMutex = G4MUTEX_INITIALIZER;
1994 // G4Mutex visBeginOfEventMutex = G4MUTEX_INITIALIZER;
1995 G4Mutex visEndOfEventMutex = G4MUTEX_INITIALIZER;
1996 // G4Mutex visEndOfRunMutex = G4MUTEX_INITIALIZER;
1997}
1998
1999#endif
2000
2001void G4VisManager::BeginOfRun ()
2002{
2003 if (fIgnoreStateChanges) return;
2004
2005#ifdef G4MULTITHREADED
2006 if (G4Threading::IsWorkerThread()) return;
2007#endif
2008 // G4cout << "G4VisManager::BeginOfRun: thread: "
2009 // << G4Threading::G4GetThreadId() << G4endl;
2010
2012
2013 // For a fake run...
2014 G4int nEventsToBeProcessed = runManager->GetNumberOfEventsToBeProcessed();
2015 if (nEventsToBeProcessed == 0) return;
2016
2017 fNKeepRequests = 0;
2018 fEventKeepingSuspended = false;
2019 fTransientsDrawnThisRun = false;
2020 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false);
2021 fNoOfEventsDrawnThisRun = 0;
2022
2023 // Check to see if the user has created a trajectory model. If not, create
2024 // a default one. To avoid code duplication the following function is used
2025 // and its result (a const G4VTrajectoryModel*) is thrown away at this point.
2026 // The function is called again later when needed.
2028
2029#ifdef G4MULTITHREADED
2030// There is a static method G4Threading::IsMultithreadedApplication()
2031// that returns true only if G4MTRunManager is instantiated with MT
2032// installation. Thus method returns false if G4RunManager base class is
2033// instantiated even with the MT installation, or of course with sequential
2034// installation.
2036
2037 // Inform viewer that we have finished all master thread drawing for now...
2038 if (fpViewer) fpViewer->DoneWithMasterThread();
2039
2040 // Start vis sub-thread
2041// G4cout << "G4VisManager::BeginOfRun: Starting vis sub-thread" << G4endl;
2042 G4MUTEXLOCK(&mtVisSubThreadMutex);
2043 mtRunInProgress = true;
2044 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
2045 mtVisSubThread = new G4Thread;
2046 // Launch vis thread
2047 G4THREADCREATE(mtVisSubThread,G4VisSubThread,this);
2048
2049 // Tricky things for some viewers (e.g., Qt):
2050 // - Launch the vis thread
2051 // - Wait for the vis thread to set its QThread
2052 // - Then move current QOpenGL context (if Qt) to this Qthread
2053 // - Go ahead
2054 if (fpViewer) fpViewer->MovingToVisSubThread();
2055 }
2056#endif
2057}
2058
2059void G4VisManager::BeginOfEvent ()
2060{
2061 if (fIgnoreStateChanges) return;
2062
2063 if (!GetConcreteInstance()) return;
2064
2065// G4cout << "G4VisManager::BeginOfEvent: thread: "
2066// << G4Threading::G4GetThreadId() << G4endl;
2067
2068 // Some instructions that should NOT be in multithreaded version.
2069#ifndef G4MULTITHREADED
2070 // These instructions are in G4VisSubThread for multithreading.
2071 fTransientsDrawnThisEvent = false;
2072 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false);
2073#endif
2074}
2075
2076void G4VisManager::EndOfEvent ()
2077{
2078 if (fIgnoreStateChanges) return;
2079
2080 if (!GetConcreteInstance()) return;
2081
2082// G4cout << "G4VisManager::EndOfEvent: thread: "
2083// << G4Threading::G4GetThreadId() << G4endl;
2084
2085#ifdef G4MULTITHREADED
2086 G4AutoLock al(&visEndOfEventMutex);
2087 // Testing.
2088// std::this_thread::sleep_for(std::chrono::seconds(5));
2089#endif
2090
2091 // Don't call IsValidView unless there is a scene handler. This
2092 // avoids WARNING message at end of event and run when the user has
2093 // not instantiated a scene handler, e.g., in batch mode.
2094 G4bool valid = fpSceneHandler && IsValidView();
2095 if (!valid) return;
2096
2098
2099 const G4Run* currentRun = runManager->GetCurrentRun();
2100 if (!currentRun) return;
2101
2102 // This gets the thread-local event manager
2104 const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
2105 if (!currentEvent) return;
2106
2107 // Discard event if fDrawEventOnlyIfToBeKept flag is set unless the
2108 // user has requested the event to be kept.
2109 if (fDrawEventOnlyIfToBeKept) {
2110 if (!currentEvent->ToBeKept()) return;
2111 }
2112
2114
2115#ifdef G4MULTITHREADED
2116
2117 // Wait if too many events in the queue.
2118 G4MUTEXLOCK(&mtVisSubThreadMutex);
2119 std::size_t eventQueueSize = mtVisEventQueue.size();
2120 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
2121// G4cout << "Event queue size (1): " << eventQueueSize << G4endl;
2122
2123 G4bool eventQueueFull = false;
2124 while (fMaxEventQueueSize > 0 && (G4int)eventQueueSize >= fMaxEventQueueSize) {
2125
2126// G4cout << "Event queue size (2): " << eventQueueSize << G4endl;
2127 if (fWaitOnEventQueueFull) {
2128 static G4bool warned = false;
2129 if (!warned) {
2130 G4warn <<
2131 "WARNING: The number of events in the visualisation queue has exceeded"
2132 "\n the maximum, "
2133 << fMaxEventQueueSize <<
2134 ".\n If, during a multithreaded run, the simulation gets ahead of the"
2135 "\n visualisation by more than this maximum, the simulation is delayed"
2136 "\n until the vis sub-thread has drawn a few more events and removed them"
2137 "\n from the queue. You may change this maximum number of events with"
2138 "\n \"/vis/multithreading/maxEventQueueSize <N>\", where N is the maximum"
2139 "\n number you wish to allow. N <= 0 means \"unlimited\"."
2140 "\n Alternatively you may choose to discard events for drawing by setting"
2141 "\n \"/vis/multithreading/actionOnEventQueueFull discard\"."
2142 "\n To avoid visualisation altogether: \"/vis/disable\"."
2143 "\n And maybe \"/tracking/storeTrajectories 0\"."
2144 << G4endl;
2145 warned = true;
2146 }
2147 // G4cout << "Event queue size (3): " << eventQueueSize << G4endl;
2148 // Wait a while to give event drawing time to reduce the queue...
2149 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2150 // G4cout << "Event queue size (4): " << eventQueueSize << G4endl;
2151 } else {
2152 static G4bool warned = false;
2153 if (!warned) {
2154 G4warn <<
2155 "WARNING: The number of events in the visualisation queue has exceeded"
2156 "\n the maximum, "
2157 << fMaxEventQueueSize <<
2158 ".\n Some events have been discarded for drawing. You may change this"
2159 "\n behaviour with \"/vis/multithreading/actionOnEventQueueFull wait\"."
2160 "\n To avoid visualisation altogether: \"/vis/disable\"."
2161 "\n And maybe \"/tracking/storeTrajectories 0\"."
2162 << G4endl;
2163 warned = true;
2164 }
2165 eventQueueFull = true; // Causes event to be discarded for drawing.
2166 break;
2167 }
2168
2169 G4MUTEXLOCK(&mtVisSubThreadMutex);
2170 eventQueueSize = mtVisEventQueue.size();
2171 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
2172 }
2173
2174 if (!eventQueueFull) {
2175 G4MUTEXLOCK(&mtVisSubThreadMutex);
2176 // Keep event for processing and put event on vis event queue
2177 currentEvent->KeepForPostProcessing();
2178 if (fpScene->GetRefreshAtEndOfEvent()) {
2179 // Keep one event (cannot know which is last so any will do)
2180 if (fNKeepRequests == 0) {
2181 eventManager->KeepTheCurrentEvent();
2182 fNKeepRequests++;
2183 }
2184 }
2185 mtVisEventQueue.push_back(currentEvent);
2186 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
2187 }
2188
2189// G4MUTEXLOCK(&mtVisSubThreadMutex);
2190// G4int eQS = mtVisEventQueue.size();
2191// G4MUTEXUNLOCK(&mtVisSubThreadMutex);
2192// G4cout << "Event queue size (5): " << eQS << G4endl;
2193
2194#endif
2195
2196 } else {
2197
2198 // Sequential mode
2199
2200 G4int nEventsToBeProcessed = 0;
2201 G4int nKeptEvents = 0;
2202 G4int eventID = -2; // (If no run manager, triggers ShowView as normal.)
2203 if (currentRun) {
2204 nEventsToBeProcessed = runManager->GetNumberOfEventsToBeProcessed();
2205 eventID = currentEvent->GetEventID();
2206 const std::vector<const G4Event*>* events = currentRun->GetEventVector();
2207 if (events) nKeptEvents = (G4int)events->size();
2208 }
2209
2210 // We are about to draw the event (trajectories, etc.), but first we
2211 // have to clear the previous event(s) if necessary. If this event
2212 // needs to be drawn afresh, e.g., the first event or any event when
2213 // "accumulate" is not requested, the old event has to be cleared.
2214 // We have postponed this so that, for normal viewers like OGL, the
2215 // previous event(s) stay on screen until this new event comes
2216 // along. For a file-writing viewer the geometry has to be drawn.
2217 // See, for example, G4HepRepFileSceneHandler::ClearTransientStore.
2218 ClearTransientStoreIfMarked();
2219
2220 // Now draw the event...
2221 fpSceneHandler->DrawEvent(currentEvent);
2222 ++fNoOfEventsDrawnThisRun;
2223
2224 if (fpScene->GetRefreshAtEndOfEvent()) {
2225
2226 // Unless last event (in which case wait end of run)...
2227 if (eventID < nEventsToBeProcessed - 1) {
2228 // ShowView guarantees the view is flushed to the screen. It also
2229 // triggers other features such picking (if enabled) and allows
2230 // file-writing viewers to close the file.
2231 fpViewer->ShowView();
2232 } else { // Last event...
2233 // Keep, but only if user has not kept any...
2234 if (nKeptEvents == 0) {
2235 eventManager->KeepTheCurrentEvent();
2236 fNKeepRequests++;
2237 }
2238 }
2239 fpSceneHandler->SetMarkForClearingTransientStore(true);
2240
2241 }
2242 }
2243
2244 // Both modes - sequential and MT
2245
2246 if (!(fpScene->GetRefreshAtEndOfEvent())) {
2247
2248 // Accumulating events...
2249
2250 G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
2251
2252 if (maxNumberOfKeptEvents >= 0 &&
2253 fNKeepRequests >= maxNumberOfKeptEvents) {
2254
2255 fEventKeepingSuspended = true;
2256 static G4bool warned = false;
2257 if (!warned) {
2258 if (fVerbosity >= warnings) {
2259 G4warn <<
2260 "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
2261 << G4endl;
2262 if (maxNumberOfKeptEvents > 0) {
2263 G4warn <<
2264 "\n The number of events exceeds the maximum, "
2265 << maxNumberOfKeptEvents <<
2266 ", that may be kept by\n the vis manager."
2267 << G4endl;
2268 }
2269 }
2270 warned = true;
2271 }
2272
2273 } else if (maxNumberOfKeptEvents != 0) {
2274
2275 // If not disabled nor suspended.
2276 if (GetConcreteInstance() && !fEventKeepingSuspended) {
2277// G4cout <<
2278// "Requesting keeping event " << currentEvent->GetEventID()
2279// << G4endl;
2280 eventManager->KeepTheCurrentEvent();
2281 fNKeepRequests++;
2282 }
2283 }
2284 }
2285}
2286
2287void G4VisManager::EndOfRun ()
2288{
2289 if (fIgnoreStateChanges) return;
2290
2291#ifdef G4MULTITHREADED
2292 if (G4Threading::IsWorkerThread()) return;
2293#endif
2294
2295 // G4cout << "G4VisManager::EndOfRun: thread: "
2296 // << G4Threading::G4GetThreadId() << G4endl;
2297
2299
2300 // For a fake run...
2301 G4int nEventsToBeProcessed = runManager->GetNumberOfEventsToBeProcessed();
2302 if (nEventsToBeProcessed == 0) return;
2303
2304 const G4Run* currentRun = runManager->GetCurrentRun();
2305 if (!currentRun) return;
2306
2307#ifdef G4MULTITHREADED
2308 // G4AutoLock al(&visEndOfRunMutex); ???
2310 // Reset flag so that sub-thread exits when it has finished processing.
2311 G4MUTEXLOCK(&mtVisSubThreadMutex);
2312 mtRunInProgress = false;
2313 G4MUTEXUNLOCK(&mtVisSubThreadMutex);
2314 // Wait for sub-thread to finish.
2315 G4THREADJOIN(*mtVisSubThread);
2316 delete mtVisSubThread;
2317 if (fpViewer) fpViewer->SwitchToMasterThread();
2318 }
2319#endif
2320
2321#ifdef G4MULTITHREADED
2322 // Print warning about discarded events, if any.
2323 // Don't call IsValidView unless there is a scene handler. This
2324 // avoids WARNING message from IsValidView() when the user has
2325 // not instantiated a scene handler, e.g., in batch mode.
2326 if (fpSceneHandler && IsValidView()) { // Events should have been drawn
2327 G4int noOfEventsRequested = runManager->GetNumberOfEventsToBeProcessed();
2328 if (fNoOfEventsDrawnThisRun != noOfEventsRequested) {
2329 if (!fWaitOnEventQueueFull && fVerbosity >= warnings) {
2330 G4warn
2331 << "WARNING: Number of events drawn this run, "
2332 << fNoOfEventsDrawnThisRun << ", is different to number requested, "
2333 << noOfEventsRequested <<
2334 ".\n (This is because you requested \"/vis/multithreading/actionOnEventQueueFull discard\".)"
2335 << G4endl;
2336 }
2337 }
2338 }
2339#endif
2340
2341 G4int nKeptEvents = 0;
2342 const std::vector<const G4Event*>* events = currentRun->GetEventVector();
2343 if (events) nKeptEvents = (G4int)events->size();
2344 if (fVerbosity >= warnings && nKeptEvents > 0) {
2345 G4warn << nKeptEvents;
2346 if (nKeptEvents == 1) G4warn << " event has";
2347 else G4warn << " events have";
2348 G4warn << " been kept for refreshing and/or reviewing." << G4endl;
2349 if (nKeptEvents != fNKeepRequests) {
2350 G4warn << " (Note: ";
2351 if (fNKeepRequests == 0) {
2352 G4warn << "No keep requests were";
2353 } else if (fNKeepRequests == 1) {
2354 G4warn << "1 keep request was";
2355 } else {
2356 G4warn << fNKeepRequests << " keep requests were";
2357 }
2358 G4warn << " made by the vis manager.";
2359 if (fNKeepRequests == 0) {
2360 G4warn <<
2361 "\n The kept events are those you have asked to be kept in your user action(s).)";
2362 } else {
2363 G4warn <<
2364 "\n The same or further events may have been kept by you in your user action(s).)";
2365 }
2366 G4warn << G4endl;
2367 }
2368 G4warn <<
2369 " \"/vis/reviewKeptEvents\" to review one by one."
2370 "\n To see accumulated, \"/vis/enable\", then \"/vis/viewer/flush\" or \"/vis/viewer/rebuild\"."
2371 << G4endl;
2372 }
2373
2374 if (fVerbosity >= warnings) PrintListOfPlots();
2375
2376 if (fEventKeepingSuspended && fVerbosity >= warnings) {
2377 G4warn <<
2378 "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
2379 << G4endl;
2380 if (fpScene->GetMaxNumberOfKeptEvents() > 0) {
2381 G4warn <<
2382 "\n The number of events in the run exceeded the maximum, "
2383 << fpScene->GetMaxNumberOfKeptEvents() <<
2384 ", that may be\n kept by the vis manager." <<
2385 "\n The number of events kept by the vis manager can be changed with"
2386 "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
2387 "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
2388 << G4endl;
2389 }
2390 }
2391
2392 // Don't call IsValidView unless there is a scene handler. This
2393 // avoids WARNING message at end of event and run when the user has
2394 // not instantiated a scene handler, e.g., in batch mode.
2395 G4bool valid = fpSceneHandler && IsValidView();
2396 if (GetConcreteInstance() && valid) {
2397// // ???? I can't remember why
2398// // if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
2399// // is here. It prevents ShowView at end of run, which seems to be OK
2400// // for sequential mode, but MT mode seems to need it (I have not
2401// // figured out why). ???? JA ????
2402// if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
2403 if (fpScene->GetRefreshAtEndOfRun()) {
2404 fpSceneHandler->DrawEndOfRunModels();
2405 // An extra refresh for auto-refresh viewers.
2406 // ???? I DON'T WHY THIS IS NECESSARY ???? JA ????
2407 if (fpViewer->GetViewParameters().IsAutoRefresh()) {
2408 fpViewer->RefreshView();
2409 }
2410 // ShowView guarantees the view is flushed to the screen. It also
2411 // triggers other features such picking (if enabled) and allows
2412 // file-writing viewers to close the file.
2413 fpViewer->ShowView();
2414 fpSceneHandler->SetMarkForClearingTransientStore(true);
2415 } else {
2416 if (fpGraphicsSystem->GetFunctionality() ==
2418 if (fVerbosity >= warnings) {
2419 G4warn << "\"/vis/viewer/update\" to close file." << G4endl;
2420 }
2421 }
2422 }
2423// }
2424 }
2425 fEventRefreshing = false;
2426}
2427
2428void G4VisManager::ClearTransientStoreIfMarked(){
2429 // Assumes valid view.
2430 if (fpSceneHandler->GetMarkForClearingTransientStore()) {
2431 fpSceneHandler->SetMarkForClearingTransientStore(false);
2432 fpSceneHandler->ClearTransientStore();
2433 }
2434 // Record if transients drawn. These local flags are only set
2435 // *after* ClearTransientStore. In the code in G4VSceneHandler
2436 // triggered by ClearTransientStore, use these flags so that
2437 // event refreshing is not done too early.
2438 fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent();
2439 fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun();
2440}
2441
2443{
2444 fTransientsDrawnThisRun = false;
2445 fTransientsDrawnThisEvent = false;
2447 for (i = fAvailableSceneHandlers.begin();
2448 i != fAvailableSceneHandlers.end(); ++i) {
2449 (*i)->SetTransientsDrawnThisEvent(false);
2450 (*i)->SetTransientsDrawnThisRun(false);
2451 }
2452}
2453
2455 G4String viewerShortName = viewerName.substr(0, viewerName.find (' '));
2456 return G4StrUtil::strip_copy(viewerShortName);
2457}
2458
2459G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const {
2460 G4String viewerShortName = ViewerShortName (viewerName);
2461 std::size_t nHandlers = fAvailableSceneHandlers.size ();
2462 std::size_t iHandler, iViewer;
2463 G4VViewer* viewer = 0;
2464 G4bool found = false;
2465 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
2466 G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler];
2467 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
2468 for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
2469 viewer = viewerList [iViewer];
2470 if (viewerShortName == viewer -> GetShortName ()) {
2471 found = true;
2472 break;
2473 }
2474 }
2475 if (found) break;
2476 }
2477 if (found) return viewer;
2478 else return 0;
2479}
2480
2481std::vector<G4String> G4VisManager::VerbosityGuidanceStrings;
2482
2484 G4String rs;
2485 switch (verbosity) {
2486 case quiet: rs = "quiet (0)"; break;
2487 case startup: rs = "startup (1)"; break;
2488 case errors: rs = "errors (2)"; break;
2489 case warnings: rs = "warnings (3)"; break;
2490 case confirmations: rs = "confirmations (4)"; break;
2491 case parameters: rs = "parameters (5)"; break;
2492 case all: rs = "all (6)"; break;
2493 }
2494 return rs;
2495}
2496
2499 G4String ss = G4StrUtil::to_lower_copy(verbosityString);
2500 Verbosity verbosity;
2501 if (ss[0] == 'q') verbosity = quiet;
2502 else if (ss[0] == 's') verbosity = startup;
2503 else if (ss[0] == 'e') verbosity = errors;
2504 else if (ss[0] == 'w') verbosity = warnings;
2505 else if (ss[0] == 'c') verbosity = confirmations;
2506 else if (ss[0] == 'p') verbosity = parameters;
2507 else if (ss[0] == 'a') verbosity = all;
2508 else {
2509 G4int intVerbosity;
2510 std::istringstream is(ss);
2511 is >> intVerbosity;
2512 if (!is) {
2513 G4warn << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
2514 << verbosityString << "\"";
2515 for (std::size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) {
2516 G4warn << '\n' << VerbosityGuidanceStrings[i];
2517 }
2518 verbosity = warnings;
2519 G4warn << "\n Returning " << VerbosityString(verbosity)
2520 << G4endl;
2521 }
2522 else {
2523 verbosity = GetVerbosityValue(intVerbosity);
2524 }
2525 }
2526 return verbosity;
2527}
2528
2530 Verbosity verbosity;
2531 if (intVerbosity < quiet) verbosity = quiet;
2532 else if (intVerbosity > all) verbosity = all;
2533 else verbosity = Verbosity(intVerbosity);
2534 return verbosity;
2535}
2536
2538 return fVerbosity;
2539}
2540
2542 fVerbosity = GetVerbosityValue(intVerbosity);
2543}
2544
2545void G4VisManager::SetVerboseLevel (const G4String& verbosityString) {
2546 fVerbosity = GetVerbosityValue(verbosityString);
2547}
2548
2549G4bool G4VisManager::IsValidView () {
2550
2551 if (!fInitialised) Initialise ();
2552
2553 static G4bool noGSPrinting = true;
2554 if (!fpGraphicsSystem) {
2555 // Limit printing - we do not want printing if the user simply does
2556 // not want to use graphics, e.g., in batch mode.
2557 if (noGSPrinting) {
2558 noGSPrinting = false;
2559 if (fVerbosity >= warnings) {
2560 G4warn <<
2561 "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
2562 "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
2563 "\n Alternatively, to avoid this message, suppress instantiation of vis"
2564 "\n manager (G4VisExecutive) and ensure drawing code is executed only if"
2565 "\n G4VVisManager::GetConcreteInstance() is non-zero."
2566 << G4endl;
2567 }
2568 }
2569 return false;
2570 }
2571
2572 if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
2573 if (fVerbosity >= errors) {
2574 G4warn <<
2575 "ERROR: G4VisManager::IsValidView(): Current view is not valid."
2576 << G4endl;
2577 PrintInvalidPointers ();
2578 }
2579 return false;
2580 }
2581
2582 if (fpScene != fpSceneHandler -> GetScene ()) {
2583 if (fVerbosity >= errors) {
2584 G4warn << "ERROR: G4VisManager::IsValidView ():";
2585 if (fpSceneHandler -> GetScene ()) {
2586 G4warn <<
2587 "\n The current scene \""
2588 << fpScene -> GetName ()
2589 << "\" is not handled by"
2590 "\n the current scene handler \""
2591 << fpSceneHandler -> GetName ()
2592 << "\""
2593 "\n (it currently handles scene \""
2594 << fpSceneHandler -> GetScene () -> GetName ()
2595 << "\")."
2596 "\n Either:"
2597 "\n (a) attach it to the scene handler with"
2598 "\n /vis/sceneHandler/attach "
2599 << fpScene -> GetName ()
2600 << ", or"
2601 "\n (b) create a new scene handler with "
2602 "\n /vis/sceneHandler/create <graphics-system>,"
2603 "\n in which case it should pick up the the new scene."
2604 << G4endl;
2605 }
2606 else {
2607 G4warn << "\n Scene handler \""
2608 << fpSceneHandler -> GetName ()
2609 << "\" has null scene pointer."
2610 "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
2611 << G4endl;
2612 }
2613 }
2614 return false;
2615 }
2616
2617 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
2618 if (viewerList.size () == 0) {
2619 if (fVerbosity >= errors) {
2620 G4warn <<
2621 "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
2622 << fpSceneHandler -> GetName ()
2623 << "\" has no viewers. Do /vis/viewer/create."
2624 << G4endl;
2625 }
2626 return false;
2627 }
2628
2629 G4bool isValid = true;
2630 if (fpScene -> IsEmpty ()) { // Add world by default if possible...
2631 G4bool warn(fVerbosity >= warnings);
2632 G4bool successful = fpScene -> AddWorldIfEmpty (warn);
2633 if (!successful || fpScene -> IsEmpty ()) { // If still empty...
2634 if (fVerbosity >= errors) {
2635 G4warn << "ERROR: G4VisManager::IsValidView ():";
2636 G4warn <<
2637 "\n Attempt at some drawing operation when scene is empty."
2638 "\n Maybe the geometry has not yet been defined."
2639 " Try /run/initialize."
2640 "\n Or use \"/vis/scene/add/extent\"."
2641 << G4endl;
2642 }
2643 isValid = false;
2644 }
2645 else {
2646 G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers");
2647 if (fVerbosity >= warnings) {
2648 G4warn <<
2649 "WARNING: G4VisManager: the scene was empty, \"world\" has been"
2650 "\n added and the scene handlers notified.";
2651 G4warn << G4endl;
2652 }
2653 }
2654 }
2655 return isValid;
2656}
2657
2658void
2660{
2661 if (fVerbosity >= warnings) {
2662 G4warn<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl;
2663 G4warn<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl;
2664 G4warn<<"class. See G4VisExecutive for an example."<<G4endl;
2665 }
2666}
2667
2668#ifdef G4MULTITHREADED
2669void G4VisManager::SetUpForAThread()
2670{
2671 new G4VisStateDependent(this);
2672}
2673#endif
2674
2676{
2677 fIgnoreStateChanges = val;
2678}
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::vector< G4VSceneHandler * >::const_iterator G4SceneHandlerListConstIterator
#define G4warn
Definition: G4Scene.cc:41
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4THREADJOIN(worker)
Definition: G4Threading.hh:259
void G4THREADCREATE(_Worker *&worker, _Func func, _Args... args)
Definition: G4Threading.hh:268
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
G4DummyThread G4Thread
Definition: G4Threading.hh:247
void * G4ThreadFunReturnType
Definition: G4Threading.hh:110
void * G4ThreadFunArgType
Definition: G4Threading.hh:111
std::mutex G4Mutex
Definition: G4Threading.hh:81
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
@ fCommandSucceeded
#define TOOLS_COLORS_STAT(name, r, g, b)
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static void InitialiseColourMap()
Definition: G4Colour.cc:135
static const std::map< G4String, G4Colour > & GetMap()
Definition: G4Colour.cc:173
void KeepTheCurrentEvent()
const G4Event * GetConstCurrentEvent()
static G4EventManager * GetEventManager()
G4bool ToBeKept() const
Definition: G4Event.hh:102
G4int GetEventID() const
Definition: G4Event.hh:118
void KeepForPostProcessing() const
Definition: G4Event.hh:104
static pool_type * GetPool()
G4VSolid * GetSolid() const
void SetWorldVolume(G4VPhysicalVolume *pWorld)
void DescribeYourselfTo(G4VGraphicsScene &)
static G4RunManager * GetMasterRunManager()
static G4RunManagerKernel * GetMasterRunManagerKernel()
static G4RunManagerKernel * GetRunManagerKernel()
G4TrackingManager * GetTrackingManager() const
G4int GetNumberOfEventsToBeProcessed() const
static G4RunManager * GetRunManager()
const G4Run * GetCurrentRun() const
Definition: G4Run.hh:49
G4int GetRunID() const
Definition: G4Run.hh:78
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:96
void CalculateExtent()
Definition: G4Scene.cc:64
G4bool AddRunDurationModel(G4VModel *, G4bool warn=false)
Definition: G4Scene.cc:160
G4bool GetRefreshAtEndOfEvent() const
const G4String & GetName() const
G4bool GetRefreshAtEndOfRun() const
G4int GetMaxNumberOfKeptEvents() const
static pool_type * GetPool()
Definition: G4Text.hh:72
G4int GetStoreTrajectory() const
void SetCurrentTrajectory(const G4VTrajectory *pTraj)
void SetEventID(G4int eventID)
void SetRunID(G4int runID)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:747
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:495
void SetUpForSpecialThread(const G4String &aPrefix)
Definition: G4UImanager.cc:893
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
Functionality GetFunctionality() const
Definition: G4VHit.hh:48
G4LogicalVolume * GetLogicalVolume() const
virtual void ClearTransientStore()
G4bool GetTransientsDrawnThisEvent() const
void SetTransientsDrawnThisRun(G4bool)
void DrawEvent(const G4Event *)
G4ModelingParameters * CreateModelingParameters()
void SetMarkForClearingTransientStore(G4bool)
G4Scene * GetScene() const
void SetTransientsDrawnThisEvent(G4bool)
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
void NeedKernelVisit()
Definition: G4VViewer.cc:80
virtual void FinishView()
Definition: G4VViewer.cc:103
void RefreshView()
virtual void ClearView()=0
virtual void ShowView()
Definition: G4VViewer.cc:105
virtual void SetView()=0
static void SetVisManager(G4VisManager *pVisManager)
static G4VVisManager * GetConcreteInstance()
static void SetConcreteInstance(G4VVisManager *)
void SetXGeometryString(const G4String &)
G4bool IsCulling() const
G4bool IsCullingInvisible() const
G4bool IsAutoRefresh() const
G4bool IsCullingCovered() const
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:75
bool Accept(const T &)
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())
void PrintAvailableGraphicsSystems(Verbosity, std::ostream &=G4cout) const
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 RegisterModelFactory(G4TrajDrawModelFactory *factory)
void EndDraw2D()
G4bool FilterHit(const G4VHit &)
G4VViewer * GetCurrentViewer() const
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
virtual void RegisterModelFactories()
virtual ~G4VisManager()
G4VSceneHandler * GetCurrentSceneHandler() const
static Verbosity GetVerbosity()
void Initialise()
void RegisterMessengers()
void ResetTransientsDrawnFlags()
G4bool FilterTrajectory(const G4VTrajectory &)
void SetVerboseLevel(G4int)
void IgnoreStateChanges(G4bool)
friend class G4VisStateDependent
void NotifyHandlers()
G4VisManager(const G4String &verbosityString="warnings")
void DrawGeometry(G4VPhysicalVolume *, const G4Transform3D &t=G4Transform3D())
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 &)
void Register(Model *)
const std::vector< Factory * > & FactoryList() const
G4String Placement() const
const char * name(G4int ptype)
G4String strip_copy(G4String str, char ch=' ')
Return copy of string with leading and trailing characters removed.
G4String to_lower_copy(G4String str)
Return lowercased copy of string.
G4bool IsWorkerThread()
Definition: G4Threading.cc:123
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:130