Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
28//
29// John Allison 27th March 1996
30//
31// Class description
32//
33// Abstract interface class for graphics viewers.
34
35#ifndef G4VVIEWER_HH
36#define G4VVIEWER_HH
37
38#include "globals.hh"
39
40#include "G4SceneTreeItem.hh"
41
42#include "G4ViewParameters.hh"
44#include "G4PseudoScene.hh"
45
46#include <vector>
47#include <list>
48
49class G4VSceneHandler;
50
51// clang-format off
52class G4VViewer {
53
54public: // With description
55
56 friend std::ostream& operator << (std::ostream& os, const G4VViewer& v);
57
58 G4VViewer (G4VSceneHandler&, G4int id, const G4String& name = "");
59 virtual ~G4VViewer ();
60
61 virtual void Initialise ();
62 // Called immediately after construction for those operations that
63 // must await complete contruction of viewer and all its bases. For
64 // example, if this class (G4VViewer) is inherited virtually, as in
65 // the OpenGL sub-category, it will not be fully constructed until
66 // *after* the the derived viewer (this is the rule about order of
67 // construction for virtual inheritance), so the derived viewer may
68 // not use information in G4VViewer in its contructor. Hence such
69 // code must be in Initialise().
70
71 //////////////////////////////////////////////////////////////
72 // View manipulation functions.
73
74 virtual void ResetView ();
75 // Reset view parameters to default, including sub-class parameters, if any.
76 // The sub-class should always invoke the base class implementation, i.e:
77 // virtual void SubClass::ResetView () {
78 // G4VViewer::ResetView();
79 // // Then reset sub-class parameters
80 // ...
81
82 virtual void SetView () = 0;
83 // Take view parameters and work out model/view transformation,
84 // projection transformation, lighting, etc.
85
86 virtual void ClearView () = 0;
87 // Clear screen/viewing buffers.
88
89 virtual void DrawView () = 0;
90 // Draw view of the scene currently attached to the scene handler -
91 // see example of a minimal function at end of this file.
92
93 void RefreshView ();
94 // Simply invokes SetView, ClearView, DrawView.
95
96 virtual void ShowView ();
97 // Show view (for graphics systems which require to process
98 // all drawn objects before finalising the view).
99
100 virtual void FinishView ();
101 // Called at the end of drawing scene. Used to flush streams, or
102 // swap buffers. (Perhaps it is inappropriately named, perhaps its
103 // function could be incorporated into EndModeling (). It marks the
104 // end of scene drawing; be aware hits and digi drawing may Follow.
105 // It is not yet the end of all drawing; that is signalled by
106 // ShowView ().)
107
108 std::vector<G4ThreeVector> ComputeFlyThrough(G4Vector3D*);
109
110#ifdef G4MULTITHREADED
111 // Note: the order of calling of MovingToVisSubThread and SwitchToVisSubThread
112 // is undefined, so you may need to implement mutexes to ensure your preferred
113 // order - see, e.g., G4OpenGLQtViewer. To summarise, the order of calling is
114 // as follows - see G4VisManager.cc.
115 // DoneWithMasterThread
116 // MovingToVisSubThread ) or ( SwitchToVisSubThread
117 // SwitchToVisSubThread ) ( MovingToVisSubThread
118 // DoneWithVisSubThread
119 // MovingToMasterThread
120 // SwitchToMasterThread
121
122 // Called on the master thread before starting the vis sub-thread.
123 virtual void DoneWithMasterThread ();
124
125 // Called on the master thread after starting the vis sub-thread.
126 virtual void MovingToVisSubThread ();
127
128 // Called on the vis sub-thread at start of vis sub-thread.
129 virtual void SwitchToVisSubThread ();
130
131 // Called on the vis sub-thread when all events have been processed.
132 virtual void DoneWithVisSubThread ();
133
134 // Called on the vis sub-thread when all events have been processed.
135 virtual void MovingToMasterThread ();
136
137 // Called on the master thread after the vis sub-thread has terminated.
138 virtual void SwitchToMasterThread ();
139#endif
140
141 //////////////////////////////////////////////////////////////
142 // Stuff for scene tree.
143 /**
144 - The scene tree is a tree of G4SceneTreeItem objects (see graphics-reps).
145 - Its root is a data member fSceneTree of all viewers by virtue of
146 G4VViewer inheritance,
147 - G4SceneTreeItem is an aggregate of data members that represent
148 properties of objects in the scene (G4Scene). Its data members are
149 low-level types - G4String, G4VisAttributes and G4AttDef/Value - so
150 that it can be used across categories, avoiding coupling.
151 - The root item has children that represent the models (G4VModel
152 sub-classes) in the scene.
153 - For a G4PhysicalVolumeModel (detector components), its children and
154 children's children, etc., imitate the geometry hierarchy of that
155 model. These descendants are called "touchables".
156 - There may be more than one G4PhysicalVolumeModel, depending how
157 the user creates his/her scene.
158 - The scene tree is reviewed, and updated if necessary, at every pass
159 of G4VSceneHandler::ProcessScene. This is called a "kernel visit".
160 - A kernel visit is triggered by some vis commands (e.g.,
161 /vis/viewer/rebuild) and by a viewer if it deems necessary. For
162 example, a kernel visit may not be required for a rotation, zoom, etc.,
163 but required for a change from surface to wireframe.
164 - The idea is that the scene tree can be passed to a GUI, the GUI can
165 create a tree widget, and interactions with it raise UI commands such as
166 /vis/scene/activateModel, /vis/set/touchable and /vis/touchable/set/...
167 The viewer decides if this requires a kernel visit, otherwise it
168 must update fSceneTree itself (utilities are provided -
169 G4VViewer::TouchableSetVisibility/Colour).
170 */
172 // G4PhysicalVolumeModel sends touchables to this scene
173 public:
174 SceneTreeScene() = default;
175 ~SceneTreeScene() = default;
176 void SetViewer(G4VViewer* pViewer) {fpViewer = pViewer;}
177 void SetModel(G4VModel* pModel); // ...and more (see .cc)
178 private:
179 void ProcessVolume(const G4VSolid& solid) override;
180 std::list<G4SceneTreeItem>::iterator FindOrInsertModel
181 (const G4String& modelType,const G4String& modelID);
182 std::list<G4SceneTreeItem>::iterator FindOrInsertTouchable
183 (const G4String& modelID, G4SceneTreeItem& mother,
184 G4int depth, const G4String& partialPathString, const G4String& fullPathString);
185 G4VViewer* fpViewer = nullptr;
186 G4VModel* fpModel = nullptr;
187 G4int fMaximumExpandedDepth = 0; // To be calculated in SetModel
188 const G4int fMaximumExpanded = 30; // So as not to swamp the GUI
189 };
192 void UpdateGUISceneTree(); // A utility
193
194 //////////////////////////////////////////////////////////////
195 // Access functions.
196 const G4String& GetName () const;
197 const G4String& GetShortName () const;
198 void SetName (const G4String&);
199 G4int GetViewId () const;
204
205 virtual const std::vector<G4ModelingParameters::VisAttributesModifier>*
207 // So that privately accumulated vis attributes modifiers may be
208 // concatenated with the standard vis attributes modifiers for commands
209 // such as /vis/viewer/set/all and /vis/viewer/save.
210
211 void SetViewParameters (const G4ViewParameters& vp);
213
214 //////////////////////////////////////////////////////////////
215 // Public utility functions.
216
218 (const G4VisAttributes*) const;
219
221 // Sets individual need-visit flag.
222
223 void NeedKernelVisit ();
224 // Flags all views the need to re-visit the GEANT4 kernel to refresh
225 // the scene.
226
227 void ProcessView ();
228 // Used by DrawView (). Invokes SetView (). The basic logic is here.
229
230protected:
231
232 //////////////////////////////////////////////////////////////
233 // Protected utility functions.
234
235 void SetTouchable
236 (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath);
237 // Set the touchable for /vis/touchable/set/... commands.
238
240 (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
241 G4bool visibility);
242 // Set the touchable visibility attribute.
243 // Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild.
244
246 (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
247 const G4Colour&);
248 // Set the touchable colour attribute.
249 // Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild.
250
251 //////////////////////////////////////////////////////////////
252 // Data members
253 G4VSceneHandler& fSceneHandler; // Abstract scene for this view.
254 G4int fViewId; // Id of this instance.
256 G4String fShortName; // Up to first ' ' character, if any.
257 G4ViewParameters fVP; // View parameters.
258 G4ViewParameters fDefaultVP; // Default view parameters.
259 G4double fKernelVisitElapsedTimeSeconds = 999.; // Default to a large number
260 // Note: fKernelVisitElapsedTimeSeconds is measured in ProcessView().
261 SceneTreeScene fSceneTreeScene; // G4PhysicalVolumeModel sends touchables to this scene
263
264 //////////////////////////////////////////////////////////////
265 // Other parameters.
266 G4bool fNeedKernelVisit; // See DrawView() for comments.
267};
268
269#include "G4VViewer.icc"
270
271/*********************************************
272
273Here is a minimal DrawView () as it might be implemented in the
274concrete viewer.
275
276void G4VViewer::DrawView () { // Default - concrete view usually overrides.
277
278 // First, a view should decide when to re-visit the G4 kernel.
279 // Sometimes it might not be necessary, e.g., if the scene is stored
280 // in a graphical database (e.g., OpenGL's display lists) and only
281 // the viewing angle has changed. But graphics systems without a
282 // graphical database will always need to visit the G4 kernel.
283
284 NeedKernelVisit (); // Default is - always visit G4 kernel.
285 // Note: this routine sets the fNeedKernelVisit flag of *all* the views of
286 // the scene.
287
288 ProcessView (); // The basic logic is here.
289
290 // Then a view may have more to do, e.g., display the graphical
291 // database. That code should come here before finally...
292
293 FinishView (); // Flush streams and/or swap buffers.
294}
295
296*********************************************/
297
298#endif
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
void SetModel(G4VModel *pModel)
Definition G4VViewer.cc:234
void SetViewer(G4VViewer *pViewer)
Definition G4VViewer.hh:176
void SetTouchable(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath)
Definition G4VViewer.cc:133
const G4String & GetName() const
G4bool fNeedKernelVisit
Definition G4VViewer.hh:266
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
void SetName(const G4String &)
Definition G4VViewer.cc:74
virtual void DrawView()=0
friend std::ostream & operator<<(std::ostream &os, const G4VViewer &v)
Definition G4VViewer.cc:462
void SetDefaultViewParameters(const G4ViewParameters &vp)
virtual void Initialise()
const G4ViewParameters & GetViewParameters() const
void ProcessView()
Definition G4VViewer.cc:108
G4VSceneHandler & fSceneHandler
Definition G4VViewer.hh:253
G4double GetKernelVisitElapsedTimeSeconds() const
G4String fShortName
Definition G4VViewer.hh:256
void SetNeedKernelVisit(G4bool need)
G4double fKernelVisitElapsedTimeSeconds
Definition G4VViewer.hh:259
G4SceneTreeItem & AccessSceneTree()
Definition G4VViewer.hh:191
virtual ~G4VViewer()
Definition G4VViewer.cc:69
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers() const
void UpdateGUISceneTree()
Definition G4VViewer.cc:227
G4String fName
Definition G4VViewer.hh:255
void NeedKernelVisit()
Definition G4VViewer.cc:81
std::vector< G4ThreeVector > ComputeFlyThrough(G4Vector3D *)
G4ViewParameters fDefaultVP
Definition G4VViewer.hh:258
const G4String & GetShortName() const
const G4ViewParameters & GetDefaultViewParameters() const
G4int fViewId
Definition G4VViewer.hh:254
void TouchableSetVisibility(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, G4bool visibility)
Definition G4VViewer.cc:154
G4ViewParameters fVP
Definition G4VViewer.hh:257
virtual void FinishView()
Definition G4VViewer.cc:104
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
Definition G4VViewer.cc:49
void SetViewParameters(const G4ViewParameters &vp)
Definition G4VViewer.cc:128
void TouchableSetColour(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, const G4Colour &)
Definition G4VViewer.cc:190
SceneTreeScene fSceneTreeScene
Definition G4VViewer.hh:261
SceneTreeScene & AccessSceneTreeScene()
Definition G4VViewer.hh:190
void RefreshView()
virtual void ClearView()=0
virtual void ShowView()
Definition G4VViewer.cc:106
G4VSceneHandler * GetSceneHandler() const
virtual void SetView()=0
G4int GetViewId() const
G4SceneTreeItem fSceneTree
Definition G4VViewer.hh:262
virtual void ResetView()