Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VisManager.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29
30// Class Description:
31//
32// The GEANT4 Visualization Manager - John Allison 02/Jan/1996.
33//
34// G4VisManager is a "Singleton", i.e., only one instance of it or any
35// derived class may exist. A G4Exception is thrown if an attempt is
36// made to instantiate more than one.
37//
38// It is also an abstract class, so the user must derive his/her own
39// class from G4VisManager, implement the pure virtual function
40// RegisterGraphicsSystems, and instantiate an object of the derived
41// class - for an example see
42// visualization/include/G4VisExecutive.hh/icc.
43//
44// The recommended way for users to obtain a pointer to the vis
45// manager is with G4VVisManager::GetConcreteInstance (), being always
46// careful to test for non-zero. This pointer is non-zero only when
47// (a) an object of the derived class exists and (b) when there is a
48// valid viewer available.
49//
50// Graphics system registration is normally done through the protected
51// pure virtual function RegisterGraphicsSystems called from
52// Initialise (). You can also use the public function
53// RegisterGraphicsSystem (new MyGraphicsSystem) if you have your own
54// graphics system. A graphics system is, in effect, a factory for
55// scene handlers and viewers.
56//
57// The VisManager creates and manages graphics systems, scenes, scene
58// handlers, viewers and some models and model makers. You can have
59// any number. It has the concept of a "current viewer", and the
60// "current scene handler", the "current scene" and the "current
61// graphics system" which go with it. You can select the current
62// viewer. Most of the the operations of the VisManager take place
63// with the current viewer, in particular, the Draw operations.
64//
65// Each scene comprises drawable objects such as detector components
66// and trajectories, hits and digis when appropriate. A scene handler
67// translates a scene into graphics-system-specific function calls
68// and, possibly, a graphics-system-dependent database - display
69// lists, scene graphs, etc. Each viewer has its "view parameters"
70// (see class description of G4ViewParameters for available parameters
71// and also for a description of the concept of a "standard view" and
72// all that).
73//
74// A friend class G4VisStateDependent is "state dependent", i.e., it
75// is notified on change of state (G4ApplicationState). This is used
76// to message the G4VisManager to draw hits, digis and trajectories in
77// the current scene at the end of event, as required.
78
79#ifndef G4VISMANAGER_HH
80#define G4VISMANAGER_HH
81
82// Temporary definition until Xeon Phi can handle full C++11.
83#ifndef __MIC__
84#define G4VIS_USE_STD11
85#endif
86
87#include "G4VVisManager.hh"
88
89#include "globals.hh"
92#include "G4NullModel.hh"
93#include "G4SceneHandlerList.hh"
94#include "G4SceneList.hh"
96#include "G4Transform3D.hh"
97#include "G4UImessenger.hh"
98
99#include <iostream>
100#include <vector>
101#include <map>
102
103#include "G4Threading.hh"
104
105class G4Scene;
106class G4UIcommand;
107class G4UImessenger;
110class G4VUserVisAction;
111template <typename> class G4VFilter;
112template <typename> class G4VisFilterManager;
113template <typename> class G4VisModelManager;
114template <typename> class G4VModelFactory;
115class G4Event;
116
117// Useful typedef's
122
124
125 // Management friends...
126 friend class G4VSceneHandler;
127 friend class G4VViewer;
129 friend class G4VisCommandList;
130
131 // operator << friends...
132 friend std::ostream& operator << (std::ostream&, const G4VGraphicsSystem&);
133 friend std::ostream& operator << (std::ostream&, const G4VSceneHandler&);
134
135public: // With description
136
138 quiet, // Nothing is printed.
139 startup, // Startup and endup messages are printed...
140 errors, // ...and errors...
141 warnings, // ...and warnings...
142 confirmations, // ...and confirming messages...
143 parameters, // ...and parameters of scenes and views...
144 all // ...and everything available.
145 };
146 // Simple graded message scheme.
147
148protected: // With description
149
150 G4VisManager (const G4String& verbosityString = "warnings");
151 // The constructor is protected so that an object of the derived
152 // class may be constructed.
153
154public: // With description
155
156 virtual ~G4VisManager ();
157
158private:
159
160 // Private copy constructor and assigment operator - copying and
161 // assignment not allowed. Keeps CodeWizard happy.
162 G4VisManager (const G4VisManager&);
163 G4VisManager& operator = (const G4VisManager&);
164
165public:
166 static G4VisManager* GetInstance ();
167 // Returns pointer to itself. Throws a G4Exception if called before
168 // instantiation. Intended only for use within the vis category; the
169 // normal user should instead use G4VVisManager::GetConcreteInstance()
170 // to get a "higher level" pointer for general use - but always test
171 // for non-zero.
172
173public: // With description
174
175 void Initialise ();
176 void Initialize (); // Alias Initialise ()
177
178 // Optional registration of user vis actions. Added to scene with
179 // /vis/scene/add/userAction.
181 (const G4String& name, G4VUserVisAction*,
182 const G4VisExtent& = G4VisExtent());
184 (const G4String& name, G4VUserVisAction*,
185 const G4VisExtent& = G4VisExtent());
187 (const G4String& name, G4VUserVisAction*,
188 const G4VisExtent& = G4VisExtent());
189
191 // Register an individual graphics system. Normally this is done in
192 // a sub-class implementation of the protected virtual function,
193 // RegisterGraphicsSystems. See, e.g., G4VisExecutive.icc.
194
196 // Register trajectory draw model factory. Assumes ownership of factory.
197
199 // Register trajectory model. Assumes ownership of model.
200
202 // Register trajectory filter model factory. Assumes ownership of factory.
203
205 // Register trajectory filter model. Assumes ownership of model.
206
208 // Register trajectory hit model factory. Assumes ownership of factory.
209
210 void RegisterModel(G4VFilter<G4VHit>* filter);
211 // Register trajectory hit model. Assumes ownership of model.
212
214 // Register trajectory digi model factory. Assumes ownership of factory.
215
216 void RegisterModel(G4VFilter<G4VDigi>* filter);
217 // Register trajectory digi model. Assumes ownership of model.
218
219 void SelectTrajectoryModel(const G4String& model);
220 // Set default trajectory model. Useful for use in compiled code
221
223 // Register messenger. Assumes ownership of messenger.
224
225 /////////////////////////////////////////////////////////////////
226 // Now functions that implement the pure virtual functions of
227 // G4VVisManager for drawing various visualization primitives, useful
228 // for representing hits, digis, etc.
229
230 void Draw (const G4Circle&,
231 const G4Transform3D& objectTransformation = G4Transform3D());
232
233 void Draw (const G4Polyhedron&,
234 const G4Transform3D& objectTransformation = G4Transform3D());
235
236 void Draw (const G4Polyline&,
237 const G4Transform3D& objectTransformation = G4Transform3D());
238
239 void Draw (const G4Polymarker&,
240 const G4Transform3D& objectTransformation = G4Transform3D());
241
242 void Draw (const G4Square&,
243 const G4Transform3D& objectTransformation = G4Transform3D());
244
245 void Draw (const G4Text&,
246 const G4Transform3D& objectTransformation = G4Transform3D());
247
248 void Draw2D (const G4Circle&,
249 const G4Transform3D& objectTransformation = G4Transform3D());
250
251 void Draw2D (const G4Polyhedron&,
252 const G4Transform3D& objectTransformation = G4Transform3D());
253
254 void Draw2D (const G4Polyline&,
255 const G4Transform3D& objectTransformation = G4Transform3D());
256
257 void Draw2D (const G4Polymarker&,
258 const G4Transform3D& objectTransformation = G4Transform3D());
259
260 void Draw2D (const G4Square&,
261 const G4Transform3D& objectTransformation = G4Transform3D());
262
263 void Draw2D (const G4Text&,
264 const G4Transform3D& objectTransformation = G4Transform3D());
265
266 ////////////////////////////////////////////////////////////////////
267 // Now functions that implement the pure virtual functions of
268 // G4VVisManager for drawing a GEANT4 object. Note that the
269 // visualization attributes needed in some cases override any
270 // visualization attributes that are associated with the object
271 // itself - thus you can, for example, change the colour of a
272 // physical volume.
273
274 void Draw (const G4VTrajectory&);
275
276 void Draw (const G4VHit&);
277
278 void Draw (const G4VDigi&);
279
280 void Draw (const G4LogicalVolume&, const G4VisAttributes&,
281 const G4Transform3D& objectTransformation = G4Transform3D());
282
283 void Draw (const G4VPhysicalVolume&, const G4VisAttributes&,
284 const G4Transform3D& objectTransformation = G4Transform3D());
285
286 void Draw (const G4VSolid&, const G4VisAttributes&,
287 const G4Transform3D& objectTransformation = G4Transform3D());
288
289 void DrawGeometry
291 // Draws a geometry tree starting at the specified physical volume.
292
293 //////////////////////////////////////////////////////////////////////
294 // Optional methods that you may use to bracket a series of Draw
295 // messages that have identical objectTransformation to improve
296 // drawing speed. Use Begin/EndDraw for a series of Draw messages,
297 // Begin/EndDraw2D for a series of Draw2D messages. Do not mix Draw
298 // and Draw2D messages.
299
300 void BeginDraw
301 (const G4Transform3D& objectTransformation = G4Transform3D());
302
303 void EndDraw ();
304
305 void BeginDraw2D
306 (const G4Transform3D& objectTransformation = G4Transform3D());
307
308 void EndDraw2D ();
309
310 ////////////////////////////////////////////////////////////////////////
311 // Now other pure virtual functions of G4VVisManager...
312
313 void GeometryHasChanged ();
314 // Used by run manager to notify change.
315
317 // This method shoud be invoked by a class that has its own event loop,
318 // such as the RayTracer, material scanner, etc. If the argument is true,
319 // the following state changes among Idle, GeomClosed and EventProc are
320 // caused by such a class, and thus not by the ordinary event simulation.
321 // The same method with false should be invoked once such an event loop
322 // is over.
323
324 void NotifyHandlers();
325 // Notify scene handlers (G4VGraphicsScene objects) that the scene
326 // has changed so that they may rebuild their graphics database, if
327 // any, and redraw all views.
328
329 void DispatchToModel(const G4VTrajectory&);
330 // Draw the trajectory.
331
333 G4bool FilterHit(const G4VHit&);
334 G4bool FilterDigi(const G4VDigi&);
335
336#ifdef G4MULTITHREADED
337
338 virtual void SetUpForAThread();
339 // This method is invoked by G4WorkerRunManager
340
341 static G4ThreadFunReturnType G4VisSubThread(G4ThreadFunArgType);
342 // Vis sub-thread function.
343
344#endif
345
346 ////////////////////////////////////////////////////////////////////////
347 // Administration routines.
348
349 void CreateSceneHandler (const G4String& name = "");
350 // Creates scene handler for the current system.
351
352 void CreateViewer (const G4String& name = "", const G4String& XGeometry = "");
353 // Creates viewer for the current scene handler.
354
355private:
356
357 void BeginOfRun ();
358
359 void BeginOfEvent ();
360
361 void EndOfEvent ();
362 // This is called on change of state (G4ApplicationState). It is
363 // used to draw hits, digis and trajectories if included in the
364 // current scene at the end of event, as required.
365
366 void EndOfRun ();
367
368public: // With description
369
370 /////////////////////////////////////////////////////////////////////
371 // Access functions.
372
373 void Enable();
374 void Disable();
376 // Global enable/disable functions.
377
379
381 UserVisAction(const G4String& name, G4VUserVisAction* pUserVisAction)
382 :fName(name), fpUserVisAction(pUserVisAction) {}
385 };
386 const std::vector<UserVisAction>& GetRunDurationUserVisActions () const;
387 const std::vector<UserVisAction>& GetEndOfEventUserVisActions () const;
388 const std::vector<UserVisAction>& GetEndOfRunUserVisActions () const;
389 const std::map<G4VUserVisAction*,G4VisExtent>& GetUserVisActionExtents () const;
395 // The above is non-const because it checks and updates the List by
396 // calling RegisterGraphicsSystems() if no graphics systems are
397 // already registered.
399 const G4SceneList& GetSceneList () const;
400 static Verbosity GetVerbosity ();
404 const G4Event* GetRequestedEvent () const;
411#ifdef G4MULTITHREADED
412 G4int GetMaxEventQueueSize () const;
413 G4bool GetWaitOnEventQueueFull () const;
414#endif
415
417 void SetCurrentScene (G4Scene*);
421 G4SceneList& SetSceneList (); // Returns lvalue.
422 void SetVerboseLevel (G4int);
423 void SetVerboseLevel (const G4String&);
430 // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
437#ifdef G4MULTITHREADED
438 void SetMaxEventQueueSize (G4int);
439 void SetWaitOnEventQueueFull (G4bool);
440#endif
441
442 /////////////////////////////////////////////////////////////////////
443 // Utility functions.
444
445 G4String ViewerShortName (const G4String& viewerName) const;
446 // Returns shortened version of viewer name, i.e., up to first space,
447 // if any.
448
449 G4VViewer* GetViewer (const G4String& viewerName) const;
450 // Returns zero if not found. Can use long or short name, but find
451 // is done on short name.
452
453 static Verbosity GetVerbosityValue(const G4String&);
454 // Returns verbosity given a string. (Uses first character only.)
455
457 // Returns verbosity given an integer. If integer is out of range,
458 // selects verbosity at extreme of range.
459
461 // Converts the verbosity into a string for suitable for printing.
462
463 static std::vector<G4String> VerbosityGuidanceStrings;
464 // Guidance on the use of visualization verbosity.
465
466 void PrintAvailableGraphicsSystems (Verbosity, std::ostream& = G4cout) const;
467
468protected:
469
470 virtual void RegisterGraphicsSystems () = 0;
471 // The sub-class must implement and make successive calls to
472 // RegisterGraphicsSystem.
473
474 virtual void RegisterModelFactories();
475 // Sub-class must register desired models
476
477 void RegisterMessengers (); // Command messengers.
478
480 // fVerbose is kept for backwards compatibility for some user
481 // examples. (It is used in the derived user vis managers to print
482 // available graphics systems.) It is initialised to 1 in the
483 // constructor and cannot be changed.
484
485private:
486
487 // Function templates to implement the Draw methods (to avoid source
488 // code duplication).
489 template <class T> void DrawT
490 (const T& graphics_primitive, const G4Transform3D& objectTransform);
491 template <class T> void DrawT2D
492 (const T& graphics_primitive, const G4Transform3D& objectTransform);
493
494 void PrintAvailableModels (Verbosity) const;
495 void InitialiseG4ColourMap () const;
496 void PrintAvailableColours (Verbosity) const;
497 void PrintAvailableUserVisActions (Verbosity) const;
498 void PrintInvalidPointers () const;
499 G4bool IsValidView ();
500 // True if view is valid. Prints messages and sanitises various data.
501 void ClearTransientStoreIfMarked();
502 // Clears transient store of current scene handler if it is marked
503 // for clearing. Assumes view is valid.
504
505 static G4VisManager* fpInstance; // Pointer to single instance.
506 G4bool fInitialised;
507 std::vector<UserVisAction> fRunDurationUserVisActions;
508 std::vector<UserVisAction> fEndOfEventUserVisActions;
509 std::vector<UserVisAction> fEndOfRunUserVisActions;
510 std::map<G4VUserVisAction*,G4VisExtent> fUserVisActionExtents;
511 G4VGraphicsSystem* fpGraphicsSystem; // Current graphics system.
512 G4Scene* fpScene; // Current scene.
513 G4VSceneHandler* fpSceneHandler; // Current scene handler.
514 G4VViewer* fpViewer; // Current viewer.
515 G4GraphicsSystemList fAvailableGraphicsSystems;
516 G4SceneList fSceneList;
517 G4SceneHandlerList fAvailableSceneHandlers;
518 static Verbosity fVerbosity;
519 std::vector<G4UImessenger*> fMessengerList;
520 std::vector<G4UIcommand*> fDirectoryList;
521 G4VisStateDependent* fpStateDependent; // Friend state dependent class.
522 G4bool fEventRefreshing;
523 G4bool fTransientsDrawnThisRun;
524 G4bool fTransientsDrawnThisEvent;
525 G4int fNoOfEventsDrawnThisRun;
526 G4int fNKeepRequests;
527 G4bool fEventKeepingSuspended;
528 G4bool fDrawEventOnlyIfToBeKept;
529 const G4Event* fpRequestedEvent; // If non-zero, scene handler uses.
530 G4bool fReviewingKeptEvents;
531 G4bool fAbortReviewKeptEvents;
532 G4bool fReviewingPlots;
533 G4bool fAbortReviewPlots;
534 G4ViewParameters fDefaultViewParameters;
535 G4bool fIsDrawGroup;
536 G4int fDrawGroupNestingDepth;
537 G4bool fIgnoreStateChanges;
538#ifdef G4MULTITHREADED
539 G4int fMaxEventQueueSize;
540 G4bool fWaitOnEventQueueFull;
541#endif
542
543 // Trajectory draw model manager
544 G4VisModelManager<G4VTrajectoryModel>* fpTrajDrawModelMgr;
545
546 // Trajectory filter model manager
547 G4VisFilterManager<G4VTrajectory>* fpTrajFilterMgr;
548
549 // Hit filter model manager
550 G4VisFilterManager<G4VHit>* fpHitFilterMgr;
551
552 // Digi filter model manager
553 G4VisFilterManager<G4VDigi>* fpDigiFilterMgr;
554};
555
556#include "G4VisManager.icc"
557
558#endif
void * G4ThreadFunReturnType
Definition: G4Threading.hh:110
void * G4ThreadFunArgType
Definition: G4Threading.hh:111
HepGeom::Transform3D G4Transform3D
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4VModelFactory< G4VFilter< G4VHit > > G4HitFilterFactory
G4VModelFactory< G4VTrajectoryModel > G4TrajDrawModelFactory
G4VModelFactory< G4VFilter< G4VTrajectory > > G4TrajFilterFactory
G4VModelFactory< G4VFilter< G4VDigi > > G4DigiFilterFactory
G4GLOB_DLL std::ostream G4cout
Definition: G4Text.hh:72
Definition: G4VHit.hh:48
void Initialize()
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 *)
G4Scene * GetCurrentScene() const
void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
void PrintAvailableGraphicsSystems(Verbosity, std::ostream &=G4cout) const
virtual void RegisterGraphicsSystems()=0
G4bool IsEnabled() const
void SetDrawEventOnlyIfToBeKept(G4bool)
void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())
void CreateSceneHandler(const G4String &name="")
G4int GetNKeepRequests() const
void SetCurrentSceneHandler(G4VSceneHandler *)
const std::vector< UserVisAction > & GetRunDurationUserVisActions() const
const G4VTrajectoryModel * CurrentTrajDrawModel() const
G4bool GetAbortReviewPlots() const
G4bool FilterDigi(const G4VDigi &)
void SetTransientsDrawnThisEvent(G4bool)
void SetEventRefreshing(G4bool)
void SetCurrentScene(G4Scene *)
static std::vector< G4String > VerbosityGuidanceStrings
static G4String VerbosityString(Verbosity)
void RegisterEndOfEventUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent())
G4bool GetTransientsDrawnThisEvent() const
G4String ViewerShortName(const G4String &viewerName) const
const std::map< G4VUserVisAction *, G4VisExtent > & GetUserVisActionExtents() const
void RegisterModel(G4VTrajectoryModel *model)
void RegisterMessenger(G4UImessenger *messenger)
G4bool GetAbortReviewKeptEvents() const
void SetCurrentViewer(G4VViewer *)
friend std::ostream & operator<<(std::ostream &, const G4VGraphicsSystem &)
const G4ViewParameters & GetDefaultViewParameters() const
void SetAbortReviewPlots(G4bool)
const std::vector< UserVisAction > & GetEndOfRunUserVisActions() const
void RegisterModelFactory(G4TrajDrawModelFactory *factory)
G4bool GetTransientsDrawnThisRun() const
void EndDraw2D()
G4SceneList & SetSceneList()
G4VGraphicsSystem * GetCurrentGraphicsSystem() const
G4bool FilterHit(const G4VHit &)
void SetAbortReviewKeptEvents(G4bool)
void SetReviewingPlots(G4bool)
G4SceneHandlerList & SetAvailableSceneHandlers()
G4VViewer * GetCurrentViewer() const
void SetRequestedEvent(const G4Event *)
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
G4bool GetDrawEventOnlyIfToBeKept() const
const std::vector< UserVisAction > & GetEndOfEventUserVisActions() const
virtual void RegisterModelFactories()
virtual ~G4VisManager()
G4VSceneHandler * GetCurrentSceneHandler() const
void SetReviewingKeptEvents(G4bool)
G4bool GetReviewingPlots() const
const G4SceneList & GetSceneList() const
static Verbosity GetVerbosity()
void Initialise()
void RegisterMessengers()
void ResetTransientsDrawnFlags()
G4bool FilterTrajectory(const G4VTrajectory &)
void SetVerboseLevel(G4int)
void IgnoreStateChanges(G4bool)
void SetTransientsDrawnThisRun(G4bool)
void SetDefaultViewParameters(const G4ViewParameters &)
void NotifyHandlers()
const G4SceneHandlerList & GetAvailableSceneHandlers() const
void SetVerboseLevel(Verbosity)
G4bool GetReviewingKeptEvents() const
const G4Event * GetRequestedEvent() const
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="")
const G4int fVerbose
void DispatchToModel(const G4VTrajectory &)
G4VViewer * GetViewer(const G4String &viewerName) const
UserVisAction(const G4String &name, G4VUserVisAction *pUserVisAction)
G4VUserVisAction * fpUserVisAction