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

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

File size: 9.6 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.45 2010/05/30 10:28:02 allison Exp $
27// GEANT4 tag $Name: geant4-09-04-ref-00 $
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 G4VDigi& digi) {
86          G4VSceneHandler::AddCompound(digi);
87        }
88        void AddCompound (const G4THitsMap<G4double>& hits) {
89          G4VSceneHandler::AddCompound(hits);
90        }
91
92        void PreAddSolid (const G4Transform3D& objectTransformation, const G4VisAttributes& visAttribs);
93        void PostAddSolid ();
94
95        void AddPrimitive (const G4Polyline&);
96        void AddPrimitive (const G4Text&);
97        void AddPrimitive (const G4Circle&);
98        void AddPrimitive (const G4Square&);
99        void AddPrimitive (const G4Polyhedron&);
100        void AddPrimitive (const G4NURBS&);
101
102        void AddPrimitive (const G4Polymarker&);
103        void AddPrimitive (const G4Scale& scale);
104
105        void BeginPrimitives (const G4Transform3D& objectTransformation);
106        void EndPrimitives ();
107        void BeginModeling ();
108        void EndModeling ();
109
110        void openHepRep();
111        bool closeHepRep(bool final = false);
112        void openFile(G4String name);
113        void closeFile();
114
115    private:
116        static G4int sceneIdCount;
117        const G4ModelingParameters* originalMP;  // Keeps pointer to original.
118        G4ModelingParameters* nonCullingMP;      // For temporary non-culling.
119
120        G4Transform3D transform;
121
122        std::ostream* out;
123        HEPREP::HepRepFactory* factory;
124        HEPREP::HepRepWriter* writer;
125       
126        // Methods
127        G4bool dontWrite();
128       
129        void setColor (HEPREP::HepRepAttribute *attribute, const G4Color& color,
130                                    const G4String& key = G4String("Color"));
131        G4Color getColorFor (const G4Visible& visible);
132        G4Color getColorFor (const G4VSolid& solid);
133       
134        void setVisibility (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
135        void setLine   (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
136       
137        void setVisibility (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
138        void setLine   (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
139
140        void setMarker (HEPREP::HepRepAttribute *attribute, const G4VMarker& marker);
141
142        inline void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, char* value) {
143            setAttribute(attribute, name, G4String(value));
144        }
145        void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, G4String value);
146        void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, bool value);
147        void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double value);
148        void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, int value);
149        void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double red, double green, double blue, double alpha);
150
151        bool isEventData();
152
153        void open(G4String name);
154        void close();
155
156        void writeLayers(HEPREP::HepRep* heprep);
157
158        void addAttributes(HEPREP::HepRepInstance* instance, HEPREP::HepRepType* type);
159
160        void addAttDefs(HEPREP::HepRepDefinition* definition, const std::map<G4String,G4AttDef>* attDefs);
161        void addAttVals(HEPREP::HepRepAttribute* attribute, const std::map<G4String,G4AttDef>* attDefs, std::vector<G4AttValue>* attValues);
162
163        void addTopLevelAttributes(HEPREP::HepRepType* type);
164
165        HEPREP::HepRepInstance*     getGeometryOrEventInstance(HEPREP::HepRepType* type);
166
167        // Returns the particular instance/type or if not created, creates them and adds them to the HepRep
168        HEPREP::HepRep*             getHepRep();
169        HEPREP::HepRep*             getHepRepGeometry();
170        HEPREP::HepRepInstanceTree* getGeometryInstanceTree();
171        HEPREP::HepRepInstance*     getGeometryInstance(G4LogicalVolume* volume, G4Material* material, int depth);
172        HEPREP::HepRepInstance*     getGeometryInstance(G4String volumeName, int depth);
173        HEPREP::HepRepInstance*     getGeometryRootInstance();
174        HEPREP::HepRepTypeTree*     getGeometryTypeTree();
175        HEPREP::HepRepType*         getGeometryType(G4String volumeName, int depth);
176        HEPREP::HepRepType*         getGeometryRootType();
177        HEPREP::HepRepInstanceTree* getEventInstanceTree();
178        HEPREP::HepRepInstance*     getEventInstance();
179        HEPREP::HepRepTypeTree*     getEventTypeTree();
180        HEPREP::HepRepType*         getEventType();
181        HEPREP::HepRepType*         getTrajectoryType       ();
182        HEPREP::HepRepType*         getHitType              ();
183        HEPREP::HepRepType*         getCalHitType           ();
184        HEPREP::HepRepType*         getCalHitFaceType       ();
185
186        G4String getFullTypeName(G4String volumeName, int depth);
187        G4String getParentTypeName(int currentDepth);
188
189        // initialized Member Variables
190        G4String geometryLayer, eventLayer, calHitLayer;
191        G4String trajectoryLayer, hitLayer;
192        G4String rootVolumeName;
193       
194        G4String baseName;
195        G4String eventNumberPrefix;
196        G4String eventNumberSuffix;
197        G4int eventNumber;
198        G4int eventNumberWidth;
199        G4String extension;
200        G4bool writeBinary;
201        G4bool writeZip;
202        G4bool writeGZ;
203        G4bool writeMultipleFiles;
204        const G4VHit* currentHit;
205        const G4VTrajectory* currentTrack;
206
207        // DO NOT USE member vars directly, use get methods.
208        HEPREP::HepRep*                         _heprep;
209        HEPREP::HepRep*                         _heprepGeometry;
210        HEPREP::HepRepInstanceTree*             _geometryInstanceTree;
211        std::vector<HEPREP::HepRepInstance*>    _geometryInstance;
212        HEPREP::HepRepInstance*                 _geometryRootInstance;
213        HEPREP::HepRepTypeTree*                 _geometryTypeTree;
214        std::vector<G4String>                   _geometryTypeName;
215        std::map<G4String, HEPREP::HepRepType*> _geometryType;
216        HEPREP::HepRepType*                     _geometryRootType;
217        HEPREP::HepRepInstanceTree*             _eventInstanceTree;
218        HEPREP::HepRepInstance*                 _eventInstance;
219        HEPREP::HepRepTypeTree*                 _eventTypeTree;
220        HEPREP::HepRepType*                     _eventType;
221        HEPREP::HepRepType*                     _trajectoryType;
222        HEPREP::HepRepType*                     _hitType;
223        HEPREP::HepRepType*                     _calHitType;
224        HEPREP::HepRepType*                     _calHitFaceType;       
225
226        std::map<int, G4String> materialState;
227};
228
229#endif
230
Note: See TracBrowser for help on using the repository browser.