Geant4-11
G4VSceneHandler.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 19th July 1996.
30//
31// Class description
32//
33// Abstract interface class for graphics scene handlers.
34// Inherits from G4VGraphicsScene, in the intercoms category, which is
35// a minimal abstract interface for the GEANT4 kernel.
36
37#ifndef G4VSCENEHANDLER_HH
38#define G4VSCENEHANDLER_HH
39
40#include "globals.hh"
41
42#include "G4VGraphicsScene.hh"
43#include "G4ViewerList.hh"
44#include "G4ViewParameters.hh"
45#include "G4THitsMap.hh"
46
47class G4Scene;
49class G4AttHolder;
50
52
53 friend class G4VViewer;
54 friend std::ostream& operator << (std::ostream& os, const G4VSceneHandler& s);
55
56public: // With description
57
59
61 G4int id,
62 const G4String& name = "");
63
64 virtual ~G4VSceneHandler ();
65
67 // Methods for adding raw GEANT4 objects to the scene handler. They
68 // must always be called in the triplet PreAddSolid, AddSolid and
69 // PostAddSolid. The transformation and visualization attributes
70 // must be set by the call to PreAddSolid. If your graphics system
71 // is sophisticated enough to handle a particular solid shape as a
72 // primitive, in your derived class write a function to override one
73 // or more of the following. See the implementation of
74 // G4VSceneHandler::AddSolid (const G4Box& box) for more
75 // suggestions. If not, please implement the base class invocation.
76
77 virtual void PreAddSolid (const G4Transform3D& objectTransformation,
78 const G4VisAttributes&);
79 // objectTransformation is the transformation in the world
80 // coordinate system of the object about to be added, and visAttribs
81 // is its visualization attributes.
82 // IMPORTANT: invoke this from your polymorphic versions, e.g.:
83 // void MyXXXSceneHandler::PreAddSolid
84 // (const G4Transform3D& objectTransformation,
85 // const G4VisAttributes& visAttribs) {
86 // G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
87 // ...
88 // }
89
90 virtual void PostAddSolid ();
91 // IMPORTANT: invoke this from your polymorphic versions, e.g.:
92 // void MyXXXSceneHandler::PostAddSolid () {
93 // ...
94 // G4VSceneHandler::PostAddSolid ();
95 // }
96
97 // From geometry/solids/CSG
98 virtual void AddSolid (const G4Box&);
99 virtual void AddSolid (const G4Cons&);
100 virtual void AddSolid (const G4Orb&);
101 virtual void AddSolid (const G4Para&);
102 virtual void AddSolid (const G4Sphere&);
103 virtual void AddSolid (const G4Torus&);
104 virtual void AddSolid (const G4Trap&);
105 virtual void AddSolid (const G4Trd&);
106 virtual void AddSolid (const G4Tubs&);
107
108 // From geometry/solids/specific
109 virtual void AddSolid (const G4Ellipsoid&);
110 virtual void AddSolid (const G4Polycone&);
111 virtual void AddSolid (const G4Polyhedra&);
112 virtual void AddSolid (const G4TessellatedSolid&);
113
114 // For solids not above.
115 virtual void AddSolid (const G4VSolid&);
116
118 // Methods for adding "compound" GEANT4 objects to the scene
119 // handler. These methods may either (a) invoke "user code" that
120 // uses the "user interface", G4VVisManager (see, for example,
121 // G4VSceneHandler, which for trajectories uses
122 // G4VTrajectory::DrawTrajectory, via G4TrajectoriesModel in the
123 // Modeling Category) or (b) invoke AddPrimitives below (between
124 // calls to Begin/EndPrimitives) or (c) use graphics-system-specific
125 // code or (d) any combination of the above.
126
127 virtual void AddCompound (const G4VTrajectory&);
128 virtual void AddCompound (const G4VHit&);
129 virtual void AddCompound (const G4VDigi&);
130 virtual void AddCompound (const G4THitsMap<G4double>&);
131 virtual void AddCompound (const G4THitsMap<G4StatDouble>&);
132 virtual void AddCompound (const G4Mesh&);
133
135 // Functions for adding primitives.
136
137 virtual void BeginModeling ();
138 // IMPORTANT: invoke this from your polymorphic versions, e.g.:
139 // void MyXXXSceneHandler::BeginModeling () {
140 // G4VSceneHandler::BeginModeling ();
141 // ...
142 // }
143
144 virtual void EndModeling ();
145 // IMPORTANT: invoke this from your polymorphic versions, e.g.:
146 // void MyXXXSceneHandler::EndModeling () {
147 // ...
148 // G4VSceneHandler::EndModeling ();
149 // }
150
151 virtual void BeginPrimitives
152 (const G4Transform3D& objectTransformation = G4Transform3D());
153 // IMPORTANT: invoke this from your polymorphic versions, e.g.:
154 // void MyXXXSceneHandler::BeginPrimitives
155 // (const G4Transform3D& objectTransformation) {
156 // G4VSceneHandler::BeginPrimitives (objectTransformation);
157 // ...
158 // }
159
160 virtual void EndPrimitives ();
161 // IMPORTANT: invoke this from your polymorphic versions, e.g.:
162 // void MyXXXSceneHandler::EndPrimitives () {
163 // ...
164 // G4VSceneHandler::EndPrimitives ();
165 // }
166
167 virtual void BeginPrimitives2D
168 (const G4Transform3D& objectTransformation = G4Transform3D());
169 // The x,y coordinates of the primitives passed to AddPrimitive are
170 // intrepreted as screen coordinates, -1 < x,y < 1. The
171 // z-coordinate is ignored.
172 // IMPORTANT: invoke this from your polymorphic versions, e.g.:
173 // void MyXXXSceneHandler::BeginPrimitives2D
174 // (const G4Transform3D& objectTransformation) {
175 // G4VSceneHandler::BeginPrimitives2D (objectTransformation);
176 // ...
177 // }
178
179 virtual void EndPrimitives2D ();
180 // IMPORTANT: invoke this from your polymorphic versions, e.g.:
181 // void MyXXXSceneHandler::EndPrimitives2D () {
182 // ...
183 // G4VSceneHandler::EndPrimitives2D ();
184 // }
185
186 virtual void AddPrimitive (const G4Polyline&) = 0;
187 virtual void AddPrimitive (const G4Text&) = 0;
188 virtual void AddPrimitive (const G4Circle&) = 0;
189 virtual void AddPrimitive (const G4Square&) = 0;
190 virtual void AddPrimitive (const G4Polymarker&);
191 virtual void AddPrimitive (const G4Polyhedron&) = 0;
192 virtual void AddPrimitive (const G4Plotter&);
193
194 // Other virtual functions
195 virtual const G4VisExtent& GetExtent() const;
196
198 // Access functions.
199 const G4String& GetName () const;
203 G4Scene* GetScene () const;
212 void SetName (const G4String&);
214 virtual void SetScene (G4Scene*);
215 G4ViewerList& SetViewerList (); // Non-const so you can change.
218 // Sets flag which will cause transient store to be cleared at the
219 // next call to BeginPrimitives(). Maintained by vis manager.
223 // Maintained by vis manager.
224
226 // Public utility functions.
227
228 const G4Colour& GetColour (); // To be deprecated?
230 // Returns colour - checks fpVisAttribs and gets applicable colour.
231 // Assumes fpVisAttribs point to the G4VisAttributes of the current object.
232 // If the pointer is null, the colour is obtained from the default view
233 // parameters of the current viewer.
234
235 const G4Colour& GetColour (const G4Visible&);
236 const G4Colour& GetColor (const G4Visible&);
237 // Returns colour, or viewer default colour.
238 // Makes no assumptions about the validity of data member fpVisAttribs.
239 // If the G4Visible has no vis attributes, i.e., the pointer is null,
240 // the colour is obtained from the default view parameters of the
241 // current viewer.
242
243 const G4Colour& GetTextColour (const G4Text&);
244 const G4Colour& GetTextColor (const G4Text&);
245 // Returns colour of G4Text object, or default text colour.
246
248 // Returns line width of G4VisAttributes multiplied by GlobalLineWidthScale.
249
251 // Returns drawing style from current view parameters, unless the user
252 // has forced through the vis attributes, thereby over-riding the
253 // current view parameter.
254
256 // Returns no of cloud points from current view parameters, unless the user
257 // has forced through the vis attributes, thereby over-riding the
258 // current view parameter.
259
261 // Returns auxiliary edge visibility from current view parameters,
262 // unless the user has forced through the vis attributes, thereby
263 // over-riding the current view parameter.
264
266 // Returns no. of sides (lines segments per circle) from current
267 // view parameters, unless the user has forced through the vis
268 // attributes, thereby over-riding the current view parameter.
269
271 // Returns applicable marker size (diameter) and type (in second
272 // argument). Uses global default marker if marker sizes are not
273 // set. Multiplies by GlobalMarkerScale.
274
276 // Alias for GetMarkerSize.
277
279 // GetMarkerSize / 2.
280
282 // Only the scene handler and view know what the Modeling Parameters should
283 // be. For historical reasons, the GEANT4 Visualization Environment
284 // maintains its own Scene Data and View Parameters, which must be
285 // converted, when needed, to Modeling Parameters.
286
287 void DrawEvent(const G4Event*);
288 // Checks scene's end-of-event model list and draws trajectories,
289 // hits, etc.
290
291 void DrawEndOfRunModels();
292 // Draws end-of-run models.
293
295 // Administration functions.
296
297 template <class T> void AddSolidT (const T& solid);
298 template <class T> void AddSolidWithAuxiliaryEdges (const T& solid);
299
301
302 virtual void ClearStore ();
303 // Clears graphics database (display lists) if any.
304
305 virtual void ClearTransientStore ();
306 // Clears transient part of graphics database (display lists) if any.
307
308 void AddViewerToList (G4VViewer* pView); // Add view to view List.
309 void RemoveViewerFromList (G4VViewer* pView); // Remove view from view List.
310
311protected:
312
314 // Core routine for looping over models, redrawing stored events, etc.
315 // Overload with care (see, for example,
316 // G4OpenGLScenehandler::ProcessScene).
317 virtual void ProcessScene ();
318
320 // Default routine used by default AddSolid ().
321 virtual void RequestPrimitives (const G4VSolid& solid);
322
324 // Other internal routines...
325
328 // Generic clipping using the BooleanProcessor in graphics_reps is
329 // implemented in this class. Subclasses that implement their own
330 // clipping should provide an override that returns zero.
331
332 void LoadAtts(const G4Visible&, G4AttHolder*);
333 // Load G4AttValues and G4AttDefs associated with the G4Visible
334 // object onto the G4AttHolder object. It checks fpModel, and also
335 // loads the G4AttValues and G4AttDefs from G4PhysicalVolumeModel,
336 // G4VTrajectory, G4VTrajectoryPoint, G4VHit or G4VDigi, as
337 // appropriate. The G4AttHolder object is an object of a class that
338 // publicly inherits G4AttHolder - see, e.g., SoG4Polyhedron in the
339 // Open Inventor driver. G4AttHolder deletes G4AttValues in its
340 // destructor to ensure proper clean-up of G4AttValues.
341
343 // Data members
344
345 G4VGraphicsSystem& fSystem; // Graphics system.
346 const G4int fSceneHandlerId; // Id of this instance.
348 G4int fViewCount; // To determine view ids.
350 G4VViewer* fpViewer; // Current viewer.
351 G4Scene* fpScene; // Scene for this scene handler.
353 G4bool fReadyForTransients; // I.e., not processing the
354 // run-duration part of scene.
355 G4bool fTransientsDrawnThisEvent; // Maintained by vis
357 G4bool fProcessingSolid; // True if within Pre/PostAddSolid.
358 G4bool fProcessing2D; // True for 2D.
359 G4VModel* fpModel; // Current model.
360 G4Transform3D fObjectTransformation; // Current accumulated
361 // object transformation.
362 G4int fNestingDepth; // For Begin/EndPrimitives.
363 const G4VisAttributes* fpVisAttribs; // Working vis attributes.
365
366private:
367
370};
371
372#include "G4VSceneHandler.icc"
373
374#endif
static constexpr double s
Definition: G4SIunits.hh:154
HepGeom::Transform3D G4Transform3D
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
Definition: G4Box.hh:56
Definition: G4Cons.hh:78
Definition: G4Mesh.hh:47
Definition: G4Orb.hh:56
Definition: G4Para.hh:79
Definition: G4Text.hh:72
Definition: G4Trd.hh:63
Definition: G4Tubs.hh:75
Definition: G4VHit.hh:48
virtual void BeginModeling()
G4int GetNumberOfCloudPoints(const G4VisAttributes *) const
const G4Colour & GetColor(const G4Visible &)
friend std::ostream & operator<<(std::ostream &os, const G4VSceneHandler &s)
G4int GetNoOfSides(const G4VisAttributes *)
virtual void AddPrimitive(const G4Polyhedron &)=0
virtual void ClearTransientStore()
G4bool GetTransientsDrawnThisEvent() const
G4VSceneHandler(const G4VSceneHandler &)
void SetTransientsDrawnThisRun(G4bool)
void LoadAtts(const G4Visible &, G4AttHolder *)
void DrawEvent(const G4Event *)
G4ModelingParameters * CreateModelingParameters()
const G4Colour & GetTextColour(const G4Text &)
void SetMarkForClearingTransientStore(G4bool)
const G4Colour & GetTextColor(const G4Text &)
G4VModel * GetModel() const
const G4Colour & GetColour()
G4VGraphicsSystem * GetGraphicsSystem() const
virtual void AddPrimitive(const G4Circle &)=0
G4double GetMarkerRadius(const G4VMarker &, MarkerSizeType &)
const G4ViewerList & GetViewerList() const
void AddSolidT(const T &solid)
G4bool IsReadyForTransients() const
G4Scene * GetScene() const
G4Transform3D fObjectTransformation
virtual void EndPrimitives()
G4bool fTransientsDrawnThisEvent
G4VViewer * GetCurrentViewer() const
void AddSolidWithAuxiliaryEdges(const T &solid)
G4int IncrementViewCount()
virtual G4DisplacedSolid * CreateSectionSolid()
virtual void AddPrimitive(const G4Text &)=0
G4ViewerList & SetViewerList()
virtual void EndModeling()
const G4int fSceneHandlerId
void SetName(const G4String &)
virtual const G4VisExtent & GetExtent() const
G4int GetSceneHandlerId() const
G4ViewerList fViewerList
virtual void ProcessScene()
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
void SetObjectTransformation(const G4Transform3D &)
void SetModel(G4VModel *)
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
G4VSceneHandler(G4VGraphicsSystem &system, G4int id, const G4String &name="")
G4bool fTransientsDrawnThisRun
G4VViewer * fpViewer
virtual void PostAddSolid()
const G4String & GetName() const
void AddViewerToList(G4VViewer *pView)
void SetTransientsDrawnThisEvent(G4bool)
virtual void EndPrimitives2D()
virtual void SetScene(G4Scene *)
G4bool fMarkForClearingTransientStore
const G4Transform3D & GetObjectTransformation() const
const G4VisAttributes * fpVisAttribs
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation=G4Transform3D())
virtual void RequestPrimitives(const G4VSolid &solid)
G4double GetMarkerDiameter(const G4VMarker &, MarkerSizeType &)
virtual void AddPrimitive(const G4Square &)=0
const G4Colour & GetColor()
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
G4bool GetTransientsDrawnThisRun() const
void RemoveViewerFromList(G4VViewer *pView)
virtual G4DisplacedSolid * CreateCutawaySolid()
G4VSceneHandler & operator=(const G4VSceneHandler &)
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())
G4double GetLineWidth(const G4VisAttributes *)
G4int GetViewCount() const
G4VGraphicsSystem & fSystem
virtual void AddSolid(const G4Box &)
virtual void ClearStore()
void SetCurrentViewer(G4VViewer *)
virtual void AddCompound(const G4VTrajectory &)
virtual ~G4VSceneHandler()
virtual void AddPrimitive(const G4Polyline &)=0
const G4Transform3D fIdentityTransformation
G4bool GetMarkForClearingTransientStore() const
G4bool GetAuxEdgeVisible(const G4VisAttributes *)
const char * name(G4int ptype)