Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 09:09:39

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  31st December 1997.
0030 //
0031 // Class Description:
0032 //
0033 // Model for physical volumes.  It describes a physical volume and its
0034 // daughters to any desired depth.  Note: the "requested depth" is
0035 // specified in the modeling parameters; enum {UNLIMITED = -1}.
0036 //
0037 // For access to base class information, e.g., modeling parameters,
0038 // use GetModelingParameters() inherited from G4VModel.  See Class
0039 // Description of the base class G4VModel.
0040 //
0041 // G4PhysicalVolumeModel assumes the modeling parameters have been set
0042 // up with meaningful information - default vis attributes and culling
0043 // policy in particular.
0044 //
0045 // The volumes are unpacked and sent to the scene handler.  They are,
0046 // in effect, "touchables" as defined by G4TouchableHistory.  A
0047 // touchable is defined not only by its physical volume name and copy
0048 // number but also by its position in the geometry hierarchy.
0049 //
0050 // It is guaranteed that touchables are presented to the scene handler
0051 // in top-down hierarchy order, i.e., ancestors first, mothers before
0052 // daughters, so the scene handler can be assured that, if it is
0053 // building its own scene graph tree, a mother, if any, will have
0054 // already been encountered and there will already be a node in place
0055 // on which to hang the current volume.  But be aware that the
0056 // visibility and culling policy might mean that some touchables are
0057 // not passed to the scene handler so the drawn tree might have
0058 // missing layers.  GetFullPVPath allows you to know the full
0059 // hierarchy.
0060 
0061 #ifndef G4PHYSICALVOLUMEMODEL_HH
0062 #define G4PHYSICALVOLUMEMODEL_HH
0063 
0064 #include "G4VModel.hh"
0065 #include "G4ModelingParameters.hh"
0066 
0067 #include "G4NavigationHistory.hh"
0068 #include "G4Transform3D.hh"
0069 #include "G4Plane3D.hh"
0070 #include <iostream>
0071 #include <vector>
0072 #include <map>
0073 
0074 class G4VPhysicalVolume;
0075 class G4LogicalVolume;
0076 class G4VSolid;
0077 class G4Material;
0078 class G4VisAttributes;
0079 class G4AttDef;
0080 class G4AttValue;
0081 
0082 class G4PhysicalVolumeModel: public G4VModel {
0083 
0084 public: // With description
0085 
0086   enum {UNLIMITED = -1};
0087 
0088   enum ClippingMode {subtraction, intersection};
0089 
0090   // Nested class for identifying physical volume nodes.
0091   class G4PhysicalVolumeNodeID {
0092   public:
0093     G4PhysicalVolumeNodeID
0094     (G4VPhysicalVolume* pPV = 0,
0095      G4int iCopyNo = 0,
0096      G4int depth = 0,
0097      const G4Transform3D& transform = G4Transform3D(),
0098      G4bool drawn = true):
0099       fpPV(pPV),
0100       fCopyNo(iCopyNo),
0101       fNonCulledDepth(depth),
0102       fTransform(transform),
0103       fDrawn(drawn) {}
0104     G4VPhysicalVolume* GetPhysicalVolume() const {return fpPV;}
0105     G4int  GetCopyNo()                     const {return fCopyNo;}
0106     G4int  GetNonCulledDepth()             const {return fNonCulledDepth;}
0107     const  G4Transform3D& GetTransform()   const {return fTransform;}
0108     G4bool GetDrawn()                      const {return fDrawn;}
0109     void SetPhysicalVolume(G4VPhysicalVolume* v)   {fpPV = v;}
0110     void SetCopyNo        (G4int n)                {fCopyNo = n;}
0111     void SetNonCulledDepth(G4int d)                {fNonCulledDepth = d;}
0112     void SetTransform     (const G4Transform3D& t) {fTransform = t;}
0113     void SetDrawn         (G4bool b)               {fDrawn = b;}
0114     G4bool operator<  (const G4PhysicalVolumeNodeID& right) const;
0115     G4bool operator!= (const G4PhysicalVolumeNodeID& right) const;
0116     G4bool operator== (const G4PhysicalVolumeNodeID& right) const {
0117       return !operator!= (right);
0118     }
0119   private:
0120     G4VPhysicalVolume* fpPV;
0121     G4int fCopyNo;
0122     G4int fNonCulledDepth;
0123     G4Transform3D fTransform;
0124     G4bool fDrawn;
0125   };
0126 
0127   // Nested struct for encapsulating touchable properties
0128   struct TouchableProperties {
0129     TouchableProperties(): fpTouchablePV(nullptr), fCopyNo(0) {}
0130     G4ModelingParameters::PVNameCopyNoPath fTouchablePath;
0131     G4VPhysicalVolume*                     fpTouchablePV;
0132     G4int                                  fCopyNo;
0133     G4Transform3D                          fTouchableGlobalTransform;
0134     std::vector<G4PhysicalVolumeNodeID>    fTouchableBaseFullPVPath;
0135     std::vector<G4PhysicalVolumeNodeID>    fTouchableFullPVPath;
0136   };
0137 
0138   G4PhysicalVolumeModel
0139   (G4VPhysicalVolume* = 0,
0140    G4int requestedDepth = UNLIMITED,
0141    const G4Transform3D& modelTransformation = G4Transform3D(),
0142    const G4ModelingParameters* = 0,
0143    G4bool useFullExtent = false,
0144    const std::vector<G4PhysicalVolumeNodeID>& baseFullPVPath =
0145    std::vector<G4PhysicalVolumeNodeID>());
0146 
0147   virtual ~G4PhysicalVolumeModel ();
0148 
0149   void DescribeYourselfTo (G4VGraphicsScene&);
0150   // The main task of a model is to describe itself to the graphics scene
0151   // handler (a object which inherits G4VSceneHandler, which inherits
0152   // G4VGraphicsScene).
0153 
0154   G4String GetCurrentDescription () const;
0155   // A description which depends on the current state of the model.
0156 
0157   G4String GetCurrentTag () const;
0158   // A tag which depends on the current state of the model.
0159 
0160   G4VPhysicalVolume* GetTopPhysicalVolume () const {return fpTopPV;}
0161 
0162   G4int GetRequestedDepth () const {return fRequestedDepth;}
0163 
0164   const G4VSolid* GetClippingSolid () const
0165   {return fpClippingSolid;}
0166 
0167   G4int GetCurrentDepth() const {return fCurrentDepth;}
0168   // Current depth in geom. hierarchy.
0169 
0170   const G4Transform3D& GetTransformation() const {return fTransform;}
0171   // Initial transformation
0172 
0173   G4VPhysicalVolume* GetCurrentPV() const {return fpCurrentPV;}
0174   // Current physical volume.
0175 
0176   G4int GetCurrentPVCopyNo() const {return fCurrentPVCopyNo;}
0177   // Current copy number.
0178 
0179   G4LogicalVolume* GetCurrentLV() const {return fpCurrentLV;}
0180   // Current logical volume.
0181 
0182   G4Material* GetCurrentMaterial() const {return fpCurrentMaterial;}
0183   // Current material.
0184 
0185   const G4Transform3D& GetCurrentTransform() const {return fCurrentTransform;}
0186   // Current transform.
0187 
0188   const std::vector<G4PhysicalVolumeNodeID>& GetBaseFullPVPath() const
0189   {return fBaseFullPVPath;}
0190   // Base for this G4PhysicalVolumeModel. It can be empty, which would be the
0191   // case for the world volume. But the user may create a G4PhysicalVolumeModel
0192   // for a volume anywhere in the tree, in which case the user must provide
0193   // the transform (in the constructor) and the base path (SetBaseFullPVPath).
0194 
0195   const std::vector<G4PhysicalVolumeNodeID>& GetFullPVPath() const
0196   {return fFullPVPath;}
0197   // Vector of physical volume node identifiers for the current
0198   // touchable.  It is its path in the geometry hierarchy, similar to
0199   // the concept of "touchable history" available from the navigator
0200   // during tracking.
0201 
0202   const std::vector<G4PhysicalVolumeNodeID>& GetDrawnPVPath() const
0203   {return fDrawnPVPath;}
0204   // Path of the current drawn (non-culled) touchable in terms of
0205   // drawn (non-culled) ancestors.  It is a vector of physical volume
0206   // node identifiers corresponding to the geometry hierarchy actually
0207   // selected, i.e., with "culled" volumes NOT included.
0208 
0209   static G4ModelingParameters::PVNameCopyNoPath GetPVNameCopyNoPath
0210   (const std::vector<G4PhysicalVolumeNodeID>&);
0211   // Converts to PVNameCopyNoPath
0212 
0213   static G4String GetPVNamePathString(const std::vector<G4PhysicalVolumeNodeID>&);
0214   // Converts to path string, e.g., " World 0 Envelope 0 Shape1 0".
0215   // Note leading space character.
0216 
0217   const std::map<G4String,G4AttDef>* GetAttDefs() const;
0218   // Attribute definitions for current solid.
0219 
0220   std::vector<G4AttValue>* CreateCurrentAttValues() const;
0221   // Attribute values for current solid.  Each must refer to an
0222   // attribute definition in the above map; its name is the key.  The
0223   // user must test the validity of this pointer (it must be non-zero
0224   // and conform to the G4AttDefs, which may be checked with
0225   // G4AttCheck) and delete the list after use.  See
0226   // G4XXXStoredSceneHandler::PreAddSolid for how to access and
0227   // G4VTrajectory::ShowTrajectory for an example of the use of
0228   // G4Atts.
0229 
0230   const std::map<G4int,G4int>& GetMapOfDrawnTouchables() const {return fMapDrawnTouchables;}
0231   // Number of touchables drawn at each depth.
0232 
0233   G4int GetTotalDrawnTouchables () {return fTotalDrawnTouchables;}
0234   // Total number of touchables drawn.
0235 
0236   G4int GetMaxFullDepth () const {return fMaxFullDepth;}
0237   // Including base path, i.e., from the world volume
0238 
0239   const std::map<G4int,G4int>& GetMapOfAllTouchables() const {return fMapAllTouchables;}
0240   // Number of all touchables at each depth.
0241 
0242   G4int GetTotalAllTouchables () {return fTotalAllTouchables;}
0243   // Total number of touchables.
0244 
0245   void SetRequestedDepth (G4int requestedDepth) {
0246     fRequestedDepth = requestedDepth;
0247   }
0248 
0249   void SetClippingSolid (G4VSolid* pClippingSolid) {
0250     fpClippingSolid = pClippingSolid;
0251   }
0252 
0253   void SetClippingMode (ClippingMode mode) {
0254     fClippingMode = mode;
0255   }
0256 
0257   G4bool Validate (G4bool warn);
0258   // Validate, but allow internal changes (hence non-const function).
0259 
0260   void Abort () const {fAbort = true;}
0261   // Abort all further traversing.
0262 
0263   void CurtailDescent() const {fCurtailDescent = true;}
0264   // Curtail descent of current branch.
0265 
0266   void CalculateExtent ();
0267 
0268 protected:
0269 
0270   void VisitGeometryAndGetVisReps (G4VPhysicalVolume*,
0271                    G4int requestedDepth,
0272                    const G4Transform3D&,
0273                    G4VGraphicsScene&);
0274 
0275   void DescribeAndDescend (G4VPhysicalVolume*,
0276                G4int requestedDepth,
0277                G4LogicalVolume*,
0278                G4VSolid*,
0279                G4Material*,
0280                const G4Transform3D&,
0281                G4VGraphicsScene&);
0282 
0283   virtual void DescribeSolid (const G4Transform3D& theAT,
0284                   G4VSolid* pSol,
0285                   const G4VisAttributes* pVisAttribs,
0286                   G4VGraphicsScene& sceneHandler);
0287 
0288   /////////////////////////////////////////////////////////
0289   // Data members...
0290 
0291   G4VPhysicalVolume* fpTopPV;        // The physical volume.
0292   G4String           fTopPVName;     // ...of the physical volume.
0293   G4int              fTopPVCopyNo;   // ...of the physical volume.
0294   G4int              fRequestedDepth;
0295                      // Requested depth of geom. hierarchy search.
0296   G4bool             fUseFullExtent; // ...if requested.
0297   G4Transform3D      fTransform;     // Initial transform
0298   G4int              fCurrentDepth;  // Current depth of geom. hierarchy.
0299   G4VPhysicalVolume* fpCurrentPV;    // Current physical volume.
0300   G4int              fCurrentPVCopyNo; // Current copy number.
0301   G4LogicalVolume*   fpCurrentLV;    // Current logical volume.
0302   G4Material*        fpCurrentMaterial;  // Current material.
0303   G4Transform3D      fCurrentTransform;  // Current transform.
0304   std::vector<G4PhysicalVolumeNodeID> fBaseFullPVPath; // Base. May be empty.
0305   std::vector<G4PhysicalVolumeNodeID> fFullPVPath;     // Starts from base.
0306   std::vector<G4PhysicalVolumeNodeID> fDrawnPVPath;    // Omits culled volumes.
0307   G4NavigationHistory fNavigationHistory;  // Starts from top PV.
0308   mutable G4bool     fAbort;         // Abort all further traversing.
0309   mutable G4bool     fCurtailDescent;// Can be set to curtail descent.
0310   G4VSolid*          fpClippingSolid;
0311   ClippingMode       fClippingMode;
0312   G4int              fNClippers;     // No of clipping/cutting solids - only 0 or 1 allowed
0313   std::map<G4int,G4int> fMapDrawnTouchables;   // No of touchables drawn at each depth
0314   G4int              fTotalDrawnTouchables;
0315   std::map<G4int,G4int> fMapAllTouchables;   // No of all touchables at each depth
0316   G4int              fTotalAllTouchables;
0317   G4int              fMaxFullDepth;  // Including base path, i.e., from the world volume
0318 
0319 
0320 private:
0321 
0322   // Private copy constructor and assigment operator - copying and
0323   // assignment not allowed.  Keeps CodeWizard happy.
0324   G4PhysicalVolumeModel (const G4PhysicalVolumeModel&);
0325   G4PhysicalVolumeModel& operator = (const G4PhysicalVolumeModel&);
0326 };
0327 
0328 std::ostream& operator<<
0329 (std::ostream& os, const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID&);
0330 
0331 std::ostream& operator<<
0332 (std::ostream& os, const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>&);
0333 
0334 #endif