![]() |
|
|||
File indexing completed on 2025-09-17 08:59:50
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. Note that 0043 // the clipping mechanism is presently inefficient. 0044 // 0045 // Some visualization/graphics functions are also defined. 0046 // 0047 // Member Data: 0048 // 0049 // G4String fshapeName 0050 // - Name for this solid. 0051 0052 // 12.04.00 J.Allison Implemented GetExtent() in terms of CalculateExtent() 0053 // 17.06.98 J.Apostolakis Added pure virtual function GetEntityType() 0054 // 26.07.96 P.Kent Added ComputeDimensions() for replication mechanism 0055 // 27.03.96 J.Allison Methods for visualisation 0056 // 30.06.95 P.Kent Initial version, no scoping or visualisation functions 0057 // -------------------------------------------------------------------- 0058 #ifndef G4VSOLID_HH 0059 #define G4VSOLID_HH 1 0060 0061 #include "G4Types.hh" 0062 #include "G4String.hh" 0063 #include "geomdefs.hh" 0064 0065 class G4AffineTransform; 0066 class G4VoxelLimits; 0067 0068 class G4VPVParameterisation; 0069 class G4VPhysicalVolume; 0070 0071 class G4VGraphicsScene; 0072 class G4Polyhedron; 0073 class G4VisExtent; 0074 class G4DisplacedSolid; 0075 0076 #include "G4ThreeVector.hh" 0077 #include <vector> 0078 0079 using G4ThreeVectorList = std::vector<G4ThreeVector>; 0080 using G4GeometryType = G4String; 0081 0082 class G4VSolid 0083 { 0084 public: // with description 0085 0086 G4VSolid(const G4String& name); 0087 // Creates a new shape, with the supplied name. No provision is made 0088 // for sharing a common name amongst multiple classes. 0089 virtual ~G4VSolid(); 0090 // Default destructor. 0091 0092 inline G4bool operator==(const G4VSolid& s) const; 0093 // Return true only if addresses are the same. 0094 0095 inline G4String GetName() const; 0096 // Returns the current shape's name. 0097 void SetName(const G4String& name); 0098 // Sets the current shape's name. 0099 0100 inline G4double GetTolerance() const; 0101 // Returns the cached geometrical tolerance. 0102 0103 virtual void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const; 0104 // Returns the bounding box of the solid. 0105 0106 virtual G4bool CalculateExtent(const EAxis pAxis, 0107 const G4VoxelLimits& pVoxelLimit, 0108 const G4AffineTransform& pTransform, 0109 G4double& pMin, G4double& pMax) const = 0; 0110 // Calculate the minimum and maximum extent of the solid, when under the 0111 // specified transform, and within the specified limits. If the solid 0112 // is not intersected by the region, return false, else return true. 0113 0114 virtual EInside Inside(const G4ThreeVector& p) const = 0; 0115 // Returns kOutside if the point at offset p is outside the shapes 0116 // boundaries plus Tolerance/2, kSurface if the point is <= Tolerance/2 0117 // from a surface, otherwise kInside. 0118 0119 virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const = 0; 0120 // Returns the outwards pointing unit normal of the shape for the 0121 // surface closest to the point at offset p. 0122 0123 virtual G4double DistanceToIn(const G4ThreeVector& p, 0124 const G4ThreeVector& v) const = 0; 0125 // Return the distance along the normalised vector v to the shape, 0126 // from the point at offset p. If there is no intersection, return 0127 // kInfinity. The first intersection resulting from `leaving' a 0128 // surface/volume is discarded. Hence, it is tolerant of points on 0129 // the surface of the shape. 0130 0131 virtual G4double DistanceToIn(const G4ThreeVector& p) const = 0; 0132 // Calculate the distance to the nearest surface of a shape from an 0133 // outside point. The distance can be an underestimate. 0134 0135 virtual G4double DistanceToOut(const G4ThreeVector& p, 0136 const G4ThreeVector& v, 0137 const G4bool calcNorm=false, 0138 G4bool* validNorm = nullptr, 0139 G4ThreeVector* n = nullptr) const = 0; 0140 // Return the distance along the normalised vector v to the shape, 0141 // from a point at an offset p inside or on the surface of the shape. 0142 // Intersections with surfaces, when the point is < Tolerance/2 from a 0143 // surface must be ignored. 0144 // If calcNorm==true: 0145 // validNorm set true if the solid lies entirely behind or on the 0146 // exiting surface. 0147 // n set to exiting outwards normal vector (undefined Magnitude). 0148 // validNorm set to false if the solid does not lie entirely behind 0149 // or on the exiting surface 0150 // If calcNorm==false: 0151 // validNorm and n are unused. 0152 // 0153 // Must be called as solid.DistanceToOut(p,v) or by specifying all 0154 // the parameters. 0155 0156 virtual G4double DistanceToOut(const G4ThreeVector& p) const = 0; 0157 // Calculate the distance to the nearest surface of a shape from an 0158 // inside point. The distance can be an underestimate. 0159 0160 0161 virtual void ComputeDimensions(G4VPVParameterisation* p, 0162 const G4int n, 0163 const G4VPhysicalVolume* pRep); 0164 // Throw exception if ComputeDimensions called from an illegal 0165 // derived class. 0166 0167 virtual G4double GetCubicVolume(); 0168 // Returns an estimation of the solid volume in internal units. 0169 // This method may be overloaded by derived classes to compute the 0170 // exact geometrical quantity for solids where this is possible, 0171 // or anyway to cache the computed value. 0172 // Note: the computed value is NOT cached. 0173 0174 virtual G4double GetSurfaceArea(); 0175 // Return an estimation of the solid surface area in internal units. 0176 // This method may be overloaded by derived classes to compute the 0177 // exact geometrical quantity for solids where this is possible, 0178 // or anyway to cache the computed value. 0179 // Note: the computed value is NOT cached. 0180 0181 virtual G4GeometryType GetEntityType() const = 0; 0182 // Provide identification of the class of an object. 0183 // (required for persistency and STEP interface) 0184 0185 virtual G4ThreeVector GetPointOnSurface() const; 0186 // Returns a random point located on the surface of the solid. 0187 // Points returned are not necessarily uniformly distributed. 0188 0189 virtual G4int GetNumOfConstituents() const; 0190 // Returns the number of constituents of the solid. 0191 // For non-Boolean solids the return value is one. 0192 0193 virtual G4bool IsFaceted() const; 0194 // Returns true if the solid has only planar faces, false otherwise. 0195 0196 virtual G4VSolid* Clone() const; 0197 // Returns a pointer of a dynamically allocated copy of the solid. 0198 // Returns NULL pointer with warning in case the concrete solid does not 0199 // implement this method. The caller has responsibility for ownership. 0200 0201 virtual std::ostream& StreamInfo(std::ostream& os) const = 0; 0202 // Dumps contents of the solid to a stream. 0203 inline void DumpInfo() const; 0204 // Dumps contents of the solid to the standard output. 0205 0206 // Visualization functions 0207 0208 virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0; 0209 // A "double dispatch" function which identifies the solid 0210 // to the graphics scene. 0211 virtual G4VisExtent GetExtent () const; 0212 // Provide extent (bounding box) as possible hint to the graphics view. 0213 virtual G4Polyhedron* CreatePolyhedron () const; 0214 // Create a G4Polyhedron. (It is the caller's responsibility 0215 // to delete it). A null pointer means "not created". 0216 virtual G4Polyhedron* GetPolyhedron () const; 0217 // Smart access function - creates on request and stores for future 0218 // access. A null pointer means "not available". 0219 0220 virtual const G4VSolid* GetConstituentSolid(G4int no) const; 0221 virtual G4VSolid* GetConstituentSolid(G4int no); 0222 // If the solid is made up from a Boolean operation of two solids, 0223 // return the "no" solid. If the solid is not a "Boolean", return 0. 0224 0225 virtual const G4DisplacedSolid* GetDisplacedSolidPtr() const; 0226 virtual G4DisplacedSolid* GetDisplacedSolidPtr(); 0227 // If the solid is a "G4DisplacedSolid", return a self pointer 0228 // else return 0. 0229 0230 public: // without description 0231 0232 G4VSolid(__void__&); 0233 // Fake default constructor for usage restricted to direct object 0234 // persistency for clients requiring preallocation of memory for 0235 // persistifiable objects. 0236 0237 G4VSolid(const G4VSolid& rhs); 0238 G4VSolid& operator=(const G4VSolid& rhs); 0239 // Copy constructor and assignment operator. 0240 0241 G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const; 0242 // Calculate cubic volume based on Inside() method. 0243 // Accuracy is limited by the second argument or the statistics 0244 // expressed by the first argument. 0245 0246 G4double EstimateSurfaceArea(G4int nStat, G4double ell) const; 0247 // Calculate surface area only based on Inside() method. 0248 // Accuracy is limited by the second argument or the statistics 0249 // expressed by the first argument. 0250 0251 protected: // with description 0252 0253 void CalculateClippedPolygonExtent(G4ThreeVectorList& pPolygon, 0254 const G4VoxelLimits& pVoxelLimit, 0255 const EAxis pAxis, 0256 G4double& pMin, G4double& pMax) const; 0257 // Calculate the maximum and minimum extents of the convex polygon 0258 // pPolygon along the axis pAxis, within the limits pVoxelLimit. 0259 // 0260 // If the minimum is <pMin pMin is set to the new minimum. 0261 // If the maximum is >pMax pMax is set to the new maximum. 0262 // 0263 // Modifications to pPolygon are made - it is left in an undefined state. 0264 0265 void ClipCrossSection(G4ThreeVectorList* pVertices, 0266 const G4int pSectionIndex, 0267 const G4VoxelLimits& pVoxelLimit, 0268 const EAxis pAxis, 0269 G4double& pMin, G4double& pMax) const; 0270 // Calculate the maximum and minimum extents of the polygon described 0271 // by the vertices: pSectionIndex->pSectionIndex+1-> 0272 // pSectionIndex+2->pSectionIndex+3->pSectionIndex 0273 // in the List pVertices. 0274 // 0275 // If the minimum is <pMin pMin is set to the new minimum. 0276 // If the maximum is >pMax pMax is set to the new maximum. 0277 // 0278 // No modifications are made to pVertices. 0279 0280 void ClipBetweenSections(G4ThreeVectorList* pVertices, 0281 const G4int pSectionIndex, 0282 const G4VoxelLimits& pVoxelLimit, 0283 const EAxis pAxis, 0284 G4double& pMin, G4double& pMax) const; 0285 // Calculate the maximum and minimum extents of the polygons 0286 // joining the CrossSections at pSectionIndex->pSectionIndex+3 and 0287 // pSectionIndex+4->pSectionIndex7 0288 // in the List pVertices, within the boundaries of the voxel limits 0289 // pVoxelLimit. 0290 // 0291 // If the minimum is <pMin pMin is set to the new minimum. 0292 // If the maximum is >pMax pMax is set to the new maximum. 0293 // 0294 // No modifications are made to pVertices. 0295 0296 void ClipPolygon( G4ThreeVectorList& pPolygon, 0297 const G4VoxelLimits& pVoxelLimit, 0298 const EAxis pAxis ) const; 0299 // Clip the specified convex polygon to the given limits, where 0300 // the polygon is described by the vertices at (0),(1),...,(n),(0) in 0301 // pPolygon. 0302 // If the polygon is completely clipped away, the polygon is cleared. 0303 0304 protected: 0305 0306 G4double kCarTolerance; // Cached geometrical tolerance 0307 0308 private: 0309 0310 void ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon, 0311 G4ThreeVectorList& outputPolygon, 0312 const G4VoxelLimits& pVoxelLimit ) const; 0313 // Clip the specified convex polygon to the given limits, storing the 0314 // result in outputPolygon. The voxel limits must be limited in one 0315 // *plane* only: This is achieved by having only x or y or z limits, 0316 // and either the minimum or maximum limit set to -+kInfinity 0317 // respectively. 0318 0319 G4String fshapeName; // Name 0320 }; 0321 0322 /// Output solid information to given ostream 0323 std::ostream& operator<<(std::ostream& os, const G4VSolid& e); 0324 0325 #include "G4VSolid.icc" 0326 0327 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |