G4HepRepSceneHandler.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 
00033 #ifndef G4HEPREPSCENEHANDLER_HH
00034 #define G4HEPREPSCENEHANDLER_HH 1
00035 
00036 #include "globals.hh"
00037 #include <iostream>
00038 #include <stack>
00039 #include <map>
00040 #include <vector>
00041 
00042 // HepRep
00043 #include "HEPREP/HepRep.h"
00044 
00045 //G4
00046 #include "G4Box.hh"
00047 #include "G4Cons.hh"
00048 #include "G4Tubs.hh"
00049 #include "G4Trd.hh"
00050 #include "G4Trap.hh"
00051 #include "G4Sphere.hh"
00052 #include "G4Para.hh"
00053 #include "G4Torus.hh"
00054 #include "G4Polycone.hh"
00055 #include "G4Polyhedra.hh"
00056 
00057 #include "G4VGraphicsSystem.hh"
00058 #include "G4VSceneHandler.hh"
00059 #include "G4Visible.hh"
00060 #include "G4Material.hh"
00061 #include "G4LogicalVolume.hh"
00062 #include "G4PhysicalVolumeModel.hh"
00063 
00064 class G4HepRepSceneHandler: public G4VSceneHandler {
00065 
00066     public:
00067         G4HepRepSceneHandler (G4VGraphicsSystem& system, const G4String& name = "");
00068         virtual ~G4HepRepSceneHandler ();
00069 
00070         void AddSolid (const G4Box& box);
00071         void AddSolid (const G4Cons& cons);
00072         void AddSolid (const G4Tubs& tubs);
00073         void AddSolid (const G4Trd& trd);
00074         void AddSolid (const G4Trap& trap);          
00075         void AddSolid (const G4Sphere& sphere);      
00076         void AddSolid (const G4Para& para);          
00077         void AddSolid (const G4Torus& torus);        
00078         void AddSolid (const G4Polycone& polycone);  
00079         void AddSolid (const G4Polyhedra& polyhedra);
00080         void AddSolid (const G4VSolid& solid);       
00081         
00082         void AddCompound (const G4VTrajectory&);
00083         void AddCompound (const G4VHit& hit);
00084         void AddCompound (const G4VDigi& digi) {
00085           G4VSceneHandler::AddCompound(digi);
00086         }
00087         void AddCompound (const G4THitsMap<G4double>& hits) {
00088           G4VSceneHandler::AddCompound(hits);
00089         }
00090 
00091         void PreAddSolid (const G4Transform3D& objectTransformation, const G4VisAttributes& visAttribs);
00092         void PostAddSolid ();
00093 
00094         void AddPrimitive (const G4Polyline&);
00095         void AddPrimitive (const G4Text&);
00096         void AddPrimitive (const G4Circle&);
00097         void AddPrimitive (const G4Square&);
00098         void AddPrimitive (const G4Polyhedron&);
00099         void AddPrimitive (const G4NURBS&);
00100 
00101         void AddPrimitive (const G4Polymarker&);
00102         void AddPrimitive (const G4Scale& scale);
00103 
00104         void BeginPrimitives (const G4Transform3D& objectTransformation);
00105         void EndPrimitives ();
00106         void BeginModeling ();
00107         void EndModeling ();
00108 
00109         void openHepRep();
00110         bool closeHepRep(bool final = false);
00111         void openFile(G4String name);
00112         void closeFile();
00113 
00114     private:
00115         static G4int sceneIdCount;
00116         const G4ModelingParameters* originalMP;  // Keeps pointer to original.
00117         G4ModelingParameters* nonCullingMP;      // For temporary non-culling.
00118 
00119         G4Transform3D transform;
00120 
00121         std::ostream* out;
00122         HEPREP::HepRepFactory* factory;
00123         HEPREP::HepRepWriter* writer;
00124         
00125         // Methods
00126         G4bool dontWrite();
00127         
00128         void setColor (HEPREP::HepRepAttribute *attribute, const G4Color& color,
00129                                     const G4String& key = G4String("Color"));
00130         G4Color getColorFor (const G4Visible& visible);
00131         G4Color getColorFor (const G4VSolid& solid);
00132         
00133         void setVisibility (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
00134         void setLine   (HEPREP::HepRepAttribute *attribute, const G4VSolid& solid);
00135         
00136         void setVisibility (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
00137         void setLine   (HEPREP::HepRepAttribute *attribute, const G4Visible& visible);
00138 
00139         void setMarker (HEPREP::HepRepAttribute *attribute, const G4VMarker& marker);
00140 
00141         inline void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, char* value) {
00142             setAttribute(attribute, name, G4String(value));
00143         }
00144         void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, G4String value);
00145         void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, bool value);
00146         void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double value);
00147         void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, int value);
00148         void setAttribute (HEPREP::HepRepAttribute* attribute, G4String name, double red, double green, double blue, double alpha);
00149 
00150         bool isEventData();
00151 
00152         void open(G4String name);
00153         void close();
00154 
00155         void writeLayers(HEPREP::HepRep* heprep);
00156 
00157         void addAttributes(HEPREP::HepRepInstance* instance, HEPREP::HepRepType* type);
00158 
00159         void addAttDefs(HEPREP::HepRepDefinition* definition, const std::map<G4String,G4AttDef>* attDefs);
00160         void addAttVals(HEPREP::HepRepAttribute* attribute, const std::map<G4String,G4AttDef>* attDefs, std::vector<G4AttValue>* attValues);
00161 
00162         void addTopLevelAttributes(HEPREP::HepRepType* type);
00163 
00164         HEPREP::HepRepInstance*     getGeometryOrEventInstance(HEPREP::HepRepType* type);
00165 
00166         // Returns the particular instance/type or if not created, creates them and adds them to the HepRep
00167         HEPREP::HepRep*             getHepRep();
00168         HEPREP::HepRep*             getHepRepGeometry();
00169         HEPREP::HepRepInstanceTree* getGeometryInstanceTree();
00170         HEPREP::HepRepInstance*     getGeometryInstance(G4LogicalVolume* volume, G4Material* material, int depth);
00171         HEPREP::HepRepInstance*     getGeometryInstance(G4String volumeName, int depth);
00172         HEPREP::HepRepInstance*     getGeometryRootInstance();
00173         HEPREP::HepRepTypeTree*     getGeometryTypeTree();
00174         HEPREP::HepRepType*         getGeometryType(G4String volumeName, int depth);
00175         HEPREP::HepRepType*         getGeometryRootType();
00176         HEPREP::HepRepInstanceTree* getEventInstanceTree();
00177         HEPREP::HepRepInstance*     getEventInstance();
00178         HEPREP::HepRepTypeTree*     getEventTypeTree();
00179         HEPREP::HepRepType*         getEventType();
00180         HEPREP::HepRepType*         getTrajectoryType       ();
00181         HEPREP::HepRepType*         getHitType              ();
00182         HEPREP::HepRepType*         getCalHitType           ();
00183         HEPREP::HepRepType*         getCalHitFaceType       ();
00184 
00185         G4String getFullTypeName(G4String volumeName, int depth);
00186         G4String getParentTypeName(int currentDepth);
00187 
00188         // initialized Member Variables
00189         G4String geometryLayer, eventLayer, calHitLayer;
00190         G4String trajectoryLayer, hitLayer;
00191         G4String rootVolumeName;
00192         
00193         G4String baseName;
00194         G4String eventNumberPrefix;
00195         G4String eventNumberSuffix;
00196         G4int eventNumber;
00197         G4int eventNumberWidth;
00198         G4String extension;
00199         G4bool writeBinary;
00200         G4bool writeZip;
00201         G4bool writeGZ;
00202         G4bool writeMultipleFiles;
00203         const G4VHit* currentHit;
00204         const G4VTrajectory* currentTrack;
00205 
00206         // DO NOT USE member vars directly, use get methods.
00207         HEPREP::HepRep*                         _heprep;
00208         HEPREP::HepRep*                         _heprepGeometry;
00209         HEPREP::HepRepInstanceTree*             _geometryInstanceTree;
00210         std::vector<HEPREP::HepRepInstance*>    _geometryInstance;
00211         HEPREP::HepRepInstance*                 _geometryRootInstance;
00212         HEPREP::HepRepTypeTree*                 _geometryTypeTree;
00213         std::vector<G4String>                   _geometryTypeName;
00214         std::map<G4String, HEPREP::HepRepType*> _geometryType;
00215         HEPREP::HepRepType*                     _geometryRootType;
00216         HEPREP::HepRepInstanceTree*             _eventInstanceTree;
00217         HEPREP::HepRepInstance*                 _eventInstance;
00218         HEPREP::HepRepTypeTree*                 _eventTypeTree;
00219         HEPREP::HepRepType*                     _eventType;
00220         HEPREP::HepRepType*                     _trajectoryType;
00221         HEPREP::HepRepType*                     _hitType;
00222         HEPREP::HepRepType*                     _calHitType;
00223         HEPREP::HepRepType*                     _calHitFaceType;        
00224 
00225         std::map<int, G4String> materialState;
00226 };
00227 
00228 #endif
00229 

Generated on Mon May 27 17:48:30 2013 for Geant4 by  doxygen 1.4.7