Geant4  10.01.p01
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 // $Id: G4VisManager.hh 85021 2014-10-23 09:53:47Z gcosmo $
28 //
29 //
30 
31 // Class Description:
32 //
33 // The GEANT4 Visualization Manager - John Allison 02/Jan/1996.
34 //
35 // G4VisManager is a "Singleton", i.e., only one instance of it or any
36 // derived class may exist. A G4Exception is thrown if an attempt is
37 // made to instantiate more than one.
38 //
39 // It is also an abstract class, so the user must derive his/her own
40 // class from G4VisManager, implement the pure virtual function
41 // RegisterGraphicsSystems, and instantiate an object of the derived
42 // class - for an example see
43 // visualization/include/G4VisExecutive.hh/icc.
44 //
45 // The recommended way for users to obtain a pointer to the vis
46 // manager is with G4VVisManager::GetConcreteInstance (), being always
47 // careful to test for non-zero. This pointer is non-zero only when
48 // (a) an object of the derived class exists and (b) when there is a
49 // valid viewer available.
50 //
51 // Graphics system registration is normally done through the protected
52 // pure virtual function RegisterGraphicsSystems called from
53 // Initialise (). You can also use the public function
54 // RegisterGraphicsSystem (new MyGraphicsSystem) if you have your own
55 // graphics system. A graphics system is, in effect, a factory for
56 // scene handlers and viewers.
57 //
58 // The VisManager creates and manages graphics systems, scenes, scene
59 // handlers, viewers and some models and model makers. You can have
60 // any number. It has the concept of a "current viewer", and the
61 // "current scene handler", the "current scene" and the "current
62 // graphics system" which go with it. You can select the current
63 // viewer. Most of the the operations of the VisManager take place
64 // with the current viewer, in particular, the Draw operations.
65 //
66 // Each scene comprises drawable objects such as detector components
67 // and trajectories, hits and digis when appropriate. A scene handler
68 // translates a scene into graphics-system-specific function calls
69 // and, possibly, a graphics-system-dependent database - display
70 // lists, scene graphs, etc. Each viewer has its "view parameters"
71 // (see class description of G4ViewParameters for available parameters
72 // and also for a description of the concept of a "standard view" and
73 // all that).
74 //
75 // A friend class G4VisStateDependent is "state dependent", i.e., it
76 // is notified on change of state (G4ApplicationState). This is used
77 // to message the G4VisManager to draw hits, digis and trajectories in
78 // the current scene at the end of event, as required.
79 
80 #ifndef G4VISMANAGER_HH
81 #define G4VISMANAGER_HH
82 
83 #include "G4VVisManager.hh"
84 
85 #include "globals.hh"
86 #include "G4GraphicsSystemList.hh"
87 #include "G4ModelingParameters.hh"
88 #include "G4NullModel.hh"
89 #include "G4SceneHandlerList.hh"
90 #include "G4SceneList.hh"
91 #include "G4TrajectoriesModel.hh"
92 #include "G4Transform3D.hh"
93 #include "G4UImessenger.hh"
94 
95 #include <iostream>
96 #include <vector>
97 #include <map>
98 
99 #include "G4Threading.hh"
100 
101 class G4Scene;
102 class G4UIcommand;
103 class G4UImessenger;
104 class G4VisStateDependent;
105 class G4VTrajectoryModel;
106 class G4VUserVisAction;
107 template <typename> class G4VFilter;
108 template <typename> class G4VisFilterManager;
109 template <typename> class G4VisModelManager;
110 template <typename> class G4VModelFactory;
111 class G4Event;
112 
113 // Useful typedef's
118 
120 
121  // Management friends...
122  friend class G4VSceneHandler;
123  friend class G4VViewer;
124  friend class G4VisStateDependent;
125  friend class G4VisCommandList;
126 
127  // operator << friends...
128  friend std::ostream& operator << (std::ostream&, const G4VGraphicsSystem&);
129  friend std::ostream& operator << (std::ostream&, const G4VSceneHandler&);
130 
131 public: // With description
132 
133  enum Verbosity {
134  quiet, // Nothing is printed.
135  startup, // Startup and endup messages are printed...
136  errors, // ...and errors...
137  warnings, // ...and warnings...
138  confirmations, // ...and confirming messages...
139  parameters, // ...and parameters of scenes and views...
140  all // ...and everything available.
141  };
142  // Simple graded message scheme.
143 
144 protected: // With description
145 
146  G4VisManager (const G4String& verbosityString = "warnings");
147  // The constructor is protected so that an object of the derived
148  // class may be constructed.
149 
150 public: // With description
151 
152  virtual ~G4VisManager ();
153 
154 private:
155 
156  // Private copy constructor and assigment operator - copying and
157  // assignment not allowed. Keeps CodeWizard happy.
158  G4VisManager (const G4VisManager&);
160 
161 public:
162  static G4VisManager* GetInstance ();
163  // Returns pointer to itself. Throws a G4Exception if called before
164  // instantiation. Intended only for use within the vis category; the
165  // normal user should instead use G4VVisManager::GetConcreteInstance()
166  // to get a "higher level" pointer for general use - but always test
167  // for non-zero.
168 
169 public: // With description
170 
171  void Initialise ();
172  void Initialize (); // Alias Initialise ().
173 
174  // Optional registration of user vis actions. Added to scene with
175  // /vis/scene/add/userAction.
177  (const G4String& name, G4VUserVisAction*,
180  (const G4String& name, G4VUserVisAction*,
183  (const G4String& name, G4VUserVisAction*,
185 
187  // Register an individual graphics system. Normally this is done in
188  // a sub-class implementation of the protected virtual function,
189  // RegisterGraphicsSystems. See, e.g., G4VisExecutive.icc.
190 
192  // Register trajectory draw model factory. Assumes ownership of factory.
193 
194  void RegisterModel(G4VTrajectoryModel* model);
195  // Register trajectory model. Assumes ownership of model.
196 
198  // Register trajectory filter model factory. Assumes ownership of factory.
199 
201  // Register trajectory filter model. Assumes ownership of model.
202 
204  // Register trajectory hit model factory. Assumes ownership of factory.
205 
206  void RegisterModel(G4VFilter<G4VHit>* filter);
207  // Register trajectory hit model. Assumes ownership of model.
208 
210  // Register trajectory digi model factory. Assumes ownership of factory.
211 
212  void RegisterModel(G4VFilter<G4VDigi>* filter);
213  // Register trajectory digi model. Assumes ownership of model.
214 
215  void SelectTrajectoryModel(const G4String& model);
216  // Set default trajectory model. Useful for use in compiled code
217 
218  void RegisterMessenger(G4UImessenger* messenger);
219  // Register messenger. Assumes ownership of messenger.
220 
222  // Now functions that implement the pure virtual functions of
223  // G4VVisManager for drawing various visualization primitives, useful
224  // for representing hits, digis, etc.
225 
226  void Draw (const G4Circle&,
227  const G4Transform3D& objectTransformation = G4Transform3D());
228 
229  void Draw (const G4Polyhedron&,
230  const G4Transform3D& objectTransformation = G4Transform3D());
231 
232  void Draw (const G4Polyline&,
233  const G4Transform3D& objectTransformation = G4Transform3D());
234 
235  void Draw (const G4Polymarker&,
236  const G4Transform3D& objectTransformation = G4Transform3D());
237 
238  void Draw (const G4Scale&,
239  const G4Transform3D& objectTransformation = G4Transform3D());
240 
241  void Draw (const G4Square&,
242  const G4Transform3D& objectTransformation = G4Transform3D());
243 
244  void Draw (const G4Text&,
245  const G4Transform3D& objectTransformation = G4Transform3D());
246 
247  void Draw2D (const G4Circle&,
248  const G4Transform3D& objectTransformation = G4Transform3D());
249 
250  void Draw2D (const G4Polyhedron&,
251  const G4Transform3D& objectTransformation = G4Transform3D());
252 
253  void Draw2D (const G4Polyline&,
254  const G4Transform3D& objectTransformation = G4Transform3D());
255 
256  void Draw2D (const G4Polymarker&,
257  const G4Transform3D& objectTransformation = G4Transform3D());
258 
259  void Draw2D (const G4Square&,
260  const G4Transform3D& objectTransformation = G4Transform3D());
261 
262  void Draw2D (const G4Text&,
263  const G4Transform3D& objectTransformation = G4Transform3D());
264 
266  // Now functions that implement the pure virtual functions of
267  // G4VVisManager for drawing a GEANT4 object. Note that the
268  // visualization attributes needed in some cases override any
269  // visualization attributes that are associated with the object
270  // itself - thus you can, for example, change the colour of a
271  // physical volume.
272 
273  void Draw (const G4VTrajectory&);
274 
275  void Draw (const G4VHit&);
276 
277  void Draw (const G4VDigi&);
278 
279  void Draw (const G4LogicalVolume&, const G4VisAttributes&,
280  const G4Transform3D& objectTransformation = G4Transform3D());
281 
282  void Draw (const G4VPhysicalVolume&, const G4VisAttributes&,
283  const G4Transform3D& objectTransformation = G4Transform3D());
284 
285  void Draw (const G4VSolid&, const G4VisAttributes&,
286  const G4Transform3D& objectTransformation = G4Transform3D());
287 
289  // Optional methods that you may use to bracket a series of Draw
290  // messages that have identical objectTransformation to improve
291  // drawing speed. Use Begin/EndDraw for a series of Draw messages,
292  // Begin/EndDraw2D for a series of Draw2D messages. Do not mix Draw
293  // and Draw2D messages.
294 
295  void BeginDraw
296  (const G4Transform3D& objectTransformation = G4Transform3D());
297 
298  void EndDraw ();
299 
300  void BeginDraw2D
301  (const G4Transform3D& objectTransformation = G4Transform3D());
302 
303  void EndDraw2D ();
304 
306  // Now other pure virtual functions of G4VVisManager...
307 
308  void GeometryHasChanged ();
309  // Used by run manager to notify change.
310 
312  // This method shoud be invoked by a class that has its own event loop,
313  // such as the RayTracer, material scanner, etc. If the argument is true,
314  // the following state changes among Idle, GeomClosed and EventProc are
315  // caused by such a class, and thus not by the ordinary event simulation.
316  // The same method with false should be invoked once such an event loop
317  // is over.
318 
319  void NotifyHandlers();
320  // Notify scene handlers (G4VGraphicsScene objects) that the scene
321  // has changed so that they may rebuild their graphics database, if
322  // any, and redraw all views.
323 
324  void DispatchToModel(const G4VTrajectory&);
325  // Draw the trajectory.
326 
328  G4bool FilterHit(const G4VHit&);
329  G4bool FilterDigi(const G4VDigi&);
330 
331 #ifdef G4MULTITHREADED
332  virtual void SetUpForAThread();
333  // This method is invoked by G4WorkerRunManager
334 #endif
335 
337  // Administration routines.
338 
339  void CreateSceneHandler (const G4String& name = "");
340  // Creates scene handler for the current system.
341 
342  void CreateViewer (const G4String& name = "", const G4String& XGeometry = "");
343  // Creates viewer for the current scene handler.
344 
345 private:
346 
347  void BeginOfRun ();
348 
349  void BeginOfEvent ();
350 
351  void EndOfEvent ();
352  // This is called on change of state (G4ApplicationState). It is
353  // used to draw hits, digis and trajectories if included in the
354  // current scene at the end of event, as required.
355 
356  void EndOfRun ();
357 
358  void DrawEvent (const G4Event*);
359 
360 public: // With description
361 
363  // Access functions.
364 
365  void Enable();
366  void Disable();
367  // Global enable/disable functions.
368 
370 
371  struct UserVisAction {
372  UserVisAction(const G4String& name, G4VUserVisAction* pUserVisAction)
373  :fName(name), fpUserVisAction(pUserVisAction) {}
376  };
377  const std::vector<UserVisAction>& GetRunDurationUserVisActions () const;
378  const std::vector<UserVisAction>& GetEndOfEventUserVisActions () const;
379  const std::vector<UserVisAction>& GetEndOfRunUserVisActions () const;
380  const std::map<G4VUserVisAction*,G4VisExtent>& GetUserVisActionExtents () const;
382  G4Scene* GetCurrentScene () const;
384  G4VViewer* GetCurrentViewer () const;
386  // The above is non-const because it checks and updates the List by
387  // calling RegisterGraphicsSystems() if no graphics systems are
388  // already registered.
390  const G4SceneList& GetSceneList () const;
391  static Verbosity GetVerbosity ();
394  const G4Event* GetRequestedEvent () const;
397 
398  void SetUserAction
399  (G4VUserVisAction* pVisAction,
400  const G4VisExtent& = G4VisExtent::NullExtent); // Register run-duration.
401  void SetUserActionExtent (const G4VisExtent&); //Legacy: deprecated.
403  void SetCurrentScene (G4Scene*);
405  void SetCurrentViewer (G4VViewer*);
406  G4SceneHandlerList& SetAvailableSceneHandlers (); // Returns lvalue.
407  G4SceneList& SetSceneList (); // Returns lvalue.
408  void SetVerboseLevel (G4int);
409  void SetVerboseLevel (const G4String&);
410  void SetVerboseLevel (Verbosity);
411  void SetEventRefreshing (G4bool);
413  // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
414  void SetRequestedEvent (const G4Event*);
417 
419  // Utility functions.
420 
421  G4String ViewerShortName (const G4String& viewerName) const;
422  // Returns shortened version of viewer name, i.e., up to first space,
423  // if any.
424 
425  G4VViewer* GetViewer (const G4String& viewerName) const;
426  // Returns zero if not found. Can use long or short name, but find
427  // is done on short name.
428 
429  static Verbosity GetVerbosityValue(const G4String&);
430  // Returns verbosity given a string. (Uses first character only.)
431 
433  // Returns verbosity given an integer. If integer is out of range,
434  // selects verbosity at extreme of range.
435 
437  // Converts the verbosity into a string for suitable for printing.
438 
439  static std::vector<G4String> VerbosityGuidanceStrings;
440  // Guidance on the use of visualization verbosity.
441 
442 protected:
443 
444  virtual void RegisterGraphicsSystems () = 0;
445  // The sub-class must implement and make successive calls to
446  // RegisterGraphicsSystem.
447 
448  virtual void RegisterModelFactories();
449  // Sub-class must register desired models
450 
451  void RegisterMessengers (); // Command messengers.
452 
454  // fVerbose is kept for backwards compatibility for some user
455  // examples. (It is used in the derived user vis managers to print
456  // available graphics systems.) It is initialised to 1 in the
457  // constructor and cannot be changed.
458 
459  void PrintAvailableGraphicsSystems () const;
460 
461 private:
462 
463  // Function templates to implement the Draw methods (to avoid source
464  // code duplication).
465  template <class T> void DrawT
466  (const T& graphics_primitive, const G4Transform3D& objectTransform);
467  template <class T> void DrawT2D
468  (const T& graphics_primitive, const G4Transform3D& objectTransform);
469 
470  void PrintAvailableModels (Verbosity) const;
471  void PrintAvailableColours (Verbosity) const;
473  void PrintInvalidPointers () const;
474  G4bool IsValidView ();
475  // True if view is valid. Prints messages and sanitises various data.
477  // Clears transient store of current scene handler if it is marked
478  // for clearing. Assumes view is valid.
479 
480  static G4VisManager* fpInstance; // Pointer to single instance.
482  std::vector<UserVisAction> fRunDurationUserVisActions;
483  std::vector<UserVisAction> fEndOfEventUserVisActions;
484  std::vector<UserVisAction> fEndOfRunUserVisActions;
485  std::map<G4VUserVisAction*,G4VisExtent> fUserVisActionExtents;
486  G4VGraphicsSystem* fpGraphicsSystem; // Current graphics system.
487  G4Scene* fpScene; // Current scene.
488  G4VSceneHandler* fpSceneHandler; // Current scene handler.
489  G4VViewer* fpViewer; // Current viewer.
494  std::vector<G4UImessenger*> fMessengerList;
495  std::vector<G4UIcommand*> fDirectoryList;
496  G4VisStateDependent* fpStateDependent; // Friend state dependent class.
503  const G4Event* fpRequestedEvent; // If non-zero, scene handler uses.
509 
510  // Trajectory draw model manager
512 
513  // Trajectory filter model manager
515 
516  // Hit filter model manager
518 
519  // Digi filter model manager
521 };
522 
523 #include "G4VisManager.icc"
524 
525 #endif
G4bool GetTransientsDrawnThisRun() const
G4bool FilterDigi(const G4VDigi &)
void Initialise()
void RegisterEndOfEventUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void RegisterModelFactory(G4TrajDrawModelFactory *factory)
G4VisFilterManager< G4VTrajectory > * fpTrajFilterMgr
Definition: G4Text.hh:73
static const G4VisExtent NullExtent
Definition: G4VisExtent.hh:80
static Verbosity fVerbosity
friend std::ostream & operator<<(std::ostream &, const G4VGraphicsSystem &)
void PrintAvailableColours(Verbosity) const
G4VisFilterManager< G4VHit > * fpHitFilterMgr
void DrawEvent(const G4Event *)
void PrintAvailableUserVisActions(Verbosity) const
virtual void RegisterModelFactories()
void PrintAvailableModels(Verbosity) const
void SetCurrentSceneHandler(G4VSceneHandler *)
void SetEventRefreshing(G4bool)
const G4int fVerbose
G4String name
Definition: TRTMaterials.hh:40
void RegisterEndOfRunUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
G4VisStateDependent * fpStateDependent
G4ViewParameters fDefaultViewParameters
void PrintInvalidPointers() const
void SetVerboseLevel(G4int)
const G4Event * fpRequestedEvent
G4int fNKeepRequests
void SetRequestedEvent(const G4Event *)
G4VModelFactory< G4VFilter< G4VDigi > > G4DigiFilterFactory
void GeometryHasChanged()
G4bool fAbortReviewKeptEvents
G4VGraphicsSystem * GetCurrentGraphicsSystem() const
Definition: G4VHit.hh:48
void SetCurrentScene(G4Scene *)
void SetUserActionExtent(const G4VisExtent &)
static std::vector< G4String > VerbosityGuidanceStrings
std::map< G4VUserVisAction *, G4VisExtent > fUserVisActionExtents
int G4int
Definition: G4Types.hh:78
static Verbosity GetVerbosityValue(const G4String &)
void EndDraw2D()
void BeginDraw(const G4Transform3D &objectTransformation=G4Transform3D())
const G4VTrajectoryModel * CurrentTrajDrawModel() const
G4bool fTransientsDrawnThisEvent
void SetDefaultViewParameters(const G4ViewParameters &)
std::vector< G4UIcommand * > fDirectoryList
G4bool IsValidView()
std::vector< G4UImessenger * > fMessengerList
void RegisterMessengers()
const G4SceneHandlerList & GetAvailableSceneHandlers() const
G4VModelFactory< G4VFilter< G4VHit > > G4HitFilterFactory
static G4VisManager * fpInstance
void RegisterMessenger(G4UImessenger *messenger)
void SelectTrajectoryModel(const G4String &model)
G4VSceneHandler * fpSceneHandler
G4VModelFactory< G4VFilter< G4VTrajectory > > G4TrajFilterFactory
void PrintAvailableGraphicsSystems() const
std::vector< UserVisAction > fEndOfRunUserVisActions
const G4ViewParameters & GetDefaultViewParameters() const
G4SceneList & SetSceneList()
G4int fDrawGroupNestingDepth
void IgnoreStateChanges(G4bool)
G4bool fEventKeepingSuspended
G4String ViewerShortName(const G4String &viewerName) const
std::vector< UserVisAction > fRunDurationUserVisActions
G4VisModelManager< G4VTrajectoryModel > * fpTrajDrawModelMgr
G4SceneHandlerList fAvailableSceneHandlers
bool G4bool
Definition: G4Types.hh:79
G4bool FilterTrajectory(const G4VTrajectory &)
void ResetTransientsDrawnFlags()
static G4VisManager * GetInstance()
const G4SceneList & GetSceneList() const
const std::vector< UserVisAction > & GetEndOfEventUserVisActions() const
G4SceneHandlerList & SetAvailableSceneHandlers()
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
HepGeom::Transform3D G4Transform3D
G4Scene * fpScene
const std::map< G4VUserVisAction *, G4VisExtent > & GetUserVisActionExtents() const
virtual ~G4VisManager()
G4VisFilterManager< G4VDigi > * fpDigiFilterMgr
G4VUserVisAction * fpUserVisAction
G4bool fEventRefreshing
const std::vector< UserVisAction > & GetRunDurationUserVisActions() const
G4bool GetTransientsDrawnThisEvent() const
void Initialize()
void RegisterRunDurationUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void SetCurrentViewer(G4VViewer *)
G4VisManager & operator=(const G4VisManager &)
G4GraphicsSystemList fAvailableGraphicsSystems
G4VisManager(const G4String &verbosityString="warnings")
Definition: G4VisManager.cc:89
G4bool FilterHit(const G4VHit &)
G4bool fInitialised
void SetUserAction(G4VUserVisAction *pVisAction, const G4VisExtent &=G4VisExtent::NullExtent)
G4VViewer * GetViewer(const G4String &viewerName) const
void DrawT(const T &graphics_primitive, const G4Transform3D &objectTransform)
std::vector< UserVisAction > fEndOfEventUserVisActions
void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())
G4VModelFactory< G4VTrajectoryModel > G4TrajDrawModelFactory
static G4String VerbosityString(Verbosity)
G4VSceneHandler * GetCurrentSceneHandler() const
UserVisAction(const G4String &name, G4VUserVisAction *pUserVisAction)
static Verbosity GetVerbosity()
const G4Event * GetRequestedEvent() const
G4bool fIgnoreStateChanges
G4VViewer * fpViewer
void Draw(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
virtual void RegisterGraphicsSystems()=0
void RegisterModel(G4VTrajectoryModel *model)
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
G4VViewer * GetCurrentViewer() const
G4bool GetAbortReviewKeptEvents() const
const std::vector< UserVisAction > & GetEndOfRunUserVisActions() const
void BeginOfEvent()
void DispatchToModel(const G4VTrajectory &)
void CreateViewer(const G4String &name="", const G4String &XGeometry="")
void CreateSceneHandler(const G4String &name="")
G4VGraphicsSystem * fpGraphicsSystem
void DrawT2D(const T &graphics_primitive, const G4Transform3D &objectTransform)
const G4GraphicsSystemList & GetAvailableGraphicsSystems()
void NotifyHandlers()
void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
void ClearTransientStoreIfMarked()
G4bool fIsDrawGroup
G4bool fKeptLastEvent
G4Scene * GetCurrentScene() const
void SetAbortReviewKeptEvents(G4bool)
G4bool fTransientsDrawnThisRun
G4SceneList fSceneList