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

Last change on this file since 1202 was 1140, checked in by garnier, 15 years ago

update to CVS

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.43 2009/10/21 15:08:35 allison 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
65#include "G4HepRepMessenger.hh"
66
67class G4HepRepSceneHandler: public G4VSceneHandler {
68
69    public:
70        G4HepRepSceneHandler (G4VGraphicsSystem& system, G4HepRepMessenger& messenger, const G4String& name = "");
71        virtual ~G4HepRepSceneHandler ();
72
73        void AddSolid (const G4Box& box);
74        void AddSolid (const G4Cons& cons);
75        void AddSolid (const G4Tubs& tubs);
76        void AddSolid (const G4Trd& trd);
77        void AddSolid (const G4Trap& trap);         
78        void AddSolid (const G4Sphere& sphere);     
79        void AddSolid (const G4Para& para);         
80        void AddSolid (const G4Torus& torus);       
81        void AddSolid (const G4Polycone& polycone); 
82        void AddSolid (const G4Polyhedra& polyhedra);
83        void AddSolid (const G4VSolid& solid);       
84       
85        void AddCompound (const G4VTrajectory&);
86        void AddCompound (const G4VHit& hit);
87        void AddCompound (const G4THitsMap<G4double>& hits) {
88          G4VSceneHandler::AddCompound(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        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        G4HepRepMessenger& messenger;
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.