Geant4 Cross Reference |
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 // 27 // 28 // 29 // Created: Mar. 31, 2009 Akinori Kimura 30 // 31 // Scene handler to export geometry and trajectories to a gMocren file. 32 // 33 #ifndef G4GMocrenFile_SCENE_HANDLER_HH 34 #define G4GMocrenFile_SCENE_HANDLER_HH 35 36 #include "globals.hh" 37 38 #include "G4VSceneHandler.hh" 39 40 #include <fstream> 41 42 #include "G4THitsMap.hh" 43 44 class G4VisAttributes ; 45 class G4GMocrenFile; 46 class G4GMocrenMessenger; 47 class G4GMocrenIO; 48 class G4VSolid; 49 class G4Polyhedron; 50 class G4Colour; 51 52 //----- 53 class G4GMocrenFileSceneHandler: public G4VSceneHandler { 54 55 friend class G4GMocrenFileViewer; 56 57 public: 58 59 //----- constructor and destructor 60 G4GMocrenFileSceneHandler (G4GMocrenFile& system, 61 G4GMocrenMessenger & messenger, 62 const G4String& name = ""); 63 virtual ~G4GMocrenFileSceneHandler (); 64 65 //----- overriding base class methods 66 using G4VSceneHandler::AddPrimitive; 67 void AddPrimitive (const G4Polyline& line); 68 void AddPrimitive (const G4Polyhedron& p); 69 void AddPrimitive (const G4Text&); 70 void AddPrimitive (const G4Circle&); 71 void AddPrimitive (const G4Square&); 72 73 virtual void BeginModeling () { G4VSceneHandler::BeginModeling ();} 74 virtual void EndModeling () { G4VSceneHandler::EndModeling ();} 75 76 virtual void BeginPrimitives (const G4Transform3D& objectTransformation); 77 virtual void EndPrimitives (); 78 79 using G4VSceneHandler::AddSolid; 80 void AddSolid ( const G4Box& box ); 81 void AddSolid ( const G4Cons& cons ); 82 void AddSolid ( const G4Tubs& tubs ); 83 void AddSolid ( const G4Trd& trd ); 84 void AddSolid ( const G4Trap& trap ); 85 void AddSolid ( const G4Sphere& sphere ); 86 void AddSolid ( const G4Para& para ); 87 void AddSolid ( const G4Torus& torus ); 88 void AddSolid ( const G4VSolid& solid ); 89 90 using G4VSceneHandler::AddCompound; 91 void AddCompound ( const G4VTrajectory& traj); 92 void AddCompound ( const G4VHit& hit); 93 void AddCompound ( const G4VDigi& hit); 94 void AddCompound ( const G4THitsMap<G4double> & hits); 95 void AddCompound ( const G4THitsMap<G4StatDouble> & hits); 96 97 98 void ClearTransientStore(); // Used for triggering detector re-drawing. 99 100 //----- public methods inherent to this class 101 void GFBeginModeling () ; 102 void GFEndModeling () ; 103 G4bool GFIsInModeling () { return kFlagInModeling ; } 104 105 G4bool IsSavingGdd ( void ) { return kFlagSaving_g4_gdd ; } 106 void BeginSavingGdd( void ); 107 void EndSavingGdd ( void ) ; 108 void SetGddFileName() ; 109 110 G4GMocrenFile& GetSystem () { return kSystem ; } 111 const char* GetGddFileName () { return kGddFileName ; } 112 113 114 private: 115 116 //----- initialize all parameters 117 void InitializeParameters(); 118 119 //----- Utilities etc. 120 G4bool IsVisible(); 121 122 // 123 void AddDetector(const G4VSolid & solid); 124 void ExtractDetector(); 125 126 void GetNestedVolumeIndex(G4int, G4int[3]); 127 128 private: 129 G4GMocrenFile& kSystem; // Graphics system for this scene. 130 G4GMocrenMessenger & kMessenger; 131 G4GMocrenIO * kgMocrenIO; 132 133 std::map<G4int, float> kModality; 134 G4int kModalitySize[3]; 135 //std::map<G4ThreeVector, float> kModalityDensities; // key: position, val: density 136 G4bool kbSetModalityVoxelSize; 137 G4bool kbModelingTrajectory; 138 139 static G4int kSceneIdCount; 140 //std::vector<float *> fTrajectories; 141 //std::vector<unsigned char *> fTrajectoryColors; 142 G4Transform3D kVolumeTrans3D; 143 144 class Detector { 145 public: 146 G4String name; 147 G4Polyhedron * polyhedron; 148 G4Transform3D transform3D; 149 unsigned char color[3]; 150 Detector(); 151 ~Detector(); 152 void clear(); 153 }; 154 std::vector<Detector> kDetectors; 155 G4ThreeVector kVolumeSize; 156 G4ThreeVector kVoxelDimension; 157 std::vector<G4String> kNestedVolumeNames; 158 G4int kNestedVolumeDimension[3]; 159 G4int kNestedVolumeDirAxis[3]; 160 161 class Index3D { 162 public: 163 G4int x, y, z; 164 165 Index3D(); 166 Index3D(const Index3D & _index3D); 167 Index3D(G4int _x, G4int _y, G4int _z); 168 ~Index3D(){;} 169 G4bool operator < (const Index3D & _right) const; 170 G4bool operator == (const Index3D & _right) const; 171 private: 172 // Private assigment operator - 173 // assignment not allowed. Keeps Coverity happy. 174 // Index3D& operator = (const Index3D&); 175 }; 176 177 std::map<Index3D, float> kNestedModality; 178 //std::map<Index3D, G4double> * fTempNestedHits; 179 std::map<G4String, std::map<Index3D, G4double> > kNestedHitsList; 180 //std::map<G4String, G4String> kNestedHitsUnit; 181 182 std::ofstream kGddDest; // defined here 183 G4bool kFlagInModeling; 184 // true: GF_BEGIN_MODELING has sent to gMocrenFile, and 185 // GF_END_MODELING has not sent yet. 186 // false: otherwise 187 // 188 // kFlagInModeling is set to "true" 189 // in GFBeginModeling(), and to "false" 190 // in GFEndModeling(). 191 192 G4bool kFlagSaving_g4_gdd ; 193 194 G4int kFlagParameterization; // 0: G4VNestedParameterisation based geometry 195 // 1: G4PhantomParameterisation 196 // 2: interactive scorer 197 G4bool kFlagProcessedInteractiveScorer; 198 199 char kGddDestDir[256]; 200 char kGddFileName[256]; 201 G4int kMaxFileNum; 202 203 }; 204 205 #endif 206