Geant4  10.03
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 99152 2016-09-07 08:04:30Z gcosmo $
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 G4Orb& orb);
81  void AddSolid (const G4Ellipsoid& ellipsoid);
82  void AddSolid (const G4VSolid& solid);
83 
84  void AddCompound (const G4VTrajectory&);
85  void AddCompound (const G4VHit& hit);
86  void AddCompound (const G4VDigi& digi) {
88  }
89  void AddCompound (const G4THitsMap<G4double>& hits) {
91  }
94  }
95 
96  void PreAddSolid (const G4Transform3D& objectTransformation, const G4VisAttributes& visAttribs);
97  void PostAddSolid ();
98 
99  void AddPrimitive (const G4Polyline&);
100  void AddPrimitive (const G4Text&);
101  void AddPrimitive (const G4Circle&);
102  void AddPrimitive (const G4Square&);
103  void AddPrimitive (const G4Polyhedron&);
104 
105  void AddPrimitive (const G4Polymarker&);
106  void AddPrimitive (const G4Scale& scale);
107 
108  void BeginPrimitives (const G4Transform3D& objectTransformation);
109  void EndPrimitives ();
110  void BeginModeling ();
111  void EndModeling ();
112 
113  void openHepRep();
114  bool closeHepRep(bool final = false);
115  void openFile(G4String name);
116  void closeFile();
117 
118  private:
122 
124 
125  std::ostream* out;
126  HEPREP::HepRepFactory* factory;
127  HEPREP::HepRepWriter* writer;
128 
129  // Methods
130  G4bool dontWrite();
131 
132  void setColor (HEPREP::HepRepAttribute *attribute, const G4Color& color,
133  const G4String& key = G4String("Color"));
134  G4Color getColorFor (const G4Visible& visible);
135  G4Color getColorFor (const G4VSolid& solid);
136 
137  void setVisibility (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
138  void setLine (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
139 
140  void setVisibility (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
141  void setLine (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
142 
143  void setMarker (HEPREP::HepRepAttribute *attribute, const G4VMarker& marker);
144 
145  inline void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, char* value) {
146  setAttribute(attribute, name, G4String(value));
147  }
148  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, G4String value);
149  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, bool value);
150  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double value);
151  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, int value);
152  void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double red, double green, double blue, double alpha);
153 
154  bool isEventData();
155 
156  void open(G4String name);
157  void close();
158 
159  void writeLayers(HEPREP::HepRep* heprep);
160 
161  void addAttributes(HEPREP::HepRepInstance* instance, HEPREP::HepRepType* type);
162 
163  void addAttDefs(HEPREP::HepRepDefinition* definition, const std::map<G4String,G4AttDef>* attDefs);
164  void addAttVals(HEPREP::HepRepAttribute* attribute, const std::map<G4String,G4AttDef>* attDefs, std::vector<G4AttValue>* attValues);
165 
166  void addTopLevelAttributes(HEPREP::HepRepType* type);
167 
168  HEPREP::HepRepInstance* getGeometryOrEventInstance(HEPREP::HepRepType* type);
169 
170  // Returns the particular instance/type or if not created, creates them and adds them to the HepRep
171  HEPREP::HepRep* getHepRep();
172  HEPREP::HepRep* getHepRepGeometry();
173  HEPREP::HepRepInstanceTree* getGeometryInstanceTree();
174  HEPREP::HepRepInstance* getGeometryInstance(G4LogicalVolume* volume, G4Material* material, int depth);
175  HEPREP::HepRepInstance* getGeometryInstance(G4String volumeName, int depth);
176  HEPREP::HepRepInstance* getGeometryRootInstance();
177  HEPREP::HepRepTypeTree* getGeometryTypeTree();
178  HEPREP::HepRepType* getGeometryType(G4String volumeName, int depth);
179  HEPREP::HepRepType* getGeometryRootType();
180  HEPREP::HepRepInstanceTree* getEventInstanceTree();
181  HEPREP::HepRepInstance* getEventInstance();
182  HEPREP::HepRepTypeTree* getEventTypeTree();
183  HEPREP::HepRepType* getEventType();
184  HEPREP::HepRepType* getTrajectoryType ();
185  HEPREP::HepRepType* getHitType ();
186  HEPREP::HepRepType* getCalHitType ();
187  HEPREP::HepRepType* getCalHitFaceType ();
188 
189  G4String getFullTypeName(G4String volumeName, int depth);
190  G4String getParentTypeName(int currentDepth);
191 
192  // initialized Member Variables
196 
209 
210  // DO NOT USE member vars directly, use get methods.
211  HEPREP::HepRep* _heprep;
212  HEPREP::HepRep* _heprepGeometry;
213  HEPREP::HepRepInstanceTree* _geometryInstanceTree;
214  std::vector<HEPREP::HepRepInstance*> _geometryInstance;
215  HEPREP::HepRepInstance* _geometryRootInstance;
216  HEPREP::HepRepTypeTree* _geometryTypeTree;
217  std::vector<G4String> _geometryTypeName;
218  std::map<G4String, HEPREP::HepRepType*> _geometryType;
219  HEPREP::HepRepType* _geometryRootType;
220  HEPREP::HepRepInstanceTree* _eventInstanceTree;
221  HEPREP::HepRepInstance* _eventInstance;
222  HEPREP::HepRepTypeTree* _eventTypeTree;
223  HEPREP::HepRepType* _eventType;
224  HEPREP::HepRepType* _trajectoryType;
225  HEPREP::HepRepType* _hitType;
226  HEPREP::HepRepType* _calHitType;
227  HEPREP::HepRepType* _calHitFaceType;
228 
229  std::map<int, G4String> materialState;
230 };
231 
232 #endif
233 
std::vector< HEPREP::HepRepInstance * > _geometryInstance
void setMarker(HEPREP::HepRepAttribute *attribute, const G4VMarker &marker)
HEPREP::HepRepType * getTrajectoryType()
void AddSolid(const G4Box &box)
Definition: G4Para.hh:77
HEPREP::HepRepInstance * getEventInstance()
Definition: G4Text.hh:73
HEPREP::HepRepType * _calHitFaceType
HEPREP::HepRepTypeTree * _geometryTypeTree
void addAttDefs(HEPREP::HepRepDefinition *definition, const std::map< G4String, G4AttDef > *attDefs)
Definition: test07.cc:36
HEPREP::HepRepTypeTree * getGeometryTypeTree()
HEPREP::HepRepTypeTree * getEventTypeTree()
G4HepRepSceneHandler & operator=(const G4HepRepSceneHandler &)
HEPREP::HepRep * getHepRepGeometry()
std::map< G4String, HEPREP::HepRepType * > _geometryType
void BeginPrimitives(const G4Transform3D &objectTransformation)
bool closeHepRep(bool final=false)
Returns true if the HepRep was (already) closed, false if the HepRep is still open.
HEPREP::HepRepType * _hitType
HEPREP::HepRepType * _geometryRootType
void openFile(G4String name)
Definition: G4Box.hh:64
void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)
HEPREP::HepRepType * getEventType()
HEPREP::HepRepType * getCalHitType()
Definition: G4Tubs.hh:85
HEPREP::HepRepType * _calHitType
std::vector< G4String > _geometryTypeName
HEPREP::HepRepFactory * factory
G4String getFullTypeName(G4String volumeName, int depth)
HEPREP::HepRepType * _eventType
Definition: G4VHit.hh:48
void AddCompound(const G4VDigi &digi)
const char * name(G4int ptype)
Definition: G4Trd.hh:72
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
HEPREP::HepRep * _heprepGeometry
HEPREP::HepRepInstance * getGeometryRootInstance()
G4Color getColorFor(const G4Visible &visible)
HEPREP::HepRepInstance * _eventInstance
HEPREP::HepRepType * getHitType()
HEPREP::HepRep * getHepRep()
G4String getParentTypeName(int currentDepth)
void AddCompound(const G4THitsMap< G4StatDouble > &hits)
std::map< int, G4String > materialState
bool G4bool
Definition: G4Types.hh:79
Definition: G4Cons.hh:83
void addTopLevelAttributes(HEPREP::HepRepType *type)
void addAttributes(HEPREP::HepRepInstance *instance, HEPREP::HepRepType *type)
HEPREP::HepRepInstanceTree * _eventInstanceTree
HepGeom::Transform3D G4Transform3D
void setLine(HEPREP::HepRepAttribute *attribute, const G4VSolid &solid)
HEPREP::HepRepInstance * _geometryRootInstance
Definition: G4Orb.hh:61
void writeLayers(HEPREP::HepRep *heprep)
HEPREP::HepRepTypeTree * _eventTypeTree
HEPREP::HepRepType * getCalHitFaceType()
virtual void AddCompound(const G4VTrajectory &)
void AddCompound(const G4THitsMap< G4double > &hits)
HEPREP::HepRepWriter * writer
void setVisibility(HEPREP::HepRepAttribute *attribute, const G4VSolid &solid)
void AddCompound(const G4VTrajectory &)
G4HepRepSceneHandler(G4VGraphicsSystem &system, const G4String &name="")
HEPREP::HepRepType * getGeometryRootType()
void setAttribute(HEPREP::HepRepAttribute *attribute, G4String name, char *value)
HEPREP::HepRepInstance * getGeometryOrEventInstance(HEPREP::HepRepType *type)
void AddPrimitive(const G4Polyline &)
static MCTruthManager * instance
HEPREP::HepRepInstanceTree * getGeometryInstanceTree()
HEPREP::HepRepInstance * getGeometryInstance(G4LogicalVolume *volume, G4Material *material, int depth)
HEPREP::HepRepType * getGeometryType(G4String volumeName, int depth)
static const G4double alpha
const G4VTrajectory * currentTrack
HEPREP::HepRepType * _trajectoryType
HEPREP::HepRepInstanceTree * getEventInstanceTree()
void open(G4String name)
HEPREP::HepRepInstanceTree * _geometryInstanceTree
void addAttVals(HEPREP::HepRepAttribute *attribute, const std::map< G4String, G4AttDef > *attDefs, std::vector< G4AttValue > *attValues)
void setColor(HEPREP::HepRepAttribute *attribute, const G4Color &color, const G4String &key=G4String("Color"))