ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VSolid.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VSolid.hh
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
60 
61 #include "G4Types.hh"
62 #include "G4String.hh"
63 #include "geomdefs.hh"
64 
65 class G4AffineTransform;
66 class G4VoxelLimits;
67 
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>;
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  friend std::ostream& operator<< ( std::ostream& os, const G4VSolid& e );
96  // Streaming operator, using DumpInfo().
97 
98  inline G4String GetName() const;
99  // Returns the current shape's name.
100  inline void SetName(const G4String& name);
101  // Sets the current shape's name.
102 
103  inline G4double GetTolerance() const;
104  // Returns the cached geometrical tolerance.
105 
106  virtual void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
107  // Returns the bounding box of the solid.
108 
109  virtual G4bool CalculateExtent(const EAxis pAxis,
110  const G4VoxelLimits& pVoxelLimit,
111  const G4AffineTransform& pTransform,
112  G4double& pMin, G4double& pMax) const = 0;
113  // Calculate the minimum and maximum extent of the solid, when under the
114  // specified transform, and within the specified limits. If the solid
115  // is not intersected by the region, return false, else return true.
116 
117  virtual EInside Inside(const G4ThreeVector& p) const = 0;
118  // Returns kOutside if the point at offset p is outside the shapes
119  // boundaries plus Tolerance/2, kSurface if the point is <= Tolerance/2
120  // from a surface, otherwise kInside.
121 
122  virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const = 0;
123  // Returns the outwards pointing unit normal of the shape for the
124  // surface closest to the point at offset p.
125 
126  virtual G4double DistanceToIn(const G4ThreeVector& p,
127  const G4ThreeVector& v) const = 0;
128  // Return the distance along the normalised vector v to the shape,
129  // from the point at offset p. If there is no intersection, return
130  // kInfinity. The first intersection resulting from `leaving' a
131  // surface/volume is discarded. Hence, it is tolerant of points on
132  // the surface of the shape.
133 
134  virtual G4double DistanceToIn(const G4ThreeVector& p) const = 0;
135  // Calculate the distance to the nearest surface of a shape from an
136  // outside point. The distance can be an underestimate.
137 
138  virtual G4double DistanceToOut(const G4ThreeVector& p,
139  const G4ThreeVector& v,
140  const G4bool calcNorm=false,
141  G4bool* validNorm = nullptr,
142  G4ThreeVector* n = nullptr) const = 0;
143  // Return the distance along the normalised vector v to the shape,
144  // from a point at an offset p inside or on the surface of the shape.
145  // Intersections with surfaces, when the point is < Tolerance/2 from a
146  // surface must be ignored.
147  // If calcNorm==true:
148  // validNorm set true if the solid lies entirely behind or on the
149  // exiting surface.
150  // n set to exiting outwards normal vector (undefined Magnitude).
151  // validNorm set to false if the solid does not lie entirely behind
152  // or on the exiting surface
153  // If calcNorm==false:
154  // validNorm and n are unused.
155  //
156  // Must be called as solid.DistanceToOut(p,v) or by specifying all
157  // the parameters.
158 
159  virtual G4double DistanceToOut(const G4ThreeVector& p) const = 0;
160  // Calculate the distance to the nearest surface of a shape from an
161  // inside point. The distance can be an underestimate.
162 
163 
165  const G4int n,
166  const G4VPhysicalVolume* pRep);
167  // Throw exception if ComputeDimensions called frrom an illegal
168  // derived class.
169 
170  virtual G4double GetCubicVolume();
171  // Returns an estimation of the solid volume in internal units.
172  // This method may be overloaded by derived classes to compute the
173  // exact geometrical quantity for solids where this is possible,
174  // or anyway to cache the computed value.
175  // Note: the computed value is NOT cached.
176 
177  virtual G4double GetSurfaceArea();
178  // Return an estimation of the solid surface area in internal units.
179  // This method may be overloaded by derived classes to compute the
180  // exact geometrical quantity for solids where this is possible,
181  // or anyway to cache the computed value.
182  // Note: the computed value is NOT cached.
183 
184  virtual G4GeometryType GetEntityType() const = 0;
185  // Provide identification of the class of an object.
186  // (required for persistency and STEP interface)
187 
188  virtual G4ThreeVector GetPointOnSurface() const;
189  // Returns a random point located on the surface of the solid.
190  // Points returned are not necessarily uniformly distributed.
191 
192  virtual G4VSolid* Clone() const;
193  // Returns a pointer of a dynamically allocated copy of the solid.
194  // Returns NULL pointer with warning in case the concrete solid does not
195  // implement this method. The caller has responsibility for ownership.
196 
197  virtual std::ostream& StreamInfo(std::ostream& os) const = 0;
198  // Dumps contents of the solid to a stream.
199  inline void DumpInfo() const;
200  // Dumps contents of the solid to the standard output.
201 
202  // Visualization functions
203 
204  virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0;
205  // A "double dispatch" function which identifies the solid
206  // to the graphics scene.
207  virtual G4VisExtent GetExtent () const;
208  // Provide extent (bounding box) as possible hint to the graphics view.
209  virtual G4Polyhedron* CreatePolyhedron () const;
210  // Create a G4Polyhedron. (It is the caller's responsibility
211  // to delete it). A null pointer means "not created".
212  virtual G4Polyhedron* GetPolyhedron () const;
213  // Smart access function - creates on request and stores for future
214  // access. A null pointer means "not available".
215 
216  virtual const G4VSolid* GetConstituentSolid(G4int no) const;
217  virtual G4VSolid* GetConstituentSolid(G4int no);
218  // If the solid is made up from a Boolean operation of two solids,
219  // return the "no" solid. If the solid is not a "Boolean", return 0.
220 
221  virtual const G4DisplacedSolid* GetDisplacedSolidPtr() const;
223  // If the solid is a "G4DisplacedSolid", return a self pointer
224  // else return 0.
225 
226  public: // without description
227 
228  G4VSolid(__void__&);
229  // Fake default constructor for usage restricted to direct object
230  // persistency for clients requiring preallocation of memory for
231  // persistifiable objects.
232 
233  G4VSolid(const G4VSolid& rhs);
234  G4VSolid& operator=(const G4VSolid& rhs);
235  // Copy constructor and assignment operator.
236 
238  // Calculate cubic volume based on Inside() method.
239  // Accuracy is limited by the second argument or the statistics
240  // expressed by the first argument.
241 
242  G4double EstimateSurfaceArea(G4int nStat, G4double ell) const;
243  // Calculate surface area only based on Inside() method.
244  // Accuracy is limited by the second argument or the statistics
245  // expressed by the first argument.
246 
247  protected: // with description
248 
250  const G4VoxelLimits& pVoxelLimit,
251  const EAxis pAxis,
252  G4double& pMin, G4double& pMax) const;
253  // Calculate the maximum and minimum extents of the convex polygon
254  // pPolygon along the axis pAxis, within the limits pVoxelLimit.
255  //
256  // If the minimum is <pMin pMin is set to the new minimum.
257  // If the maximum is >pMax pMax is set to the new maximum.
258  //
259  // Modifications to pPolygon are made - it is left in an undefined state.
260 
261  void ClipCrossSection(G4ThreeVectorList* pVertices,
262  const G4int pSectionIndex,
263  const G4VoxelLimits& pVoxelLimit,
264  const EAxis pAxis,
265  G4double& pMin, G4double& pMax) const;
266  // Calculate the maximum and minimum extents of the polygon described
267  // by the vertices: pSectionIndex->pSectionIndex+1->
268  // pSectionIndex+2->pSectionIndex+3->pSectionIndex
269  // in the List pVertices.
270  //
271  // If the minimum is <pMin pMin is set to the new minimum.
272  // If the maximum is >pMax pMax is set to the new maximum.
273  //
274  // No modifications are made to pVertices.
275 
276  void ClipBetweenSections(G4ThreeVectorList* pVertices,
277  const G4int pSectionIndex,
278  const G4VoxelLimits& pVoxelLimit,
279  const EAxis pAxis,
280  G4double& pMin, G4double& pMax) const;
281  // Calculate the maximum and minimum extents of the polygons
282  // joining the CrossSections at pSectionIndex->pSectionIndex+3 and
283  // pSectionIndex+4->pSectionIndex7
284  // in the List pVertices, within the boundaries of the voxel limits
285  // pVoxelLimit.
286  //
287  // If the minimum is <pMin pMin is set to the new minimum.
288  // If the maximum is >pMax pMax is set to the new maximum.
289  //
290  // No modifications are made to pVertices.
291 
292  void ClipPolygon( G4ThreeVectorList& pPolygon,
293  const G4VoxelLimits& pVoxelLimit,
294  const EAxis pAxis ) const;
295  // Clip the specified convex polygon to the given limits, where
296  // the polygon is described by the vertices at (0),(1),...,(n),(0) in
297  // pPolygon.
298  // If the polygon is completely clipped away, the polygon is cleared.
299 
300  protected:
301 
302  G4double kCarTolerance; // Cached geometrical tolerance
303 
304  private:
305 
307  G4ThreeVectorList& outputPolygon,
308  const G4VoxelLimits& pVoxelLimit ) const;
309  // Clip the specified convex polygon to the given limits, storing the
310  // result in outputPolygon. The voxel limits must be limited in one
311  // *plane* only: This is achieved by having only x or y or z limits,
312  // and either the minimum or maximum limit set to -+kInfinity
313  // respectively.
314 
316 };
317 
318 #include "G4VSolid.icc"
319 
320 #endif