Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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//
27// $Id$
28//
29//
30// class G4VSolid
31//
32// Class description:
33//
34// Abstract base class for solids, physical shapes that can be tracked through.
35// Each solid has a name, and the constructors and destructors automatically
36// add and subtract them from the G4SolidStore, a singleton `master' List
37// of available solids.
38//
39// This class defines, but does not implement, functions to compute
40// distances to/from the shape. Functions are also defined
41// to check whether a point is inside the shape, to return the
42// surface normal of the shape at a given point, and to compute
43// the extent of the shape. [see descriptions below]
44//
45// Some protected/private utility functions are implemented for the
46// clipping of regions for the computation of a solid's extent. Note that
47// the clipping mechanism is presently inefficient.
48//
49// Some visualization/graphics functions are also defined.
50//
51// Member Data:
52//
53// G4String fshapeName
54// - Name for this solid.
55
56// History:
57// 12.04.00 J.Allison Implemented GetExtent() in terms of CalculateExtent()
58// 17.06.98 J.Apostolakis Added pure virtual function GetEntityType()
59// 26.07.96 P.Kent Added ComputeDimensions for replication mechanism
60// 27.03.96 J.Allison Methods for visualisation
61// 30.06.95 P.Kent Initial version, no scoping or visualisation functions
62// --------------------------------------------------------------------
63#ifndef G4VSOLID_HH
64#define G4VSOLID_HH
65
66#include "G4Types.hh"
67#include "G4String.hh"
68#include "geomdefs.hh"
69
71class G4VoxelLimits;
72
75
77class G4Polyhedron;
78class G4NURBS;
79class G4VisExtent;
81
82#include "G4ThreeVector.hh"
83#include <vector>
84
85typedef std::vector<G4ThreeVector> G4ThreeVectorList;
87
89{
90 public: // with description
91
92 G4VSolid(const G4String& name);
93 // Creates a new shape, with the supplied name. No provision is made
94 // for sharing a common name amongst multiple classes.
95 virtual ~G4VSolid();
96 // Default destructor.
97
98 inline G4bool operator==( const G4VSolid& s ) const;
99 // Return true only if addresses are the same.
100
101 friend std::ostream& operator<< ( std::ostream& os, const G4VSolid& e );
102 // Streaming operator, using DumpInfo().
103
104 inline G4String GetName() const;
105 // Returns the current shape's name.
106 inline void SetName(const G4String& name);
107 // Sets the current shape's name.
108
109 inline G4double GetTolerance() const;
110 // Returns the cached geometrical tolerance.
111
112 virtual G4bool CalculateExtent(const EAxis pAxis,
113 const G4VoxelLimits& pVoxelLimit,
114 const G4AffineTransform& pTransform,
115 G4double& pMin, G4double& pMax) const = 0;
116 // Calculate the minimum and maximum extent of the solid, when under the
117 // specified transform, and within the specified limits. If the solid
118 // is not intersected by the region, return false, else return true.
119
120 virtual EInside Inside(const G4ThreeVector& p) const = 0;
121 // Returns kOutside if the point at offset p is outside the shapes
122 // boundaries plus Tolerance/2, kSurface if the point is <= Tolerance/2
123 // from a surface, otherwise kInside.
124
125 virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const = 0;
126 // Returns the outwards pointing unit normal of the shape for the
127 // surface closest to the point at offset p.
128
130 const G4ThreeVector& v) const = 0;
131 // Return the distance along the normalised vector v to the shape,
132 // from the point at offset p. If there is no intersection, return
133 // kInfinity. The first intersection resulting from `leaving' a
134 // surface/volume is discarded. Hence, it is tolerant of points on
135 // the surface of the shape.
136
137 virtual G4double DistanceToIn(const G4ThreeVector& p) const = 0;
138 // Calculate the distance to the nearest surface of a shape from an
139 // outside point. The distance can be an underestimate.
140
142 const G4ThreeVector& v,
143 const G4bool calcNorm=false,
144 G4bool *validNorm=0,
145 G4ThreeVector *n=0) const = 0;
146 // Return the distance along the normalised vector v to the shape,
147 // from a point at an offset p inside or on the surface of the shape.
148 // Intersections with surfaces, when the point is < Tolerance/2 from a
149 // surface must be ignored.
150 // If calcNorm==true:
151 // validNorm set true if the solid lies entirely behind or on the
152 // exiting surface.
153 // n set to exiting outwards normal vector (undefined Magnitude).
154 // validNorm set to false if the solid does not lie entirely behind
155 // or on the exiting surface
156 // If calcNorm==false:
157 // validNorm and n are unused.
158 //
159 // Must be called as solid.DistanceToOut(p,v) or by specifying all
160 // the parameters.
161
162 virtual G4double DistanceToOut(const G4ThreeVector& p) const = 0;
163 // Calculate the distance to the nearest surface of a shape from an
164 // inside point. The distance can be an underestimate.
165
166
168 const G4int n,
169 const G4VPhysicalVolume* pRep);
170 // Throw exception if ComputeDimensions called frrom an illegal
171 // derived class.
172
173 virtual G4double GetCubicVolume();
174 // Returns an estimation of the solid volume in internal units.
175 // This method may be overloaded by derived classes to compute the
176 // exact geometrical quantity for solids where this is possible,
177 // or anyway to cache the computed value.
178 // Note: the computed value is NOT cached.
179
180 virtual G4double GetSurfaceArea();
181 // Return an estimation of the solid surface area in internal units.
182 // This method may be overloaded by derived classes to compute the
183 // exact geometrical quantity for solids where this is possible,
184 // or anyway to cache the computed value.
185 // Note: the computed value is NOT cached.
186
187 virtual G4GeometryType GetEntityType() const = 0;
188 // Provide identification of the class of an object.
189 // (required for persistency and STEP interface)
190
191 virtual G4ThreeVector GetPointOnSurface() const;
192 // Returns a random point located on the surface of the solid.
193 // Points returned are not necessarily uniformly distributed.
194
195 virtual G4VSolid* Clone() const;
196 // Returns a pointer of a dynamically allocated copy of the solid.
197 // Returns NULL pointer with warning in case the concrete solid does not
198 // implement this method. The caller has responsibility for ownership.
199
200 virtual std::ostream& StreamInfo(std::ostream& os) const = 0;
201 // Dumps contents of the solid to a stream.
202 inline void DumpInfo() const;
203 // Dumps contents of the solid to the standard output.
204
205 // Visualization functions
206
207 virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0;
208 // A "double dispatch" function which identifies the solid
209 // to the graphics scene.
210 virtual G4VisExtent GetExtent () const;
211 // Provide extent (bounding box) as possible hint to the graphics view.
212 virtual G4Polyhedron* CreatePolyhedron () const;
213 virtual G4NURBS* CreateNURBS () const;
214 // Create a G4Polyhedron/G4NURBS/... (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;
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;
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 protected: // with description
242
244 const G4VoxelLimits& pVoxelLimit,
245 const EAxis pAxis,
246 G4double& pMin, G4double& pMax) const;
247 // Calculate the maximum and minimum extents of the convex polygon
248 // pPolygon along the axis pAxis, within the limits pVoxelLimit.
249 //
250 // If the minimum is <pMin pMin is set to the new minimum.
251 // If the maximum is >pMax pMax is set to the new maximum.
252 //
253 // Modifications to pPolygon are made - it is left in an undefined state.
254
255 void ClipCrossSection(G4ThreeVectorList* pVertices,
256 const G4int pSectionIndex,
257 const G4VoxelLimits& pVoxelLimit,
258 const EAxis pAxis,
259 G4double& pMin, G4double& pMax) const;
260 // Calculate the maximum and minimum extents of the polygon described
261 // by the vertices: pSectionIndex->pSectionIndex+1->
262 // pSectionIndex+2->pSectionIndex+3->pSectionIndex
263 // in the List pVertices.
264 //
265 // If the minimum is <pMin pMin is set to the new minimum.
266 // If the maximum is >pMax pMax is set to the new maximum.
267 //
268 // No modifications are made to pVertices.
269
271 const G4int pSectionIndex,
272 const G4VoxelLimits& pVoxelLimit,
273 const EAxis pAxis,
274 G4double& pMin, G4double& pMax) const;
275 // Calculate the maximum and minimum extents of the polygons
276 // joining the CrossSections at pSectionIndex->pSectionIndex+3 and
277 // pSectionIndex+4->pSectionIndex7
278 // in the List pVertices, within the boundaries of the voxel limits
279 // pVoxelLimit.
280 //
281 // If the minimum is <pMin pMin is set to the new minimum.
282 // If the maximum is >pMax pMax is set to the new maximum.
283 //
284 // No modifications are made to pVertices.
285
286 void ClipPolygon( G4ThreeVectorList& pPolygon,
287 const G4VoxelLimits& pVoxelLimit,
288 const EAxis pAxis ) const;
289 // Clip the specified convex polygon to the given limits, where
290 // the polygon is described by the vertices at (0),(1),...,(n),(0) in
291 // pPolygon.
292 // If the polygon is completely clipped away, the polygon is cleared.
293
294
295 G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const;
296 // Calculate cubic volume based on Inside() method.
297 // Accuracy is limited by the second argument or the statistics
298 // expressed by the first argument.
299
300 G4double EstimateSurfaceArea(G4int nStat, G4double ell) const;
301 // Calculate surface area only based on Inside() method.
302 // Accuracy is limited by the second argument or the statistics
303 // expressed by the first argument.
304
305 protected:
306
307 G4double kCarTolerance; // Cached geometrical tolerance
308
309 private:
310
311 void ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon,
312 G4ThreeVectorList& outputPolygon,
313 const G4VoxelLimits& pVoxelLimit ) const;
314 // Clip the specified convex polygon to the given limits, storing the
315 // result in outputPolygon. The voxel limits must be limited in one
316 // *plane* only: This is achieved by having only x or y or z limits,
317 // and either the minimum or maximum limit set to -+kInfinity
318 // respectively.
319
320 G4String fshapeName; // Name
321};
322
323#include "G4VSolid.icc"
324
325#endif
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
std::vector< G4ThreeVector > G4ThreeVectorList
Definition: G4VSolid.hh:85
G4String G4GeometryType
Definition: G4VSolid.hh:86
G4double EstimateSurfaceArea(G4int nStat, G4double ell) const
Definition: G4VSolid.cc:261
G4String GetName() const
virtual G4VSolid * Clone() const
Definition: G4VSolid.cc:322
virtual const G4VSolid * GetConstituentSolid(G4int no) const
Definition: G4VSolid.cc:167
virtual ~G4VSolid()
Definition: G4VSolid.cc:101
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:376
G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const
Definition: G4VSolid.cc:203
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:619
virtual G4NURBS * CreateNURBS() const
Definition: G4VSolid.cc:642
G4double GetTolerance() const
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
Definition: G4VSolid.cc:137
void SetName(const G4String &name)
void DumpInfo() const
G4double kCarTolerance
Definition: G4VSolid.hh:307
friend std::ostream & operator<<(std::ostream &os, const G4VSolid &e)
Definition: G4VSolid.cc:128
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
virtual G4ThreeVector GetPointOnSurface() const
Definition: G4VSolid.cc:152
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const =0
void ClipPolygon(G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
Definition: G4VSolid.cc:492
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual G4Polyhedron * GetPolyhedron() const
Definition: G4VSolid.cc:647
virtual G4double DistanceToOut(const G4ThreeVector &p) const =0
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:637
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:110
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual const G4DisplacedSolid * GetDisplacedSolidPtr() const
Definition: G4VSolid.cc:173
virtual G4double GetCubicVolume()
Definition: G4VSolid.cc:188
void ClipCrossSection(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:345
G4bool operator==(const G4VSolid &s) const
virtual G4double GetSurfaceArea()
Definition: G4VSolid.cc:248
void CalculateClippedPolygonExtent(G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:425
virtual G4double DistanceToIn(const G4ThreeVector &p) const =0
virtual G4GeometryType GetEntityType() const =0
EAxis
Definition: geomdefs.hh:54
EInside
Definition: geomdefs.hh:58