Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GMocrenFileSceneHandler.hh
Go to the documentation of this file.
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$
28 //
29 //
30 // Created: Mar. 31, 2009 Akinori Kimura
31 //
32 // Scene handler to export geometry and trajectories to a gMocren file.
33 //
34 #ifndef G4GMocrenFile_SCENE_HANDLER_HH
35 #define G4GMocrenFile_SCENE_HANDLER_HH
36 
37 #include "globals.hh"
38 
39 #include "G4VSceneHandler.hh"
40 
41 #include <fstream>
42 
43 #include "G4THitsMap.hh"
44 
45 class G4VisAttributes ;
46 class G4GMocrenFile;
47 class G4GMocrenMessenger;
48 class G4GMocrenIO;
49 class G4VSolid;
50 class G4Polyhedron;
51 class G4Colour;
52 
53 //-----
55 
56  friend class G4GMocrenFileViewer;
57 
58 public:
59 
60  //----- constructor and destructor
62  G4GMocrenMessenger & messenger,
63  const G4String& name = "");
64  virtual ~G4GMocrenFileSceneHandler ();
65 
66  //----- overriding base class methods
67  void AddPrimitive (const G4Polyline& line);
68  void AddPrimitive (const G4Polyhedron& p);
69  void AddPrimitive (const G4NURBS& nurb);
70  void AddPrimitive (const G4Text&);
71  void AddPrimitive (const G4Circle&);
72  void AddPrimitive (const G4Square&);
73 
74  //----- explicitly invoke base class methods to avoid warnings about
75  //----- hiding of base class methods.
76  void AddPrimitive (const G4Polymarker& polymarker)
77  { G4VSceneHandler::AddPrimitive (polymarker); }
78  void AddPrimitive (const G4Scale& scale)
80 
83 
84  virtual void BeginPrimitives (const G4Transform3D& objectTransformation);
85  virtual void EndPrimitives ();
86 
87  void AddSolid ( const G4Box& box );
88  void AddSolid ( const G4Cons& cons );
89  void AddSolid ( const G4Tubs& tubs );
90  void AddSolid ( const G4Trd& trd );
91  void AddSolid ( const G4Trap& trap );
92  void AddSolid ( const G4Sphere& sphere );
93  void AddSolid ( const G4Para& para );
94  void AddSolid ( const G4Torus& torus );
95  void AddSolid ( const G4Polycone& polycone ) {
96  G4VSceneHandler::AddSolid (polycone);
97  }
98  void AddSolid ( const G4Polyhedra& polyhedra) {
99  G4VSceneHandler::AddSolid (polyhedra);
100  }
101  void AddSolid ( const G4VSolid& solid );
102  void AddCompound ( const G4VTrajectory& traj);
103  void AddCompound ( const G4VHit& hit);
104  void AddCompound ( const G4VDigi& 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