Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4VSolid.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 // G4VSolid
0027 //
0028 // Class description:
0029 //
0030 // Abstract base class for solids, physical shapes that can be tracked through.
0031 // Each solid has a name, and the constructors and destructors automatically
0032 // add and subtract them from the G4SolidStore, a singleton `master' List
0033 // of available solids.
0034 //
0035 // This class defines, but does not implement, functions to compute
0036 // distances to/from the shape. Functions are also defined
0037 // to check whether a point is inside the shape, to return the
0038 // surface normal of the shape at a given point, and to compute
0039 // the extent of the shape. [see descriptions below]
0040 //
0041 // Some protected/private utility functions are implemented for the
0042 // clipping of regions for the computation of a solid's extent.
0043 //
0044 // Some visualization/graphics functions are also defined.
0045 
0046 // Author: Paul Kent (CERN), 30.06.1995 - Initial version
0047 // --------------------------------------------------------------------
0048 #ifndef G4VSOLID_HH
0049 #define G4VSOLID_HH
0050 
0051 #include "G4Types.hh"
0052 #include "G4String.hh"
0053 #include "geomdefs.hh"
0054 
0055 class G4AffineTransform;
0056 class G4VoxelLimits;
0057 
0058 class G4VPVParameterisation;
0059 class G4VPhysicalVolume;
0060 
0061 class G4VGraphicsScene;
0062 class G4Polyhedron;
0063 class G4VisExtent;
0064 class G4DisplacedSolid;
0065 
0066 #include "G4ThreeVector.hh"
0067 #include <vector>
0068 
0069 using G4ThreeVectorList = std::vector<G4ThreeVector>;
0070 using G4GeometryType = G4String;
0071 
0072 /**
0073  * @brief G4VSolid is an abstract base class for solids, physical shapes that
0074  * can be tracked through. Each solid has a name, and the constructors and
0075  * destructors automatically add and subtract them from the G4SolidStore, a
0076  * singleton 'master' list of available solids.
0077  */
0078 
0079 class G4VSolid
0080 {
0081   public:
0082 
0083     /**
0084      * Constructor for G4VSolid. Creates a new shape, with the supplied name.
0085      * No provision is made for sharing a common name amongst multiple classes.
0086      *  @param[in] name The solid's name.
0087      */
0088     G4VSolid(const G4String& name);
0089 
0090     /**
0091      * Default Destructor.
0092      */
0093     virtual ~G4VSolid();
0094 
0095     /**
0096      * Copy constructor and assignment operator.
0097      */
0098     G4VSolid(const G4VSolid& rhs);
0099     G4VSolid& operator=(const G4VSolid& rhs);
0100 
0101     /**
0102      * Equality operator. Returns true only if addresses are the same.
0103      */
0104     inline G4bool operator==(const G4VSolid& s) const;
0105 
0106     /**
0107      * Getter/setter for the shape's name.
0108      */
0109     inline G4String GetName() const;
0110     void SetName(const G4String& name);
0111 
0112     /**
0113      * Returns the cached geometrical tolerance.
0114      */
0115     inline G4double GetTolerance() const;
0116 
0117     /**
0118      * Computes the bounding limits of the solid.
0119      *  @param[out] pMin The minimum bounding limit point.
0120      *  @param[out] pMax The maximum bounding limit point.
0121      */
0122     virtual void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
0123 
0124     /**
0125      * Calculates the minimum and maximum extent of the solid, when under the
0126      * specified transform, and within the specified limits.
0127      *  @param[in] pAxis The axis along which compute the extent.
0128      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0129      *  @param[in] pTransform The internal transformation applied to the solid.
0130      *  @param[out] pMin The minimum extent value.
0131      *  @param[out] pMax The maximum extent value.
0132      *  @returns True if the solid is intersected by the extent region.
0133      */
0134     virtual G4bool CalculateExtent(const EAxis pAxis,
0135                    const G4VoxelLimits& pVoxelLimit,
0136                    const G4AffineTransform& pTransform,
0137                    G4double& pMin, G4double& pMax) const = 0;
0138 
0139     /**
0140      * Returns the characterisation of a point at offset 'p' respect
0141      * to the shape.
0142      *  @param[in] p The point at offset p.
0143      *  @returns kOutside if the point is outside the shapes boundaries
0144      *           plus Tolerance/2; kSurface if the point is less than
0145      *           Tolerance/2 from a surface; kInside otherwise.
0146      */
0147     virtual EInside Inside(const G4ThreeVector& p) const = 0;
0148 
0149     /**
0150      * Returns the outwards pointing unit normal of the shape for the
0151      * surface closest to the point at offset 'p'.
0152      *  @param[in] p The point at offset p.
0153      *  @returns The outwards pointing unit normal.
0154      */
0155     virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const = 0;
0156 
0157     /**
0158      * Returns the distance along the normalised vector 'v' to the shape,
0159      * from the point at offset 'p'. If there is no intersection, returns
0160      * kInfinity. The first intersection resulting from 'leaving' a
0161      * surface/volume is discarded. Hence, it is tolerant of points on
0162      * the surface of the shape.
0163      *  @param[in] p The point at offset p.
0164      *  @param[in] v The normalised direction vector.
0165      *  @returns The distance to enter the shape.
0166      */
0167     virtual G4double DistanceToIn(const G4ThreeVector& p,
0168                                   const G4ThreeVector& v) const = 0;
0169 
0170     /**
0171      * Calculates the distance to the nearest surface of a shape from an
0172      * outside point. The distance can be an underestimate.
0173      *  @param[in] p The point at offset p.
0174      *  @returns The safety distance to enter the shape.
0175      */
0176     virtual G4double DistanceToIn(const G4ThreeVector& p) const = 0;
0177 
0178     /**
0179      * Returns the distance along the normalised vector 'v' to the shape,
0180      * from a point at an offset 'p' inside or on the surface of the shape.
0181      * Intersections with surfaces, when the point is less than Tolerance/2
0182      * from a surface must be ignored.
0183      *  @param[in] p The point at offset p.
0184      *  @param[in] v The normalised direction vector.
0185      *  @param[in] calcNorm Flag to indicate if to calculate the normal or not.
0186      *  @param[out] validNorm Flag set to true if the solid lies entirely
0187      *              behind or on the exiting surface. It is set false if the
0188      *              solid does not lie entirely behind or on the exiting surface.
0189      *              'calcNorm' must be true, otherwise it is unused.
0190      *  @param[out] n The exiting outwards normal vector (undefined Magnitude).
0191      *              'calcNorm' must be true, otherwise it is unused.
0192      *  @returns The distance to exit the shape.
0193      */
0194     virtual G4double DistanceToOut(const G4ThreeVector& p,
0195                    const G4ThreeVector& v,
0196                    const G4bool calcNorm = false,
0197                    G4bool* validNorm = nullptr,
0198                    G4ThreeVector* n = nullptr) const = 0;
0199 
0200     /**
0201      * Calculates the distance to the nearest surface of a shape from an
0202      * inside point 'p'. The distance can be an underestimate.
0203      *  @param[in] p The point at offset p.
0204      *  @returns The safety distance to exit the shape.
0205      */
0206     virtual G4double DistanceToOut(const G4ThreeVector& p) const = 0;
0207 
0208     /**
0209      * Dispatch method for parameterisation replication mechanism and
0210      * dimension computation. Throws exception if ComputeDimensions() is
0211      * called from an illegal derived class.
0212      */
0213     virtual void ComputeDimensions(G4VPVParameterisation* p,
0214                                const G4int n,
0215                                    const G4VPhysicalVolume* pRep);
0216 
0217     /**
0218      * Returns an estimation of the solid volume in internal units.
0219      * This method may be overloaded by derived classes to compute the
0220      * exact geometrical quantity for solids where this is possible,
0221      * or anyway to cache the computed value.
0222      * Note: the computed value is NOT cached.
0223      */
0224     virtual G4double GetCubicVolume();
0225 
0226     /**
0227      * Returns an estimation of the solid surface area in internal units.
0228      * This method may be overloaded by derived classes to compute the
0229      * exact geometrical quantity for solids where this is possible,
0230      * or anyway to cache the computed value.
0231      * Note: the computed value is NOT cached.
0232      */
0233     virtual G4double GetSurfaceArea();
0234 
0235     /**
0236      * Provides identification of the class of an object
0237      * (required for persistency).
0238      */
0239     virtual G4GeometryType GetEntityType() const = 0;
0240 
0241     /**
0242      * Returns a random point located on the surface of the solid.
0243      * Points returned are not necessarily uniformly distributed.
0244      */
0245     virtual G4ThreeVector GetPointOnSurface() const;
0246 
0247     /**
0248      * Returns the number of constituents used for construction of the solid.
0249      * For non-Boolean solids the return value is one.
0250      */
0251     virtual G4int GetNumOfConstituents() const;
0252 
0253     /**
0254      * Returns true if the solid has only planar faces, false otherwise.
0255      */
0256     virtual G4bool IsFaceted() const;
0257 
0258     /**
0259      * Returns a pointer of a dynamically allocated copy of the solid.
0260      * Returns a null pointer with warning in case the concrete solid does not
0261      * implement this method. The caller has responsibility for ownership.
0262      */
0263     virtual G4VSolid* Clone() const;
0264 
0265     /**
0266      * Dumps contents of the solid to a stream.
0267      */
0268     virtual std::ostream& StreamInfo(std::ostream& os) const = 0;
0269 
0270     /**
0271      * Dumps contents of the solid to the standard output.
0272      */
0273     inline void DumpInfo() const;
0274 
0275     // Visualization functions
0276 
0277     /**
0278      * A "double dispatch" function which identifies the solid
0279      * to the graphics scene for visualization.
0280      */
0281     virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0;
0282 
0283     /**
0284      * Provides extent (bounding box) as possible hint to the graphics view.
0285      */
0286     virtual G4VisExtent GetExtent() const;
0287 
0288     /**
0289      * Creates a Polyhedron used for Visualisation. It is the caller's
0290      * responsibility to delete it. A null pointer means "not created".
0291      */
0292     virtual G4Polyhedron* CreatePolyhedron() const;
0293 
0294     /**
0295      * Smart access function - creates on request and stores for future
0296      * access. A null pointer means "not available".
0297      */
0298     virtual G4Polyhedron* GetPolyhedron() const;
0299 
0300     /**
0301      * If the solid is made up from a Boolean operation of two solids,
0302      * it returns the number 'no' solid. If the solid is not a "Boolean",
0303      * it returns a null pointer.
0304      */
0305     virtual const G4VSolid* GetConstituentSolid(G4int no) const;
0306     virtual G4VSolid* GetConstituentSolid(G4int no);
0307 
0308     /**
0309      * If the solid is a "G4DisplacedSolid", it returns a self pointer
0310      * else it returns a null pointer.
0311      */
0312     virtual const G4DisplacedSolid* GetDisplacedSolidPtr() const;
0313     virtual G4DisplacedSolid* GetDisplacedSolidPtr();
0314 
0315     /**
0316      * Fake default constructor for usage restricted to direct object
0317      * persistency for clients requiring preallocation of memory for
0318      * persistifiable objects.
0319      */
0320     G4VSolid(__void__&);
0321 
0322     /**
0323      * Calculates the cubic volume only based on the Inside() method.
0324      * The accuracy is limited by the second argument 'epsilon' or the
0325      * statistics expressed by 'nStat'.
0326      *  @param[in] nStat The number of points to generate for the calculation.
0327      *  @param[in] epsilon The accuracy value.
0328      */
0329     G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const;
0330 
0331     /**
0332      * Calculates the surface area only based on the Inside() method.
0333      * The accuracy is limited by the second argument 'epsilon' or the
0334      * statistics expressed by 'nStat'.
0335      *  @param[in] nStat The number of points to generate for the calculation.
0336      *  @param[in] epsilon The accuracy value.
0337      */
0338     G4double EstimateSurfaceArea(G4int nStat, G4double epsilon) const;
0339 
0340   protected:
0341 
0342     /**
0343      * Calculates the maximum and minimum extents of the convex polygon
0344      * 'pPolygon' along the axis 'pAxis', within the limits 'pVoxelLimit'.
0345      * If the minimum is less than 'pMin', 'pMin' is set to the new minimum.
0346      * If the maximum is greater than 'pMax', 'pMax' is set to the new maximum.
0347      * Modifications to 'pPolygon' are made - it is left in an undefined state.
0348      *  @param[in,out] pPolygon The points defining the convex polygon.
0349      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0350      *  @param[in] pAxis The axis along which compute the extent.
0351      *  @param[out] pMin The minimum extent value.
0352      *  @param[out] pMax The maximum extent value.
0353      */
0354     void CalculateClippedPolygonExtent(G4ThreeVectorList& pPolygon,
0355                        const G4VoxelLimits& pVoxelLimit,
0356                        const EAxis pAxis,
0357                        G4double& pMin, G4double& pMax) const;
0358 
0359     /**
0360      * Calculates the maximum and minimum extents of the polygon described
0361      * by the vertices: pSectionIndex->pSectionIndex+1->
0362      *                  pSectionIndex+2->pSectionIndex+3->pSectionIndex
0363      * in the list 'pVertices'.
0364      * If the minimum is less than 'pMin', 'pMin' is set to the new minimum.
0365      * If the maximum is greater than 'pMax', 'pMax' is set to the new maximum.
0366      * No modifications are made to 'pVertices'.
0367      *  @param[in] pVertices The vertices list defining the convex polygon.
0368      *  @param[in] pSectionIndex The starting index for vertices.
0369      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0370      *  @param[in] pAxis The axis along which compute the extent.
0371      *  @param[out] pMin The minimum extent value.
0372      *  @param[out] pMax The maximum extent value.
0373      */
0374     void ClipCrossSection(G4ThreeVectorList* pVertices,
0375               const G4int pSectionIndex,
0376               const G4VoxelLimits& pVoxelLimit,
0377               const EAxis pAxis,
0378               G4double& pMin, G4double& pMax) const;
0379 
0380     /**
0381      * Calculates the maximum and minimum extents of the polygons
0382      * joining the CrossSections at pSectionIndex->pSectionIndex+3 and
0383      *                              pSectionIndex+4->pSectionIndex7
0384      * in the list 'pVertices', within the boundaries of the voxel limits
0385      * 'pVoxelLimit'.
0386      * If the minimum is less than 'pMin', 'pMin' is set to the new minimum.
0387      * If the maximum is greater than 'pMax', 'pMax' is set to the new maximum.
0388      * No modifications are made to 'pVertices'.
0389      *  @param[in] pVertices The vertices list defining the convex polygon.
0390      *  @param[in] pSectionIndex The starting index for vertices.
0391      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0392      *  @param[in] pAxis The axis along which compute the extent.
0393      *  @param[out] pMin The minimum extent value.
0394      *  @param[out] pMax The maximum extent value.
0395      */
0396     void ClipBetweenSections(G4ThreeVectorList* pVertices,
0397                  const G4int pSectionIndex,
0398                  const G4VoxelLimits& pVoxelLimit,
0399                  const EAxis pAxis,
0400                  G4double& pMin, G4double& pMax) const;
0401 
0402     /**
0403      * Clips the specified convex polygon to the given limits, where
0404      * the polygon is described by the vertices at (0),(1),...,(n),(0) in
0405      * 'pPolygon'. If the polygon is completely clipped away, the polygon
0406      * is cleared.
0407      *  @param[in,out] pPolygon pPolygon The points defining the convex polygon.
0408      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0409      *  @param[in] pAxis The axis along which apply the clipping.
0410      */
0411     void ClipPolygon(G4ThreeVectorList& pPolygon,
0412              const G4VoxelLimits& pVoxelLimit,
0413                      const EAxis pAxis) const;
0414 
0415   protected:
0416 
0417     /** Cached geometrical tolerance. */
0418     G4double kCarTolerance;
0419 
0420   private:
0421 
0422     /**
0423      * Clips the specified convex polygon to the given limits, storing the
0424      * result in 'outputPolygon'. The voxel limits must be limited in one
0425      * *plane* only: this is achieved by having only X or Y or Z limits,
0426      * and either the minimum or maximum limit set to -+kInfinity respectively.
0427      *  @param[in,out] pPolygon pPolygon The points defining the convex polygon.
0428      *  @param[out] outputPolygon The resulting polygon.
0429      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0430      */
0431     void ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon,
0432                    G4ThreeVectorList& outputPolygon,
0433                  const G4VoxelLimits& pVoxelLimit) const;
0434 
0435   private:
0436 
0437     /** The shape's name. */
0438     G4String fshapeName;
0439 };
0440 
0441 /// 
0442 /**
0443  * Streaming operator. Outputs the solid information to the given stream.
0444  */
0445 std::ostream& operator<<(std::ostream& os, const G4VSolid& e);
0446 
0447 #include "G4VSolid.icc"
0448 
0449 #endif