source: trunk/source/visualization/HepRep/include/G4HepRepSceneHandler.hh@ 1236

Last change on this file since 1236 was 1228, checked in by garnier, 16 years ago

update geant4.9.3 tag

File size: 9.5 KB
Line 
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.44 2009/11/23 05:42:28 perl Exp $
27// GEANT4 tag $Name: $
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
65class G4HepRepSceneHandler: public G4VSceneHandler {
66
67 public:
68 G4HepRepSceneHandler (G4VGraphicsSystem& system, const G4String& name = "");
69 virtual ~G4HepRepSceneHandler ();
70
71 void AddSolid (const G4Box& box);
72 void AddSolid (const G4Cons& cons);
73 void AddSolid (const G4Tubs& tubs);
74 void AddSolid (const G4Trd& trd);
75 void AddSolid (const G4Trap& trap);
76 void AddSolid (const G4Sphere& sphere);
77 void AddSolid (const G4Para& para);
78 void AddSolid (const G4Torus& torus);
79 void AddSolid (const G4Polycone& polycone);
80 void AddSolid (const G4Polyhedra& polyhedra);
81 void AddSolid (const G4VSolid& solid);
82
83 void AddCompound (const G4VTrajectory&);
84 void AddCompound (const G4VHit& hit);
85 void AddCompound (const G4THitsMap<G4double>& hits) {
86 G4VSceneHandler::AddCompound(hits);
87 }
88
89 void PreAddSolid (const G4Transform3D& objectTransformation, const G4VisAttributes& visAttribs);
90 void PostAddSolid ();
91
92 void AddPrimitive (const G4Polyline&);
93 void AddPrimitive (const G4Text&);
94 void AddPrimitive (const G4Circle&);
95 void AddPrimitive (const G4Square&);
96 void AddPrimitive (const G4Polyhedron&);
97 void AddPrimitive (const G4NURBS&);
98
99 void AddPrimitive (const G4Polymarker&);
100 void AddPrimitive (const G4Scale& scale);
101
102 void BeginPrimitives (const G4Transform3D& objectTransformation);
103 void EndPrimitives ();
104 void BeginModeling ();
105 void EndModeling ();
106
107 void openHepRep();
108 bool closeHepRep(bool final = false);
109 void openFile(G4String name);
110 void closeFile();
111
112 private:
113 static G4int sceneIdCount;
114 const G4ModelingParameters* originalMP; // Keeps pointer to original.
115 G4ModelingParameters* nonCullingMP; // For temporary non-culling.
116
117 G4Transform3D transform;
118
119 std::ostream* out;
120 HEPREP::HepRepFactory* factory;
121 HEPREP::HepRepWriter* writer;
122
123 // Methods
124 G4bool dontWrite();
125
126 void setColor (HEPREP::HepRepAttribute *attribute, const G4Color& color,
127 const G4String& key = G4String("Color"));
128 G4Color getColorFor (const G4Visible& visible);
129 G4Color getColorFor (const G4VSolid& solid);
130
131 void setVisibility (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
132 void setLine (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
133
134 void setVisibility (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
135 void setLine (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
136
137 void setMarker (HEPREP::HepRepAttribute *attribute, const G4VMarker& marker);
138
139 inline void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, char* value) {
140 setAttribute(attribute, name, G4String(value));
141 }
142 void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, G4String value);
143 void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, bool value);
144 void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double value);
145 void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, int value);
146 void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double red, double green, double blue, double alpha);
147
148 bool isEventData();
149
150 void open(G4String name);
151 void close();
152
153 void writeLayers(HEPREP::HepRep* heprep);
154
155 void addAttributes(HEPREP::HepRepInstance* instance, HEPREP::HepRepType* type);
156
157 void addAttDefs(HEPREP::HepRepDefinition* definition, const std::map<G4String,G4AttDef>* attDefs);
158 void addAttVals(HEPREP::HepRepAttribute* attribute, const std::map<G4String,G4AttDef>* attDefs, std::vector<G4AttValue>* attValues);
159
160 void addTopLevelAttributes(HEPREP::HepRepType* type);
161
162 HEPREP::HepRepInstance* getGeometryOrEventInstance(HEPREP::HepRepType* type);
163
164 // Returns the particular instance/type or if not created, creates them and adds them to the HepRep
165 HEPREP::HepRep* getHepRep();
166 HEPREP::HepRep* getHepRepGeometry();
167 HEPREP::HepRepInstanceTree* getGeometryInstanceTree();
168 HEPREP::HepRepInstance* getGeometryInstance(G4LogicalVolume* volume, G4Material* material, int depth);
169 HEPREP::HepRepInstance* getGeometryInstance(G4String volumeName, int depth);
170 HEPREP::HepRepInstance* getGeometryRootInstance();
171 HEPREP::HepRepTypeTree* getGeometryTypeTree();
172 HEPREP::HepRepType* getGeometryType(G4String volumeName, int depth);
173 HEPREP::HepRepType* getGeometryRootType();
174 HEPREP::HepRepInstanceTree* getEventInstanceTree();
175 HEPREP::HepRepInstance* getEventInstance();
176 HEPREP::HepRepTypeTree* getEventTypeTree();
177 HEPREP::HepRepType* getEventType();
178 HEPREP::HepRepType* getTrajectoryType ();
179 HEPREP::HepRepType* getHitType ();
180 HEPREP::HepRepType* getCalHitType ();
181 HEPREP::HepRepType* getCalHitFaceType ();
182
183 G4String getFullTypeName(G4String volumeName, int depth);
184 G4String getParentTypeName(int currentDepth);
185
186 // initialized Member Variables
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
Note: See TracBrowser for help on using the repository browser.