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: G4VSolid.hh,v 1.29 2008/09/10 13:18:42 gcosmo Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // class G4VSolid |
---|
32 | // |
---|
33 | // Class description: |
---|
34 | // |
---|
35 | // Abstract base class for solids, physical shapes that can be tracked through. |
---|
36 | // Each solid has a name, and the constructors and destructors automatically |
---|
37 | // add and subtract them from the G4SolidStore, a singleton `master' List |
---|
38 | // of available solids. |
---|
39 | // |
---|
40 | // This class defines, but does not implement, functions to compute |
---|
41 | // distances to/from the shape. Functions are also defined |
---|
42 | // to check whether a point is inside the shape, to return the |
---|
43 | // surface normal of the shape at a given point, and to compute |
---|
44 | // the extent of the shape. [see descriptions below] |
---|
45 | // |
---|
46 | // Some protected/private utility functions are implemented for the |
---|
47 | // clipping of regions for the computation of a solid's extent. Note that |
---|
48 | // the clipping mechanism is presently inefficient. |
---|
49 | // |
---|
50 | // Some visualization/graphics functions are also defined. |
---|
51 | // |
---|
52 | // Member Data: |
---|
53 | // |
---|
54 | // G4String fshapeName |
---|
55 | // - Name for this solid. |
---|
56 | |
---|
57 | // History: |
---|
58 | // 12.04.00 J.Allison Implemented GetExtent() in terms of CalculateExtent() |
---|
59 | // 17.06.98 J.Apostolakis Added pure virtual function GetEntityType() |
---|
60 | // 26.07.96 P.Kent Added ComputeDimensions for replication mechanism |
---|
61 | // 27.03.96 J.Allison Methods for visualisation |
---|
62 | // 30.06.95 P.Kent Initial version, no scoping or visualisation functions |
---|
63 | // -------------------------------------------------------------------- |
---|
64 | #ifndef G4VSOLID_HH |
---|
65 | #define G4VSOLID_HH |
---|
66 | |
---|
67 | #include "G4Types.hh" |
---|
68 | #include "G4String.hh" |
---|
69 | #include "geomdefs.hh" |
---|
70 | |
---|
71 | class G4AffineTransform; |
---|
72 | class G4VoxelLimits; |
---|
73 | |
---|
74 | class G4VPVParameterisation; |
---|
75 | class G4VPhysicalVolume; |
---|
76 | |
---|
77 | class G4VGraphicsScene; |
---|
78 | class G4Polyhedron; |
---|
79 | class G4NURBS; |
---|
80 | class G4VisExtent; |
---|
81 | class G4DisplacedSolid; |
---|
82 | |
---|
83 | #include "G4ThreeVector.hh" |
---|
84 | #include <vector> |
---|
85 | |
---|
86 | typedef std::vector<G4ThreeVector> G4ThreeVectorList; |
---|
87 | typedef G4String G4GeometryType; |
---|
88 | |
---|
89 | class G4VSolid |
---|
90 | { |
---|
91 | public: // with description |
---|
92 | |
---|
93 | G4VSolid(const G4String& name); |
---|
94 | // Creates a new shape, with the supplied name. No provision is made |
---|
95 | // for sharing a common name amongst multiple classes. |
---|
96 | virtual ~G4VSolid(); |
---|
97 | // Default destructor. |
---|
98 | |
---|
99 | inline G4bool operator==( const G4VSolid& s ) const; |
---|
100 | // Return true only if addresses are the same. |
---|
101 | |
---|
102 | friend std::ostream& operator<< ( std::ostream& os, const G4VSolid& e ); |
---|
103 | // Streaming operator, using DumpInfo(). |
---|
104 | |
---|
105 | inline G4String GetName() const; |
---|
106 | // Returns the current shape's name. |
---|
107 | inline void SetName(const G4String& name); |
---|
108 | // Sets the current shape's name. |
---|
109 | |
---|
110 | inline G4double GetTolerance() const; |
---|
111 | // Returns the cached geometrical tolerance. |
---|
112 | |
---|
113 | virtual G4bool CalculateExtent(const EAxis pAxis, |
---|
114 | const G4VoxelLimits& pVoxelLimit, |
---|
115 | const G4AffineTransform& pTransform, |
---|
116 | G4double& pMin, G4double& pMax) const = 0; |
---|
117 | // Calculate the minimum and maximum extent of the solid, when under the |
---|
118 | // specified transform, and within the specified limits. If the solid |
---|
119 | // is not intersected by the region, return false, else return true. |
---|
120 | |
---|
121 | virtual EInside Inside(const G4ThreeVector& p) const = 0; |
---|
122 | // Returns kOutside if the point at offset p is outside the shapes |
---|
123 | // boundaries plus Tolerance/2, kSurface if the point is <= Tolerance/2 |
---|
124 | // from a surface, otherwise kInside. |
---|
125 | |
---|
126 | virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const = 0; |
---|
127 | // Returns the outwards pointing unit normal of the shape for the |
---|
128 | // surface closest to the point at offset p. |
---|
129 | |
---|
130 | virtual G4double DistanceToIn(const G4ThreeVector& p, |
---|
131 | const G4ThreeVector& v) const = 0; |
---|
132 | // Return the distance along the normalised vector v to the shape, |
---|
133 | // from the point at offset p. If there is no intersection, return |
---|
134 | // kInfinity. The first intersection resulting from `leaving' a |
---|
135 | // surface/volume is discarded. Hence, it is tolerant of points on |
---|
136 | // the surface of the shape. |
---|
137 | |
---|
138 | virtual G4double DistanceToIn(const G4ThreeVector& p) const = 0; |
---|
139 | // Calculate the distance to the nearest surface of a shape from an |
---|
140 | // outside point. The distance can be an underestimate. |
---|
141 | |
---|
142 | virtual G4double DistanceToOut(const G4ThreeVector& p, |
---|
143 | const G4ThreeVector& v, |
---|
144 | const G4bool calcNorm=false, |
---|
145 | G4bool *validNorm=0, |
---|
146 | G4ThreeVector *n=0) const = 0; |
---|
147 | // Return the distance along the normalised vector v to the shape, |
---|
148 | // from a point at an offset p inside or on the surface of the shape. |
---|
149 | // Intersections with surfaces, when the point is < Tolerance/2 from a |
---|
150 | // surface must be ignored. |
---|
151 | // If calcNorm==true: |
---|
152 | // validNorm set true if the solid lies entirely behind or on the |
---|
153 | // exiting surface. |
---|
154 | // n set to exiting outwards normal vector (undefined Magnitude). |
---|
155 | // validNorm set to false if the solid does not lie entirely behind |
---|
156 | // or on the exiting surface |
---|
157 | // If calcNorm==false: |
---|
158 | // validNorm and n are unused. |
---|
159 | // |
---|
160 | // Must be called as solid.DistanceToOut(p,v) or by specifying all |
---|
161 | // the parameters. |
---|
162 | |
---|
163 | virtual G4double DistanceToOut(const G4ThreeVector& p) const = 0; |
---|
164 | // Calculate the distance to the nearest surface of a shape from an |
---|
165 | // inside point. The distance can be an underestimate. |
---|
166 | |
---|
167 | |
---|
168 | virtual void ComputeDimensions(G4VPVParameterisation* p, |
---|
169 | const G4int n, |
---|
170 | const G4VPhysicalVolume* pRep); |
---|
171 | // Throw exception if ComputeDimensions called frrom an illegal |
---|
172 | // derived class. |
---|
173 | |
---|
174 | virtual G4double GetCubicVolume(); |
---|
175 | // Returns an estimation of the solid volume 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 G4double GetSurfaceArea(); |
---|
182 | // Return an estimation of the solid surface area in internal units. |
---|
183 | // This method may be overloaded by derived classes to compute the |
---|
184 | // exact geometrical quantity for solids where this is possible, |
---|
185 | // or anyway to cache the computed value. |
---|
186 | // Note: the computed value is NOT cached. |
---|
187 | |
---|
188 | virtual G4GeometryType GetEntityType() const = 0; |
---|
189 | // Provide identification of the class of an object. |
---|
190 | // (required for persistency and STEP interface) |
---|
191 | |
---|
192 | virtual G4ThreeVector GetPointOnSurface() const; |
---|
193 | // Returns a random point located on the surface of the solid. |
---|
194 | |
---|
195 | virtual std::ostream& StreamInfo(std::ostream& os) const = 0; |
---|
196 | // Dumps contents of the solid to a stream. |
---|
197 | inline void DumpInfo() const; |
---|
198 | // Dumps contents of the solid to the standard output. |
---|
199 | |
---|
200 | // Visualization functions |
---|
201 | |
---|
202 | virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0; |
---|
203 | // A "double dispatch" function which identifies the solid |
---|
204 | // to the graphics scene. |
---|
205 | virtual G4VisExtent GetExtent () const; |
---|
206 | // Provide extent (bounding box) as possible hint to the graphics view. |
---|
207 | virtual G4Polyhedron* CreatePolyhedron () const; |
---|
208 | virtual G4NURBS* CreateNURBS () const; |
---|
209 | // Create a G4Polyhedron/G4NURBS/... (It is the caller's responsibility |
---|
210 | // to delete it). A null pointer means "not created". |
---|
211 | virtual G4Polyhedron* GetPolyhedron () const; |
---|
212 | // Smart access function - creates on request and stores for future |
---|
213 | // access. A null pointer means "not available". |
---|
214 | |
---|
215 | virtual const G4VSolid* GetConstituentSolid(G4int no) const; |
---|
216 | virtual G4VSolid* GetConstituentSolid(G4int no); |
---|
217 | // If the solid is made up from a Boolean operation of two solids, |
---|
218 | // return the "no" solid. If the solid is not a "Boolean", return 0. |
---|
219 | |
---|
220 | virtual const G4DisplacedSolid* GetDisplacedSolidPtr() const; |
---|
221 | virtual G4DisplacedSolid* GetDisplacedSolidPtr(); |
---|
222 | // If the solid is a "G4DisplacedSolid", return a self pointer |
---|
223 | // else return 0. |
---|
224 | |
---|
225 | public: // without description |
---|
226 | |
---|
227 | G4VSolid(__void__&); |
---|
228 | // Fake default constructor for usage restricted to direct object |
---|
229 | // persistency for clients requiring preallocation of memory for |
---|
230 | // persistifiable objects. |
---|
231 | |
---|
232 | G4VSolid(const G4VSolid& rhs); |
---|
233 | G4VSolid& operator=(const G4VSolid& rhs); |
---|
234 | // Copy constructor and assignment operator. |
---|
235 | |
---|
236 | protected: // with description |
---|
237 | |
---|
238 | void CalculateClippedPolygonExtent(G4ThreeVectorList& pPolygon, |
---|
239 | const G4VoxelLimits& pVoxelLimit, |
---|
240 | const EAxis pAxis, |
---|
241 | G4double& pMin, G4double& pMax) const; |
---|
242 | // Calculate the maximum and minimum extents of the convex polygon |
---|
243 | // pPolygon along the axis pAxis, within the limits pVoxelLimit. |
---|
244 | // |
---|
245 | // If the minimum is <pMin pMin is set to the new minimum. |
---|
246 | // If the maximum is >pMax pMax is set to the new maximum. |
---|
247 | // |
---|
248 | // Modifications to pPolygon are made - it is left in an undefined state. |
---|
249 | |
---|
250 | void ClipCrossSection(G4ThreeVectorList* pVertices, |
---|
251 | const G4int pSectionIndex, |
---|
252 | const G4VoxelLimits& pVoxelLimit, |
---|
253 | const EAxis pAxis, |
---|
254 | G4double& pMin, G4double& pMax) const; |
---|
255 | // Calculate the maximum and minimum extents of the polygon described |
---|
256 | // by the vertices: pSectionIndex->pSectionIndex+1-> |
---|
257 | // pSectionIndex+2->pSectionIndex+3->pSectionIndex |
---|
258 | // in the List pVertices. |
---|
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 | // No modifications are made to pVertices. |
---|
264 | |
---|
265 | void ClipBetweenSections(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 polygons |
---|
271 | // joining the CrossSections at pSectionIndex->pSectionIndex+3 and |
---|
272 | // pSectionIndex+4->pSectionIndex7 |
---|
273 | // in the List pVertices, within the boundaries of the voxel limits |
---|
274 | // pVoxelLimit. |
---|
275 | // |
---|
276 | // If the minimum is <pMin pMin is set to the new minimum. |
---|
277 | // If the maximum is >pMax pMax is set to the new maximum. |
---|
278 | // |
---|
279 | // No modifications are made to pVertices. |
---|
280 | |
---|
281 | void ClipPolygon( G4ThreeVectorList& pPolygon, |
---|
282 | const G4VoxelLimits& pVoxelLimit, |
---|
283 | const EAxis pAxis ) const; |
---|
284 | // Clip the specified convex polygon to the given limits, where |
---|
285 | // the polygon is described by the vertices at (0),(1),...,(n),(0) in |
---|
286 | // pPolygon. |
---|
287 | // If the polygon is completely clipped away, the polygon is cleared. |
---|
288 | |
---|
289 | |
---|
290 | G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const; |
---|
291 | // Calculate cubic volume based on Inside() method. |
---|
292 | // Accuracy is limited by the second argument or the statistics |
---|
293 | // expressed by the first argument. |
---|
294 | |
---|
295 | G4double EstimateSurfaceArea(G4int nStat, G4double ell) const; |
---|
296 | // Calculate surface area only based on Inside() method. |
---|
297 | // Accuracy is limited by the second argument or the statistics |
---|
298 | // expressed by the first argument. |
---|
299 | |
---|
300 | protected: |
---|
301 | |
---|
302 | G4double kCarTolerance; // Cached geometrical tolerance |
---|
303 | |
---|
304 | private: |
---|
305 | |
---|
306 | void ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon, |
---|
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 | |
---|
315 | G4String fshapeName; // Name |
---|
316 | }; |
---|
317 | |
---|
318 | #include "G4VSolid.icc" |
---|
319 | |
---|
320 | #endif |
---|