Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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"
88#include "G4NullModel.hh"
89#include "G4SceneHandlerList.hh"
90#include "G4SceneList.hh"
92#include "G4Transform3D.hh"
93#include "G4UImessenger.hh"
94
95#include <iostream>
96#include <vector>
97#include <map>
98
99class G4Scene;
100class G4UIcommand;
101class G4UImessenger;
104class G4VUserVisAction;
105template <typename> class G4VFilter;
106template <typename> class G4VisFilterManager;
107template <typename> class G4VisModelManager;
108template <typename> class G4VModelFactory;
109class 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;
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
145public: // With description
146
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
158protected: // 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
164public: // With description
165
166 virtual ~G4VisManager ();
167
168private:
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
182public: // 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
232 // Register messenger. Assumes ownership of messenger.
233
234 /////////////////////////////////////////////////////////////////
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
284 ////////////////////////////////////////////////////////////////////
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
310 //////////////////////////////////////////////////////////////////////
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
327 ////////////////////////////////////////////////////////////////////////
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
346 ////////////////////////////////////////////////////////////////////////
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
355private:
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
368public: // With description
369
370 /////////////////////////////////////////////////////////////////////
371 // Access functions.
372
373 void Enable();
374 void Disable();
375 // Global enable/disable functions.
376
378
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;
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
407 (G4VUserVisAction* pVisAction,
408 const G4VisExtent& = G4VisExtent::NullExtent); // Register run-duration.
409 void SetUserActionExtent (const G4VisExtent&); //Legacy: deprecated.
411 void SetCurrentScene (G4Scene*);
415 G4SceneList& SetSceneList (); // Returns lvalue.
416 void SetVerboseLevel (G4int);
417 void SetVerboseLevel (const G4String&);
421 // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
425
426 /////////////////////////////////////////////////////////////////////
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
450protected:
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
469private:
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
HepGeom::Transform3D G4Transform3D
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
G4VModelFactory< G4VFilter< G4VHit > > G4HitFilterFactory
G4VModelFactory< G4VTrajectoryModel > G4TrajDrawModelFactory
G4VModelFactory< G4VFilter< G4VTrajectory > > G4TrajFilterFactory
G4VModelFactory< G4VFilter< G4VDigi > > G4DigiFilterFactory
Definition: G4Text.hh:73
Definition: G4VHit.hh:49
static const G4VisExtent NullExtent
Definition: G4VisExtent.hh:80
void Initialize()
void SelectTrajectoryModel(const G4String &model)
void Draw(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
G4Scene * GetCurrentScene() const
void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
virtual void RegisterGraphicsSystems()=0
void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())
friend class G4OpenGLXmViewerMessenger
void SetCurrentSceneHandler(G4VSceneHandler *)
const std::vector< UserVisAction > & GetRunDurationUserVisActions() const
const G4VTrajectoryModel * CurrentTrajDrawModel() const
G4bool FilterDigi(const G4VDigi &)
void SetEventRefreshing(G4bool)
void SetCurrentScene(G4Scene *)
static std::vector< G4String > VerbosityGuidanceStrings
static G4String VerbosityString(Verbosity)
void RegisterEndOfEventUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
G4bool GetTransientsDrawnThisEvent() const
G4String ViewerShortName(const G4String &viewerName) const
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 CreateSceneHandler(G4String name="")
const G4ViewParameters & GetDefaultViewParameters() const
void SetUserActionExtent(const G4VisExtent &)
const std::vector< UserVisAction > & GetEndOfRunUserVisActions() const
void RegisterModelFactory(G4TrajDrawModelFactory *factory)
G4bool GetTransientsDrawnThisRun() const
void EndDraw2D()
G4SceneList & SetSceneList()
G4VGraphicsSystem * GetCurrentGraphicsSystem() const
G4bool FilterHit(const G4VHit &)
void SetUserAction(G4VUserVisAction *pVisAction, const G4VisExtent &=G4VisExtent::NullExtent)
void SetAbortReviewKeptEvents(G4bool)
G4SceneHandlerList & SetAvailableSceneHandlers()
G4VViewer * GetCurrentViewer() const
void SetRequestedEvent(const G4Event *)
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
const std::vector< UserVisAction > & GetEndOfEventUserVisActions() const
virtual void RegisterModelFactories()
virtual ~G4VisManager()
G4VSceneHandler * GetCurrentSceneHandler() const
void RegisterEndOfRunUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
const G4SceneList & GetSceneList() const
static Verbosity GetVerbosity()
void Initialise()
void RegisterMessengers()
void ResetTransientsDrawnFlags()
void CreateViewer(G4String name="", G4String XGeometry="")
G4bool FilterTrajectory(const G4VTrajectory &)
void SetVerboseLevel(G4int)
void SetDefaultViewParameters(const G4ViewParameters &)
void NotifyHandlers()
void RegisterRunDurationUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
const G4SceneHandlerList & GetAvailableSceneHandlers() const
void SetVerboseLevel(Verbosity)
const G4Event * GetRequestedEvent() const
static Verbosity GetVerbosityValue(const G4String &)
void GeometryHasChanged()
const G4GraphicsSystemList & GetAvailableGraphicsSystems()
void BeginDraw(const G4Transform3D &objectTransformation=G4Transform3D())
const G4int fVerbose
void DispatchToModel(const G4VTrajectory &)
void PrintAvailableGraphicsSystems() const
G4VViewer * GetViewer(const G4String &viewerName) const
UserVisAction(const G4String &name, G4VUserVisAction *pUserVisAction)
G4VUserVisAction * fpUserVisAction