Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-20 08:30:44

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 // G4ScaledSolid
0027 //
0028 // Class description:
0029 //
0030 // A scaled solid is a solid that has been scaled in dimensions
0031 // in X, Y or Z, from its original description.
0032 
0033 // Author: Gabriele Cosmo (CERN), 27.10.2015 - Created
0034 // --------------------------------------------------------------------
0035 #ifndef G4SCALEDSOLID_HH
0036 #define G4SCALEDSOLID_HH
0037 
0038 #include "G4VSolid.hh"
0039 #include "G4ThreeVector.hh"
0040 #include "G4Transform3D.hh"
0041 #include "G4AffineTransform.hh"
0042 
0043 class G4ScaleTransform;
0044 
0045 /**
0046  * @brief G4ScaledSolid is a solid that has been scaled in dimensions
0047  * in X, Y or Z, from its original description.
0048  */
0049 
0050 class G4ScaledSolid : public G4VSolid
0051 {
0052   public:
0053 
0054     /**
0055      * Constructor of a solid with scaled transformation.
0056      *  @param[in] pName The name of the solid.
0057      *  @param[in] pSolid Pointer to the original reference solid.
0058      *  @param[in] pScale The scaling transformation.
0059      */
0060     G4ScaledSolid( const G4String& pName,
0061                          G4VSolid* pSolid ,
0062                    const G4Scale3D& pScale  );
0063 
0064     /**
0065      * The destructor, clearing the cached transformation.
0066      */
0067     ~G4ScaledSolid() override;
0068 
0069     /**
0070      * Fake default constructor for usage restricted to direct object
0071      * persistency for clients requiring preallocation of memory for
0072      * persistifiable objects.
0073      */
0074     G4ScaledSolid(__void__&);
0075 
0076     /**
0077      * Copy constructor and assignment operator.
0078      */
0079     G4ScaledSolid(const G4ScaledSolid& rhs);
0080     G4ScaledSolid& operator=(const G4ScaledSolid& rhs);
0081 
0082     /**
0083      * Returns if the given point "p" is inside or not the solid.
0084      */
0085     EInside Inside( const G4ThreeVector& p ) const override;
0086 
0087     /**
0088      * Computes the bounding limits of the solid.
0089      *  @param[out] pMin The minimum bounding limit point.
0090      *  @param[out] pMax The maximum bounding limit point.
0091      */
0092     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0093 
0094     /**
0095      * Calculates the minimum and maximum extent of the solid, when under the
0096      * specified transform, and within the specified limits.
0097      *  @param[in] pAxis The axis along which compute the extent.
0098      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0099      *  @param[in] pTransform The internal transformation applied to the solid.
0100      *  @param[out] pMin The minimum extent value.
0101      *  @param[out] pMax The maximum extent value.
0102      *  @returns True if the solid is intersected by the extent region.
0103      */
0104     G4bool CalculateExtent(const EAxis pAxis,
0105                            const G4VoxelLimits& pVoxelLimit,
0106                            const G4AffineTransform& pTransform,
0107                                  G4double& pMin, G4double& pMax) const override;
0108 
0109     /**
0110      * Returns the outwards pointing unit normal of the shape for the
0111      * surface closest to the point at offset "p".
0112      */
0113     G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const override;
0114 
0115     /**
0116      * Returns the distance along the normalised vector "v" to the shape,
0117      * from the point at offset "p". If there is no intersection, return
0118      * kInfinity. The first intersection resulting from leaving a
0119      * surface/volume is discarded. Hence, it is tolerant of points on
0120      * the surface of the shape.
0121      */
0122     G4double DistanceToIn( const G4ThreeVector& p,
0123                            const G4ThreeVector& v  ) const override;
0124 
0125     /**
0126      * Calculates the safety distance to the nearest surface of a shape from
0127      * an outside point. The distance can be an underestimate.
0128      */
0129     G4double DistanceToIn( const G4ThreeVector& p) const override;
0130 
0131     /**
0132      * Returns the distance along the normalised vector "v" to the shape,
0133      * from a point at an offset "p" inside or on the surface of the shape.
0134      * Intersections with surfaces, when the point is < Tolerance/2 from a
0135      * surface must be ignored. Must be called as solid.DistanceToOut(p,v)
0136      * or by specifying all the parameters.
0137      *  @param[in] p The reference point in space.
0138      *  @param[in] v The normalised direction.
0139      *  @param[in] calcNorm Flag to enable the normal computation or not.
0140      *  @param[out] validNorm Set to true if the solid lies entirely behind
0141      *              or on the exiting surface (calcNorm must be true, otherwise
0142      *              it is unused).
0143      *  @param[out] n The exiting outwards normal vector (undefined Magnitude).
0144      *              (calcNorm must be true, otherwise it is unused). 
0145      *  @returns The distance value to exit the volume.
0146      */
0147     G4double DistanceToOut( const G4ThreeVector& p,
0148                             const G4ThreeVector& v,
0149                             const G4bool calcNorm = false,
0150                                   G4bool* validNorm = nullptr,
0151                                   G4ThreeVector* n = nullptr ) const override;
0152 
0153     /**
0154      * Calculates the safety distance to the nearest surface of a shape from
0155      * an inside point "p". The distance can be an underestimate.
0156      */
0157     G4double DistanceToOut( const G4ThreeVector& p ) const override;
0158 
0159     /**
0160      * Throws an exception as paramterisations are not allowed for these solids.
0161      */
0162     void ComputeDimensions(       G4VPVParameterisation* p,
0163                             const G4int n,
0164                             const G4VPhysicalVolume* pRep ) override;
0165 
0166     /**
0167      * Methods returning an estimation of the solid volume (capacity) and
0168      * surface area, in internal units.
0169      */
0170     G4double GetCubicVolume() override;
0171     G4double GetSurfaceArea() override;
0172 
0173     /**
0174      * Returns a random point located on the surface of the solid.
0175      * Points returned may not necessarily be uniformly distributed.
0176      */
0177     G4ThreeVector GetPointOnSurface() const override;
0178 
0179     /**
0180      * Returns the number of constituents of the solid.
0181      * For non-Boolean solids the return value is one.
0182      */
0183     G4int GetNumOfConstituents() const override;
0184 
0185     /**
0186      * Returns true if the solid has only planar faces, false otherwise.
0187      */
0188     G4bool IsFaceted() const override;
0189 
0190     /**
0191      * Accessor and setter for the scaling transformation.
0192      */
0193     G4Scale3D GetScaleTransform() const; 
0194     void SetScaleTransform(const G4Scale3D& scale); 
0195 
0196     /**
0197      * Returns a pointer to the original not scaled  solid.
0198      */
0199     G4VSolid* GetUnscaledSolid() const;
0200 
0201     /**
0202      * Returns the type ID, "G4ScaledSolid" of the solid.
0203      */
0204     G4GeometryType  GetEntityType() const override;
0205 
0206     /**
0207      * Makes a clone of the object for use in multi-treading.
0208      *  @returns A pointer to the new cloned allocated solid.
0209      */
0210     G4VSolid* Clone() const override;
0211 
0212     /**
0213      * Streams the object contents to an output stream.
0214      */
0215     std::ostream& StreamInfo(std::ostream& os) const override;
0216 
0217     /**
0218      * Methods for creating graphical representations (i.e. for visualisation).
0219      */
0220     void DescribeYourselfTo ( G4VGraphicsScene& scene ) const override;
0221     G4Polyhedron* CreatePolyhedron () const override;
0222     G4Polyhedron* GetPolyhedron    () const override;
0223 
0224   private:
0225 
0226     G4VSolid* fPtrSolid = nullptr;
0227     G4ScaleTransform* fScale = nullptr;
0228     G4double fCubicVolume = -1.0;
0229     G4double fSurfaceArea = -1.0;
0230     mutable G4bool fRebuildPolyhedron = false;
0231     mutable G4Polyhedron* fpPolyhedron = nullptr;
0232 };
0233 
0234 #endif