Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VSolid.hh
Go to the documentation of this file.
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.
43//
44// Some visualization/graphics functions are also defined.
45
46// Author: Paul Kent (CERN), 30.06.1995 - Initial version
47// --------------------------------------------------------------------
48#ifndef G4VSOLID_HH
49#define G4VSOLID_HH
50
51#include "G4Types.hh"
52#include "G4String.hh"
53#include "geomdefs.hh"
54
56class G4VoxelLimits;
57
60
62class G4Polyhedron;
63class G4VisExtent;
65
66#include "G4ThreeVector.hh"
67#include <vector>
68
69using G4ThreeVectorList = std::vector<G4ThreeVector>;
71
72/**
73 * @brief G4VSolid is an abstract base class for solids, physical shapes that
74 * can be tracked through. Each solid has a name, and the constructors and
75 * destructors automatically add and subtract them from the G4SolidStore, a
76 * singleton 'master' list of available solids.
77 */
78
80{
81 public:
82
83 /**
84 * Constructor for G4VSolid. Creates a new shape, with the supplied name.
85 * No provision is made for sharing a common name amongst multiple classes.
86 * @param[in] name The solid's name.
87 */
88 G4VSolid(const G4String& name);
89
90 /**
91 * Default Destructor.
92 */
93 virtual ~G4VSolid();
94
95 /**
96 * Copy constructor and assignment operator.
97 */
98 G4VSolid(const G4VSolid& rhs);
99 G4VSolid& operator=(const G4VSolid& rhs);
100
101 /**
102 * Equality operator. Returns true only if addresses are the same.
103 */
104 inline G4bool operator==(const G4VSolid& s) const;
105
106 /**
107 * Getter/setter for the shape's name.
108 */
109 inline G4String GetName() const;
110 void SetName(const G4String& name);
111
112 /**
113 * Returns the cached geometrical tolerance.
114 */
115 inline G4double GetTolerance() const;
116
117 /**
118 * Computes the bounding limits of the solid.
119 * @param[out] pMin The minimum bounding limit point.
120 * @param[out] pMax The maximum bounding limit point.
121 */
122 virtual void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
123
124 /**
125 * Calculates the minimum and maximum extent of the solid, when under the
126 * specified transform, and within the specified limits.
127 * @param[in] pAxis The axis along which compute the extent.
128 * @param[in] pVoxelLimit The limiting space dictated by voxels.
129 * @param[in] pTransform The internal transformation applied to the solid.
130 * @param[out] pMin The minimum extent value.
131 * @param[out] pMax The maximum extent value.
132 * @returns True if the solid is intersected by the extent region.
133 */
134 virtual G4bool CalculateExtent(const EAxis pAxis,
135 const G4VoxelLimits& pVoxelLimit,
136 const G4AffineTransform& pTransform,
137 G4double& pMin, G4double& pMax) const = 0;
138
139 /**
140 * Returns the characterisation of a point at offset 'p' respect
141 * to the shape.
142 * @param[in] p The point at offset p.
143 * @returns kOutside if the point is outside the shapes boundaries
144 * plus Tolerance/2; kSurface if the point is less than
145 * Tolerance/2 from a surface; kInside otherwise.
146 */
147 virtual EInside Inside(const G4ThreeVector& p) const = 0;
148
149 /**
150 * Returns the outwards pointing unit normal of the shape for the
151 * surface closest to the point at offset 'p'.
152 * @param[in] p The point at offset p.
153 * @returns The outwards pointing unit normal.
154 */
155 virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const = 0;
156
157 /**
158 * Returns the distance along the normalised vector 'v' to the shape,
159 * from the point at offset 'p'. If there is no intersection, returns
160 * kInfinity. The first intersection resulting from 'leaving' a
161 * surface/volume is discarded. Hence, it is tolerant of points on
162 * the surface of the shape.
163 * @param[in] p The point at offset p.
164 * @param[in] v The normalised direction vector.
165 * @returns The distance to enter the shape.
166 */
168 const G4ThreeVector& v) const = 0;
169
170 /**
171 * Calculates the distance to the nearest surface of a shape from an
172 * outside point. The distance can be an underestimate.
173 * @param[in] p The point at offset p.
174 * @returns The safety distance to enter the shape.
175 */
176 virtual G4double DistanceToIn(const G4ThreeVector& p) const = 0;
177
178 /**
179 * Returns the distance along the normalised vector 'v' to the shape,
180 * from a point at an offset 'p' inside or on the surface of the shape.
181 * Intersections with surfaces, when the point is less than Tolerance/2
182 * from a surface must be ignored.
183 * @param[in] p The point at offset p.
184 * @param[in] v The normalised direction vector.
185 * @param[in] calcNorm Flag to indicate if to calculate the normal or not.
186 * @param[out] validNorm Flag set to true if the solid lies entirely
187 * behind or on the exiting surface. It is set false if the
188 * solid does not lie entirely behind or on the exiting surface.
189 * 'calcNorm' must be true, otherwise it is unused.
190 * @param[out] n The exiting outwards normal vector (undefined Magnitude).
191 * 'calcNorm' must be true, otherwise it is unused.
192 * @returns The distance to exit the shape.
193 */
195 const G4ThreeVector& v,
196 const G4bool calcNorm = false,
197 G4bool* validNorm = nullptr,
198 G4ThreeVector* n = nullptr) const = 0;
199
200 /**
201 * Calculates the distance to the nearest surface of a shape from an
202 * inside point 'p'. The distance can be an underestimate.
203 * @param[in] p The point at offset p.
204 * @returns The safety distance to exit the shape.
205 */
206 virtual G4double DistanceToOut(const G4ThreeVector& p) const = 0;
207
208 /**
209 * Dispatch method for parameterisation replication mechanism and
210 * dimension computation. Throws exception if ComputeDimensions() is
211 * called from an illegal derived class.
212 */
214 const G4int n,
215 const G4VPhysicalVolume* pRep);
216
217 /**
218 * Returns an estimation of the solid volume in internal units.
219 * This method may be overloaded by derived classes to compute the
220 * exact geometrical quantity for solids where this is possible,
221 * or anyway to cache the computed value.
222 * Note: the computed value is NOT cached.
223 */
224 virtual G4double GetCubicVolume();
225
226 /**
227 * Returns an estimation of the solid surface area in internal units.
228 * This method may be overloaded by derived classes to compute the
229 * exact geometrical quantity for solids where this is possible,
230 * or anyway to cache the computed value.
231 * Note: the computed value is NOT cached.
232 */
233 virtual G4double GetSurfaceArea();
234
235 /**
236 * Provides identification of the class of an object
237 * (required for persistency).
238 */
239 virtual G4GeometryType GetEntityType() const = 0;
240
241 /**
242 * Returns a random point located on the surface of the solid.
243 * Points returned are not necessarily uniformly distributed.
244 */
245 virtual G4ThreeVector GetPointOnSurface() const;
246
247 /**
248 * Returns the number of constituents used for construction of the solid.
249 * For non-Boolean solids the return value is one.
250 */
251 virtual G4int GetNumOfConstituents() const;
252
253 /**
254 * Returns true if the solid has only planar faces, false otherwise.
255 */
256 virtual G4bool IsFaceted() const;
257
258 /**
259 * Returns a pointer of a dynamically allocated copy of the solid.
260 * Returns a null pointer with warning in case the concrete solid does not
261 * implement this method. The caller has responsibility for ownership.
262 */
263 virtual G4VSolid* Clone() const;
264
265 /**
266 * Dumps contents of the solid to a stream.
267 */
268 virtual std::ostream& StreamInfo(std::ostream& os) const = 0;
269
270 /**
271 * Dumps contents of the solid to the standard output.
272 */
273 inline void DumpInfo() const;
274
275 // Visualization functions
276
277 /**
278 * A "double dispatch" function which identifies the solid
279 * to the graphics scene for visualization.
280 */
281 virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0;
282
283 /**
284 * Provides extent (bounding box) as possible hint to the graphics view.
285 */
286 virtual G4VisExtent GetExtent() const;
287
288 /**
289 * Creates a Polyhedron used for Visualisation. It is the caller's
290 * responsibility to delete it. A null pointer means "not created".
291 */
292 virtual G4Polyhedron* CreatePolyhedron() const;
293
294 /**
295 * Smart access function - creates on request and stores for future
296 * access. A null pointer means "not available".
297 */
298 virtual G4Polyhedron* GetPolyhedron() const;
299
300 /**
301 * If the solid is made up from a Boolean operation of two solids,
302 * it returns the number 'no' solid. If the solid is not a "Boolean",
303 * it returns a null pointer.
304 */
305 virtual const G4VSolid* GetConstituentSolid(G4int no) const;
307
308 /**
309 * If the solid is a "G4DisplacedSolid", it returns a self pointer
310 * else it returns a null pointer.
311 */
312 virtual const G4DisplacedSolid* GetDisplacedSolidPtr() const;
314
315 /**
316 * Fake default constructor for usage restricted to direct object
317 * persistency for clients requiring preallocation of memory for
318 * persistifiable objects.
319 */
320 G4VSolid(__void__&);
321
322 /**
323 * Calculates the cubic volume only based on the Inside() method.
324 * The accuracy is limited by the second argument 'epsilon' or the
325 * statistics expressed by 'nStat'.
326 * @param[in] nStat The number of points to generate for the calculation.
327 * @param[in] epsilon The accuracy value.
328 */
330
331 /**
332 * Calculates the surface area only based on the Inside() method.
333 * The accuracy is limited by the second argument 'epsilon' or the
334 * statistics expressed by 'nStat'.
335 * @param[in] nStat The number of points to generate for the calculation.
336 * @param[in] epsilon The accuracy value.
337 */
339
340 protected:
341
342 /**
343 * Calculates the maximum and minimum extents of the convex polygon
344 * 'pPolygon' along the axis 'pAxis', within the limits 'pVoxelLimit'.
345 * If the minimum is less than 'pMin', 'pMin' is set to the new minimum.
346 * If the maximum is greater than 'pMax', 'pMax' is set to the new maximum.
347 * Modifications to 'pPolygon' are made - it is left in an undefined state.
348 * @param[in,out] pPolygon The points defining the convex polygon.
349 * @param[in] pVoxelLimit The limiting space dictated by voxels.
350 * @param[in] pAxis The axis along which compute the extent.
351 * @param[out] pMin The minimum extent value.
352 * @param[out] pMax The maximum extent value.
353 */
355 const G4VoxelLimits& pVoxelLimit,
356 const EAxis pAxis,
357 G4double& pMin, G4double& pMax) const;
358
359 /**
360 * Calculates the maximum and minimum extents of the polygon described
361 * by the vertices: pSectionIndex->pSectionIndex+1->
362 * pSectionIndex+2->pSectionIndex+3->pSectionIndex
363 * in the list 'pVertices'.
364 * If the minimum is less than 'pMin', 'pMin' is set to the new minimum.
365 * If the maximum is greater than 'pMax', 'pMax' is set to the new maximum.
366 * No modifications are made to 'pVertices'.
367 * @param[in] pVertices The vertices list defining the convex polygon.
368 * @param[in] pSectionIndex The starting index for vertices.
369 * @param[in] pVoxelLimit The limiting space dictated by voxels.
370 * @param[in] pAxis The axis along which compute the extent.
371 * @param[out] pMin The minimum extent value.
372 * @param[out] pMax The maximum extent value.
373 */
374 void ClipCrossSection(G4ThreeVectorList* pVertices,
375 const G4int pSectionIndex,
376 const G4VoxelLimits& pVoxelLimit,
377 const EAxis pAxis,
378 G4double& pMin, G4double& pMax) const;
379
380 /**
381 * Calculates the maximum and minimum extents of the polygons
382 * joining the CrossSections at pSectionIndex->pSectionIndex+3 and
383 * pSectionIndex+4->pSectionIndex7
384 * in the list 'pVertices', within the boundaries of the voxel limits
385 * 'pVoxelLimit'.
386 * If the minimum is less than 'pMin', 'pMin' is set to the new minimum.
387 * If the maximum is greater than 'pMax', 'pMax' is set to the new maximum.
388 * No modifications are made to 'pVertices'.
389 * @param[in] pVertices The vertices list defining the convex polygon.
390 * @param[in] pSectionIndex The starting index for vertices.
391 * @param[in] pVoxelLimit The limiting space dictated by voxels.
392 * @param[in] pAxis The axis along which compute the extent.
393 * @param[out] pMin The minimum extent value.
394 * @param[out] pMax The maximum extent value.
395 */
397 const G4int pSectionIndex,
398 const G4VoxelLimits& pVoxelLimit,
399 const EAxis pAxis,
400 G4double& pMin, G4double& pMax) const;
401
402 /**
403 * Clips the specified convex polygon to the given limits, where
404 * the polygon is described by the vertices at (0),(1),...,(n),(0) in
405 * 'pPolygon'. If the polygon is completely clipped away, the polygon
406 * is cleared.
407 * @param[in,out] pPolygon pPolygon The points defining the convex polygon.
408 * @param[in] pVoxelLimit The limiting space dictated by voxels.
409 * @param[in] pAxis The axis along which apply the clipping.
410 */
411 void ClipPolygon(G4ThreeVectorList& pPolygon,
412 const G4VoxelLimits& pVoxelLimit,
413 const EAxis pAxis) const;
414
415 protected:
416
417 /** Cached geometrical tolerance. */
419
420 private:
421
422 /**
423 * Clips the specified convex polygon to the given limits, storing the
424 * result in 'outputPolygon'. The voxel limits must be limited in one
425 * *plane* only: this is achieved by having only X or Y or Z limits,
426 * and either the minimum or maximum limit set to -+kInfinity respectively.
427 * @param[in,out] pPolygon pPolygon The points defining the convex polygon.
428 * @param[out] outputPolygon The resulting polygon.
429 * @param[in] pVoxelLimit The limiting space dictated by voxels.
430 */
431 void ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon,
432 G4ThreeVectorList& outputPolygon,
433 const G4VoxelLimits& pVoxelLimit) const;
434
435 private:
436
437 /** The shape's name. */
438 G4String fshapeName;
439};
440
441///
442/**
443 * Streaming operator. Outputs the solid information to the given stream.
444 */
445std::ostream& operator<<(std::ostream& os, const G4VSolid& e);
446
447#include "G4VSolid.icc"
448
449#endif
std::vector< G4ThreeVector > G4ThreeVectorList
G4double epsilon(G4double density, G4double temperature)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
std::ostream & operator<<(std::ostream &os, const G4VSolid &e)
Definition G4VSolid.cc:48
std::vector< G4ThreeVector > G4ThreeVectorList
Definition G4VSolid.hh:69
G4String G4GeometryType
Definition G4VSolid.hh:70
G4AffineTransform is a class for geometric affine transformations. It supports efficient arbitrary ro...
G4DisplacedSolid is a solid that has been shifted from its original frame of reference to a new one....
G4VPVParameterisation ia an abstract base class for Parameterisation, able to compute the transformat...
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4VSolid is an abstract base class for solids, physical shapes that can be tracked through....
Definition G4VSolid.hh:80
G4String GetName() const
virtual G4VSolid * Clone() const
Definition G4VSolid.cc:417
virtual const G4VSolid * GetConstituentSolid(G4int no) const
Definition G4VSolid.cc:185
virtual ~G4VSolid()
Definition G4VSolid.cc:99
virtual std::ostream & StreamInfo(std::ostream &os) const =0
void ClipBetweenSections(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition G4VSolid.cc:470
G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const
Definition G4VSolid.cc:229
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
virtual G4VisExtent GetExtent() const
Definition G4VSolid.cc:708
virtual G4bool IsFaceted() const
Definition G4VSolid.cc:176
G4double GetTolerance() const
G4VSolid(const G4String &name)
Definition G4VSolid.cc:59
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
Definition G4VSolid.cc:136
void SetName(const G4String &name)
Definition G4VSolid.cc:126
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
virtual G4int GetNumOfConstituents() const
Definition G4VSolid.cc:167
void DumpInfo() const
G4double kCarTolerance
Definition G4VSolid.hh:418
virtual G4ThreeVector GetPointOnSurface() const
Definition G4VSolid.cc:151
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const =0
void ClipPolygon(G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
Definition G4VSolid.cc:565
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual G4Polyhedron * GetPolyhedron() const
Definition G4VSolid.cc:731
virtual void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
Definition G4VSolid.cc:691
virtual G4double DistanceToOut(const G4ThreeVector &p) const =0
virtual G4Polyhedron * CreatePolyhedron() const
Definition G4VSolid.cc:726
G4VSolid & operator=(const G4VSolid &rhs)
Definition G4VSolid.cc:108
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual const G4DisplacedSolid * GetDisplacedSolidPtr() const
Definition G4VSolid.cc:195
virtual G4double GetCubicVolume()
Definition G4VSolid.cc:214
void ClipCrossSection(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition G4VSolid.cc:440
G4bool operator==(const G4VSolid &s) const
virtual G4double GetSurfaceArea()
Definition G4VSolid.cc:275
void CalculateClippedPolygonExtent(G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition G4VSolid.cc:515
G4double EstimateSurfaceArea(G4int nStat, G4double epsilon) const
Definition G4VSolid.cc:290
virtual G4double DistanceToIn(const G4ThreeVector &p) const =0
virtual G4GeometryType GetEntityType() const =0
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67