Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:27

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 //
0028 //
0029 // John Allison  19th July 1996.
0030 //
0031 // Class description
0032 //
0033 // Abstract interface class for graphics scene handlers.
0034 // Inherits from G4VGraphicsScene, in the intercoms category, which is
0035 // a minimal abstract interface for the GEANT4 kernel.
0036 
0037 #ifndef G4VSCENEHANDLER_HH
0038 #define G4VSCENEHANDLER_HH
0039 
0040 #include "globals.hh"
0041 
0042 #include "G4VGraphicsScene.hh"
0043 #include "G4ViewerList.hh"
0044 #include "G4ViewParameters.hh"
0045 #include "G4THitsMap.hh"
0046 #include "G4PseudoScene.hh"
0047 
0048 class G4Scene;
0049 class G4VGraphicsSystem;
0050 class G4AttHolder;
0051 
0052 class G4VSceneHandler: public G4VGraphicsScene {
0053 
0054   friend class G4VViewer;
0055   friend std::ostream& operator << (std::ostream& os, const G4VSceneHandler& s);
0056 
0057 public: // With description
0058 
0059   enum MarkerSizeType {world, screen};
0060 
0061   G4VSceneHandler (G4VGraphicsSystem& system,
0062            G4int id,
0063            const G4String& name = "");
0064 
0065   virtual ~G4VSceneHandler ();
0066 
0067   ///////////////////////////////////////////////////////////////////
0068   // Methods for adding raw GEANT4 objects to the scene handler.  They
0069   // must always be called in the triplet PreAddSolid, AddSolid and
0070   // PostAddSolid.  The transformation and visualization attributes
0071   // must be set by the call to PreAddSolid.  If your graphics system
0072   // is sophisticated enough to handle a particular solid shape as a
0073   // primitive, in your derived class write a function to override one
0074   // or more of the following.  See the implementation of
0075   // G4VSceneHandler::AddSolid (const G4Box& box) for more
0076   // suggestions.  If not, please implement the base class invocation.
0077 
0078   virtual void PreAddSolid (const G4Transform3D& objectTransformation,
0079                 const G4VisAttributes&);
0080   // objectTransformation is the transformation in the world
0081   // coordinate system of the object about to be added, and visAttribs
0082   // is its visualization attributes.
0083   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
0084   // void MyXXXSceneHandler::PreAddSolid
0085   //  (const G4Transform3D& objectTransformation,
0086   //   const G4VisAttributes& visAttribs) {
0087   //   G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
0088   //   ...
0089   // }
0090 
0091   virtual void PostAddSolid ();
0092   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
0093   // void MyXXXSceneHandler::PostAddSolid () {
0094   //   ...
0095   //   G4VSceneHandler::PostAddSolid ();
0096   // }
0097 
0098   // From geometry/solids/CSG
0099   virtual void AddSolid (const G4Box&);
0100   virtual void AddSolid (const G4Cons&);
0101   virtual void AddSolid (const G4Orb&);
0102   virtual void AddSolid (const G4Para&);
0103   virtual void AddSolid (const G4Sphere&);
0104   virtual void AddSolid (const G4Torus&);
0105   virtual void AddSolid (const G4Trap&);
0106   virtual void AddSolid (const G4Trd&);
0107   virtual void AddSolid (const G4Tubs&);
0108 
0109   // From geometry/solids/specific
0110   virtual void AddSolid (const G4Ellipsoid&);
0111   virtual void AddSolid (const G4Polycone&);
0112   virtual void AddSolid (const G4Polyhedra&);
0113   virtual void AddSolid (const G4TessellatedSolid&);
0114 
0115   // For solids not above.
0116   virtual void AddSolid (const G4VSolid&);
0117 
0118   ///////////////////////////////////////////////////////////////////
0119   // Methods for adding "compound" GEANT4 objects to the scene
0120   // handler.  These methods may either (a) invoke "user code" that
0121   // uses the "user interface", G4VVisManager (see, for example,
0122   // G4VSceneHandler, which for trajectories uses
0123   // G4VTrajectory::DrawTrajectory, via G4TrajectoriesModel in the
0124   // Modeling Category) or (b) invoke AddPrimitives below (between
0125   // calls to Begin/EndPrimitives) or (c) use graphics-system-specific
0126   // code or (d) any combination of the above.
0127 
0128   virtual void AddCompound (const G4VTrajectory&);
0129   virtual void AddCompound (const G4VHit&);
0130   virtual void AddCompound (const G4VDigi&);
0131   virtual void AddCompound (const G4THitsMap<G4double>&);
0132   virtual void AddCompound (const G4THitsMap<G4StatDouble>&);
0133   virtual void AddCompound (const G4Mesh&);
0134 
0135   //////////////////////////////////////////////////////////////
0136   // Functions for adding primitives.
0137 
0138   virtual void BeginModeling ();
0139   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
0140   // void MyXXXSceneHandler::BeginModeling () {
0141   //   G4VSceneHandler::BeginModeling ();
0142   //   ...
0143   // }
0144 
0145   virtual void EndModeling ();
0146   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
0147   // void MyXXXSceneHandler::EndModeling () {
0148   //   ...
0149   //   G4VSceneHandler::EndModeling ();
0150   // }
0151 
0152   virtual void BeginPrimitives
0153   (const G4Transform3D& objectTransformation = G4Transform3D());
0154   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
0155   // void MyXXXSceneHandler::BeginPrimitives
0156   // (const G4Transform3D& objectTransformation) {
0157   //   G4VSceneHandler::BeginPrimitives (objectTransformation);
0158   //   ...
0159   // }
0160 
0161   virtual void EndPrimitives ();
0162   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
0163   // void MyXXXSceneHandler::EndPrimitives () {
0164   //   ...
0165   //   G4VSceneHandler::EndPrimitives ();
0166   // }
0167 
0168   virtual void BeginPrimitives2D
0169   (const G4Transform3D& objectTransformation = G4Transform3D());
0170   // The x,y coordinates of the primitives passed to AddPrimitive are
0171   // intrepreted as screen coordinates, -1 < x,y < 1.  The
0172   // z-coordinate is ignored.
0173   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
0174   // void MyXXXSceneHandler::BeginPrimitives2D
0175   // (const G4Transform3D& objectTransformation) {
0176   //   G4VSceneHandler::BeginPrimitives2D (objectTransformation);
0177   //   ...
0178   // }
0179 
0180   virtual void EndPrimitives2D ();
0181   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
0182   // void MyXXXSceneHandler::EndPrimitives2D () {
0183   //   ...
0184   //   G4VSceneHandler::EndPrimitives2D ();
0185   // }
0186 
0187   virtual void AddPrimitive (const G4Polyline&)   = 0;
0188   virtual void AddPrimitive (const G4Text&)       = 0;
0189   virtual void AddPrimitive (const G4Circle&)     = 0;      
0190   virtual void AddPrimitive (const G4Square&)     = 0;      
0191   virtual void AddPrimitive (const G4Polymarker&);
0192   virtual void AddPrimitive (const G4Polyhedron&) = 0;
0193   virtual void AddPrimitive (const G4Plotter&);
0194   
0195   // Other virtual functions
0196   virtual const G4VisExtent& GetExtent() const;
0197 
0198   //////////////////////////////////////////////////////////////
0199   // Access functions.
0200   const G4String&     GetName           () const;
0201   G4int               GetSceneHandlerId () const;
0202   G4int               GetViewCount      () const;
0203   G4VGraphicsSystem*  GetGraphicsSystem () const;
0204   G4Scene*            GetScene          () const;
0205   const G4ViewerList& GetViewerList     () const;
0206   G4VModel*           GetModel          () const;
0207   G4VViewer*          GetCurrentViewer  () const;
0208   G4bool              GetMarkForClearingTransientStore () const;
0209   G4bool              IsReadyForTransients () const;
0210   G4bool              GetTransientsDrawnThisEvent () const;
0211   G4bool              GetTransientsDrawnThisRun   () const;
0212   const G4Transform3D& GetObjectTransformation    () const;
0213   void                SetName          (const G4String&);
0214   void          SetCurrentViewer (G4VViewer*);
0215   virtual void        SetScene         (G4Scene*);
0216   G4ViewerList& SetViewerList    ();  // Non-const so you can change.
0217   void          SetModel         (G4VModel*);
0218   void          SetMarkForClearingTransientStore (G4bool);
0219   // Sets flag which will cause transient store to be cleared at the
0220   // next call to BeginPrimitives().  Maintained by vis manager.
0221   void          SetTransientsDrawnThisEvent      (G4bool);
0222   void          SetTransientsDrawnThisRun        (G4bool);
0223   void          SetObjectTransformation          (const G4Transform3D&);
0224   // Maintained by vis manager.
0225 
0226   //////////////////////////////////////////////////////////////
0227   // Public utility functions.
0228 
0229   const G4Colour& GetColour ();  // To be deprecated?
0230   const G4Colour& GetColor  ();
0231   // Returns colour - checks fpVisAttribs and gets applicable colour.
0232   // Assumes fpVisAttribs point to the G4VisAttributes of the current object.
0233   // If the pointer is null, the colour is obtained from the default view
0234   // parameters of the current viewer.
0235 
0236   const G4Colour& GetColour (const G4Visible&);
0237   const G4Colour& GetColor  (const G4Visible&);
0238   // Returns colour, or viewer default colour.
0239   // Makes no assumptions about the validity of data member fpVisAttribs.
0240   // If the G4Visible has no vis attributes, i.e., the pointer is null,
0241   // the colour is obtained from the default view parameters of the
0242   // current viewer.
0243 
0244   const G4Colour& GetTextColour (const G4Text&);
0245   const G4Colour& GetTextColor  (const G4Text&);
0246   // Returns colour of G4Text object, or default text colour.
0247 
0248   G4double GetLineWidth(const G4VisAttributes*);
0249   // Returns line width of G4VisAttributes multiplied by GlobalLineWidthScale.
0250 
0251   G4ViewParameters::DrawingStyle GetDrawingStyle (const G4VisAttributes*);
0252   // Returns drawing style from current view parameters, unless the user
0253   // has forced through the vis attributes, thereby over-riding the
0254   // current view parameter.
0255 
0256   G4int GetNumberOfCloudPoints (const G4VisAttributes*) const;
0257   // Returns no of cloud points from current view parameters, unless the user
0258   // has forced through the vis attributes, thereby over-riding the
0259   // current view parameter.
0260 
0261   G4bool GetAuxEdgeVisible (const G4VisAttributes*);
0262   // Returns auxiliary edge visibility from current view parameters,
0263   // unless the user has forced through the vis attributes, thereby
0264   // over-riding the current view parameter.
0265 
0266   G4int GetNoOfSides(const G4VisAttributes*);
0267   // Returns no. of sides (lines segments per circle) from current
0268   // view parameters, unless the user has forced through the vis
0269   // attributes, thereby over-riding the current view parameter.
0270 
0271   G4double GetMarkerSize (const G4VMarker&, MarkerSizeType&);
0272   // Returns applicable marker size (diameter) and type (in second
0273   // argument).  Uses global default marker if marker sizes are not
0274   // set.  Multiplies by GlobalMarkerScale.
0275 
0276   G4double GetMarkerDiameter (const G4VMarker&, MarkerSizeType&);
0277   // Alias for GetMarkerSize.
0278 
0279   G4double GetMarkerRadius (const G4VMarker&, MarkerSizeType&);
0280   // GetMarkerSize / 2.
0281 
0282   G4ModelingParameters* CreateModelingParameters ();
0283   // Only the scene handler and view know what the Modeling Parameters should
0284   // be.  For historical reasons, the GEANT4 Visualization Environment
0285   // maintains its own Scene Data and View Parameters, which must be
0286   // converted, when needed, to Modeling Parameters.
0287 
0288   void DrawEvent(const G4Event*);
0289   // Checks scene's end-of-event model list and draws trajectories,
0290   // hits, etc.
0291 
0292   void DrawEndOfRunModels();
0293   // Draws end-of-run models.
0294 
0295   //////////////////////////////////////////////////////////////
0296   // Administration functions.
0297 
0298   template <class T> void AddSolidT (const T& solid);
0299   template <class T> void AddSolidWithAuxiliaryEdges (const T& solid);
0300 
0301   G4int IncrementViewCount ();
0302 
0303   virtual void ClearStore ();
0304   // Clears graphics database (display lists) if any.
0305 
0306   virtual void ClearTransientStore ();
0307   // Clears transient part of graphics database (display lists) if any.
0308 
0309   void AddViewerToList      (G4VViewer* pView);  // Add view to view List.
0310   void RemoveViewerFromList (G4VViewer* pView);  // Remove view from view List.
0311 
0312 protected:
0313 
0314   //////////////////////////////////////////////////////////////
0315   // Core routine for looping over models, redrawing stored events, etc.
0316   // Overload with care (see, for example,
0317   // G4OpenGLScenehandler::ProcessScene).
0318   virtual void ProcessScene ();
0319 
0320   //////////////////////////////////////////////////////////////
0321   // Default routine used by default AddSolid ().
0322   virtual void RequestPrimitives (const G4VSolid& solid);
0323 
0324   //////////////////////////////////////////////////////////////
0325   // Other internal routines...
0326 
0327   virtual G4DisplacedSolid* CreateSectionSolid ();
0328   virtual G4DisplacedSolid* CreateCutawaySolid ();
0329   // Generic clipping using the BooleanProcessor in graphics_reps is
0330   // implemented in this class.  Subclasses that implement their own
0331   // clipping should provide an override that returns zero.
0332 
0333   void LoadAtts(const G4Visible&, G4AttHolder*);
0334   // Load G4AttValues and G4AttDefs associated with the G4Visible
0335   // object onto the G4AttHolder object.  It checks fpModel, and also
0336   // loads the G4AttValues and G4AttDefs from G4PhysicalVolumeModel,
0337   // G4VTrajectory, G4VTrajectoryPoint, G4VHit or G4VDigi, as
0338   // appropriate.  The G4AttHolder object is an object of a class that
0339   // publicly inherits G4AttHolder - see, e.g., SoG4Polyhedron in the
0340   // Open Inventor driver.  G4AttHolder deletes G4AttValues in its
0341   // destructor to ensure proper clean-up of G4AttValues.
0342 
0343   //////////////////////////////////////////////////////////////
0344   // Special mesh rendering utilities...
0345 
0346   struct NameAndVisAtts {
0347     NameAndVisAtts(const G4String& name = "",const G4VisAttributes& visAtts = G4VisAttributes())
0348     : fName(name),fVisAtts(visAtts) {}
0349     G4String fName;
0350     G4VisAttributes fVisAtts;
0351   };
0352 
0353   class PseudoSceneFor3DRectMeshPositions: public G4PseudoScene {
0354   public:
0355     PseudoSceneFor3DRectMeshPositions
0356     (G4PhysicalVolumeModel* pvModel  // input
0357      , const G4Mesh* pMesh  // input...the following are outputs by reference
0358      , std::multimap<const G4Material*,const G4ThreeVector>& positionByMaterial
0359      , std::map<const G4Material*,NameAndVisAtts>& nameAndVisAttsByMaterial)
0360     : fpPVModel(pvModel)
0361     , fpMesh(pMesh)
0362     , fPositionByMaterial(positionByMaterial)
0363     , fNameAndVisAttsByMaterial(nameAndVisAttsByMaterial)
0364     {}
0365   private:
0366     using G4PseudoScene::AddSolid;  // except for...
0367     void AddSolid(const G4Box&) override;
0368     void ProcessVolume(const G4VSolid&) override {
0369       // Do nothing if uninteresting solids found, e.g., the container if not marked invisible.
0370     }
0371     G4PhysicalVolumeModel* fpPVModel;
0372     const G4Mesh* fpMesh;
0373     std::multimap<const G4Material*,const G4ThreeVector>& fPositionByMaterial;
0374     std::map<const G4Material*,NameAndVisAtts>& fNameAndVisAttsByMaterial;
0375   };
0376 
0377   class PseudoSceneForTetVertices: public G4PseudoScene {
0378   public:
0379     PseudoSceneForTetVertices
0380     (G4PhysicalVolumeModel* pvModel  // input
0381      , const G4Mesh* pMesh  // input...the following are outputs by reference
0382      , std::multimap<const G4Material*,std::vector<G4ThreeVector>>& verticesByMaterial
0383      , std::map<const G4Material*,NameAndVisAtts>& nameAndVisAttsByMaterial)
0384     : fpPVModel(pvModel)
0385     , fpMesh(pMesh)
0386     , fVerticesByMaterial(verticesByMaterial)
0387     , fNameAndVisAttsByMaterial(nameAndVisAttsByMaterial)
0388     {}
0389   private:
0390     using G4PseudoScene::AddSolid;  // except for...
0391     void AddSolid(const G4VSolid& solid) override;
0392     void ProcessVolume(const G4VSolid&) override {
0393       // Do nothing if uninteresting solids found, e.g., the container if not marked invisible.
0394     }
0395     G4PhysicalVolumeModel* fpPVModel;
0396     const G4Mesh* fpMesh;
0397     std::multimap<const G4Material*,std::vector<G4ThreeVector>>& fVerticesByMaterial;
0398     std::map<const G4Material*,NameAndVisAtts>& fNameAndVisAttsByMaterial;
0399   };
0400 
0401   void StandardSpecialMeshRendering(const G4Mesh&);
0402   // Standard way of special mesh rendering.
0403   // MySceneHandler::AddCompound(const G4Mesh& mesh) may use this if
0404   // appropriate or implement its own special mesh rendereing.
0405 
0406   void Draw3DRectMeshAsDots(const G4Mesh&);
0407   // For a rectangular 3-D mesh, draw as coloured dots by colour and material,
0408   // one dot randomly placed in each visible mesh cell.
0409 
0410   void Draw3DRectMeshAsSurfaces(const G4Mesh&);
0411   // For a rectangular 3-D mesh, draw as surfaces by colour and material
0412   // with inner shared faces removed.
0413 
0414   void DrawTetMeshAsDots(const G4Mesh&);
0415   // For a tetrahedron mesh, draw as coloured dots by colour and material,
0416   // one dot randomly placed in each visible mesh cell.
0417 
0418   void DrawTetMeshAsSurfaces(const G4Mesh&);
0419   // For a tetrahedron mesh, draw as surfaces by colour and material
0420   // with inner shared faces removed.
0421 
0422   G4ThreeVector GetPointInBox(const G4ThreeVector& pos,
0423                               G4double halfX,
0424                               G4double halfY,
0425                               G4double halfZ) const;
0426   // Sample a random point inside the box
0427 
0428   G4ThreeVector GetPointInTet(const std::vector<G4ThreeVector>& vertices) const;
0429   // Sample a random point inside the tetrahedron
0430 
0431   //////////////////////////////////////////////////////////////
0432   // Data members
0433 
0434   G4VGraphicsSystem& fSystem;          // Graphics system.
0435   const G4int        fSceneHandlerId;  // Id of this instance.
0436   G4String           fName;
0437   G4int              fViewCount;       // To determine view ids.
0438   G4ViewerList       fViewerList;      // Viewers.
0439   G4VViewer*         fpViewer;         // Current viewer.
0440   G4Scene*           fpScene;          // Scene for this scene handler.
0441   G4bool             fMarkForClearingTransientStore;
0442   G4bool             fReadyForTransients;  // I.e., not processing the
0443                                // run-duration part of scene.
0444   G4bool             fTransientsDrawnThisEvent;  // Maintained by vis
0445   G4bool             fTransientsDrawnThisRun;    // manager.
0446   G4bool             fProcessingSolid; // True if within Pre/PostAddSolid.
0447   G4bool             fProcessing2D;    // True for 2D.
0448   G4VModel*          fpModel;          // Current model.
0449   G4Transform3D fObjectTransformation; // Current accumulated
0450                        // object transformation.
0451   G4int              fNestingDepth;    // For Begin/EndPrimitives.
0452   const G4VisAttributes* fpVisAttribs; // Working vis attributes.
0453   const G4Transform3D fIdentityTransformation;
0454 
0455 private:
0456 
0457   G4VSceneHandler (const G4VSceneHandler&);
0458   G4VSceneHandler& operator = (const G4VSceneHandler&);
0459 };
0460 
0461 #include "G4VSceneHandler.icc"
0462 
0463 #endif