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: G4BREPSolid.hh,v 1.17 2006/10/19 15:35:36 gcosmo Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
29 | // |
---|
30 | // ---------------------------------------------------------------------- |
---|
31 | // Class G4BREPSolid |
---|
32 | // |
---|
33 | // Class description: |
---|
34 | // |
---|
35 | // Base class for generic Boundary REPresentation solid. |
---|
36 | |
---|
37 | // Authors: J.Sulkimo, P.Urban. |
---|
38 | // Revisions by: L.Broglia, G.Cosmo. |
---|
39 | // ---------------------------------------------------------------------- |
---|
40 | #ifndef __SOLID_H |
---|
41 | #define __SOLID_H |
---|
42 | |
---|
43 | #include "G4VSolid.hh" |
---|
44 | #include "G4Surface.hh" |
---|
45 | #include "G4Axis2Placement3D.hh" |
---|
46 | #include "G4PointRat.hh" |
---|
47 | #include "G4BoundingBox3D.hh" |
---|
48 | |
---|
49 | class G4Ray; |
---|
50 | |
---|
51 | class G4BREPSolid : public G4VSolid |
---|
52 | { |
---|
53 | |
---|
54 | public: // with description |
---|
55 | |
---|
56 | G4BREPSolid(const G4String& name); |
---|
57 | G4BREPSolid(const G4String&, G4Surface**, G4int); |
---|
58 | virtual ~G4BREPSolid(); |
---|
59 | // Constructors & destructor |
---|
60 | |
---|
61 | virtual void Initialize(); |
---|
62 | // Calculates the bounding box for solids and surfaces. |
---|
63 | // Converts concave planes to convex. |
---|
64 | |
---|
65 | G4bool CalculateExtent(const EAxis pAxis , |
---|
66 | const G4VoxelLimits& pVoxelLimit, |
---|
67 | const G4AffineTransform& pTransform , |
---|
68 | G4double& pMin , |
---|
69 | G4double& pMax ) const; |
---|
70 | // Calculate the minimum and maximum extent of the solid, when under the |
---|
71 | // specified transform, and within the specified limits. If the solid |
---|
72 | // is not intersected by the region, return false, else return true. |
---|
73 | |
---|
74 | virtual EInside Inside(register const G4ThreeVector& Pt) const; |
---|
75 | // Determines if the point Pt is inside, outside or on the surface |
---|
76 | // of the solid. |
---|
77 | |
---|
78 | virtual G4ThreeVector SurfaceNormal(const G4ThreeVector&) const; |
---|
79 | // Calculates the normal of the surface at a point on the surface |
---|
80 | // The sense of the normal depends on the sense of the surface. |
---|
81 | |
---|
82 | virtual G4double DistanceToIn(const G4ThreeVector&) const; |
---|
83 | // Calculates the shortest distance ("safety") from a point |
---|
84 | // outside the solid to any boundary of this solid. |
---|
85 | // Return 0 if the point is already inside. |
---|
86 | |
---|
87 | virtual G4double DistanceToIn(register const G4ThreeVector& Pt, |
---|
88 | register const G4ThreeVector& V) const; |
---|
89 | // Calculates the distance from a point Pt outside the solid |
---|
90 | // to the solid's boundary along a specified direction vector V. |
---|
91 | // Note: Intersections with boundaries less than the tolerance must |
---|
92 | // be ignored if the direction is away from the boundary. |
---|
93 | |
---|
94 | virtual G4double DistanceToOut(const G4ThreeVector&) const; |
---|
95 | // Calculates the shortest distance ("safety") from a point inside the |
---|
96 | // solid to any boundary of this solid. |
---|
97 | // Return 0 if the point is already outside. |
---|
98 | |
---|
99 | virtual G4double DistanceToOut(register const G4ThreeVector& Pt, |
---|
100 | register const G4ThreeVector& V, |
---|
101 | const G4bool calcNorm=false , |
---|
102 | G4bool *validNorm=0 , |
---|
103 | G4ThreeVector *n=0 ) const; |
---|
104 | // Calculates the distance from a point inside the solid to the solid`s |
---|
105 | // boundary along a specified direction vector. |
---|
106 | // Return 0 if the point is already outside. |
---|
107 | // Note: If the shortest distance to a boundary is less than the |
---|
108 | // tolerance, it is ignored. This allows for a point within a |
---|
109 | // tolerant boundary to leave immediately. |
---|
110 | |
---|
111 | G4Point3D Scope() const; |
---|
112 | // Utility function to determine the maximum scope of the solid |
---|
113 | // in the coordinates X, Y, Z. Returned as a G4Point3D. |
---|
114 | |
---|
115 | virtual G4String GetEntityType() const; |
---|
116 | // Returns identifier for solid type entity. |
---|
117 | // A generic BREP solid is considered a "Closed_Shell". |
---|
118 | |
---|
119 | virtual std::ostream& StreamInfo(std::ostream& os) const; |
---|
120 | // Streams solid contents to output stream. |
---|
121 | |
---|
122 | void DescribeYourselfTo (G4VGraphicsScene& scene) const; |
---|
123 | // Dispatch function which identifies the solid to the graphics scene. |
---|
124 | |
---|
125 | G4Polyhedron* CreatePolyhedron () const; |
---|
126 | G4NURBS* CreateNURBS () const; |
---|
127 | // Create a G4Polyhedron/G4NURBS/... (It is the caller's responsibility |
---|
128 | // to delete it). A null pointer means "not created". |
---|
129 | virtual G4Polyhedron* GetPolyhedron () const; |
---|
130 | // Smart access function - creates on request and stores for future |
---|
131 | // access. A null pointer means "not available". |
---|
132 | |
---|
133 | G4int Intersect(register const G4Ray&) const; |
---|
134 | // Gets the roughly calculated closest intersection point for |
---|
135 | // a b_spline and the accurate point for others. |
---|
136 | |
---|
137 | inline G4Surface* GetSurface(G4int) const; |
---|
138 | inline void Active(G4int) const; |
---|
139 | inline G4int Active() const; |
---|
140 | inline G4double GetShortestDistance() const; |
---|
141 | inline G4int GetId() const; |
---|
142 | inline void SetId(G4int); |
---|
143 | inline const G4String& GetName() const; |
---|
144 | inline void SetName(const G4String& name); |
---|
145 | inline G4int GetNumberOfFaces() const; |
---|
146 | inline G4int GetNumberOfSolids() const; |
---|
147 | inline const G4Axis2Placement3D* GetPlace() const; |
---|
148 | inline const G4BoundingBox3D* GetBBox() const; |
---|
149 | // Accessors methods. |
---|
150 | |
---|
151 | inline G4int GetCubVolStatistics() const; |
---|
152 | inline G4double GetCubVolEpsilon() const; |
---|
153 | inline void SetCubVolStatistics(G4int st); |
---|
154 | inline void SetCubVolEpsilon(G4double ep); |
---|
155 | inline G4int GetAreaStatistics() const; |
---|
156 | inline G4double GetAreaAccuracy() const; |
---|
157 | inline void SetAreaStatistics(G4int st); |
---|
158 | inline void SetAreaAccuracy(G4double ep); |
---|
159 | // Accessors methods. |
---|
160 | |
---|
161 | public: |
---|
162 | |
---|
163 | inline G4double GetCubicVolume(); |
---|
164 | // Returns an estimation of the geometrical cubic volume of the |
---|
165 | // solid. Caches the computed value once computed the first time. |
---|
166 | inline G4double GetSurfaceArea(); |
---|
167 | // Returns an estimation of the geometrical surface area of the |
---|
168 | // solid. Caches the computed value once computed the first time. |
---|
169 | |
---|
170 | inline G4double IntersectionDistance() const; |
---|
171 | inline void IntersectionDistance(G4double) const; |
---|
172 | // Gets and sets intersection distance. |
---|
173 | |
---|
174 | virtual void Reset() const; |
---|
175 | // Resets all distance attributes. |
---|
176 | |
---|
177 | public: // without description |
---|
178 | |
---|
179 | G4BREPSolid(__void__&); |
---|
180 | // Fake default constructor for usage restricted to direct object |
---|
181 | // persistency for clients requiring preallocation of memory for |
---|
182 | // persistifiable objects. |
---|
183 | |
---|
184 | protected: |
---|
185 | |
---|
186 | G4ThreeVectorList* CreateRotatedVertices(const G4AffineTransform&) const; |
---|
187 | G4bool IsConvex(); |
---|
188 | |
---|
189 | virtual void CalcBBoxes(); |
---|
190 | // Calculates the bounding boxes for the surfaces and for the solid. |
---|
191 | |
---|
192 | void CheckSurfaceNormals(); |
---|
193 | void RemoveHiddenFaces(register const G4Ray& G4Rayref, G4int) const; |
---|
194 | // Deactivates the planar faces that are on the "back" side of a solid. |
---|
195 | // B-splines are not handled by this function. Also cases where the ray |
---|
196 | // starting point is Inside the bbox of the solid are ignored as we don't |
---|
197 | // know if the starting point is Inside the actual solid except for |
---|
198 | // axis-oriented box-like solids. |
---|
199 | |
---|
200 | void TestSurfaceBBoxes(register const G4Ray&) const; |
---|
201 | // Tests the bounding-box to all surfaces in List. |
---|
202 | // For planar faces the intersection is instead evaluated. |
---|
203 | |
---|
204 | inline G4int StartInside() const; |
---|
205 | inline void StartInside(G4int si) const; |
---|
206 | |
---|
207 | inline void QuickSort( register G4Surface** SrfVec, |
---|
208 | register G4int left, register G4int right) const; |
---|
209 | |
---|
210 | protected: |
---|
211 | |
---|
212 | static G4int NumberOfSolids; |
---|
213 | static G4Ray Track; |
---|
214 | static G4double ShortestDistance; |
---|
215 | |
---|
216 | G4int Box, Convex, AxisBox, PlaneSolid; |
---|
217 | G4Axis2Placement3D* place; |
---|
218 | G4BoundingBox3D* bbox; |
---|
219 | G4double intersectionDistance; |
---|
220 | G4int active; |
---|
221 | G4int startInside; |
---|
222 | G4int nb_of_surfaces; |
---|
223 | G4Point3D intersection_point; |
---|
224 | G4Surface** SurfaceVec; |
---|
225 | G4double RealDist; |
---|
226 | G4String solidname; |
---|
227 | G4int Id; |
---|
228 | |
---|
229 | |
---|
230 | private: |
---|
231 | |
---|
232 | G4int fStatistics; |
---|
233 | G4double fCubVolEpsilon; |
---|
234 | G4double fAreaAccuracy; |
---|
235 | G4double fCubicVolume; |
---|
236 | G4double fSurfaceArea; |
---|
237 | // Statistics, error accuracy and cached value for volume and area. |
---|
238 | |
---|
239 | mutable G4Polyhedron* fpPolyhedron; |
---|
240 | |
---|
241 | G4BREPSolid(const G4BREPSolid&); |
---|
242 | G4BREPSolid& operator=(const G4BREPSolid&); |
---|
243 | // Private copy constructor and assignment operator. |
---|
244 | |
---|
245 | G4int IsBox(); |
---|
246 | G4int FinalEvaluation(register const G4Ray&, G4int =0) const; |
---|
247 | |
---|
248 | }; |
---|
249 | |
---|
250 | #include "G4BREPSolid.icc" |
---|
251 | |
---|
252 | #endif |
---|