Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-09 09:09:06

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 // G4DisplacedSolid
0027 //
0028 // Class description:
0029 //
0030 // A displaced solid is a solid that has been shifted from its original
0031 // frame of reference to a new one. It is meant to be used **internally only**
0032 // for simplifying the implementation of "Boolean solids". 
0033 
0034 // Author: Vladimir Grichine (CERN), 28.10.1998 - Created.
0035 // --------------------------------------------------------------------
0036 #ifndef G4DISPLACEDSOLID_HH
0037 #define G4DISPLACEDSOLID_HH
0038 
0039 #include "G4VSolid.hh"
0040 #include "G4RotationMatrix.hh"
0041 #include "G4ThreeVector.hh"
0042 #include "G4Transform3D.hh"
0043 #include "G4AffineTransform.hh"
0044 
0045 /**
0046  * @brief G4DisplacedSolid is a solid that has been shifted from its original
0047  * frame of reference to a new one. It is meant to be used **internally only**,
0048  * for simplifying the implementation of "Boolean solids".
0049  */
0050 
0051 class G4DisplacedSolid : public G4VSolid
0052 {
0053   public:
0054 
0055     /**
0056      * Constructor of a displaced solid rotation and translation vectors.
0057      *  @param[in] pName The name of the diplaced solid.
0058      *  @param[in] pSolid Pointer to the original reference solid.
0059      *  @param[in] rotMatrix Pointer to the rotation vector.
0060      *  @param[in] transVector The translation vector.
0061      */
0062     G4DisplacedSolid( const G4String& pName,
0063                             G4VSolid* pSolid ,
0064                             G4RotationMatrix* rotMatrix,
0065                       const G4ThreeVector& transVector  ) ;
0066 
0067     /**
0068      * Constructor of a displaced solid with a transformation.
0069      *  @param[in] pName The name of the displaced solid.
0070      *  @param[in] pSolid Pointer to the original reference solid.
0071      *  @param[in] transform The composed 3D transformation.
0072      */
0073     G4DisplacedSolid( const G4String& pName,
0074                             G4VSolid* pSolid ,
0075                       const G4Transform3D& transform  ) ;
0076 
0077     /**
0078      * Constructor for use in instantiating a transient instance from a
0079      * persistent one.
0080      *  @param[in] pName The name of the displaced solid.
0081      *  @param[in] pSolid Pointer to the original reference solid.
0082      *  @param[in] directTransform The internal transformation.
0083      */
0084     G4DisplacedSolid( const G4String& pName,
0085                             G4VSolid* pSolid ,
0086                       const G4AffineTransform directTransform );
0087 
0088     /**
0089      * Destructor. Deletes all cached transformations.
0090      */
0091     ~G4DisplacedSolid() override ;
0092 
0093     /**
0094      * Fake default constructor for usage restricted to direct object
0095      * persistency for clients requiring preallocation of memory for
0096      * persistifiable objects.
0097      */
0098     G4DisplacedSolid(__void__&);
0099 
0100     /**
0101      * Copy constructor and assignment operator.
0102      */
0103     G4DisplacedSolid(const G4DisplacedSolid& rhs);
0104     G4DisplacedSolid& operator=(const G4DisplacedSolid& rhs);
0105 
0106     /**
0107      * Returns if the given point "p" is inside or not the solid.
0108      */
0109     EInside Inside( const G4ThreeVector& p ) const override ; 
0110 
0111     /**
0112      * Computes the bounding limits of the solid.
0113      *  @param[out] pMin The minimum bounding limit point.
0114      *  @param[out] pMax The maximum bounding limit point.
0115      */
0116     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0117 
0118     /**
0119      * Calculates the minimum and maximum extent of the solid, when under the
0120      * specified transform, and within the specified limits.
0121      *  @param[in] pAxis The axis along which compute the extent.
0122      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0123      *  @param[in] pTransform The internal transformation applied to the solid.
0124      *  @param[out] pMin The minimum extent value.
0125      *  @param[out] pMax The maximum extent value.
0126      *  @returns True if the solid is intersected by the extent region.
0127      */
0128     G4bool CalculateExtent(const EAxis pAxis,
0129                            const G4VoxelLimits& pVoxelLimit,
0130                            const G4AffineTransform& pTransform,
0131                                  G4double& pMin, G4double& pMax) const override ;
0132 
0133     /**
0134      * Returns the outwards pointing unit normal of the shape for the
0135      * surface closest to the point at offset "p".
0136      */
0137     G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const override ;
0138 
0139     /**
0140      * Returns the distance along the normalised vector "v" to the shape,
0141      * from the point at offset "p". If there is no intersection, return
0142      * kInfinity. The first intersection resulting from leaving a
0143      * surface/volume is discarded. Hence, it is tolerant of points on
0144      * the surface of the shape.
0145      */
0146     G4double DistanceToIn( const G4ThreeVector& p,
0147                            const G4ThreeVector& v  ) const override ;
0148 
0149     /**
0150      * Calculates the safety distance to the nearest surface of a shape from
0151      * an outside point. The distance can be an underestimate.
0152      */
0153     G4double DistanceToIn( const G4ThreeVector& p) const override ;
0154 
0155     /**
0156      * Returns the distance along the normalised vector "v" to the shape,
0157      * from a point at an offset "p" inside or on the surface of the shape.
0158      * Intersections with surfaces, when the point is < Tolerance/2 from a
0159      * surface must be ignored. Must be called as solid.DistanceToOut(p,v)
0160      * or by specifying all the parameters.
0161      *  @param[in] p The reference point in space.
0162      *  @param[in] v The normalised direction.
0163      *  @param[in] calcNorm Flag to enable the normal computation or not.
0164      *  @param[out] validNorm Set to true if the solid lies entirely behind
0165      *              or on the exiting surface (calcNorm must be true, otherwise
0166      *              it is unused).
0167      *  @param[out] n The exiting outwards normal vector (undefined Magnitude).
0168      *              (calcNorm must be true, otherwise it is unused). 
0169      *  @returns The distance value to exit the volume.
0170      */
0171     G4double DistanceToOut( const G4ThreeVector& p,
0172                             const G4ThreeVector& v,
0173                             const G4bool calcNorm = false,
0174                                   G4bool* validNorm = nullptr,
0175                                   G4ThreeVector* n = nullptr ) const override ;
0176 
0177     /**
0178      * Calculates the safety distance to the nearest surface of a shape from
0179      * an inside point "p". The distance can be an underestimate.
0180      */
0181     G4double DistanceToOut( const G4ThreeVector& p ) const override ;
0182 
0183 
0184     /**
0185      * Throws an exception as paramterisations are not allowed for these solids.
0186      */
0187     void ComputeDimensions(       G4VPVParameterisation* p,
0188                             const G4int n,
0189                             const G4VPhysicalVolume* pRep ) override ;
0190 
0191     /**
0192      * Deletes cached transformations. Used in destructor.
0193      */
0194     void CleanTransformations();
0195 
0196     /**
0197      * Methods returning an estimation of the solid volume (capacity) and
0198      * surface area, in internal units.
0199      */
0200     G4double GetCubicVolume() override;
0201     G4double GetSurfaceArea() override;
0202 
0203     /**
0204      * Returns a random point located on the surface of the solid.
0205      * Points returned may not necessarily be uniformly distributed.
0206      */
0207     G4ThreeVector GetPointOnSurface() const override;
0208 
0209     /**
0210      * Returns the number of constituents of the solid.
0211      * For non-Boolean solids the return value is one.
0212      */
0213     G4int GetNumOfConstituents() const override;
0214 
0215     /**
0216      * Returns true if the solid has only planar faces, false otherwise.
0217      */
0218     G4bool IsFaceted() const override;
0219 
0220     /**
0221      * Returns the type ID, "G4DisplacedSolid" of the solid.
0222      */
0223     G4GeometryType  GetEntityType() const override;
0224 
0225     /**
0226      * Makes a clone of the object for use in multi-treading.
0227      *  @returns A pointer to the new cloned allocated solid.
0228      */
0229     G4VSolid* Clone() const override;
0230 
0231     /**
0232      * If the Solid is a "G4DisplacedSolid", return a self pointer else
0233      * return nullptr.
0234      */
0235     const G4DisplacedSolid* GetDisplacedSolidPtr() const override;
0236           G4DisplacedSolid* GetDisplacedSolidPtr() override;
0237 
0238     /**
0239      * Returns a pointer to the original not displaced solid.
0240      */
0241     G4VSolid* GetConstituentMovedSolid() const;
0242 
0243     /**
0244      * Accessor/modifier for the associated internal transformation.
0245      */
0246     G4AffineTransform GetTransform() const; 
0247     void SetTransform(G4AffineTransform& ); 
0248 
0249     /**
0250      * Accessor/modifier for the associated internal transformation, as above.
0251      */
0252     G4AffineTransform GetDirectTransform() const; 
0253     void SetDirectTransform(G4AffineTransform&); 
0254 
0255     /**
0256      * Get/Set the rotation/translation, as applied to the frame of reference.
0257      */
0258     G4RotationMatrix GetFrameRotation() const;
0259     void SetFrameRotation(const G4RotationMatrix&);
0260     G4ThreeVector GetFrameTranslation() const; 
0261     void SetFrameTranslation(const G4ThreeVector&); 
0262 
0263     /**
0264      * Get/Set the rotation/translation, as applied to the object.
0265      */
0266     G4RotationMatrix GetObjectRotation() const;
0267     void SetObjectRotation(const G4RotationMatrix&);
0268     G4ThreeVector GetObjectTranslation() const; 
0269     void SetObjectTranslation(const G4ThreeVector&); 
0270 
0271     /**
0272      * Streams the object contents to an output stream.
0273      */
0274     std::ostream& StreamInfo(std::ostream& os) const override;
0275 
0276     /**
0277      * Methods for creating graphical representations (i.e. for visualisation).
0278      */
0279     void DescribeYourselfTo ( G4VGraphicsScene& scene ) const override ;
0280     G4Polyhedron* CreatePolyhedron () const override ;
0281     G4Polyhedron* GetPolyhedron () const override ;
0282 
0283   protected:
0284 
0285     G4VSolid* fPtrSolid = nullptr;
0286     G4AffineTransform* fPtrTransform = nullptr;
0287     G4AffineTransform* fDirectTransform = nullptr;
0288     mutable G4bool fRebuildPolyhedron = false;
0289     mutable G4Polyhedron* fpPolyhedron = nullptr;
0290 };
0291 
0292 #endif