| 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 frrom 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 G4VSolid* Clone() const;
190 // Returns a pointer of a dynamically allocated copy of the solid.
191 // Returns NULL pointer with warning in case the concrete solid does not
192 // implement this method. The caller has responsibility for ownership.
193
194 virtual std::ostream& StreamInfo(std::ostream& os) const = 0;
195 // Dumps contents of the solid to a stream.
196 inline void DumpInfo() const;
197 // Dumps contents of the solid to the standard output.
198
199 // Visualization functions
200
201 virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0;
202 // A "double dispatch" function which identifies the solid
203 // to the graphics scene.
204 virtual G4VisExtent GetExtent () const;
205 // Provide extent (bounding box) as possible hint to the graphics view.
206 virtual G4Polyhedron* CreatePolyhedron () const;
207 // Create a G4Polyhedron. (It is the caller's responsibility
208 // to delete it). A null pointer means "not created".
209 virtual G4Polyhedron* GetPolyhedron () const;
210 // Smart access function - creates on request and stores for future
211 // access. A null pointer means "not available".
212
213 virtual const G4VSolid* GetConstituentSolid(G4int no) const;
214 virtual G4VSolid* GetConstituentSolid(G4int no);
215 // If the solid is made up from a Boolean operation of two solids,
216 // return the "no" solid. If the solid is not a "Boolean", return 0.
217
218 virtual const G4DisplacedSolid* GetDisplacedSolidPtr() const;
219 virtual G4DisplacedSolid* GetDisplacedSolidPtr();
220 // If the solid is a "G4DisplacedSolid", return a self pointer
221 // else return 0.
222
223 public: // without description
224
225 G4VSolid(__void__&);
226 // Fake default constructor for usage restricted to direct object
227 // persistency for clients requiring preallocation of memory for
228 // persistifiable objects.
229
230 G4VSolid(const G4VSolid& rhs);
231 G4VSolid& operator=(const G4VSolid& rhs);
232 // Copy constructor and assignment operator.
233
234 G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const;
235 // Calculate cubic volume based on Inside() method.
236 // Accuracy is limited by the second argument or the statistics
237 // expressed by the first argument.
238
239 G4double EstimateSurfaceArea(G4int nStat, G4double ell) const;
240 // Calculate surface area only based on Inside() method.
241 // Accuracy is limited by the second argument or the statistics
242 // expressed by the first argument.
243
244 protected: // with description
245
246 void CalculateClippedPolygonExtent(G4ThreeVectorList& pPolygon,
247 const G4VoxelLimits& pVoxelLimit,
248 const EAxis pAxis,
249 G4double& pMin, G4double& pMax) const;
250 // Calculate the maximum and minimum extents of the convex polygon
251 // pPolygon along the axis pAxis, within the limits pVoxelLimit.
252 //
253 // If the minimum is <pMin pMin is set to the new minimum.
254 // If the maximum is >pMax pMax is set to the new maximum.
255 //
256 // Modifications to pPolygon are made - it is left in an undefined state.
257
258 void ClipCrossSection(G4ThreeVectorList* pVertices,
259 const G4int pSectionIndex,
260 const G4VoxelLimits& pVoxelLimit,
261 const EAxis pAxis,
262 G4double& pMin, G4double& pMax) const;
263 // Calculate the maximum and minimum extents of the polygon described
264 // by the vertices: pSectionIndex->pSectionIndex+1->
265 // pSectionIndex+2->pSectionIndex+3->pSectionIndex
266 // in the List pVertices.
267 //
268 // If the minimum is <pMin pMin is set to the new minimum.
269 // If the maximum is >pMax pMax is set to the new maximum.
270 //
271 // No modifications are made to pVertices.
272
273 void ClipBetweenSections(G4ThreeVectorList* pVertices,
274 const G4int pSectionIndex,
275 const G4VoxelLimits& pVoxelLimit,
276 const EAxis pAxis,
277 G4double& pMin, G4double& pMax) const;
278 // Calculate the maximum and minimum extents of the polygons
279 // joining the CrossSections at pSectionIndex->pSectionIndex+3 and
280 // pSectionIndex+4->pSectionIndex7
281 // in the List pVertices, within the boundaries of the voxel limits
282 // pVoxelLimit.
283 //
284 // If the minimum is <pMin pMin is set to the new minimum.
285 // If the maximum is >pMax pMax is set to the new maximum.
286 //
287 // No modifications are made to pVertices.
288
289 void ClipPolygon( G4ThreeVectorList& pPolygon,
290 const G4VoxelLimits& pVoxelLimit,
291 const EAxis pAxis ) const;
292 // Clip the specified convex polygon to the given limits, where
293 // the polygon is described by the vertices at (0),(1),...,(n),(0) in
294 // pPolygon.
295 // If the polygon is completely clipped away, the polygon is cleared.
296
297 protected:
298
299 G4double kCarTolerance; // Cached geometrical tolerance
300
301 private:
302
303 void ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon,
304 G4ThreeVectorList& outputPolygon,
305 const G4VoxelLimits& pVoxelLimit ) const;
306 // Clip the specified convex polygon to the given limits, storing the
307 // result in outputPolygon. The voxel limits must be limited in one
308 // *plane* only: This is achieved by having only x or y or z limits,
309 // and either the minimum or maximum limit set to -+kInfinity
310 // respectively.
311
312 G4String fshapeName; // Name
313 };
314
315 /// Output solid information to given ostream
316 std::ostream& operator<<(std::ostream& os, const G4VSolid& e);
317
318 #include "G4VSolid.icc"
319
320 #endif
321