Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 09:08:08

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 // G4UnionSolid
0027 //
0028 // Class description:
0029 //
0030 // Class for description of union of two solids.
0031 
0032 // Author: Vladimir Grichine (CERN), 12.09.1998 - Created
0033 // --------------------------------------------------------------------
0034 #ifndef G4UNIONSOLID_HH
0035 #define G4UNIONSOLID_HH
0036 
0037 #include "G4BooleanSolid.hh"
0038 #include "G4VSolid.hh"
0039 
0040 #include "G4RotationMatrix.hh"
0041 #include "G4ThreeVector.hh"
0042 #include "G4Transform3D.hh"
0043 #include "G4AffineTransform.hh"
0044 
0045 /**
0046  * @brief G4UnionSolid is a solid describing the Boolean union of two solids.
0047  */
0048 
0049 class G4UnionSolid : public G4BooleanSolid
0050 {
0051   public:
0052 
0053     /**
0054      * Constructor of a Boolean union between two solids with no
0055      * displacement.
0056      *  @param[in] pName The name of the Boolean composition.
0057      *  @param[in] pSolidA Pointer to the first reference solid.
0058      *  @param[in] pSolidB Pointer to the second solid to form the composition.
0059      */
0060     G4UnionSolid( const G4String& pName,
0061                         G4VSolid* pSolidA ,
0062                         G4VSolid* pSolidB   ) ;
0063 
0064     /**
0065      * Constructor of a Boolean union between two solids with rotation
0066      * and translation, used to transform the coordinate system of the second
0067      * solid to the coordinate system of the first solid.
0068      *  @param[in] pName The name of the Boolean composition.
0069      *  @param[in] pSolidA Pointer to the first reference solid.
0070      *  @param[in] pSolidB Pointer to the second solid to form the composition.
0071      *  @param[in] rotMatrix Pointer to the rotation vector.
0072      *  @param[in] transVector The translation vector.
0073      */
0074     G4UnionSolid( const G4String& pName,
0075                         G4VSolid* pSolidA ,
0076                         G4VSolid* pSolidB ,
0077                         G4RotationMatrix* rotMatrix,
0078                   const G4ThreeVector& transVector    ) ;
0079 
0080     /**
0081      * Constructor of a Boolean union between two solids with a
0082      * transformation that moves the second solid from its desired position
0083      * to its standard position.
0084      *  @param[in] pName The name of the Boolean composition.
0085      *  @param[in] pSolidA Pointer to the first reference solid.
0086      *  @param[in] pSolidB Pointer to the second solid to form the composition.
0087      *  @param[in] transform The composed 3D transformation.
0088      */
0089     G4UnionSolid( const G4String& pName,
0090                         G4VSolid* pSolidA ,
0091                         G4VSolid* pSolidB ,
0092                   const G4Transform3D& transform   ) ;
0093 
0094     /**
0095      * Default destructor.
0096      */
0097     ~G4UnionSolid() override = default ;
0098 
0099     /**
0100      * Fake default constructor for usage restricted to direct object
0101      * persistency for clients requiring preallocation of memory for
0102      * persistifiable objects.
0103      */
0104     G4UnionSolid(__void__&);
0105 
0106     /**
0107      * Copy constructor and assignment operator.
0108      */
0109     G4UnionSolid(const G4UnionSolid& rhs);
0110     G4UnionSolid& operator=(const G4UnionSolid& rhs);
0111 
0112     /**
0113      * Returns the type ID, "G4UnionSolid" of the solid.
0114      */
0115     G4GeometryType GetEntityType() const override ;
0116 
0117     /**
0118      * Makes a clone of the object for use in multi-treading.
0119      *  @returns A pointer to the new cloned allocated solid.
0120      */
0121     G4VSolid* Clone() const override;
0122 
0123     /**
0124      * Computes the bounding limits of the solid.
0125      *  @param[out] pMin The minimum bounding limit point.
0126      *  @param[out] pMax The maximum bounding limit point.
0127      */
0128     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0129 
0130     /**
0131      * Calculates the minimum and maximum extent of the solid, when under the
0132      * specified transform, and within the specified limits.
0133      *  @param[in] pAxis The axis along which compute the extent.
0134      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0135      *  @param[in] pTransform The internal transformation applied to the solid.
0136      *  @param[out] pMin The minimum extent value.
0137      *  @param[out] pMax The maximum extent value.
0138      *  @returns True if the solid is intersected by the extent region.
0139      */
0140     G4bool CalculateExtent( const EAxis pAxis,
0141                             const G4VoxelLimits& pVoxelLimit,
0142                             const G4AffineTransform& pTransform,
0143                                   G4double& pMin, G4double& pMax ) const override ;
0144        
0145     /**
0146      * Returns if the given point "p" is inside or not the solid.
0147      */
0148     EInside Inside( const G4ThreeVector& p ) const override ;
0149 
0150     /**
0151      * Returns the outwards pointing unit normal of the shape for the
0152      * surface closest to the point at offset "p".
0153      */
0154     G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const override ;
0155 
0156     /**
0157      * Returns the distance along the normalised vector "v" to the shape,
0158      * from the point at offset "p". If there is no intersection, return
0159      * kInfinity. The first intersection resulting from leaving a
0160      * surface/volume is discarded. Hence, it is tolerant of points on
0161      * the surface of the shape.
0162      */
0163     G4double DistanceToIn( const G4ThreeVector& p,
0164                            const G4ThreeVector& v  ) const override ;
0165 
0166     /**
0167      * Calculates the safety distance to the nearest surface of a shape from
0168      * an outside point. The distance can be an underestimate.
0169      */
0170     G4double DistanceToIn( const G4ThreeVector& p ) const override ;
0171 
0172     /**
0173      * Returns the distance along the normalised vector "v" to the shape,
0174      * from a point at an offset "p" inside or on the surface of the shape.
0175      * Intersections with surfaces, when the point is < Tolerance/2 from a
0176      * surface must be ignored. Must be called as solid.DistanceToOut(p,v)
0177      * or by specifying all the parameters.
0178      *  @param[in] p The reference point in space.
0179      *  @param[in] v The normalised direction.
0180      *  @param[in] calcNorm Flag to enable the normal computation or not.
0181      *  @param[out] validNorm Set to true if the solid lies entirely behind
0182      *              or on the exiting surface (calcNorm must be true, otherwise
0183      *              it is unused).
0184      *  @param[out] n The exiting outwards normal vector (undefined Magnitude).
0185      *              (calcNorm must be true, otherwise it is unused). 
0186      *  @returns The distance value to exit the volume.
0187      */
0188     G4double DistanceToOut( const G4ThreeVector& p,
0189                             const G4ThreeVector& v,
0190                             const G4bool calcNorm = false,
0191                                   G4bool* validNorm = nullptr,
0192                                   G4ThreeVector* n = nullptr ) const override ;
0193 
0194     /**
0195      * Calculates the safety distance to the nearest surface of a shape from
0196      * an inside point "p". The distance can be an underestimate.
0197      */
0198     G4double DistanceToOut( const G4ThreeVector& p ) const override ;
0199 
0200     /**
0201      * Throws an exception as paramterisations are not allowed for these solids.
0202      */
0203     void ComputeDimensions(       G4VPVParameterisation* p,
0204                             const G4int n,
0205                             const G4VPhysicalVolume* pRep ) override ;
0206                                    
0207     /**
0208      * Methods for creating graphical representations (i.e. for visualisation).
0209      */
0210     void DescribeYourselfTo ( G4VGraphicsScene& scene ) const override ;
0211     G4Polyhedron* CreatePolyhedron () const override ;
0212 
0213     /**
0214      * Returns an estimate of the capacity of the Boolean composition.
0215      */
0216     G4double GetCubicVolume() final;
0217 
0218   private:
0219 
0220     /**
0221      * Initialisation method used in constructors.
0222      */
0223     void Init();
0224 
0225     G4ThreeVector fPMin, fPMax; // bounding box extended by half-tolerance
0226     G4double halfCarTolerance;
0227 };
0228 
0229 #endif