ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGLStoredSceneHandler.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenGLStoredSceneHandler.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 // Andrew Walkden 10th February 1997
30 // G4OpenGLStoredSceneHandler - creates OpenGL Display lists.
31 
32 #if defined (G4VIS_BUILD_OPENGL_DRIVER) || defined (G4VIS_USE_OPENGL)
33 
34 #ifndef G4OPENGLSTOREDSCENEHANDLER_HH
35 #define G4OPENGLSTOREDSCENEHANDLER_HH
36 
37 #include "globals.hh"
38 #include "G4OpenGLSceneHandler.hh"
39 #include "G4Text.hh"
40 #include <map>
41 #include <vector>
42 
43 class G4OpenGLStored;
44 
45 class G4OpenGLStoredSceneHandler: public G4OpenGLSceneHandler {
46 
47  friend class G4OpenGLStoredViewer; // ..allows access to P/TODLs.
48 
49 public:
50 
51  G4OpenGLStoredSceneHandler (G4VGraphicsSystem& system, const G4String& name = "");
52  virtual ~G4OpenGLStoredSceneHandler ();
53  void BeginPrimitives (const G4Transform3D& objectTransformation);
54  void EndPrimitives ();
55  void BeginPrimitives2D (const G4Transform3D& objectTransformation);
56  void EndPrimitives2D ();
57  void BeginModeling ();
58  void EndModeling ();
59  void AddPrimitive (const G4Polyline&);
60  void AddPrimitive (const G4Polymarker&);
61  void AddPrimitive (const G4Circle&);
62  void AddPrimitive (const G4Square&);
63  void AddPrimitive (const G4Text&);
64  void AddPrimitive (const G4Scale&);
65  void AddPrimitive (const G4Polyhedron&);
66  void ClearStore ();
67  void ClearTransientStore ();
68 
69  static G4int GetDisplayListLimit() {return fDisplayListLimit;}
70  static void SetDisplayListLimit(G4int lim) {fDisplayListLimit = lim;}
71 
72 protected:
73 
74  G4bool AddPrimitivePreamble(const G4VMarker& visible);
75  G4bool AddPrimitivePreamble(const G4Polyline& visible);
76  G4bool AddPrimitivePreamble(const G4Polyhedron& visible);
77  // Return false if no further processing required.
78 
79  void AddPrimitivePostamble();
80 
81  // Two virtual functions for extra processing in a sub-class, for
82  // example, to make a display tree. They are to return true if the
83  // visible object uses gl commands for drawing. This is
84  // predominantly true; a notable exception is Qt text. In that
85  // case, a display list does not need to be created; all relevant
86  // information is assumed to be stored in the PO/TOList.
87  virtual G4bool ExtraPOProcessing
88  (const G4Visible&, size_t /*currentPOListIndex*/) {return true;}
89  virtual G4bool ExtraTOProcessing
90  (const G4Visible&, size_t /*currentTOListIndex*/) {return true;}
91 
92  static G4int fSceneIdCount; // static counter for OpenGLStored scenes.
93  // Display list management. All static since there's only one OGL store.
94  static G4int fDisplayListId; // Workspace.
95  static G4bool fMemoryForDisplayLists; // avoid memory overflow
96  static G4int fDisplayListLimit; // avoid memory overflow
97 
98  // PODL = Persistent Object Display List.
99  // This "top PODL" was made redundant when the PO list was
100  // "unwrapped" 27th October 2011, but keep it for now in case we
101  // need to wrap it again.
102  GLint fTopPODL; // List which calls the other PODLs.
103 
104  // G4Text plus transform and 2/3D.
105  struct G4TextPlus {
106  G4TextPlus(const G4Text& text): fG4Text(text), fProcessing2D(false) {}
107  G4Text fG4Text;
108  G4bool fProcessing2D;
109  };
110 
111  // PO = Persistent Object, i.e., run-durantion object, e.g., geometry.
112  struct PO {
113  PO();
114  PO(const PO&);
115  PO(G4int id, const G4Transform3D& tr = G4Transform3D());
116  ~PO();
117  PO& operator= (const PO&);
118  G4int fDisplayListId;
119  G4Transform3D fTransform;
120  GLuint fPickName;
121  G4Colour fColour;
122  G4TextPlus* fpG4TextPlus;
123  G4bool fMarkerOrPolyline;
124  };
125  std::vector<PO> fPOList;
126 
127  // TO = Transient Object, e.g., trajectories.
128  struct TO {
129  TO();
130  TO(const TO&);
131  TO(G4int id, const G4Transform3D& tr = G4Transform3D());
132  ~TO();
133  TO& operator= (const TO&);
134  G4int fDisplayListId;
135  G4Transform3D fTransform;
136  GLuint fPickName;
137  G4double fStartTime, fEndTime; // Time range (e.g., for trajectory steps).
138  G4Colour fColour;
139  G4TextPlus* fpG4TextPlus;
140  G4bool fMarkerOrPolyline;
141  };
142  std::vector<TO> fTOList;
143 
144  // Stop-gap solution of structure re-use.
145  // A proper implementation would use geometry hierarchy.
146  std::map <const G4VSolid*, G4int, std::less <const G4VSolid*> > fSolidMap;
147 
148 private:
149  bool AddPrimitivePreambleInternal(const G4Visible& visible, bool isMarker, bool isPolyline);
150 
151 };
152 
153 #endif
154 
155 #endif