Geant4.10
 All Data Structures 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: G4HepRepSceneHandler.hh 68043 2013-03-13 14:27:49Z gcosmo $
27 //
28 
29 /**
30  * @author Mark Donszelmann
31  */
32 
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  }
87  void AddCompound (const G4THitsMap<G4double>& hits) {
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 
100  void AddPrimitive (const G4Polymarker&);
101  void AddPrimitive (const G4Scale& scale);
102 
103  void BeginPrimitives (const G4Transform3D& objectTransformation);
104  void EndPrimitives ();
105  void BeginModeling ();
106  void EndModeling ();
107 
108  void openHepRep();
109  bool closeHepRep(bool final = false);
110  void openFile(G4String name);
111  void closeFile();
112 
113  private:
115  G4HepRepSceneHandler& operator= (const G4HepRepSceneHandler&);
116  static G4int sceneIdCount;
117 
118  G4Transform3D transform;
119 
120  std::ostream* out;
121  HEPREP::HepRepFactory* factory;
122  HEPREP::HepRepWriter* writer;
123 
124  // Methods
125  G4bool dontWrite();
126 
127  void setColor (HEPREP::HepRepAttribute *attribute, const G4Color& color,
128  const G4String& key = G4String("Color"));
129  G4Color getColorFor (const G4Visible& visible);
130  G4Color getColorFor (const G4VSolid& solid);
131 
132  void setVisibility (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
133  void setLine (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
134 
135  void setVisibility (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
136  void setLine (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
137 
138  void setMarker (HEPREP::HepRepAttribute *attribute, const G4VMarker& marker);
139 
140  inline void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, char* value) {
141  setAttribute(attribute, name, G4String(value));
142  }
143  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, G4String value);
144  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, bool value);
145  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double value);
146  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, int value);
147  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double red, double green, double blue, double alpha);
148 
149  bool isEventData();
150 
151  void open(G4String name);
152  void close();
153 
154  void writeLayers(HEPREP::HepRep* heprep);
155 
156  void addAttributes(HEPREP::HepRepInstance* instance, HEPREP::HepRepType* type);
157 
158  void addAttDefs(HEPREP::HepRepDefinition* definition, const std::map<G4String,G4AttDef>* attDefs);
159  void addAttVals(HEPREP::HepRepAttribute* attribute, const std::map<G4String,G4AttDef>* attDefs, std::vector<G4AttValue>* attValues);
160 
161  void addTopLevelAttributes(HEPREP::HepRepType* type);
162 
163  HEPREP::HepRepInstance* getGeometryOrEventInstance(HEPREP::HepRepType* type);
164 
165  // Returns the particular instance/type or if not created, creates them and adds them to the HepRep
166  HEPREP::HepRep* getHepRep();
167  HEPREP::HepRep* getHepRepGeometry();
168  HEPREP::HepRepInstanceTree* getGeometryInstanceTree();
169  HEPREP::HepRepInstance* getGeometryInstance(G4LogicalVolume* volume, G4Material* material, int depth);
170  HEPREP::HepRepInstance* getGeometryInstance(G4String volumeName, int depth);
171  HEPREP::HepRepInstance* getGeometryRootInstance();
172  HEPREP::HepRepTypeTree* getGeometryTypeTree();
173  HEPREP::HepRepType* getGeometryType(G4String volumeName, int depth);
174  HEPREP::HepRepType* getGeometryRootType();
175  HEPREP::HepRepInstanceTree* getEventInstanceTree();
176  HEPREP::HepRepInstance* getEventInstance();
177  HEPREP::HepRepTypeTree* getEventTypeTree();
178  HEPREP::HepRepType* getEventType();
179  HEPREP::HepRepType* getTrajectoryType ();
180  HEPREP::HepRepType* getHitType ();
181  HEPREP::HepRepType* getCalHitType ();
182  HEPREP::HepRepType* getCalHitFaceType ();
183 
184  G4String getFullTypeName(G4String volumeName, int depth);
185  G4String getParentTypeName(int currentDepth);
186 
187  // initialized Member Variables
188  G4String geometryLayer, eventLayer, calHitLayer;
189  G4String trajectoryLayer, hitLayer;
190  G4String rootVolumeName;
191 
192  G4String baseName;
193  G4String eventNumberPrefix;
194  G4String eventNumberSuffix;
195  G4int eventNumber;
196  G4int eventNumberWidth;
197  G4String extension;
198  G4bool writeBinary;
199  G4bool writeZip;
200  G4bool writeGZ;
201  G4bool writeMultipleFiles;
202  const G4VHit* currentHit;
203  const G4VTrajectory* currentTrack;
204 
205  // DO NOT USE member vars directly, use get methods.
206  HEPREP::HepRep* _heprep;
207  HEPREP::HepRep* _heprepGeometry;
208  HEPREP::HepRepInstanceTree* _geometryInstanceTree;
209  std::vector<HEPREP::HepRepInstance*> _geometryInstance;
210  HEPREP::HepRepInstance* _geometryRootInstance;
211  HEPREP::HepRepTypeTree* _geometryTypeTree;
212  std::vector<G4String> _geometryTypeName;
213  std::map<G4String, HEPREP::HepRepType*> _geometryType;
214  HEPREP::HepRepType* _geometryRootType;
215  HEPREP::HepRepInstanceTree* _eventInstanceTree;
216  HEPREP::HepRepInstance* _eventInstance;
217  HEPREP::HepRepTypeTree* _eventTypeTree;
218  HEPREP::HepRepType* _eventType;
219  HEPREP::HepRepType* _trajectoryType;
220  HEPREP::HepRepType* _hitType;
221  HEPREP::HepRepType* _calHitType;
222  HEPREP::HepRepType* _calHitFaceType;
223 
224  std::map<int, G4String> materialState;
225 };
226 
227 #endif
228 
void AddSolid(const G4Box &box)
Definition: G4Para.hh:76
Definition: G4Text.hh:73
Definition: test07.cc:36
void BeginPrimitives(const G4Transform3D &objectTransformation)
bool closeHepRep(bool final=false)
void openFile(G4String name)
Definition: G4Box.hh:63
void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)
Definition: G4Tubs.hh:84
const XML_Char * name
Definition: G4VHit.hh:48
void AddCompound(const G4VDigi &digi)
Definition: G4Trd.hh:71
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
string material
Definition: eplot.py:19
bool G4bool
Definition: G4Types.hh:79
Definition: G4Cons.hh:82
virtual void AddCompound(const G4VTrajectory &)
void AddCompound(const G4THitsMap< G4double > &hits)
void AddCompound(const G4VTrajectory &)
G4HepRepSceneHandler(G4VGraphicsSystem &system, const G4String &name="")
const XML_Char int const XML_Char * value
void AddPrimitive(const G4Polyline &)