Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:55

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 "G4VTouchable.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 class for handling nested parameterisations.
0128   class G4PhysicalVolumeModelTouchable: public G4VTouchable {
0129   public:
0130     G4PhysicalVolumeModelTouchable
0131     (const std::vector<G4PhysicalVolumeNodeID>& fullPVPath);
0132     const G4ThreeVector& GetTranslation(G4int depth) const;
0133     const G4RotationMatrix* GetRotation(G4int depth) const;
0134     G4VPhysicalVolume* GetVolume(G4int depth) const;
0135     G4VSolid* GetSolid(G4int depth) const;
0136     G4int GetReplicaNumber(G4int depth) const;
0137     G4int GetHistoryDepth() const {return G4int(fFullPVPath.size());}
0138   private:
0139     const std::vector<G4PhysicalVolumeNodeID>& fFullPVPath;
0140   };
0141 
0142   // Nested struct for encapsulating touchable properties
0143   struct TouchableProperties {
0144     TouchableProperties(): fpTouchablePV(nullptr), fCopyNo(0) {}
0145     G4ModelingParameters::PVNameCopyNoPath fTouchablePath;
0146     G4VPhysicalVolume*                     fpTouchablePV;
0147     G4int                                  fCopyNo;
0148     G4Transform3D                          fTouchableGlobalTransform;
0149     std::vector<G4PhysicalVolumeNodeID>    fTouchableBaseFullPVPath;
0150     std::vector<G4PhysicalVolumeNodeID>    fTouchableFullPVPath;
0151   };
0152 
0153   G4PhysicalVolumeModel
0154   (G4VPhysicalVolume* = 0,
0155    G4int requestedDepth = UNLIMITED,
0156    const G4Transform3D& modelTransformation = G4Transform3D(),
0157    const G4ModelingParameters* = 0,
0158    G4bool useFullExtent = false,
0159    const std::vector<G4PhysicalVolumeNodeID>& baseFullPVPath =
0160    std::vector<G4PhysicalVolumeNodeID>());
0161 
0162   virtual ~G4PhysicalVolumeModel ();
0163 
0164   void DescribeYourselfTo (G4VGraphicsScene&);
0165   // The main task of a model is to describe itself to the graphics scene
0166   // handler (a object which inherits G4VSceneHandler, which inherits
0167   // G4VGraphicsScene).
0168 
0169   G4String GetCurrentDescription () const;
0170   // A description which depends on the current state of the model.
0171 
0172   G4String GetCurrentTag () const;
0173   // A tag which depends on the current state of the model.
0174 
0175   G4VPhysicalVolume* GetTopPhysicalVolume () const {return fpTopPV;}
0176 
0177   G4int GetRequestedDepth () const {return fRequestedDepth;}
0178 
0179   const G4VSolid* GetClippingSolid () const
0180   {return fpClippingSolid;}
0181 
0182   G4int GetCurrentDepth() const {return fCurrentDepth;}
0183   // Current depth in geom. hierarchy.
0184 
0185   const G4Transform3D& GetTransformation() const {return fTransform;}
0186   // Initial transformation
0187 
0188   G4VPhysicalVolume* GetCurrentPV() const {return fpCurrentPV;}
0189   // Current physical volume.
0190 
0191   G4int GetCurrentPVCopyNo() const {return fCurrentPVCopyNo;}
0192   // Current copy number.
0193 
0194   G4LogicalVolume* GetCurrentLV() const {return fpCurrentLV;}
0195   // Current logical volume.
0196 
0197   G4Material* GetCurrentMaterial() const {return fpCurrentMaterial;}
0198   // Current material.
0199 
0200   const G4Transform3D& GetCurrentTransform() const {return fCurrentTransform;}
0201   // Current transform.
0202 
0203   const std::vector<G4PhysicalVolumeNodeID>& GetBaseFullPVPath() const
0204   {return fBaseFullPVPath;}
0205   // Base for this G4PhysicalVolumeModel. It can be empty, which would be the
0206   // case for the world volume. But the user may create a G4PhysicalVolumeModel
0207   // for a volume anywhere in the tree, in which case the user must provide
0208   // the transform (in the constructor) and the base path (SetBaseFullPVPath).
0209 
0210   const std::vector<G4PhysicalVolumeNodeID>& GetFullPVPath() const
0211   {return fFullPVPath;}
0212   // Vector of physical volume node identifiers for the current
0213   // touchable.  It is its path in the geometry hierarchy, similar to
0214   // the concept of "touchable history" available from the navigator
0215   // during tracking.
0216 
0217   const std::vector<G4PhysicalVolumeNodeID>& GetDrawnPVPath() const
0218   {return fDrawnPVPath;}
0219   // Path of the current drawn (non-culled) touchable in terms of
0220   // drawn (non-culled) ancestors.  It is a vector of physical volume
0221   // node identifiers corresponding to the geometry hierarchy actually
0222   // selected, i.e., with "culled" volumes NOT included.
0223 
0224   static G4ModelingParameters::PVNameCopyNoPath GetPVNameCopyNoPath
0225   (const std::vector<G4PhysicalVolumeNodeID>&);
0226   // Converts to PVNameCopyNoPath
0227 
0228   static G4String GetPVNamePathString(const std::vector<G4PhysicalVolumeNodeID>&);
0229   // Converts to path string, e.g., " World 0 Envelope 0 Shape1 0".
0230   // Note leading space character.
0231 
0232   const std::map<G4String,G4AttDef>* GetAttDefs() const;
0233   // Attribute definitions for current solid.
0234 
0235   std::vector<G4AttValue>* CreateCurrentAttValues() const;
0236   // Attribute values for current solid.  Each must refer to an
0237   // attribute definition in the above map; its name is the key.  The
0238   // user must test the validity of this pointer (it must be non-zero
0239   // and conform to the G4AttDefs, which may be checked with
0240   // G4AttCheck) and delete the list after use.  See
0241   // G4XXXStoredSceneHandler::PreAddSolid for how to access and
0242   // G4VTrajectory::ShowTrajectory for an example of the use of
0243   // G4Atts.
0244 
0245   const std::map<G4int,G4int>& GetNumberOfTouchables() const {return fNTouchables;}
0246   // Total number of touchables drawn at each depth
0247   
0248   void SetRequestedDepth (G4int requestedDepth) {
0249     fRequestedDepth = requestedDepth;
0250   }
0251 
0252   void SetClippingSolid (G4VSolid* pClippingSolid) {
0253     fpClippingSolid = pClippingSolid;
0254   }
0255 
0256   void SetClippingMode (ClippingMode mode) {
0257     fClippingMode = mode;
0258   }
0259 
0260   G4bool Validate (G4bool warn);
0261   // Validate, but allow internal changes (hence non-const function).
0262 
0263   void Abort () const {fAbort = true;}
0264   // Abort all further traversing.
0265 
0266   void CurtailDescent() const {fCurtailDescent = true;}
0267   // Curtail descent of current branch.
0268 
0269   void CalculateExtent ();
0270 
0271 protected:
0272 
0273   void VisitGeometryAndGetVisReps (G4VPhysicalVolume*,
0274                    G4int requestedDepth,
0275                    const G4Transform3D&,
0276                    G4VGraphicsScene&);
0277 
0278   void DescribeAndDescend (G4VPhysicalVolume*,
0279                G4int requestedDepth,
0280                G4LogicalVolume*,
0281                G4VSolid*,
0282                G4Material*,
0283                const G4Transform3D&,
0284                G4VGraphicsScene&);
0285 
0286   virtual void DescribeSolid (const G4Transform3D& theAT,
0287                   G4VSolid* pSol,
0288                   const G4VisAttributes* pVisAttribs,
0289                   G4VGraphicsScene& sceneHandler);
0290 
0291   /////////////////////////////////////////////////////////
0292   // Data members...
0293 
0294   G4VPhysicalVolume* fpTopPV;        // The physical volume.
0295   G4String           fTopPVName;     // ...of the physical volume.
0296   G4int              fTopPVCopyNo;   // ...of the physical volume.
0297   G4int              fRequestedDepth;
0298                      // Requested depth of geom. hierarchy search.
0299   G4bool             fUseFullExtent; // ...if requested.
0300   G4Transform3D      fTransform;     // Initial transform
0301   G4int              fCurrentDepth;  // Current depth of geom. hierarchy.
0302   G4VPhysicalVolume* fpCurrentPV;    // Current physical volume.
0303   G4int              fCurrentPVCopyNo; // Current copy number.
0304   G4LogicalVolume*   fpCurrentLV;    // Current logical volume.
0305   G4Material*        fpCurrentMaterial;  // Current material.
0306   G4Transform3D      fCurrentTransform;  // Current transform.
0307   std::vector<G4PhysicalVolumeNodeID> fBaseFullPVPath; // Base. May be empty.
0308   std::vector<G4PhysicalVolumeNodeID> fFullPVPath;     // Starts from base.
0309   std::vector<G4PhysicalVolumeNodeID> fDrawnPVPath;    // Omits culled volumes.
0310   mutable G4bool     fAbort;         // Abort all further traversing.
0311   mutable G4bool     fCurtailDescent;// Can be set to curtail descent.
0312   G4VSolid*          fpClippingSolid;
0313   ClippingMode       fClippingMode;
0314   G4int              fNClippers;     // No of clipping/cutting solids - only 0 or 1 allowed
0315   std::map<G4int,G4int> fNTouchables;   // No of touchables at each depth
0316 
0317 private:
0318 
0319   // Private copy constructor and assigment operator - copying and
0320   // assignment not allowed.  Keeps CodeWizard happy.
0321   G4PhysicalVolumeModel (const G4PhysicalVolumeModel&);
0322   G4PhysicalVolumeModel& operator = (const G4PhysicalVolumeModel&);
0323 };
0324 
0325 std::ostream& operator<<
0326 (std::ostream& os, const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID&);
0327 
0328 std::ostream& operator<<
0329 (std::ostream& os, const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>&);
0330 
0331 #endif