Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 // $Id$
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 class G4Scene;
100 class G4UIcommand;
101 class G4UImessenger;
102 class G4VisStateDependent;
103 class G4VTrajectoryModel;
104 class G4VUserVisAction;
105 template <typename> class G4VFilter;
106 template <typename> class G4VisFilterManager;
107 template <typename> class G4VisModelManager;
108 template <typename> class G4VModelFactory;
109 class G4Event;
110 
111 // Useful typedef's
116 
118 
119  // Friends - classes and functions which need access to private
120  // members of G4VisManager. This is mainly to obtain access to
121  // GetInstance (), which is private. The correct way for normal
122  // users to obtain a pointer to the vis manager is with
123  // G4VVisManager::GetConcreteInstance (), always testing for
124  // non-zero.
125 
126  // Odd friends that need access to the G4VisManager...
127  friend class G4RTSteppingAction;
128  friend class G4RayTrajectory;
130  friend class G4RTMessenger;
134 
135  // Management friends...
136  friend class G4VSceneHandler;
137  friend class G4VViewer;
138  friend class G4VisStateDependent;
139  friend class G4VisCommandList;
140 
141  // operator << friends...
142  friend std::ostream& operator << (std::ostream&, const G4VGraphicsSystem&);
143  friend std::ostream& operator << (std::ostream&, const G4VSceneHandler&);
144 
145 public: // With description
146 
147  enum Verbosity {
148  quiet, // Nothing is printed.
149  startup, // Startup and endup messages are printed...
150  errors, // ...and errors...
151  warnings, // ...and warnings...
152  confirmations, // ...and confirming messages...
153  parameters, // ...and parameters of scenes and views...
154  all // ...and everything available.
155  };
156  // Simple graded message scheme.
157 
158 protected: // With description
159 
160  G4VisManager (const G4String& verbosityString = "warnings");
161  // The constructor is protected so that an object of the derived
162  // class may be constructed.
163 
164 public: // With description
165 
166  virtual ~G4VisManager ();
167 
168 private:
169 
170  // Private copy constructor and assigment operator - copying and
171  // assignment not allowed. Keeps CodeWizard happy.
172  G4VisManager (const G4VisManager&);
173  G4VisManager& operator = (const G4VisManager&);
174 
175  static G4VisManager* GetInstance ();
176  // Returns pointer to itself. Throws a G4Exception if called before
177  // instantiation. Private so that only friends can use; the normal
178  // user should instead use G4VVisManager::GetConcreteInstance () to
179  // get a "higher level" pointer for general use - but always test
180  // for non-zero.
181 
182 public: // With description
183 
184  void Initialise ();
185  void Initialize (); // Alias Initialise ().
186 
187  // Optional registration of user vis actions. Added to scene with
188  // /vis/scene/add/userAction.
190  (const G4String& name, G4VUserVisAction*,
193  (const G4String& name, G4VUserVisAction*,
196  (const G4String& name, G4VUserVisAction*,
198 
200  // Register an individual graphics system. Normally this is done in
201  // a sub-class implementation of the protected virtual function,
202  // RegisterGraphicsSystems. See, e.g., G4VisExecutive.icc.
203 
205  // Register trajectory draw model factory. Assumes ownership of factory.
206 
208  // Register trajectory model. Assumes ownership of model.
209 
211  // Register trajectory filter model factory. Assumes ownership of factory.
212 
214  // Register trajectory filter model. Assumes ownership of model.
215 
217  // Register trajectory hit model factory. Assumes ownership of factory.
218 
219  void RegisterModel(G4VFilter<G4VHit>* filter);
220  // Register trajectory hit model. Assumes ownership of model.
221 
223  // Register trajectory digi model factory. Assumes ownership of factory.
224 
225  void RegisterModel(G4VFilter<G4VDigi>* filter);
226  // Register trajectory digi model. Assumes ownership of model.
227 
228  void SelectTrajectoryModel(const G4String& model);
229  // Set default trajectory model. Useful for use in compiled code
230 
231  void RegisterMessenger(G4UImessenger* messenger);
232  // Register messenger. Assumes ownership of messenger.
233 
235  // Now functions that implement the pure virtual functions of
236  // G4VVisManager for drawing various visualization primitives, useful
237  // for representing hits, digis, etc.
238 
239  void Draw (const G4Circle&,
240  const G4Transform3D& objectTransformation = G4Transform3D());
241 
242  void Draw (const G4NURBS&,
243  const G4Transform3D& objectTransformation = G4Transform3D());
244 
245  void Draw (const G4Polyhedron&,
246  const G4Transform3D& objectTransformation = G4Transform3D());
247 
248  void Draw (const G4Polyline&,
249  const G4Transform3D& objectTransformation = G4Transform3D());
250 
251  void Draw (const G4Polymarker&,
252  const G4Transform3D& objectTransformation = G4Transform3D());
253 
254  void Draw (const G4Scale&,
255  const G4Transform3D& objectTransformation = G4Transform3D());
256 
257  void Draw (const G4Square&,
258  const G4Transform3D& objectTransformation = G4Transform3D());
259 
260  void Draw (const G4Text&,
261  const G4Transform3D& objectTransformation = G4Transform3D());
262 
263  void Draw2D (const G4Circle&,
264  const G4Transform3D& objectTransformation = G4Transform3D());
265 
266  void Draw2D (const G4NURBS&,
267  const G4Transform3D& objectTransformation = G4Transform3D());
268 
269  void Draw2D (const G4Polyhedron&,
270  const G4Transform3D& objectTransformation = G4Transform3D());
271 
272  void Draw2D (const G4Polyline&,
273  const G4Transform3D& objectTransformation = G4Transform3D());
274 
275  void Draw2D (const G4Polymarker&,
276  const G4Transform3D& objectTransformation = G4Transform3D());
277 
278  void Draw2D (const G4Square&,
279  const G4Transform3D& objectTransformation = G4Transform3D());
280 
281  void Draw2D (const G4Text&,
282  const G4Transform3D& objectTransformation = G4Transform3D());
283 
285  // Now functions that implement the pure virtual functions of
286  // G4VVisManager for drawing a GEANT4 object. Note that the
287  // visualization attributes needed in some cases override any
288  // visualization attributes that are associated with the object
289  // itself - thus you can, for example, change the colour of a
290  // physical volume.
291 
292  void Draw (const G4VHit&);
293 
294  void Draw (const G4VDigi&);
295 
296  void Draw (const G4VTrajectory&, G4int i_mode);
297  // i_mode is a parameter that can be used to control the drawing of
298  // the trajectory. See, e.g., G4VTrajectory::DrawTrajectory.
299  // i_mode defaults to 0 by inheritance from G4VVisManager.
300 
301  void Draw (const G4LogicalVolume&, const G4VisAttributes&,
302  const G4Transform3D& objectTransformation = G4Transform3D());
303 
304  void Draw (const G4VPhysicalVolume&, const G4VisAttributes&,
305  const G4Transform3D& objectTransformation = G4Transform3D());
306 
307  void Draw (const G4VSolid&, const G4VisAttributes&,
308  const G4Transform3D& objectTransformation = G4Transform3D());
309 
311  // Optional methods that you may use to bracket a series of Draw
312  // messages that have identical objectTransformation to improve
313  // drawing speed. Use Begin/EndDraw for a series of Draw messages,
314  // Begin/EndDraw2D for a series of Draw2D messages. Do not mix Draw
315  // and Draw2D messages.
316 
317  void BeginDraw
318  (const G4Transform3D& objectTransformation = G4Transform3D());
319 
320  void EndDraw ();
321 
322  void BeginDraw2D
323  (const G4Transform3D& objectTransformation = G4Transform3D());
324 
325  void EndDraw2D ();
326 
328  // Now other pure virtual functions of G4VVisManager...
329 
330  void GeometryHasChanged ();
331  // Used by run manager to notify change.
332 
333  void NotifyHandlers();
334  // Notify scene handlers (G4VGraphicsScene objects) that the scene
335  // has changed so that they may rebuild their graphics database, if
336  // any, and redraw all views.
337 
338  void DispatchToModel(const G4VTrajectory&);
339  void DispatchToModel(const G4VTrajectory&, G4int i_mode);
340  // Draw the trajectory.
341 
343  G4bool FilterHit(const G4VHit&);
344  G4bool FilterDigi(const G4VDigi&);
345 
347  // Administration routines.
348 
349  void CreateSceneHandler (G4String name = "");
350  // Creates scene handler for the current system.
351 
352  void CreateViewer (G4String name = "",G4String XGeometry = "");
353  // Creates viewer for the current scene handler.
354 
355 private:
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 
368 public: // With description
369 
371  // Access functions.
372 
373  void Enable();
374  void Disable();
375  // Global enable/disable functions.
376 
378 
379  struct UserVisAction {
380  UserVisAction(const G4String& name, G4VUserVisAction* pUserVisAction)
381  :fName(name), fpUserVisAction(pUserVisAction) {}
384  };
385  const std::vector<UserVisAction>& GetRunDurationUserVisActions () const;
386  const std::vector<UserVisAction>& GetEndOfEventUserVisActions () const;
387  const std::vector<UserVisAction>& GetEndOfRunUserVisActions () const;
388  const std::map<G4VUserVisAction*,G4VisExtent>& GetUserVisActionExtents () const;
390  G4Scene* GetCurrentScene () const;
392  G4VViewer* GetCurrentViewer () const;
394  // The above is non-const because it checks and updates the List by
395  // calling RegisterGraphicsSystems() if no graphics systems are
396  // already registered.
398  const G4SceneList& GetSceneList () const;
399  static Verbosity GetVerbosity ();
402  const G4Event* GetRequestedEvent () const;
405 
406  void SetUserAction
407  (G4VUserVisAction* pVisAction,
408  const G4VisExtent& = G4VisExtent::NullExtent); // Register run-duration.
409  void SetUserActionExtent (const G4VisExtent&); //Legacy: deprecated.
411  void SetCurrentScene (G4Scene*);
413  void SetCurrentViewer (G4VViewer*);
414  G4SceneHandlerList& SetAvailableSceneHandlers (); // Returns lvalue.
415  G4SceneList& SetSceneList (); // Returns lvalue.
416  void SetVerboseLevel (G4int);
417  void SetVerboseLevel (const G4String&);
418  void SetVerboseLevel (Verbosity);
419  void SetEventRefreshing (G4bool);
421  // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
422  void SetRequestedEvent (const G4Event*);
425 
427  // Utility functions.
428 
429  G4String ViewerShortName (const G4String& viewerName) const;
430  // Returns shortened version of viewer name, i.e., up to first space,
431  // if any.
432 
433  G4VViewer* GetViewer (const G4String& viewerName) const;
434  // Returns zero if not found. Can use long or short name, but find
435  // is done on short name.
436 
437  static Verbosity GetVerbosityValue(const G4String&);
438  // Returns verbosity given a string. (Uses first character only.)
439 
441  // Returns verbosity given an integer. If integer is out of range,
442  // selects verbosity at extreme of range.
443 
445  // Converts the verbosity into a string for suitable for printing.
446 
447  static std::vector<G4String> VerbosityGuidanceStrings;
448  // Guidance on the use of visualization verbosity.
449 
450 protected:
451 
452  virtual void RegisterGraphicsSystems () = 0;
453  // The sub-class must implement and make successive calls to
454  // RegisterGraphicsSystem.
455 
456  virtual void RegisterModelFactories();
457  // Sub-class must register desired models
458 
459  void RegisterMessengers (); // Command messengers.
460 
462  // fVerbose is kept for backwards compatibility for some user
463  // examples. (It is used in the derived user vis managers to print
464  // available graphics systems.) It is initialised to 1 in the
465  // constructor and cannot be changed.
466 
467  void PrintAvailableGraphicsSystems () const;
468 
469 private:
470 
471  // Function templates to implement the Draw methods (to avoid source
472  // code duplication).
473  template <class T> void DrawT
474  (const T& graphics_primitive, const G4Transform3D& objectTransform);
475  template <class T> void DrawT2D
476  (const T& graphics_primitive, const G4Transform3D& objectTransform);
477 
478  void PrintAvailableModels (Verbosity) const;
479  void PrintAvailableColours (Verbosity) const;
480  void PrintAvailableUserVisActions (Verbosity) const;
481  void PrintInvalidPointers () const;
482  G4bool IsValidView ();
483  // True if view is valid. Prints messages and sanitises various data.
484  void ClearTransientStoreIfMarked();
485  // Clears transient store of current scene handler if it is marked
486  // for clearing. Assumes view is valid.
487 
488  static G4VisManager* fpInstance; // Pointer to single instance.
489  G4bool fInitialised;
490  std::vector<UserVisAction> fRunDurationUserVisActions;
491  std::vector<UserVisAction> fEndOfEventUserVisActions;
492  std::vector<UserVisAction> fEndOfRunUserVisActions;
493  std::map<G4VUserVisAction*,G4VisExtent> fUserVisActionExtents;
494  G4VGraphicsSystem* fpGraphicsSystem; // Current graphics system.
495  G4Scene* fpScene; // Current scene.
496  G4VSceneHandler* fpSceneHandler; // Current scene handler.
497  G4VViewer* fpViewer; // Current viewer.
498  G4GraphicsSystemList fAvailableGraphicsSystems;
499  G4SceneList fSceneList;
500  G4SceneHandlerList fAvailableSceneHandlers;
501  static Verbosity fVerbosity;
502  std::vector<G4UImessenger*> fMessengerList;
503  std::vector<G4UIcommand*> fDirectoryList;
504  G4VisStateDependent* fpStateDependent; // Friend state dependent class.
505  G4TrajectoriesModel dummyTrajectoriesModel; // For passing drawing mode.
506  G4bool fEventRefreshing;
507  G4bool fTransientsDrawnThisRun;
508  G4bool fTransientsDrawnThisEvent;
509  G4bool fEventKeepingSuspended;
510  G4bool fKeptLastEvent;
511  const G4Event* fpRequestedEvent; // If non-zero, scene handler uses.
512  G4bool fAbortReviewKeptEvents;
513  G4ViewParameters fDefaultViewParameters;
514  G4bool fIsDrawGroup;
515  G4int fDrawGroupNestingDepth;
516 
517  // Trajectory draw model manager
518  G4VisModelManager<G4VTrajectoryModel>* fpTrajDrawModelMgr;
519 
520  // Trajectory filter model manager
521  G4VisFilterManager<G4VTrajectory>* fpTrajFilterMgr;
522 
523  // Hit filter model manager
524  G4VisFilterManager<G4VHit>* fpHitFilterMgr;
525 
526  // Digi filter model manager
527  G4VisFilterManager<G4VDigi>* fpDigiFilterMgr;
528 
529 };
530 
531 #include "G4VisManager.icc"
532 
533 #endif