ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisManager.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VisManager.hh
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"
90 #include "G4GraphicsSystemList.hh"
91 #include "G4ModelingParameters.hh"
92 #include "G4NullModel.hh"
93 #include "G4SceneHandlerList.hh"
94 #include "G4SceneList.hh"
95 #include "G4TrajectoriesModel.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 
105 class G4Scene;
106 class G4UIcommand;
107 class G4UImessenger;
108 class G4VisStateDependent;
109 class G4VTrajectoryModel;
110 class G4VUserVisAction;
111 template <typename> class G4VFilter;
112 template <typename> class G4VisFilterManager;
113 template <typename> class G4VisModelManager;
114 template <typename> class G4VModelFactory;
115 class G4Event;
116 
117 // Useful typedef's
122 
124 
125  // Management friends...
126  friend class G4VSceneHandler;
127  friend class G4VViewer;
128  friend class G4VisStateDependent;
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 
135 public: // With description
136 
137  enum Verbosity {
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 
148 protected: // 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 
154 public: // With description
155 
156  virtual ~G4VisManager ();
157 
158 private:
159 
160  // Private copy constructor and assigment operator - copying and
161  // assignment not allowed. Keeps CodeWizard happy.
162  G4VisManager (const G4VisManager&);
164 
165 public:
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 
173 public: // 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  void SetUserAction
190  (G4VUserVisAction* pVisAction,
191  const G4VisExtent& = G4VisExtent());
192  // SetUserAction is deprecated. Use RegisterRunDurationUserVisAction
193  // or other of the above.
194  void SetUserActionExtent (const G4VisExtent&); //Legacy: deprecated.
195 
197  // Register an individual graphics system. Normally this is done in
198  // a sub-class implementation of the protected virtual function,
199  // RegisterGraphicsSystems. See, e.g., G4VisExecutive.icc.
200 
202  // Register trajectory draw model factory. Assumes ownership of factory.
203 
205  // Register trajectory model. Assumes ownership of model.
206 
208  // Register trajectory filter model factory. Assumes ownership of factory.
209 
211  // Register trajectory filter model. Assumes ownership of model.
212 
214  // Register trajectory hit model factory. Assumes ownership of factory.
215 
217  // Register trajectory hit model. Assumes ownership of model.
218 
220  // Register trajectory digi model factory. Assumes ownership of factory.
221 
223  // Register trajectory digi model. Assumes ownership of model.
224 
225  void SelectTrajectoryModel(const G4String& model);
226  // Set default trajectory model. Useful for use in compiled code
227 
228  void RegisterMessenger(G4UImessenger* messenger);
229  // Register messenger. Assumes ownership of messenger.
230 
232  // Now functions that implement the pure virtual functions of
233  // G4VVisManager for drawing various visualization primitives, useful
234  // for representing hits, digis, etc.
235 
236  void Draw (const G4Circle&,
237  const G4Transform3D& objectTransformation = G4Transform3D());
238 
239  void Draw (const G4Polyhedron&,
240  const G4Transform3D& objectTransformation = G4Transform3D());
241 
242  void Draw (const G4Polyline&,
243  const G4Transform3D& objectTransformation = G4Transform3D());
244 
245  void Draw (const G4Polymarker&,
246  const G4Transform3D& objectTransformation = G4Transform3D());
247 
248  void Draw (const G4Scale&,
249  const G4Transform3D& objectTransformation = G4Transform3D());
250 
251  void Draw (const G4Square&,
252  const G4Transform3D& objectTransformation = G4Transform3D());
253 
254  void Draw (const G4Text&,
255  const G4Transform3D& objectTransformation = G4Transform3D());
256 
257  void Draw2D (const G4Circle&,
258  const G4Transform3D& objectTransformation = G4Transform3D());
259 
260  void Draw2D (const G4Polyhedron&,
261  const G4Transform3D& objectTransformation = G4Transform3D());
262 
263  void Draw2D (const G4Polyline&,
264  const G4Transform3D& objectTransformation = G4Transform3D());
265 
266  void Draw2D (const G4Polymarker&,
267  const G4Transform3D& objectTransformation = G4Transform3D());
268 
269  void Draw2D (const G4Square&,
270  const G4Transform3D& objectTransformation = G4Transform3D());
271 
272  void Draw2D (const G4Text&,
273  const G4Transform3D& objectTransformation = G4Transform3D());
274 
276  // Now functions that implement the pure virtual functions of
277  // G4VVisManager for drawing a GEANT4 object. Note that the
278  // visualization attributes needed in some cases override any
279  // visualization attributes that are associated with the object
280  // itself - thus you can, for example, change the colour of a
281  // physical volume.
282 
283  void Draw (const G4VTrajectory&);
284 
285  void Draw (const G4VHit&);
286 
287  void Draw (const G4VDigi&);
288 
289  void Draw (const G4LogicalVolume&, const G4VisAttributes&,
290  const G4Transform3D& objectTransformation = G4Transform3D());
291 
292  void Draw (const G4VPhysicalVolume&, const G4VisAttributes&,
293  const G4Transform3D& objectTransformation = G4Transform3D());
294 
295  void Draw (const G4VSolid&, const G4VisAttributes&,
296  const G4Transform3D& objectTransformation = G4Transform3D());
297 
299  // Optional methods that you may use to bracket a series of Draw
300  // messages that have identical objectTransformation to improve
301  // drawing speed. Use Begin/EndDraw for a series of Draw messages,
302  // Begin/EndDraw2D for a series of Draw2D messages. Do not mix Draw
303  // and Draw2D messages.
304 
305  void BeginDraw
306  (const G4Transform3D& objectTransformation = G4Transform3D());
307 
308  void EndDraw ();
309 
310  void BeginDraw2D
311  (const G4Transform3D& objectTransformation = G4Transform3D());
312 
313  void EndDraw2D ();
314 
316  // Now other pure virtual functions of G4VVisManager...
317 
318  void GeometryHasChanged ();
319  // Used by run manager to notify change.
320 
322  // This method shoud be invoked by a class that has its own event loop,
323  // such as the RayTracer, material scanner, etc. If the argument is true,
324  // the following state changes among Idle, GeomClosed and EventProc are
325  // caused by such a class, and thus not by the ordinary event simulation.
326  // The same method with false should be invoked once such an event loop
327  // is over.
328 
329  void NotifyHandlers();
330  // Notify scene handlers (G4VGraphicsScene objects) that the scene
331  // has changed so that they may rebuild their graphics database, if
332  // any, and redraw all views.
333 
334  void DispatchToModel(const G4VTrajectory&);
335  // Draw the trajectory.
336 
338  G4bool FilterHit(const G4VHit&);
339  G4bool FilterDigi(const G4VDigi&);
340 
341 #ifdef G4MULTITHREADED
342 
343  virtual void SetUpForAThread();
344  // This method is invoked by G4WorkerRunManager
345 
346  static G4ThreadFunReturnType G4VisSubThread(G4ThreadFunArgType);
347  // Vis sub-thread function.
348 
349 #endif
350 
352  // Administration routines.
353 
354  void CreateSceneHandler (const G4String& name = "");
355  // Creates scene handler for the current system.
356 
357  void CreateViewer (const G4String& name = "", const G4String& XGeometry = "");
358  // Creates viewer for the current scene handler.
359 
360 private:
361 
362  void BeginOfRun ();
363 
364  void BeginOfEvent ();
365 
366  void EndOfEvent ();
367  // This is called on change of state (G4ApplicationState). It is
368  // used to draw hits, digis and trajectories if included in the
369  // current scene at the end of event, as required.
370 
371  void EndOfRun ();
372 
373 public: // With description
374 
376  // Access functions.
377 
378  void Enable();
379  void Disable();
380  // Global enable/disable functions.
381 
383 
384  struct UserVisAction {
385  UserVisAction(const G4String& name, G4VUserVisAction* pUserVisAction)
386  :fName(name), fpUserVisAction(pUserVisAction) {}
389  };
390  const std::vector<UserVisAction>& GetRunDurationUserVisActions () const;
391  const std::vector<UserVisAction>& GetEndOfEventUserVisActions () const;
392  const std::vector<UserVisAction>& GetEndOfRunUserVisActions () const;
393  const std::map<G4VUserVisAction*,G4VisExtent>& GetUserVisActionExtents () const;
395  G4Scene* GetCurrentScene () const;
397  G4VViewer* GetCurrentViewer () const;
399  // The above is non-const because it checks and updates the List by
400  // calling RegisterGraphicsSystems() if no graphics systems are
401  // already registered.
403  const G4SceneList& GetSceneList () const;
404  static Verbosity GetVerbosity ();
408  const G4Event* GetRequestedEvent () const;
409  G4int GetNKeepRequests () const;
413 #ifdef G4MULTITHREADED
414  G4int GetMaxEventQueueSize () const;
415  G4bool GetWaitOnEventQueueFull () const;
416 #endif
417 
419  void SetCurrentScene (G4Scene*);
421  void SetCurrentViewer (G4VViewer*);
422  G4SceneHandlerList& SetAvailableSceneHandlers (); // Returns lvalue.
423  G4SceneList& SetSceneList (); // Returns lvalue.
424  void SetVerboseLevel (G4int);
425  void SetVerboseLevel (const G4String&);
426  void SetVerboseLevel (Verbosity);
427  void SetEventRefreshing (G4bool);
432  // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
433  void SetRequestedEvent (const G4Event*);
437 #ifdef G4MULTITHREADED
438  void SetMaxEventQueueSize (G4int);
439  void SetWaitOnEventQueueFull (G4bool);
440 #endif
441 
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 protected:
467 
468  virtual void RegisterGraphicsSystems () = 0;
469  // The sub-class must implement and make successive calls to
470  // RegisterGraphicsSystem.
471 
472  virtual void RegisterModelFactories();
473  // Sub-class must register desired models
474 
475  void RegisterMessengers (); // Command messengers.
476 
478  // fVerbose is kept for backwards compatibility for some user
479  // examples. (It is used in the derived user vis managers to print
480  // available graphics systems.) It is initialised to 1 in the
481  // constructor and cannot be changed.
482 
484 
485 private:
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;
498  void PrintInvalidPointers () const;
499  G4bool IsValidView ();
500  // True if view is valid. Prints messages and sanitises various data.
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.
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.
519  std::vector<G4UImessenger*> fMessengerList;
520  std::vector<G4UIcommand*> fDirectoryList;
521  G4VisStateDependent* fpStateDependent; // Friend state dependent class.
530  const G4Event* fpRequestedEvent; // If non-zero, scene handler uses.
537 #ifdef G4MULTITHREADED
538  G4int fMaxEventQueueSize;
539  G4bool fWaitOnEventQueueFull;
540 #endif
541 
542  // Trajectory draw model manager
544 
545  // Trajectory filter model manager
547 
548  // Hit filter model manager
550 
551  // Digi filter model manager
553 };
554 
555 #include "G4VisManager.icc"
556 
557 #endif