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