G4GMocrenFileSceneHandler.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 //
00027 // $Id$
00028 //
00029 //
00030 // Created:  Mar. 31, 2009  Akinori Kimura  
00031 //
00032 // Scene handler to export geometry and trajectories to a gMocren file.
00033 //
00034 #ifndef G4GMocrenFile_SCENE_HANDLER_HH
00035 #define G4GMocrenFile_SCENE_HANDLER_HH
00036 
00037 #include "globals.hh"
00038 
00039 #include "G4VSceneHandler.hh"
00040 
00041 #include <fstream>
00042 
00043 #include "G4THitsMap.hh"
00044 
00045 class G4VisAttributes ;
00046 class G4GMocrenFile;
00047 class G4GMocrenMessenger;
00048 class G4GMocrenIO;
00049 class G4VSolid;
00050 class G4Polyhedron;
00051 class G4Colour;
00052 
00053 //-----
00054 class G4GMocrenFileSceneHandler: public G4VSceneHandler {
00055 
00056   friend class G4GMocrenFileViewer;
00057 
00058 public:
00059 
00060         //----- constructor and destructor
00061   G4GMocrenFileSceneHandler (G4GMocrenFile& system,
00062                              G4GMocrenMessenger & messenger,
00063                              const G4String& name = "");
00064   virtual ~G4GMocrenFileSceneHandler ();
00065 
00066         //----- overriding base class methods
00067   void AddPrimitive (const G4Polyline& line);
00068   void AddPrimitive (const G4Polyhedron& p);
00069   void AddPrimitive (const G4NURBS& nurb);
00070   void AddPrimitive (const G4Text&);
00071   void AddPrimitive (const G4Circle&);
00072   void AddPrimitive (const G4Square&);
00073 
00074         //----- explicitly invoke base class methods to avoid warnings about
00075         //----- hiding of base class methods.
00076   void AddPrimitive (const G4Polymarker& polymarker) 
00077        { G4VSceneHandler::AddPrimitive (polymarker); }
00078   void AddPrimitive (const G4Scale& scale) 
00079        { G4VSceneHandler::AddPrimitive (scale); }
00080 
00081   virtual void BeginModeling () { G4VSceneHandler::BeginModeling ();} 
00082   virtual void EndModeling   () { G4VSceneHandler::EndModeling   ();}
00083 
00084   virtual void BeginPrimitives (const G4Transform3D& objectTransformation);
00085   virtual void EndPrimitives ();
00086 
00087   void AddSolid ( const G4Box&    box    );
00088   void AddSolid ( const G4Cons&   cons   );
00089   void AddSolid ( const G4Tubs&   tubs   );
00090   void AddSolid ( const G4Trd&    trd    );
00091   void AddSolid ( const G4Trap&   trap   );
00092   void AddSolid ( const G4Sphere& sphere );
00093   void AddSolid ( const G4Para&   para   );
00094   void AddSolid ( const G4Torus&  torus  );
00095   void AddSolid ( const G4Polycone& polycone ) {
00096     G4VSceneHandler::AddSolid (polycone);
00097   }
00098   void AddSolid ( const G4Polyhedra& polyhedra) {
00099     G4VSceneHandler::AddSolid (polyhedra);
00100   }
00101   void AddSolid ( const G4VSolid& solid  );
00102   void AddCompound ( const G4VTrajectory& traj);
00103   void AddCompound ( const G4VHit& hit);
00104   void AddCompound ( const G4VDigi& hit);
00105   void AddCompound ( const G4THitsMap<G4double> & hits);
00106 
00107 
00108   void ClearTransientStore();  // Used for triggering detector re-drawing.
00109 
00110   //----- public methods inherent to this class
00111   void         GFBeginModeling () ;
00112   void         GFEndModeling   () ;
00113   G4bool       GFIsInModeling  () { return kFlagInModeling ; }
00114 
00115   G4bool IsSavingGdd   ( void ) { return kFlagSaving_g4_gdd ;   }
00116   void  BeginSavingGdd( void ); 
00117   void  EndSavingGdd  ( void ) ;
00118   void  SetGddFileName() ;
00119 
00120   G4GMocrenFile&  GetSystem   () { return kSystem   ; }
00121   const char*  GetGddFileName () { return kGddFileName ; }
00122 
00123 
00124 private:
00125 
00126   //----- initialize all parameters
00127   void InitializeParameters();
00128 
00129   //----- Utilities etc.
00130   G4bool IsVisible();
00131 
00132   //
00133   void AddDetector(const G4VSolid & solid);
00134   void ExtractDetector();
00135 
00136   void GetNestedVolumeIndex(G4int, G4int[3]);
00137 
00138 private:
00139   G4GMocrenFile&        kSystem;     // Graphics system for this scene.
00140   G4GMocrenMessenger & kMessenger;
00141   G4GMocrenIO * kgMocrenIO;
00142 
00143   std::map<G4int, float> kModality;
00144   G4int kModalitySize[3];
00145   //std::map<G4ThreeVector, float> kModalityDensities; // key: position, val: density
00146   G4bool kbSetModalityVoxelSize;
00147   G4bool kbModelingTrajectory;
00148 
00149   static G4int  kSceneIdCount;
00150   //std::vector<float *> fTrajectories;
00151   //std::vector<unsigned char *> fTrajectoryColors;
00152   G4Transform3D kVolumeTrans3D;
00153 
00154   class Detector {
00155   public:
00156     G4String name;
00157     G4Polyhedron * polyhedron;
00158     G4Transform3D transform3D;
00159     unsigned char color[3];
00160     Detector();
00161     ~Detector();
00162     void clear();
00163   };
00164   std::vector<Detector> kDetectors;
00165   G4ThreeVector kVolumeSize;
00166   G4ThreeVector kVoxelDimension;
00167   std::vector<G4String> kNestedVolumeNames;
00168   G4int kNestedVolumeDimension[3];
00169   G4int kNestedVolumeDirAxis[3];
00170 
00171   class Index3D {
00172   public:
00173     G4int x, y, z;
00174 
00175     Index3D();
00176     Index3D(const Index3D & _index3D);
00177     Index3D(G4int _x, G4int _y, G4int _z);
00178     ~Index3D(){;}
00179     G4bool operator < (const Index3D & _right) const;
00180     G4bool operator == (const Index3D & _right) const;
00181   };
00182 
00183   std::map<Index3D, float> kNestedModality;
00184   std::map<Index3D, G4double> * fTempNestedHits;
00185   std::map<G4String, std::map<Index3D, G4double> > kNestedHitsList;
00186   //std::map<G4String, G4String> kNestedHitsUnit;
00187 
00188   std::ofstream kGddDest;  // defined here
00189   G4bool kFlagInModeling;       
00190                 // true:  GF_BEGIN_MODELING has sent to gMocrenFile, and
00191                 //        GF_END_MODELING   has not sent yet.
00192                 // false:  otherwise
00193                 // 
00194                 // kFlagInModeling is set to "true"
00195                 // in GFBeginModeling(), and to "false" 
00196                 // in GFEndModeling().
00197 
00198   G4bool kFlagSaving_g4_gdd ;   
00199 
00200   G4int kFlagParameterization; // 0: G4VNestedParameterisation based geometry
00201                                // 1: G4PhantomParameterisation
00202                                // 2: interactive scorer
00203   G4bool kFLagProcessedInteractiveScorer;
00204 
00205   char kGddDestDir[256]; 
00206   char kGddFileName[256];
00207   G4int kMaxFileNum;
00208 
00209 };
00210 
00211 #endif

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