Geant4  10.02.p01
G4VViewer.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: G4VViewer.hh 90651 2015-06-05 13:30:54Z gcosmo $
28 //
29 //
30 // John Allison 27th March 1996
31 //
32 // Class description
33 //
34 // Abstract interface class for graphics viewers.
35 
36 #ifndef G4VVIEWER_HH
37 #define G4VVIEWER_HH
38 
39 #include "globals.hh"
40 
41 #include "G4ViewParameters.hh"
42 
43 class G4VSceneHandler;
44 
45 class G4VViewer {
46 
47 public: // With description
48 
49  friend std::ostream& operator << (std::ostream& os, const G4VViewer& v);
50 
51  G4VViewer (G4VSceneHandler&, G4int id, const G4String& name = "");
52  virtual ~G4VViewer ();
53 
54  virtual void Initialise ();
55  // Called immediately after construction for those operations that
56  // must await complete contruction of viewer and all its bases. For
57  // example, if this class (G4VViewer) is inherited virtually, as in
58  // the OpenGL sub-category, it will not be fully constructed until
59  // *after* the the derived viewer (this is the rule about order of
60  // construction for virtual inheritance), so the derived viewer may
61  // not use information in G4VViewer in its contructor. Hence such
62  // code must be in Initialise().
63 
65  // View manipulation functions.
66 
67  virtual void ResetView ();
68  // Reset view parameters to default, including sub-class parameters, if any.
69  // The sub-class should always invoke the base class implementation, i.e:
70  // virtual void SubClass::ResetView () {
71  // G4VViewer::ResetView();
72  // // Then reset sub-class parameters
73  // ...
74 
75  virtual void SetView () = 0;
76  // Take view parameters and work out model/view transformation,
77  // projection transformation, lighting, etc.
78 
79  virtual void ClearView () = 0;
80  // Clear screen/viewing buffers.
81 
82  virtual void DrawView () = 0;
83  // Draw view of the scene currently attached to the scene handler -
84  // see example of a minimal function at end of this file.
85 
86  void RefreshView ();
87  // Simply invokes SetView, ClearView, DrawView.
88 
89  virtual void ShowView ();
90  // Show view (for graphics systems which require to process
91  // all drawn objects before finalising the view).
92 
93  virtual void FinishView ();
94  // Called at the end of drawing scene. Used to flush streams, or
95  // swap buffers. (Perhaps it is inappropriately named, perhaps its
96  // function could be incorporated into EndModeling (). It marks the
97  // end of scene drawing; be aware hits and digi drawing may Follow.
98  // It is not yet the end of all drawing; that is signalled by
99  // ShowView ().)
100 
101 #ifdef G4MULTITHREADED
102  // In MT mode these functions are called in the following order for each run:
103  // Called on the master thread before starting the vis sub-thread.
104  virtual void DoneWithMasterThread ();
105  // Called on the master thread after starting the vis sub-thread.
106  virtual void MovingToVisSubThread ();
107  // Called on the vis sub-thread when waiting for events.
108  virtual void SwitchToVisSubThread ();
109  // Called on the vis sub-thread when all events have been processed.
110  virtual void DoneWithVisSubThread ();
111  // Called on the vis sub-thread when all events have been processed.
112  virtual void MovingToMasterThread ();
113  // Called on the master thread after the vis sub-thread has terminated.
114  virtual void SwitchToMasterThread ();
115 #endif
116 
118  // Access functions.
119  const G4String& GetName () const;
120  const G4String& GetShortName () const;
121  void SetName (const G4String&);
122  G4int GetViewId () const;
124  const G4ViewParameters& GetViewParameters () const;
126 
127  virtual const std::vector<G4ModelingParameters::VisAttributesModifier>*
129  // So that privately accumulated vis attributes modifiers may be
130  // concatenated with the standard vis attributes modifiers for commands
131  // such as /vis/viewer/set/all and /vis/viewer/save.
132 
133  void SetViewParameters (const G4ViewParameters& vp);
135 
137  // Public utility functions.
138 
140  (const G4VisAttributes*) const;
141 
142  void SetNeedKernelVisit (G4bool need);
143  // Sets individual need-visit flag.
144 
145  void NeedKernelVisit ();
146  // Flags all views the need to re-visit the GEANT4 kernel to refresh
147  // the scene.
148 
149  void ProcessView ();
150  // Used by DrawView (). Invokes SetView (). The basic logic is here.
151 
152 protected:
153 
155  // Data members
156  G4VSceneHandler& fSceneHandler; // Abstract scene for this view.
157  G4int fViewId; // Id of this instance.
159  G4String fShortName; // Up to first ' ' character, if any.
160  G4ViewParameters fVP; // View parameters.
161  G4ViewParameters fDefaultVP; // Default view parameters.
162 
164  // Other parameters.
165  G4bool fNeedKernelVisit; // See DrawView() for comments.
166 };
167 
168 #include "G4VViewer.icc"
169 
170 /*********************************************
171 
172 Here is a minimal DrawView () as it might be implemented in the
173 concrete viewer.
174 
175 void G4VViewer::DrawView () { // Default - concrete view usually overrides.
176 
177  // First, a view should decide when to re-visit the G4 kernel.
178  // Sometimes it might not be necessary, e.g., if the scene is stored
179  // in a graphical database (e.g., OpenGL's display lists) and only
180  // the viewing angle has changed. But graphics systems without a
181  // graphical database will always need to visit the G4 kernel.
182 
183  NeedKernelVisit (); // Default is - always visit G4 kernel.
184  // Note: this routine sets the fNeedKernelVisit flag of *all* the views of
185  // the scene.
186 
187  ProcessView (); // The basic logic is here.
188 
189  // Then a view may have more to do, e.g., display the graphical
190  // database. That code should come here before finally...
191 
192  FinishView (); // Flush streams and/or swap buffers.
193 }
194 
195 *********************************************/
196 
197 #endif
void SetName(const G4String &)
Definition: G4VViewer.cc:71
const G4String & GetName() const
G4int fViewId
Definition: G4VViewer.hh:157
virtual void SetView()=0
G4int GetViewId() const
virtual void ClearView()=0
virtual void ShowView()
Definition: G4VViewer.cc:113
G4String name
Definition: TRTMaterials.hh:40
const G4ViewParameters & GetViewParameters() const
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:130
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
Definition: G4VViewer.cc:78
int G4int
Definition: G4Types.hh:78
G4ViewParameters fDefaultVP
Definition: G4VViewer.hh:161
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
Definition: G4VViewer.cc:45
const G4String & GetShortName() const
const G4ViewParameters & GetDefaultViewParameters() const
virtual void ResetView()
void SetNeedKernelVisit(G4bool need)
bool G4bool
Definition: G4Types.hh:79
void SetDefaultViewParameters(const G4ViewParameters &vp)
G4ViewParameters fVP
Definition: G4VViewer.hh:160
virtual void Initialise()
G4bool fNeedKernelVisit
Definition: G4VViewer.hh:165
G4String fName
Definition: G4VViewer.hh:158
virtual ~G4VViewer()
Definition: G4VViewer.cc:67
G4VSceneHandler * GetSceneHandler() const
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers() const
void NeedKernelVisit()
Definition: G4VViewer.cc:86
void RefreshView()
void ProcessView()
Definition: G4VViewer.cc:115
G4String fShortName
Definition: G4VViewer.hh:159
G4VSceneHandler & fSceneHandler
Definition: G4VViewer.hh:156
virtual void FinishView()
Definition: G4VViewer.cc:111
virtual void DrawView()=0
friend std::ostream & operator<<(std::ostream &os, const G4VViewer &v)
Definition: G4VViewer.cc:163