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