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 | // $Id: G4HepRepSceneHandler.hh,v 1.42 2006/11/06 09:22:26 allison Exp $ |
---|
27 | // GEANT4 tag $Name: HEAD $ |
---|
28 | // |
---|
29 | |
---|
30 | /** |
---|
31 | * @author Mark Donszelmann |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef G4HEPREPSCENEHANDLER_HH |
---|
35 | #define G4HEPREPSCENEHANDLER_HH 1 |
---|
36 | |
---|
37 | #include "globals.hh" |
---|
38 | #include <iostream> |
---|
39 | #include <stack> |
---|
40 | #include <map> |
---|
41 | #include <vector> |
---|
42 | |
---|
43 | // HepRep |
---|
44 | #include "HEPREP/HepRep.h" |
---|
45 | |
---|
46 | //G4 |
---|
47 | #include "G4Box.hh" |
---|
48 | #include "G4Cons.hh" |
---|
49 | #include "G4Tubs.hh" |
---|
50 | #include "G4Trd.hh" |
---|
51 | #include "G4Trap.hh" |
---|
52 | #include "G4Sphere.hh" |
---|
53 | #include "G4Para.hh" |
---|
54 | #include "G4Torus.hh" |
---|
55 | #include "G4Polycone.hh" |
---|
56 | #include "G4Polyhedra.hh" |
---|
57 | |
---|
58 | #include "G4VGraphicsSystem.hh" |
---|
59 | #include "G4VSceneHandler.hh" |
---|
60 | #include "G4Visible.hh" |
---|
61 | #include "G4Material.hh" |
---|
62 | #include "G4LogicalVolume.hh" |
---|
63 | #include "G4PhysicalVolumeModel.hh" |
---|
64 | |
---|
65 | #include "G4HepRepMessenger.hh" |
---|
66 | |
---|
67 | class G4HepRepSceneHandler: public G4VSceneHandler { |
---|
68 | |
---|
69 | public: |
---|
70 | G4HepRepSceneHandler (G4VGraphicsSystem& system, G4HepRepMessenger& messenger, const G4String& name = ""); |
---|
71 | virtual ~G4HepRepSceneHandler (); |
---|
72 | |
---|
73 | void AddSolid (const G4Box& box); |
---|
74 | void AddSolid (const G4Cons& cons); |
---|
75 | void AddSolid (const G4Tubs& tubs); |
---|
76 | void AddSolid (const G4Trd& trd); |
---|
77 | void AddSolid (const G4Trap& trap); |
---|
78 | void AddSolid (const G4Sphere& sphere); |
---|
79 | void AddSolid (const G4Para& para); |
---|
80 | void AddSolid (const G4Torus& torus); |
---|
81 | void AddSolid (const G4Polycone& polycone); |
---|
82 | void AddSolid (const G4Polyhedra& polyhedra); |
---|
83 | void AddSolid (const G4VSolid& solid); |
---|
84 | |
---|
85 | void AddCompound (const G4VTrajectory&); |
---|
86 | void AddCompound (const G4VHit& hit); |
---|
87 | |
---|
88 | void PreAddSolid (const G4Transform3D& objectTransformation, const G4VisAttributes& visAttribs); |
---|
89 | void PostAddSolid (); |
---|
90 | |
---|
91 | void AddPrimitive (const G4Polyline&); |
---|
92 | void AddPrimitive (const G4Text&); |
---|
93 | void AddPrimitive (const G4Circle&); |
---|
94 | void AddPrimitive (const G4Square&); |
---|
95 | void AddPrimitive (const G4Polyhedron&); |
---|
96 | void AddPrimitive (const G4NURBS&); |
---|
97 | |
---|
98 | void AddPrimitive (const G4Polymarker&); |
---|
99 | void AddPrimitive (const G4Scale& scale); |
---|
100 | |
---|
101 | void BeginPrimitives (const G4Transform3D& objectTransformation); |
---|
102 | void EndPrimitives (); |
---|
103 | void BeginModeling (); |
---|
104 | void EndModeling (); |
---|
105 | |
---|
106 | void openHepRep(); |
---|
107 | bool closeHepRep(bool final = false); |
---|
108 | void openFile(G4String name); |
---|
109 | void closeFile(); |
---|
110 | |
---|
111 | private: |
---|
112 | static G4int sceneIdCount; |
---|
113 | const G4ModelingParameters* originalMP; // Keeps pointer to original. |
---|
114 | G4ModelingParameters* nonCullingMP; // For temporary non-culling. |
---|
115 | |
---|
116 | G4Transform3D transform; |
---|
117 | |
---|
118 | std::ostream* out; |
---|
119 | HEPREP::HepRepFactory* factory; |
---|
120 | HEPREP::HepRepWriter* writer; |
---|
121 | |
---|
122 | // Methods |
---|
123 | G4bool dontWrite(); |
---|
124 | |
---|
125 | void setColor (HEPREP::HepRepAttribute *attribute, const G4Color& color, |
---|
126 | const G4String& key = G4String("Color")); |
---|
127 | G4Color getColorFor (const G4Visible& visible); |
---|
128 | G4Color getColorFor (const G4VSolid& solid); |
---|
129 | |
---|
130 | void setVisibility (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid); |
---|
131 | void setLine (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid); |
---|
132 | |
---|
133 | void setVisibility (HEPREP::HepRepAttribute *attribute, const G4Visible& visible); |
---|
134 | void setLine (HEPREP::HepRepAttribute *attribute, const G4Visible& visible); |
---|
135 | |
---|
136 | void setMarker (HEPREP::HepRepAttribute *attribute, const G4VMarker& marker); |
---|
137 | |
---|
138 | inline void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, char* value) { |
---|
139 | setAttribute(attribute, name, G4String(value)); |
---|
140 | } |
---|
141 | void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, G4String value); |
---|
142 | void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, bool value); |
---|
143 | void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double value); |
---|
144 | void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, int value); |
---|
145 | void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double red, double green, double blue, double alpha); |
---|
146 | |
---|
147 | bool isEventData(); |
---|
148 | |
---|
149 | void open(G4String name); |
---|
150 | void close(); |
---|
151 | |
---|
152 | void writeLayers(HEPREP::HepRep* heprep); |
---|
153 | |
---|
154 | void addAttributes(HEPREP::HepRepInstance* instance, HEPREP::HepRepType* type); |
---|
155 | |
---|
156 | void addAttDefs(HEPREP::HepRepDefinition* definition, const std::map<G4String,G4AttDef>* attDefs); |
---|
157 | void addAttVals(HEPREP::HepRepAttribute* attribute, const std::map<G4String,G4AttDef>* attDefs, std::vector<G4AttValue>* attValues); |
---|
158 | |
---|
159 | void addTopLevelAttributes(HEPREP::HepRepType* type); |
---|
160 | |
---|
161 | HEPREP::HepRepInstance* getGeometryOrEventInstance(HEPREP::HepRepType* type); |
---|
162 | |
---|
163 | // Returns the particular instance/type or if not created, creates them and adds them to the HepRep |
---|
164 | HEPREP::HepRep* getHepRep(); |
---|
165 | HEPREP::HepRep* getHepRepGeometry(); |
---|
166 | HEPREP::HepRepInstanceTree* getGeometryInstanceTree(); |
---|
167 | HEPREP::HepRepInstance* getGeometryInstance(G4LogicalVolume* volume, G4Material* material, int depth); |
---|
168 | HEPREP::HepRepInstance* getGeometryInstance(G4String volumeName, int depth); |
---|
169 | HEPREP::HepRepInstance* getGeometryRootInstance(); |
---|
170 | HEPREP::HepRepTypeTree* getGeometryTypeTree(); |
---|
171 | HEPREP::HepRepType* getGeometryType(G4String volumeName, int depth); |
---|
172 | HEPREP::HepRepType* getGeometryRootType(); |
---|
173 | HEPREP::HepRepInstanceTree* getEventInstanceTree(); |
---|
174 | HEPREP::HepRepInstance* getEventInstance(); |
---|
175 | HEPREP::HepRepTypeTree* getEventTypeTree(); |
---|
176 | HEPREP::HepRepType* getEventType(); |
---|
177 | HEPREP::HepRepType* getTrajectoryType (); |
---|
178 | HEPREP::HepRepType* getHitType (); |
---|
179 | HEPREP::HepRepType* getCalHitType (); |
---|
180 | HEPREP::HepRepType* getCalHitFaceType (); |
---|
181 | |
---|
182 | G4String getFullTypeName(G4String volumeName, int depth); |
---|
183 | G4String getParentTypeName(int currentDepth); |
---|
184 | |
---|
185 | // initialized Member Variables |
---|
186 | G4HepRepMessenger& messenger; |
---|
187 | G4String geometryLayer, eventLayer, calHitLayer; |
---|
188 | G4String trajectoryLayer, hitLayer; |
---|
189 | G4String rootVolumeName; |
---|
190 | |
---|
191 | G4String baseName; |
---|
192 | G4String eventNumberPrefix; |
---|
193 | G4String eventNumberSuffix; |
---|
194 | G4int eventNumber; |
---|
195 | G4int eventNumberWidth; |
---|
196 | G4String extension; |
---|
197 | G4bool writeBinary; |
---|
198 | G4bool writeZip; |
---|
199 | G4bool writeGZ; |
---|
200 | G4bool writeMultipleFiles; |
---|
201 | const G4VHit* currentHit; |
---|
202 | const G4VTrajectory* currentTrack; |
---|
203 | |
---|
204 | // DO NOT USE member vars directly, use get methods. |
---|
205 | HEPREP::HepRep* _heprep; |
---|
206 | HEPREP::HepRep* _heprepGeometry; |
---|
207 | HEPREP::HepRepInstanceTree* _geometryInstanceTree; |
---|
208 | std::vector<HEPREP::HepRepInstance*> _geometryInstance; |
---|
209 | HEPREP::HepRepInstance* _geometryRootInstance; |
---|
210 | HEPREP::HepRepTypeTree* _geometryTypeTree; |
---|
211 | std::vector<G4String> _geometryTypeName; |
---|
212 | std::map<G4String, HEPREP::HepRepType*> _geometryType; |
---|
213 | HEPREP::HepRepType* _geometryRootType; |
---|
214 | HEPREP::HepRepInstanceTree* _eventInstanceTree; |
---|
215 | HEPREP::HepRepInstance* _eventInstance; |
---|
216 | HEPREP::HepRepTypeTree* _eventTypeTree; |
---|
217 | HEPREP::HepRepType* _eventType; |
---|
218 | HEPREP::HepRepType* _trajectoryType; |
---|
219 | HEPREP::HepRepType* _hitType; |
---|
220 | HEPREP::HepRepType* _calHitType; |
---|
221 | HEPREP::HepRepType* _calHitFaceType; |
---|
222 | |
---|
223 | std::map<int, G4String> materialState; |
---|
224 | }; |
---|
225 | |
---|
226 | #endif |
---|
227 | |
---|