Geant4-11
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.
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.
182 const G4VisExtent& = G4VisExtent());
185 const G4VisExtent& = G4VisExtent());
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
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
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
290 // Optional methods that you may use to bracket a series of Draw
291 // messages that have identical objectTransformation to improve
292 // drawing speed. Use Begin/EndDraw for a series of Draw messages,
293 // Begin/EndDraw2D for a series of Draw2D messages. Do not mix Draw
294 // and Draw2D messages.
295
296 void BeginDraw
297 (const G4Transform3D& objectTransformation = G4Transform3D());
298
299 void EndDraw ();
300
301 void BeginDraw2D
302 (const G4Transform3D& objectTransformation = G4Transform3D());
303
304 void EndDraw2D ();
305
307 // Now other pure virtual functions of G4VVisManager...
308
309 void GeometryHasChanged ();
310 // Used by run manager to notify change.
311
313 // This method shoud be invoked by a class that has its own event loop,
314 // such as the RayTracer, material scanner, etc. If the argument is true,
315 // the following state changes among Idle, GeomClosed and EventProc are
316 // caused by such a class, and thus not by the ordinary event simulation.
317 // The same method with false should be invoked once such an event loop
318 // is over.
319
320 void NotifyHandlers();
321 // Notify scene handlers (G4VGraphicsScene objects) that the scene
322 // has changed so that they may rebuild their graphics database, if
323 // any, and redraw all views.
324
325 void DispatchToModel(const G4VTrajectory&);
326 // Draw the trajectory.
327
329 G4bool FilterHit(const G4VHit&);
330 G4bool FilterDigi(const G4VDigi&);
331
332#ifdef G4MULTITHREADED
333
334 virtual void SetUpForAThread();
335 // This method is invoked by G4WorkerRunManager
336
337 static G4ThreadFunReturnType G4VisSubThread(G4ThreadFunArgType);
338 // Vis sub-thread function.
339
340#endif
341
343 // Administration routines.
344
345 void CreateSceneHandler (const G4String& name = "");
346 // Creates scene handler for the current system.
347
348 void CreateViewer (const G4String& name = "", const G4String& XGeometry = "");
349 // Creates viewer for the current scene handler.
350
351private:
352
353 void BeginOfRun ();
354
355 void BeginOfEvent ();
356
357 void EndOfEvent ();
358 // This is called on change of state (G4ApplicationState). It is
359 // used to draw hits, digis and trajectories if included in the
360 // current scene at the end of event, as required.
361
362 void EndOfRun ();
363
364public: // With description
365
367 // Access functions.
368
369 void Enable();
370 void Disable();
371 // Global enable/disable functions.
372
374
377 :fName(name), fpUserVisAction(pUserVisAction) {}
380 };
381 const std::vector<UserVisAction>& GetRunDurationUserVisActions () const;
382 const std::vector<UserVisAction>& GetEndOfEventUserVisActions () const;
383 const std::vector<UserVisAction>& GetEndOfRunUserVisActions () const;
384 const std::map<G4VUserVisAction*,G4VisExtent>& GetUserVisActionExtents () const;
390 // The above is non-const because it checks and updates the List by
391 // calling RegisterGraphicsSystems() if no graphics systems are
392 // already registered.
394 const G4SceneList& GetSceneList () const;
395 static Verbosity GetVerbosity ();
399 const G4Event* GetRequestedEvent () const;
404#ifdef G4MULTITHREADED
405 G4int GetMaxEventQueueSize () const;
406 G4bool GetWaitOnEventQueueFull () const;
407#endif
408
410 void SetCurrentScene (G4Scene*);
414 G4SceneList& SetSceneList (); // Returns lvalue.
415 void SetVerboseLevel (G4int);
416 void SetVerboseLevel (const G4String&);
423 // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
428#ifdef G4MULTITHREADED
429 void SetMaxEventQueueSize (G4int);
430 void SetWaitOnEventQueueFull (G4bool);
431#endif
432
434 // Utility functions.
435
436 G4String ViewerShortName (const G4String& viewerName) const;
437 // Returns shortened version of viewer name, i.e., up to first space,
438 // if any.
439
440 G4VViewer* GetViewer (const G4String& viewerName) const;
441 // Returns zero if not found. Can use long or short name, but find
442 // is done on short name.
443
444 static Verbosity GetVerbosityValue(const G4String&);
445 // Returns verbosity given a string. (Uses first character only.)
446
448 // Returns verbosity given an integer. If integer is out of range,
449 // selects verbosity at extreme of range.
450
452 // Converts the verbosity into a string for suitable for printing.
453
454 static std::vector<G4String> VerbosityGuidanceStrings;
455 // Guidance on the use of visualization verbosity.
456
457protected:
458
459 virtual void RegisterGraphicsSystems () = 0;
460 // The sub-class must implement and make successive calls to
461 // RegisterGraphicsSystem.
462
463 virtual void RegisterModelFactories();
464 // Sub-class must register desired models
465
466 void RegisterMessengers (); // Command messengers.
467
469 // fVerbose is kept for backwards compatibility for some user
470 // examples. (It is used in the derived user vis managers to print
471 // available graphics systems.) It is initialised to 1 in the
472 // constructor and cannot be changed.
473
475
476private:
477
478 // Function templates to implement the Draw methods (to avoid source
479 // code duplication).
480 template <class T> void DrawT
481 (const T& graphics_primitive, const G4Transform3D& objectTransform);
482 template <class T> void DrawT2D
483 (const T& graphics_primitive, const G4Transform3D& objectTransform);
484
485 void PrintAvailableModels (Verbosity) const;
486 void InitialiseG4ColourMap () const;
487 void PrintAvailableColours (Verbosity) const;
489 void PrintInvalidPointers () const;
491 // True if view is valid. Prints messages and sanitises various data.
493 // Clears transient store of current scene handler if it is marked
494 // for clearing. Assumes view is valid.
495
496 static G4VisManager* fpInstance; // Pointer to single instance.
498 std::vector<UserVisAction> fRunDurationUserVisActions;
499 std::vector<UserVisAction> fEndOfEventUserVisActions;
500 std::vector<UserVisAction> fEndOfRunUserVisActions;
501 std::map<G4VUserVisAction*,G4VisExtent> fUserVisActionExtents;
502 G4VGraphicsSystem* fpGraphicsSystem; // Current graphics system.
503 G4Scene* fpScene; // Current scene.
504 G4VSceneHandler* fpSceneHandler; // Current scene handler.
505 G4VViewer* fpViewer; // Current viewer.
510 std::vector<G4UImessenger*> fMessengerList;
511 std::vector<G4UIcommand*> fDirectoryList;
512 G4VisStateDependent* fpStateDependent; // Friend state dependent class.
520 const G4Event* fpRequestedEvent; // If non-zero, scene handler uses.
527#ifdef G4MULTITHREADED
528 G4int fMaxEventQueueSize;
529 G4bool fWaitOnEventQueueFull;
530#endif
531
532 // Trajectory draw model manager
534
535 // Trajectory filter model manager
537
538 // Hit filter model manager
540
541 // Digi filter model manager
543};
544
545#include "G4VisManager.icc"
546
547#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
Definition: G4Text.hh:72
Definition: G4VHit.hh:48
void Initialize()
std::vector< G4UImessenger * > fMessengerList
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
G4bool fEventRefreshing
void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
static G4VisManager * fpInstance
G4bool fEventKeepingSuspended
std::vector< G4UIcommand * > fDirectoryList
virtual void RegisterGraphicsSystems()=0
G4GraphicsSystemList fAvailableGraphicsSystems
G4bool IsValidView()
void SetDrawEventOnlyIfToBeKept(G4bool)
void InitialiseG4ColourMap() const
void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())
void CreateSceneHandler(const G4String &name="")
G4int GetNKeepRequests() const
void DrawT2D(const T &graphics_primitive, const G4Transform3D &objectTransform)
G4VSceneHandler * fpSceneHandler
void SetCurrentSceneHandler(G4VSceneHandler *)
const std::vector< UserVisAction > & GetRunDurationUserVisActions() const
void ClearTransientStoreIfMarked()
void PrintAvailableModels(Verbosity) const
const G4VTrajectoryModel * CurrentTrajDrawModel() const
G4int fNoOfEventsDrawnThisRun
void BeginOfEvent()
static Verbosity fVerbosity
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())
G4VisFilterManager< G4VHit > * fpHitFilterMgr
G4bool GetTransientsDrawnThisEvent() const
G4String ViewerShortName(const G4String &viewerName) const
G4VisModelManager< G4VTrajectoryModel > * fpTrajDrawModelMgr
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 &)
void DrawT(const T &graphics_primitive, const G4Transform3D &objectTransform)
G4VViewer * fpViewer
const G4ViewParameters & GetDefaultViewParameters() const
const G4Event * fpRequestedEvent
std::vector< UserVisAction > fRunDurationUserVisActions
const std::vector< UserVisAction > & GetEndOfRunUserVisActions() const
G4VisFilterManager< G4VTrajectory > * fpTrajFilterMgr
void RegisterModelFactory(G4TrajDrawModelFactory *factory)
G4bool GetTransientsDrawnThisRun() const
void EndDraw2D()
G4SceneList & SetSceneList()
G4VGraphicsSystem * GetCurrentGraphicsSystem() const
G4bool FilterHit(const G4VHit &)
G4int fNKeepRequests
void SetAbortReviewKeptEvents(G4bool)
std::map< G4VUserVisAction *, G4VisExtent > fUserVisActionExtents
std::vector< UserVisAction > fEndOfRunUserVisActions
G4SceneHandlerList & SetAvailableSceneHandlers()
G4bool fAbortReviewKeptEvents
G4bool fIgnoreStateChanges
G4VViewer * GetCurrentViewer() const
void SetRequestedEvent(const G4Event *)
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
G4bool GetDrawEventOnlyIfToBeKept() const
const std::vector< UserVisAction > & GetEndOfEventUserVisActions() const
void PrintAvailableGraphicsSystems(Verbosity) const
G4VisFilterManager< G4VDigi > * fpDigiFilterMgr
virtual void RegisterModelFactories()
virtual ~G4VisManager()
G4int fDrawGroupNestingDepth
G4VSceneHandler * GetCurrentSceneHandler() const
void SetReviewingKeptEvents(G4bool)
const G4SceneList & GetSceneList() const
static Verbosity GetVerbosity()
void Initialise()
void RegisterMessengers()
G4VisStateDependent * fpStateDependent
G4bool fReviewingKeptEvents
G4VisManager(const G4VisManager &)
void ResetTransientsDrawnFlags()
std::vector< UserVisAction > fEndOfEventUserVisActions
G4bool FilterTrajectory(const G4VTrajectory &)
void PrintAvailableColours(Verbosity) const
void SetVerboseLevel(G4int)
void PrintAvailableUserVisActions(Verbosity) const
G4VisManager & operator=(const G4VisManager &)
void IgnoreStateChanges(G4bool)
void SetTransientsDrawnThisRun(G4bool)
void SetDefaultViewParameters(const G4ViewParameters &)
void NotifyHandlers()
G4ViewParameters fDefaultViewParameters
const G4SceneHandlerList & GetAvailableSceneHandlers() const
G4bool fDrawEventOnlyIfToBeKept
void SetVerboseLevel(Verbosity)
G4bool GetReviewingKeptEvents() const
G4bool fIsDrawGroup
const G4Event * GetRequestedEvent() const
void PrintInvalidPointers() const
G4VisManager(const G4String &verbosityString="warnings")
Definition: G4VisManager.cc:98
G4SceneHandlerList fAvailableSceneHandlers
static Verbosity GetVerbosityValue(const G4String &)
static G4VisManager * GetInstance()
void GeometryHasChanged()
const G4GraphicsSystemList & GetAvailableGraphicsSystems()
G4VGraphicsSystem * fpGraphicsSystem
G4bool fTransientsDrawnThisEvent
void RegisterEndOfRunUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent())
G4SceneList fSceneList
void BeginDraw(const G4Transform3D &objectTransformation=G4Transform3D())
void CreateViewer(const G4String &name="", const G4String &XGeometry="")
const G4int fVerbose
void DispatchToModel(const G4VTrajectory &)
G4bool fInitialised
G4bool fTransientsDrawnThisRun
G4Scene * fpScene
G4VViewer * GetViewer(const G4String &viewerName) const
const char * name(G4int ptype)
factory
Definition: test.py:55
UserVisAction(const G4String &name, G4VUserVisAction *pUserVisAction)
G4VUserVisAction * fpUserVisAction