ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VSceneHandler.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VSceneHandler.hh
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 
47 class G4Scene;
48 class G4VViewer;
49 class G4Colour;
50 class G4Visible;
52 class G4VModel;
53 class G4VGraphicsSystem;
54 class G4LogicalVolume;
55 class G4VPhysicalVolume;
56 class G4Material;
57 class G4Event;
58 class G4AttHolder;
59 class G4DisplacedSolid;
60 
62 
63  friend class G4VViewer;
64  friend std::ostream& operator << (std::ostream& os, const G4VSceneHandler& s);
65 
66 public: // With description
67 
69 
71  G4int id,
72  const G4String& name = "");
73 
74  virtual ~G4VSceneHandler ();
75 
77  // Methods for adding raw GEANT4 objects to the scene handler. They
78  // must always be called in the triplet PreAddSolid, AddSolid and
79  // PostAddSolid. The transformation and visualization attributes
80  // must be set by the call to PreAddSolid. If your graphics system
81  // is sophisticated enough to handle a particular solid shape as a
82  // primitive, in your derived class write a function to override one
83  // or more of the following. See the implementation of
84  // G4VSceneHandler::AddSolid (const G4Box& box) for more
85  // suggestions. If not, please implement the base class invocation.
86 
87  virtual void PreAddSolid (const G4Transform3D& objectTransformation,
88  const G4VisAttributes&);
89  // objectTransformation is the transformation in the world
90  // coordinate system of the object about to be added, and visAttribs
91  // is its visualization attributes.
92  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
93  // void MyXXXSceneHandler::PreAddSolid
94  // (const G4Transform3D& objectTransformation,
95  // const G4VisAttributes& visAttribs) {
96  // G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
97  // ...
98  // }
99 
100  virtual void PostAddSolid ();
101  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
102  // void MyXXXSceneHandler::PostAddSolid () {
103  // ...
104  // G4VSceneHandler::PostAddSolid ();
105  // }
106 
107  // From geometry/solids/CSG
108  virtual void AddSolid (const G4Box&);
109  virtual void AddSolid (const G4Cons&);
110  virtual void AddSolid (const G4Orb&);
111  virtual void AddSolid (const G4Para&);
112  virtual void AddSolid (const G4Sphere&);
113  virtual void AddSolid (const G4Torus&);
114  virtual void AddSolid (const G4Trap&);
115  virtual void AddSolid (const G4Trd&);
116  virtual void AddSolid (const G4Tubs&);
117 
118  // From geometry/solids/specific
119  virtual void AddSolid (const G4Ellipsoid&);
120  virtual void AddSolid (const G4Polycone&);
121  virtual void AddSolid (const G4Polyhedra&);
122  virtual void AddSolid (const G4TessellatedSolid&);
123 
124  // For solids not above.
125  virtual void AddSolid (const G4VSolid&);
126 
128  // Methods for adding "compound" GEANT4 objects to the scene
129  // handler. These methods may either (a) invoke "user code" that
130  // uses the "user interface", G4VVisManager (see, for example,
131  // G4VSceneHandler, which for trajectories uses
132  // G4VTrajectory::DrawTrajectory, via G4TrajectoriesModel in the
133  // Modeling Category) or (b) invoke AddPrimitives below (between
134  // calls to Begin/EndPrimitives) or (c) use graphics-system-specific
135  // code or (d) any combination of the above.
136 
137  virtual void AddCompound (const G4VTrajectory&);
138  virtual void AddCompound (const G4VHit&);
139  virtual void AddCompound (const G4VDigi&);
140  virtual void AddCompound (const G4THitsMap<G4double>&);
141  virtual void AddCompound (const G4THitsMap<G4StatDouble>&);
142 
144  // Functions for adding primitives.
145 
146  virtual void BeginModeling ();
147  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
148  // void MyXXXSceneHandler::BeginModeling () {
149  // G4VSceneHandler::BeginModeling ();
150  // ...
151  // }
152 
153  virtual void EndModeling ();
154  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
155  // void MyXXXSceneHandler::EndModeling () {
156  // ...
157  // G4VSceneHandler::EndModeling ();
158  // }
159 
160  virtual void BeginPrimitives
161  (const G4Transform3D& objectTransformation = G4Transform3D());
162  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
163  // void MyXXXSceneHandler::BeginPrimitives
164  // (const G4Transform3D& objectTransformation) {
165  // G4VSceneHandler::BeginPrimitives (objectTransformation);
166  // ...
167  // }
168 
169  virtual void EndPrimitives ();
170  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
171  // void MyXXXSceneHandler::EndPrimitives () {
172  // ...
173  // G4VSceneHandler::EndPrimitives ();
174  // }
175 
176  virtual void BeginPrimitives2D
177  (const G4Transform3D& objectTransformation = G4Transform3D());
178  // The x,y coordinates of the primitives passed to AddPrimitive are
179  // intrepreted as screen coordinates, -1 < x,y < 1. The
180  // z-coordinate is ignored.
181  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
182  // void MyXXXSceneHandler::BeginPrimitives2D
183  // (const G4Transform3D& objectTransformation) {
184  // G4VSceneHandler::BeginPrimitives2D ();
185  // ...
186  // }
187 
188  virtual void EndPrimitives2D ();
189  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
190  // void MyXXXSceneHandler::EndPrimitives2D () {
191  // ...
192  // G4VSceneHandler::EndPrimitives2D ();
193  // }
194 
195  virtual void AddPrimitive (const G4Polyline&) = 0;
196  virtual void AddPrimitive (const G4Scale&);
197  // Default implementation in this class but can be over-ridden.
198  virtual void AddPrimitive (const G4Text&) = 0;
199  virtual void AddPrimitive (const G4Circle&) = 0;
200  virtual void AddPrimitive (const G4Square&) = 0;
201  virtual void AddPrimitive (const G4Polymarker&);
202  // Default implementation in this class but can be over-ridden.
203  virtual void AddPrimitive (const G4Polyhedron&) = 0;
204 
205  virtual const G4VisExtent& GetExtent() const;
206 
208  // Access functions.
209  const G4String& GetName () const;
210  G4int GetSceneHandlerId () const;
211  G4int GetViewCount () const;
213  G4Scene* GetScene () const;
214  const G4ViewerList& GetViewerList () const;
215  G4VModel* GetModel () const;
216  G4VViewer* GetCurrentViewer () const;
218  G4bool IsReadyForTransients () const;
221  const G4Transform3D& GetObjectTransformation () const;
222  void SetName (const G4String&);
223  void SetCurrentViewer (G4VViewer*);
224  virtual void SetScene (G4Scene*);
225  G4ViewerList& SetViewerList (); // Non-const so you can change.
226  void SetModel (G4VModel*);
228  // Sets flag which will cause transient store to be cleared at the
229  // next call to BeginPrimitives(). Maintained by vis manager.
233  // Maintained by vis manager.
234 
236  // Public utility functions.
237 
238  const G4Colour& GetColour ();
239  const G4Colour& GetColor ();
240  // Returns colour - checks fpVisAttribs and gets applicable colour.
241 
242  const G4Colour& GetTextColour (const G4Text&);
243  const G4Colour& GetTextColor (const G4Text&);
244  // Returns colour of G4Text object, or default text colour.
245 
247  // Returns line width of G4VisAttributes multiplied by GlobalLineWidthScale.
248 
250  // Returns drawing style from current view parameters, unless the user
251  // has forced through the vis attributes, thereby over-riding the
252  // current view parameter.
253 
255  // Returns no of cloud points from current view parameters, unless the user
256  // has forced through the vis attributes, thereby over-riding the
257  // current view parameter.
258 
260  // Returns auxiliary edge visibility from current view parameters,
261  // unless the user has forced through the vis attributes, thereby
262  // over-riding the current view parameter.
263 
265  // Returns no. of sides (lines segments per circle) from current
266  // view parameters, unless the user has forced through the vis
267  // attributes, thereby over-riding the current view parameter.
268 
270  // Returns applicable marker size (diameter) and type (in second
271  // argument). Uses global default marker if marker sizes are not
272  // set. Multiplies by GlobalMarkerScale.
273 
275  // Alias for GetMarkerSize.
276 
278  // GetMarkerSize / 2.
279 
281  // Only the scene handler and view know what the Modeling Parameters should
282  // be. For historical reasons, the GEANT4 Visualization Environment
283  // maintains its own Scene Data and View Parameters, which must be
284  // converted, when needed, to Modeling Parameters.
285 
286  void DrawEvent(const G4Event*);
287  // Checks scene's end-of-event model list and draws trajectories,
288  // hits, etc.
289 
290  void DrawEndOfRunModels();
291  // Draws end-of-run models.
292 
294  // Administration functions.
295 
296  template <class T> void AddSolidT (const T& solid);
297  template <class T> void AddSolidWithAuxiliaryEdges (const T& solid);
298 
300 
301  virtual void ClearStore ();
302  // Clears graphics database (display lists) if any.
303 
304  virtual void ClearTransientStore ();
305  // Clears transient part of graphics database (display lists) if any.
306 
307  void AddViewerToList (G4VViewer* pView); // Add view to view List.
308  void RemoveViewerFromList (G4VViewer* pView); // Remove view from view List.
309 
310 protected:
311 
313  // Core routine for looping over models, redrawing stored events, etc.
314  // Overload with care (see, for example,
315  // G4OpenGLScenehandler::ProcessScene).
316  virtual void ProcessScene ();
317 
319  // Default routine used by default AddSolid ().
320  virtual void RequestPrimitives (const G4VSolid& solid);
321 
323  // Other internal routines...
324 
327  // Generic clipping using the BooleanProcessor in graphics_reps is
328  // implemented in this class. Subclasses that implement their own
329  // clipping should provide an override that returns zero.
330 
331  void LoadAtts(const G4Visible&, G4AttHolder*);
332  // Load G4AttValues and G4AttDefs associated with the G4Visible
333  // object onto the G4AttHolder object. It checks fpModel, and also
334  // loads the G4AttValues and G4AttDefs from G4PhysicalVolumeModel,
335  // G4VTrajectory, G4VTrajectoryPoint, G4VHit or G4VDigi, as
336  // appropriate. The G4AttHolder object is an object of a class that
337  // publicly inherits G4AttHolder - see, e.g., SoG4Polyhedron in the
338  // Open Inventor driver. G4AttHolder deletes G4AttValues in its
339  // destructor to ensure proper clean-up of G4AttValues.
340 
342  // Data members
343 
344  G4VGraphicsSystem& fSystem; // Graphics system.
345  const G4int fSceneHandlerId; // Id of this instance.
347  G4int fViewCount; // To determine view ids.
349  G4VViewer* fpViewer; // Current viewer.
350  G4Scene* fpScene; // Scene for this scene handler.
352  G4bool fReadyForTransients; // I.e., not processing the
353  // run-duration part of scene.
354  G4bool fTransientsDrawnThisEvent; // Maintained by vis
356  G4bool fProcessingSolid; // True if within Pre/PostAddSolid.
357  G4bool fProcessing2D; // True for 2D.
358  G4VModel* fpModel; // Current model.
359  G4Transform3D fObjectTransformation; // Current accumulated
360  // object transformation.
361  G4int fNestingDepth; // For Begin/EndPrimitives.
362  const G4VisAttributes* fpVisAttribs; // Working vis attributes.
364 
365 private:
366 
369 };
370 
371 #include "G4VSceneHandler.icc"
372 
373 #endif