Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // G4VSolid 27 // 28 // Class description: 29 // 30 // Abstract base class for solids, physical shapes that can be tracked through. 31 // Each solid has a name, and the constructors and destructors automatically 32 // add and subtract them from the G4SolidStore, a singleton `master' List 33 // of available solids. 34 // 35 // This class defines, but does not implement, functions to compute 36 // distances to/from the shape. Functions are also defined 37 // to check whether a point is inside the shape, to return the 38 // surface normal of the shape at a given point, and to compute 39 // the extent of the shape. [see descriptions below] 40 // 41 // Some protected/private utility functions are implemented for the 42 // clipping of regions for the computation of a solid's extent. Note that 43 // the clipping mechanism is presently inefficient. 44 // 45 // Some visualization/graphics functions are also defined. 46 // 47 // Member Data: 48 // 49 // G4String fshapeName 50 // - Name for this solid. 51 52 // 12.04.00 J.Allison Implemented GetExtent() in terms of CalculateExtent() 53 // 17.06.98 J.Apostolakis Added pure virtual function GetEntityType() 54 // 26.07.96 P.Kent Added ComputeDimensions() for replication mechanism 55 // 27.03.96 J.Allison Methods for visualisation 56 // 30.06.95 P.Kent Initial version, no scoping or visualisation functions 57 // -------------------------------------------------------------------- 58 #ifndef G4VSOLID_HH 59 #define G4VSOLID_HH 1 60 61 #include "G4Types.hh" 62 #include "G4String.hh" 63 #include "geomdefs.hh" 64 65 class G4AffineTransform; 66 class G4VoxelLimits; 67 68 class G4VPVParameterisation; 69 class G4VPhysicalVolume; 70 71 class G4VGraphicsScene; 72 class G4Polyhedron; 73 class G4VisExtent; 74 class G4DisplacedSolid; 75 76 #include "G4ThreeVector.hh" 77 #include <vector> 78 79 using G4ThreeVectorList = std::vector<G4ThreeVector>; 80 using G4GeometryType = G4String; 81 82 class G4VSolid 83 { 84 public: // with description 85 86 G4VSolid(const G4String& name); 87 // Creates a new shape, with the supplied name. No provision is made 88 // for sharing a common name amongst multiple classes. 89 virtual ~G4VSolid(); 90 // Default destructor. 91 92 inline G4bool operator==(const G4VSolid& s) const; 93 // Return true only if addresses are the same. 94 95 inline G4String GetName() const; 96 // Returns the current shape's name. 97 void SetName(const G4String& name); 98 // Sets the current shape's name. 99 100 inline G4double GetTolerance() const; 101 // Returns the cached geometrical tolerance. 102 103 virtual void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const; 104 // Returns the bounding box of the solid. 105 106 virtual G4bool CalculateExtent(const EAxis pAxis, 107 const G4VoxelLimits& pVoxelLimit, 108 const G4AffineTransform& pTransform, 109 G4double& pMin, G4double& pMax) const = 0; 110 // Calculate the minimum and maximum extent of the solid, when under the 111 // specified transform, and within the specified limits. If the solid 112 // is not intersected by the region, return false, else return true. 113 114 virtual EInside Inside(const G4ThreeVector& p) const = 0; 115 // Returns kOutside if the point at offset p is outside the shapes 116 // boundaries plus Tolerance/2, kSurface if the point is <= Tolerance/2 117 // from a surface, otherwise kInside. 118 119 virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const = 0; 120 // Returns the outwards pointing unit normal of the shape for the 121 // surface closest to the point at offset p. 122 123 virtual G4double DistanceToIn(const G4ThreeVector& p, 124 const G4ThreeVector& v) const = 0; 125 // Return the distance along the normalised vector v to the shape, 126 // from the point at offset p. If there is no intersection, return 127 // kInfinity. The first intersection resulting from `leaving' a 128 // surface/volume is discarded. Hence, it is tolerant of points on 129 // the surface of the shape. 130 131 virtual G4double DistanceToIn(const G4ThreeVector& p) const = 0; 132 // Calculate the distance to the nearest surface of a shape from an 133 // outside point. The distance can be an underestimate. 134 135 virtual G4double DistanceToOut(const G4ThreeVector& p, 136 const G4ThreeVector& v, 137 const G4bool calcNorm=false, 138 G4bool* validNorm = nullptr, 139 G4ThreeVector* n = nullptr) const = 0; 140 // Return the distance along the normalised vector v to the shape, 141 // from a point at an offset p inside or on the surface of the shape. 142 // Intersections with surfaces, when the point is < Tolerance/2 from a 143 // surface must be ignored. 144 // If calcNorm==true: 145 // validNorm set true if the solid lies entirely behind or on the 146 // exiting surface. 147 // n set to exiting outwards normal vector (undefined Magnitude). 148 // validNorm set to false if the solid does not lie entirely behind 149 // or on the exiting surface 150 // If calcNorm==false: 151 // validNorm and n are unused. 152 // 153 // Must be called as solid.DistanceToOut(p,v) or by specifying all 154 // the parameters. 155 156 virtual G4double DistanceToOut(const G4ThreeVector& p) const = 0; 157 // Calculate the distance to the nearest surface of a shape from an 158 // inside point. The distance can be an underestimate. 159 160 161 virtual void ComputeDimensions(G4VPVParameterisation* p, 162 const G4int n, 163 const G4VPhysicalVolume* pRep); 164 // Throw exception if ComputeDimensions called from an illegal 165 // derived class. 166 167 virtual G4double GetCubicVolume(); 168 // Returns an estimation of the solid volume in internal units. 169 // This method may be overloaded by derived classes to compute the 170 // exact geometrical quantity for solids where this is possible, 171 // or anyway to cache the computed value. 172 // Note: the computed value is NOT cached. 173 174 virtual G4double GetSurfaceArea(); 175 // Return an estimation of the solid surface area in internal units. 176 // This method may be overloaded by derived classes to compute the 177 // exact geometrical quantity for solids where this is possible, 178 // or anyway to cache the computed value. 179 // Note: the computed value is NOT cached. 180 181 virtual G4GeometryType GetEntityType() const = 0; 182 // Provide identification of the class of an object. 183 // (required for persistency and STEP interface) 184 185 virtual G4ThreeVector GetPointOnSurface() const; 186 // Returns a random point located on the surface of the solid. 187 // Points returned are not necessarily uniformly distributed. 188 189 virtual G4int GetNumOfConstituents() const; 190 // Returns the number of constituents of the solid. 191 // For non-Boolean solids the return value is one. 192 193 virtual G4bool IsFaceted() const; 194 // Returns true if the solid has only planar faces, false otherwise. 195 196 virtual G4VSolid* Clone() const; 197 // Returns a pointer of a dynamically allocated copy of the solid. 198 // Returns NULL pointer with warning in case the concrete solid does not 199 // implement this method. The caller has responsibility for ownership. 200 201 virtual std::ostream& StreamInfo(std::ostream& os) const = 0; 202 // Dumps contents of the solid to a stream. 203 inline void DumpInfo() const; 204 // Dumps contents of the solid to the standard output. 205 206 // Visualization functions 207 208 virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0; 209 // A "double dispatch" function which identifies the solid 210 // to the graphics scene. 211 virtual G4VisExtent GetExtent () const; 212 // Provide extent (bounding box) as possible hint to the graphics view. 213 virtual G4Polyhedron* CreatePolyhedron () const; 214 // Create a G4Polyhedron. (It is the caller's responsibility 215 // to delete it). A null pointer means "not created". 216 virtual G4Polyhedron* GetPolyhedron () const; 217 // Smart access function - creates on request and stores for future 218 // access. A null pointer means "not available". 219 220 virtual const G4VSolid* GetConstituentSolid(G4int no) const; 221 virtual G4VSolid* GetConstituentSolid(G4int no); 222 // If the solid is made up from a Boolean operation of two solids, 223 // return the "no" solid. If the solid is not a "Boolean", return 0. 224 225 virtual const G4DisplacedSolid* GetDisplacedSolidPtr() const; 226 virtual G4DisplacedSolid* GetDisplacedSolidPtr(); 227 // If the solid is a "G4DisplacedSolid", return a self pointer 228 // else return 0. 229 230 public: // without description 231 232 G4VSolid(__void__&); 233 // Fake default constructor for usage restricted to direct object 234 // persistency for clients requiring preallocation of memory for 235 // persistifiable objects. 236 237 G4VSolid(const G4VSolid& rhs); 238 G4VSolid& operator=(const G4VSolid& rhs); 239 // Copy constructor and assignment operator. 240 241 G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const; 242 // Calculate cubic volume based on Inside() method. 243 // Accuracy is limited by the second argument or the statistics 244 // expressed by the first argument. 245 246 G4double EstimateSurfaceArea(G4int nStat, G4double ell) const; 247 // Calculate surface area only based on Inside() method. 248 // Accuracy is limited by the second argument or the statistics 249 // expressed by the first argument. 250 251 protected: // with description 252 253 void CalculateClippedPolygonExtent(G4ThreeVectorList& pPolygon, 254 const G4VoxelLimits& pVoxelLimit, 255 const EAxis pAxis, 256 G4double& pMin, G4double& pMax) const; 257 // Calculate the maximum and minimum extents of the convex polygon 258 // pPolygon along the axis pAxis, within the limits pVoxelLimit. 259 // 260 // If the minimum is <pMin pMin is set to the new minimum. 261 // If the maximum is >pMax pMax is set to the new maximum. 262 // 263 // Modifications to pPolygon are made - it is left in an undefined state. 264 265 void ClipCrossSection(G4ThreeVectorList* pVertices, 266 const G4int pSectionIndex, 267 const G4VoxelLimits& pVoxelLimit, 268 const EAxis pAxis, 269 G4double& pMin, G4double& pMax) const; 270 // Calculate the maximum and minimum extents of the polygon described 271 // by the vertices: pSectionIndex->pSectionIndex+1-> 272 // pSectionIndex+2->pSectionIndex+3->pSectionIndex 273 // in the List pVertices. 274 // 275 // If the minimum is <pMin pMin is set to the new minimum. 276 // If the maximum is >pMax pMax is set to the new maximum. 277 // 278 // No modifications are made to pVertices. 279 280 void ClipBetweenSections(G4ThreeVectorList* pVertices, 281 const G4int pSectionIndex, 282 const G4VoxelLimits& pVoxelLimit, 283 const EAxis pAxis, 284 G4double& pMin, G4double& pMax) const; 285 // Calculate the maximum and minimum extents of the polygons 286 // joining the CrossSections at pSectionIndex->pSectionIndex+3 and 287 // pSectionIndex+4->pSectionIndex7 288 // in the List pVertices, within the boundaries of the voxel limits 289 // pVoxelLimit. 290 // 291 // If the minimum is <pMin pMin is set to the new minimum. 292 // If the maximum is >pMax pMax is set to the new maximum. 293 // 294 // No modifications are made to pVertices. 295 296 void ClipPolygon( G4ThreeVectorList& pPolygon, 297 const G4VoxelLimits& pVoxelLimit, 298 const EAxis pAxis ) const; 299 // Clip the specified convex polygon to the given limits, where 300 // the polygon is described by the vertices at (0),(1),...,(n),(0) in 301 // pPolygon. 302 // If the polygon is completely clipped away, the polygon is cleared. 303 304 protected: 305 306 G4double kCarTolerance; // Cached geometrical tolerance 307 308 private: 309 310 void ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon, 311 G4ThreeVectorList& outputPolygon, 312 const G4VoxelLimits& pVoxelLimit ) const; 313 // Clip the specified convex polygon to the given limits, storing the 314 // result in outputPolygon. The voxel limits must be limited in one 315 // *plane* only: This is achieved by having only x or y or z limits, 316 // and either the minimum or maximum limit set to -+kInfinity 317 // respectively. 318 319 G4String fshapeName; // Name 320 }; 321 322 /// Output solid information to given ostream 323 std::ostream& operator<<(std::ostream& os, const G4VSolid& e); 324 325 #include "G4VSolid.icc" 326 327 #endif 328