source: trunk/source/visualization/management/include/G4VisManager.hh @ 1288

Last change on this file since 1288 was 1288, checked in by garnier, 14 years ago

update from CVS

  • Property svn:mime-type set to text/cpp
File size: 18.9 KB
Line 
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,v 1.75 2010/06/01 16:08:15 allison Exp $
28// GEANT4 tag $Name:  $
29//
30//
31
32// Class Description:
33//
34// The GEANT4 Visualization Manager - John Allison 02/Jan/1996.
35//
36// G4VisManager is a "Singleton", i.e., only one instance of it or any
37// derived class may exist.  A G4Exception is thrown if an attempt is
38// made to instantiate more than one.
39//
40// It is also an abstract class, so the user must derive his/her own
41// class from G4VisManager, implement the pure virtual function
42// RegisterGraphicsSystems, and instantiate an object of the derived
43// class - for an example see
44// visualization/include/G4VisExecutive.hh/icc.
45//
46// The recommended way for users to obtain a pointer to the vis
47// manager is with G4VVisManager::GetConcreteInstance (), being always
48// careful to test for non-zero.  This pointer is non-zero only when
49// (a) an object of the derived class exists and (b) when there is a
50// valid viewer available.
51//
52// Graphics system registration is normally done through the protected
53// pure virtual function RegisterGraphicsSystems called from
54// Initialise ().  You can also use the public function
55// RegisterGraphicsSystem (new MyGraphicsSystem) if you have your own
56// graphics system. A graphics system is, in effect, a factory for
57// scene handlers and viewers.
58//
59// The VisManager creates and manages graphics systems, scenes, scene
60// handlers, viewers and some models and model makers.  You can have
61// any number.  It has the concept of a "current viewer", and the
62// "current scene handler", the "current scene" and the "current
63// graphics system" which go with it.  You can select the current
64// viewer.  Most of the the operations of the VisManager take place
65// with the current viewer, in particular, the Draw operations.
66//
67// Each scene comprises drawable objects such as detector components
68// and trajectories, hits and digis when appropriate.  A scene handler
69// translates a scene into graphics-system-specific function calls
70// and, possibly, a graphics-system-dependent database - display
71// lists, scene graphs, etc.  Each viewer has its "view parameters"
72// (see class description of G4ViewParameters for available parameters
73// and also for a description of the concept of a "standard view" and
74// all that).
75//
76// A friend class G4VisStateDependent is "state dependent", i.e., it
77// is notified on change of state (G4ApplicationState).  This is used
78// to message the G4VisManager to draw hits, digis and trajectories in
79// the current scene at the end of event, as required.
80
81#ifndef G4VISMANAGER_HH
82#define G4VISMANAGER_HH
83
84#include "G4VVisManager.hh"
85
86#include "globals.hh"
87#include "G4GraphicsSystemList.hh"
88#include "G4ModelingParameters.hh"
89#include "G4NullModel.hh"
90#include "G4SceneHandlerList.hh"
91#include "G4SceneList.hh"
92#include "G4TrajectoriesModel.hh"
93#include "G4Transform3D.hh"
94#include "G4UImessenger.hh"
95
96#include <iostream>
97#include <vector>
98
99class G4Scene;
100class G4UIcommand;
101class G4UImessenger;
102class G4VisStateDependent;
103class G4VTrajectoryModel;
104class G4VUserVisAction;
105template <typename T> class G4VFilter;
106template <typename T> class G4VisFilterManager;
107template <typename T> class G4VisModelManager;
108template <typename T> class G4VModelFactory;
109class G4Event;
110
111namespace {
112  // Useful typedef's
113  typedef G4VModelFactory<G4VTrajectoryModel> G4TrajDrawModelFactory;
114  typedef G4VModelFactory< G4VFilter<G4VTrajectory> > G4TrajFilterFactory;
115  typedef G4VModelFactory< G4VFilter<G4VHit> > G4HitFilterFactory;
116  typedef G4VModelFactory< G4VFilter<G4VDigi> > G4DigiFilterFactory;
117}
118
119class G4VisManager: public G4VVisManager {
120
121  // Friends - classes and functions which need access to private
122  // members of G4VisManager.  This is mainly to obtain access to
123  // GetInstance (), which is private.  The correct way for normal
124  // users to obtain a pointer to the vis manager is with
125  // G4VVisManager::GetConcreteInstance (), always testing for
126  // non-zero.
127
128  // Odd friends that need access to the G4VisManager...
129  friend class G4RTSteppingAction;
130  friend class G4RayTrajectory;
131  friend class G4RayTracerSceneHandler;
132  friend class G4RTMessenger;
133  friend class G4OpenGLViewerMessenger;
134  friend class G4OpenGLXmViewerMessenger;
135  friend class G4HepRepFileSceneHandler;
136
137  // Management friends...
138  friend class G4VSceneHandler;
139  friend class G4VViewer;
140  friend class G4VisStateDependent;
141  friend class G4VisCommandList;
142
143  // operator << friends...
144  friend std::ostream& operator << (std::ostream&, const G4VGraphicsSystem&);
145  friend std::ostream& operator << (std::ostream&, const G4VSceneHandler&);
146
147public: // With description
148
149  enum Verbosity {
150    quiet,         // Nothing is printed.
151    startup,       // Startup and endup messages are printed...
152    errors,        // ...and errors...
153    warnings,      // ...and warnings...
154    confirmations, // ...and confirming messages...
155    parameters,    // ...and parameters of scenes and views...
156    all            // ...and everything available.
157  };
158  // Simple graded message scheme.
159
160protected: // With description
161
162  G4VisManager (const G4String& verbosityString = "warnings");
163  // The constructor is protected so that an object of the derived
164  // class may be constructed.
165
166public: // With description
167
168  virtual ~G4VisManager ();
169
170private:
171
172  // Private copy constructor and assigment operator - copying and
173  // assignment not allowed.  Keeps CodeWizard happy.
174  G4VisManager (const G4VisManager&);
175  G4VisManager& operator = (const G4VisManager&);
176
177  static G4VisManager* GetInstance ();
178  // Returns pointer to itself.  Throws a G4Exception if called before
179  // instantiation.  Private so that only friends can use; the normal
180  // user should instead use G4VVisManager::GetConcreteInstance () to
181  // get a "higher level" pointer for general use - but always test
182  // for non-zero.
183
184public: // With description
185
186  void Initialise ();
187  void Initialize ();  // Alias Initialise ().
188
189  G4bool RegisterGraphicsSystem (G4VGraphicsSystem*);
190  // Register an individual graphics system.  Normally this is done in
191  // a sub-class implementation of the protected virtual function,
192  // RegisterGraphicsSystems.  See, e.g., G4VisExecutive.icc.
193
194  void RegisterModelFactory(G4TrajDrawModelFactory* factory);
195  // Register trajectory draw model factory. Assumes ownership of factory.
196
197  void RegisterModel(G4VTrajectoryModel* model);
198  // Register trajectory model. Assumes ownership of model.
199
200  void RegisterModelFactory(G4TrajFilterFactory* factory);
201  // Register trajectory filter model factory. Assumes ownership of factory.
202
203  void RegisterModel(G4VFilter<G4VTrajectory>* filter);
204  // Register trajectory filter model. Assumes ownership of model.
205
206  void RegisterModelFactory(G4HitFilterFactory* factory);
207  // Register trajectory hit model factory. Assumes ownership of factory.
208
209  void RegisterModel(G4VFilter<G4VHit>* filter);
210  // Register trajectory hit model. Assumes ownership of model.
211
212  void RegisterModelFactory(G4DigiFilterFactory* factory);
213  // Register trajectory digi model factory. Assumes ownership of factory.
214
215  void RegisterModel(G4VFilter<G4VDigi>* filter);
216  // Register trajectory digi model. Assumes ownership of model.
217
218  void SelectTrajectoryModel(const G4String& model);
219  // Set default trajectory model. Useful for use in compiled code
220
221  void RegisterMessenger(G4UImessenger* messenger);
222  // Register messenger. Assumes ownership of messenger.
223
224  /////////////////////////////////////////////////////////////////
225  // Now functions that implement the pure virtual functions of
226  // G4VVisManager for drawing various visualization primitives, useful
227  // for representing hits, digis, etc.
228
229  void Draw (const G4Circle&,
230    const G4Transform3D& objectTransformation = G4Transform3D());
231
232  void Draw (const G4NURBS&,
233    const G4Transform3D& objectTransformation = G4Transform3D());
234
235  void Draw (const G4Polyhedron&,
236    const G4Transform3D& objectTransformation = G4Transform3D());
237
238  void Draw (const G4Polyline&,
239    const G4Transform3D& objectTransformation = G4Transform3D());
240
241  void Draw (const G4Polymarker&,
242    const G4Transform3D& objectTransformation = G4Transform3D());
243
244  void Draw (const G4Scale&,
245    const G4Transform3D& objectTransformation = G4Transform3D());
246
247  void Draw (const G4Square&,
248    const G4Transform3D& objectTransformation = G4Transform3D());
249
250  void Draw (const G4Text&,
251    const G4Transform3D& objectTransformation = G4Transform3D());
252
253  virtual void Draw2D (const G4Circle&,
254    const G4Transform3D& objectTransformation = G4Transform3D());
255
256  virtual void Draw2D (const G4NURBS&,
257    const G4Transform3D& objectTransformation = G4Transform3D());
258
259  virtual void Draw2D (const G4Polyhedron&,
260    const G4Transform3D& objectTransformation = G4Transform3D());
261
262  virtual void Draw2D (const G4Polyline&,
263    const G4Transform3D& objectTransformation = G4Transform3D());
264
265  virtual void Draw2D (const G4Polymarker&,
266    const G4Transform3D& objectTransformation = G4Transform3D());
267
268  virtual void Draw2D (const G4Square&,
269    const G4Transform3D& objectTransformation = G4Transform3D());
270
271  virtual void Draw2D (const G4Text&,
272    const G4Transform3D& objectTransformation = G4Transform3D());
273
274  ////////////////////////////////////////////////////////////////////
275  // Now functions that implement the pure virtual functions of
276  // G4VVisManager for drawing a GEANT4 object.  Note that the
277  // visualization attributes needed in some cases override any
278  // visualization attributes that are associated with the object
279  // itself - thus you can, for example, change the colour of a
280  // physical volume.
281
282  void Draw (const G4VHit&);
283
284  void Draw (const G4VDigi&);
285
286  void Draw (const G4VTrajectory&, G4int i_mode);
287  // i_mode is a parameter that can be used to control the drawing of
288  // the trajectory.  See, e.g., G4VTrajectory::DrawTrajectory.
289  // i_mode defaults to 0 by inheritance from G4VVisManager.
290
291  void Draw (const G4LogicalVolume&, const G4VisAttributes&,
292    const G4Transform3D& objectTransformation = G4Transform3D());
293
294  void Draw (const G4VPhysicalVolume&, const G4VisAttributes&,
295    const G4Transform3D& objectTransformation = G4Transform3D());
296
297  void Draw (const G4VSolid&, const G4VisAttributes&,
298    const G4Transform3D& objectTransformation = G4Transform3D());
299
300  ////////////////////////////////////////////////////////////////////////
301  // Now other pure virtual functions of G4VVisManager...
302
303  void GeometryHasChanged ();
304  // Used by run manager to notify change.
305
306  void NotifyHandlers();
307  // Notify scene handlers (G4VGraphicsScene objects) that the scene
308  // has changed so that they may rebuild their graphics database, if
309  // any, and redraw all views.
310
311  void DispatchToModel(const G4VTrajectory&);
312  void DispatchToModel(const G4VTrajectory&, G4int i_mode);
313  // Draw the trajectory.
314
315  G4bool FilterTrajectory(const G4VTrajectory&);
316  G4bool FilterHit(const G4VHit&);
317  G4bool FilterDigi(const G4VDigi&);
318
319  ////////////////////////////////////////////////////////////////////////
320  // Administration routines.
321
322  void CreateSceneHandler (G4String name = "");
323  // Creates scene handler for the current system.
324
325  void CreateViewer  (G4String name = "",G4String XGeometry = "");
326  // Creates viewer for the current scene handler.
327
328private:
329
330  void BeginOfRun ();
331
332  void BeginOfEvent ();
333
334  void EndOfEvent ();
335  // This is called on change of state (G4ApplicationState).  It is
336  // used to draw hits, digis and trajectories if included in the
337  // current scene at the end of event, as required.
338
339  void EndOfRun ();
340
341public: // With description
342
343  /////////////////////////////////////////////////////////////////////
344  // Access functions.
345
346  void Enable();
347  void Disable();
348  // Global enable/disable functions.
349
350  const G4VTrajectoryModel* CurrentTrajDrawModel() const;
351
352  G4VUserVisAction*            GetUserAction               () const;
353  G4VisExtent                  GetUserActionExtent         () const;
354  G4VGraphicsSystem*           GetCurrentGraphicsSystem    () const;
355  G4Scene*                     GetCurrentScene             () const;
356  G4VSceneHandler*             GetCurrentSceneHandler      () const;
357  G4VViewer*                   GetCurrentViewer            () const;
358  const G4GraphicsSystemList&  GetAvailableGraphicsSystems ();
359  // The above is non-const because it checks and updates the List by
360  // calling RegisterGraphicsSystems() if no graphics systems are
361  // already registered.
362  const G4SceneHandlerList&    GetAvailableSceneHandlers   () const;
363  const G4SceneList&           GetSceneList                () const;
364  static Verbosity             GetVerbosity                ();
365  G4bool                       GetTransientsDrawnThisRun       () const;
366  G4bool                       GetTransientsDrawnThisEvent     () const;
367  const G4Event*               GetRequestedEvent               () const;
368  G4bool                       GetAbortReviewKeptEvents        () const;
369
370  void SetUserAction (G4VUserVisAction* pVisAction,
371                      const G4VisExtent& = G4VisExtent::NullExtent);
372  void SetUserActionExtent (const G4VisExtent&);
373  void              SetCurrentGraphicsSystem    (G4VGraphicsSystem*);
374  void              SetCurrentScene             (G4Scene*);
375  void              SetCurrentSceneHandler      (G4VSceneHandler*);
376  void              SetCurrentViewer            (G4VViewer*);
377  G4SceneHandlerList& SetAvailableSceneHandlers ();  // Returns lvalue.
378  G4SceneList&      SetSceneList                ();  // Returns lvalue.
379  void              SetVerboseLevel             (G4int);
380  void              SetVerboseLevel             (const G4String&);
381  void              SetVerboseLevel             (Verbosity);
382  void              SetEventRefreshing          (G4bool);
383  void              ResetTransientsDrawnFlags   ();
384  // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
385  void              SetRequestedEvent           (const G4Event*);
386  void              SetAbortReviewKeptEvents    (G4bool);
387
388  /////////////////////////////////////////////////////////////////////
389  // Utility functions.
390
391  G4String ViewerShortName (const G4String& viewerName) const;
392  // Returns shortened version of viewer name, i.e., up to first space,
393  // if any.
394
395  G4VViewer* GetViewer (const G4String& viewerName) const;
396  // Returns zero if not found.  Can use long or short name, but find
397  // is done on short name.
398
399  static Verbosity GetVerbosityValue(const G4String&);
400  // Returns verbosity given a string.  (Uses first character only.)
401
402  static Verbosity GetVerbosityValue(G4int);
403  // Returns verbosity given an integer.  If integer is out of range,
404  // selects verbosity at extreme of range.
405
406  static G4String VerbosityString(Verbosity);
407  // Converts the verbosity into a string for suitable for printing.
408 
409  static std::vector<G4String> VerbosityGuidanceStrings;
410  // Guidance on the use of visualization verbosity.
411
412protected:
413
414  virtual void RegisterGraphicsSystems () = 0;
415  // The sub-class must implement and make successive calls to
416  // RegisterGraphicsSystem.
417
418  virtual void RegisterModelFactories();
419  // Sub-class must register desired models
420
421  void RegisterMessengers              ();   // Command messengers.
422
423  const G4int           fVerbose;
424  // fVerbose is kept for backwards compatibility for some user
425  // examples.  (It is used in the derived user vis managers to print
426  // available graphics systems.)  It is initialised to 1 in the
427  // constructor and cannot be changed.
428
429  void PrintAvailableGraphicsSystems   () const;
430
431private:
432
433  void PrintAvailableModels            (Verbosity) const;
434  void PrintInvalidPointers            () const;
435  G4bool IsValidView ();
436  // True if view is valid.  Prints messages and sanitises various data.
437  void ClearTransientStoreIfMarked();
438  // Clears transient store of current scene handler if it is marked
439  // for clearing.  Assumes view is valid.
440
441  static G4VisManager*  fpInstance;         // Pointer to single instance.
442  G4bool                fInitialised;
443  G4VUserVisAction*     fpUserVisAction;    // User vis action callback.
444  G4VisExtent           fUserVisActionExtent;
445  G4VGraphicsSystem*    fpGraphicsSystem;   // Current graphics system.
446  G4Scene*              fpScene;            // Current scene.
447  G4VSceneHandler*      fpSceneHandler;     // Current scene handler.
448  G4VViewer*            fpViewer;           // Current viewer.
449  G4GraphicsSystemList  fAvailableGraphicsSystems;
450  G4SceneList           fSceneList;
451  G4SceneHandlerList    fAvailableSceneHandlers;
452  static Verbosity             fVerbosity;
453  std::vector<G4UImessenger*> fMessengerList;
454  std::vector<G4UIcommand*>   fDirectoryList;
455  G4VisStateDependent*  fpStateDependent;   // Friend state dependent class.
456  G4TrajectoriesModel   dummyTrajectoriesModel;  // For passing drawing mode.
457  G4bool                fEventRefreshing;
458  G4bool                fTransientsDrawnThisRun;
459  G4bool                fTransientsDrawnThisEvent;
460  G4bool                fEventKeepingSuspended;
461  G4bool                fKeptLastEvent;
462  const G4Event*        fpRequestedEvent; // If non-zero, scene handler uses.
463  G4bool                fAbortReviewKeptEvents;
464
465  // Trajectory draw model manager
466  G4VisModelManager<G4VTrajectoryModel>* fpTrajDrawModelMgr;
467 
468  // Trajectory filter model manager
469  G4VisFilterManager<G4VTrajectory>* fpTrajFilterMgr;
470
471  // Hit filter model manager
472  G4VisFilterManager<G4VHit>* fpHitFilterMgr;
473
474  // Digi filter model manager
475  G4VisFilterManager<G4VDigi>* fpDigiFilterMgr;
476
477};
478
479#include "G4VisManager.icc"
480
481#endif
Note: See TracBrowser for help on using the repository browser.