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: G4PolyPhiFace.hh,v 1.12 2008/05/15 11:41:58 gcosmo Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // -------------------------------------------------------------------- |
---|
32 | // GEANT 4 class header file |
---|
33 | // |
---|
34 | // |
---|
35 | // G4PolyPhiFace |
---|
36 | // |
---|
37 | // Class description: |
---|
38 | // |
---|
39 | // Definition of a face that bounds a polycone or polyhedra when |
---|
40 | // it has a phi opening: |
---|
41 | // |
---|
42 | // G4PolyPhiFace( const G4ReduciblePolygon *rz, |
---|
43 | // G4double phi, |
---|
44 | // G4double deltaPhi, |
---|
45 | // G4double phiOther ) |
---|
46 | // |
---|
47 | // Specifically: a face that lies on a plane that passes through |
---|
48 | // the z axis. It has boundaries that are straight lines of arbitrary |
---|
49 | // length and direction, but with corners aways on the same side of |
---|
50 | // the z axis. |
---|
51 | |
---|
52 | // Author: |
---|
53 | // David C. Williams (davidw@scipp.ucsc.edu) |
---|
54 | // -------------------------------------------------------------------- |
---|
55 | |
---|
56 | #ifndef G4PolyPhiFace_hh |
---|
57 | #define G4PolyPhiFace_hh |
---|
58 | |
---|
59 | #include "G4VCSGface.hh" |
---|
60 | #include "G4TwoVector.hh" |
---|
61 | |
---|
62 | class G4ReduciblePolygon; |
---|
63 | |
---|
64 | struct G4PolyPhiFaceVertex |
---|
65 | { |
---|
66 | G4double x, y, r, z; // position |
---|
67 | G4double rNorm, |
---|
68 | zNorm; // r/z normal |
---|
69 | G4ThreeVector norm3D; // 3D normal |
---|
70 | |
---|
71 | // Needed for Triangulation Algorithm |
---|
72 | // |
---|
73 | G4bool ear; |
---|
74 | G4PolyPhiFaceVertex *next,*prev; |
---|
75 | }; |
---|
76 | |
---|
77 | struct G4PolyPhiFaceEdge |
---|
78 | { |
---|
79 | G4PolyPhiFaceEdge(): v0(0), v1(0) {} |
---|
80 | G4PolyPhiFaceVertex *v0, *v1; // Corners |
---|
81 | G4double tr, tz, // Unit vector along edge |
---|
82 | length; // Length of edge |
---|
83 | G4ThreeVector norm3D; // 3D edge normal vector |
---|
84 | }; |
---|
85 | |
---|
86 | class G4PolyPhiFace : public G4VCSGface |
---|
87 | { |
---|
88 | |
---|
89 | public: // with description |
---|
90 | |
---|
91 | G4PolyPhiFace( const G4ReduciblePolygon *rz, |
---|
92 | G4double phi, G4double deltaPhi, G4double phiOther ); |
---|
93 | // Constructor. |
---|
94 | // Points r,z should be supplied in clockwise order in r,z. |
---|
95 | // For example: |
---|
96 | // [1]---------[2] ^ R |
---|
97 | // | | | |
---|
98 | // | | +--> z |
---|
99 | // [0]---------[3] |
---|
100 | |
---|
101 | virtual ~G4PolyPhiFace(); |
---|
102 | // Destructor. Removes edges and corners. |
---|
103 | |
---|
104 | G4PolyPhiFace( const G4PolyPhiFace &source ); |
---|
105 | G4PolyPhiFace& operator=( const G4PolyPhiFace &source ); |
---|
106 | // Copy constructor and assgnment operator. |
---|
107 | |
---|
108 | G4bool Intersect( const G4ThreeVector &p, const G4ThreeVector &v, |
---|
109 | G4bool outgoing, G4double surfTolerance, |
---|
110 | G4double &distance, G4double &distFromSurface, |
---|
111 | G4ThreeVector &normal, G4bool &allBehind ); |
---|
112 | |
---|
113 | G4double Distance( const G4ThreeVector &p, G4bool outgoing ); |
---|
114 | |
---|
115 | EInside Inside( const G4ThreeVector &p, G4double tolerance, |
---|
116 | G4double *bestDistance ); |
---|
117 | |
---|
118 | G4ThreeVector Normal( const G4ThreeVector &p, G4double *bestDistance ); |
---|
119 | |
---|
120 | G4double Extent( const G4ThreeVector axis ); |
---|
121 | |
---|
122 | void CalculateExtent( const EAxis axis, |
---|
123 | const G4VoxelLimits &voxelLimit, |
---|
124 | const G4AffineTransform &tranform, |
---|
125 | G4SolidExtentList &extentList ); |
---|
126 | |
---|
127 | inline G4VCSGface *Clone(); |
---|
128 | // Allocates on the heap a clone of this face. |
---|
129 | |
---|
130 | G4double SurfaceArea(); |
---|
131 | G4double SurfaceTriangle( G4ThreeVector p1, G4ThreeVector p2, |
---|
132 | G4ThreeVector p3, G4ThreeVector* p4); |
---|
133 | G4ThreeVector GetPointOnFace(); |
---|
134 | // Auxiliary methods for determination of points on surface. |
---|
135 | |
---|
136 | public: // without description |
---|
137 | |
---|
138 | G4PolyPhiFace(__void__&); |
---|
139 | // Fake default constructor for usage restricted to direct object |
---|
140 | // persistency for clients requiring preallocation of memory for |
---|
141 | // persistifiable objects. |
---|
142 | |
---|
143 | void Diagnose( G4VSolid *solid ); |
---|
144 | // Throw an exception if something is found inconsistent with |
---|
145 | // the solid. For debugging purposes only |
---|
146 | |
---|
147 | protected: |
---|
148 | |
---|
149 | G4bool InsideEdgesExact( G4double r, G4double z, G4double normSign, |
---|
150 | const G4ThreeVector &p, const G4ThreeVector &v ); |
---|
151 | // Decide if the point in r,z is inside the edges of our face, |
---|
152 | // **but** do so consistently with other faces. |
---|
153 | |
---|
154 | G4bool InsideEdges( G4double r, G4double z ); |
---|
155 | G4bool InsideEdges( G4double r, G4double z, G4double *distRZ2, |
---|
156 | G4PolyPhiFaceVertex **base3Dnorm=0, |
---|
157 | G4ThreeVector **head3Dnorm=0 ); |
---|
158 | // Decide if the point in r,z is inside the edges of our face. |
---|
159 | |
---|
160 | inline G4double ExactZOrder( G4double z, |
---|
161 | G4double qx, G4double qy, G4double qz, |
---|
162 | const G4ThreeVector &v, |
---|
163 | G4double normSign, |
---|
164 | const G4PolyPhiFaceVertex *vert ) const; |
---|
165 | // Decide precisely whether a trajectory passes to the left, right, |
---|
166 | // or exactly passes through the z position of a vertex point in face. |
---|
167 | |
---|
168 | void CopyStuff( const G4PolyPhiFace &source ); |
---|
169 | |
---|
170 | protected: |
---|
171 | |
---|
172 | // Functions used for Triangulation in Case of generic Polygone. |
---|
173 | // The triangulation is used for GetPointOnFace() |
---|
174 | |
---|
175 | G4double Area2( G4TwoVector a, G4TwoVector b, G4TwoVector c); |
---|
176 | // Calculation of 2*Area of Triangle with Sign |
---|
177 | |
---|
178 | G4bool Left( G4TwoVector a, G4TwoVector b, G4TwoVector c ); |
---|
179 | G4bool LeftOn( G4TwoVector a, G4TwoVector b, G4TwoVector c ); |
---|
180 | G4bool Collinear( G4TwoVector a, G4TwoVector b, G4TwoVector c ); |
---|
181 | // Boolean functions for sign of Surface |
---|
182 | |
---|
183 | G4bool IntersectProp( G4TwoVector a, G4TwoVector b, |
---|
184 | G4TwoVector c, G4TwoVector d ); |
---|
185 | // Boolean function for finding proper intersection of two |
---|
186 | // line segments (a,b) and (c,d). |
---|
187 | |
---|
188 | G4bool Between( G4TwoVector a, G4TwoVector b, G4TwoVector c ); |
---|
189 | // Boolean function for determining if point c is between a and b |
---|
190 | // where the three points (a,b,c) are on the same line. |
---|
191 | |
---|
192 | G4bool Intersect( G4TwoVector a, G4TwoVector b, |
---|
193 | G4TwoVector c, G4TwoVector d ); |
---|
194 | // Boolean function for finding proper intersection or not |
---|
195 | // of two line segments (a,b) and (c,d). |
---|
196 | |
---|
197 | G4bool Diagonalie( G4PolyPhiFaceVertex *a, G4PolyPhiFaceVertex *b ); |
---|
198 | // Boolean Diagonalie help to determine if diagonal s |
---|
199 | // of segment (a,b) is convex or reflex. |
---|
200 | |
---|
201 | G4bool InCone( G4PolyPhiFaceVertex *a, G4PolyPhiFaceVertex *b ); |
---|
202 | // Boolean function for determining if b is inside the cone (a0,a,a1) |
---|
203 | // where a is the center of the cone. |
---|
204 | |
---|
205 | G4bool Diagonal( G4PolyPhiFaceVertex *a, G4PolyPhiFaceVertex *b ); |
---|
206 | // Boolean function for determining if Diagonal is possible |
---|
207 | // inside Polycone or PolyHedra. |
---|
208 | |
---|
209 | void EarInit(); |
---|
210 | // Initialisation for Triangulisation by ear tips. |
---|
211 | // For details see "Computational Geometry in C" by Joseph O'Rourke. |
---|
212 | |
---|
213 | void Triangulate(); |
---|
214 | // Triangulisation by ear tips for Polycone or Polyhedra. |
---|
215 | // For details see "Computational Geometry in C" by Joseph O'Rourke. |
---|
216 | // NOTE: a copy of the shape is made and this copy is reordered in |
---|
217 | // order to have a list of triangles. This list is used by the |
---|
218 | // method GetPointOnFace(). |
---|
219 | |
---|
220 | protected: |
---|
221 | |
---|
222 | G4int numEdges; // Number of edges |
---|
223 | G4PolyPhiFaceEdge *edges; // The edges of the face |
---|
224 | G4PolyPhiFaceVertex *corners; // And the corners |
---|
225 | G4ThreeVector normal; // Normal unit vector |
---|
226 | G4ThreeVector radial; // Unit vector along radial direction |
---|
227 | G4ThreeVector surface; // Point on surface |
---|
228 | G4ThreeVector surface_point; // Auxiliary point on surface used for |
---|
229 | // method GetPointOnFace() |
---|
230 | G4double rMin, rMax, // Extent in r |
---|
231 | zMin, zMax; // Extent in z |
---|
232 | G4bool allBehind; // True if the polycone/polyhedra |
---|
233 | // is behind the place of this face |
---|
234 | G4double kCarTolerance;// Surface thickness |
---|
235 | G4double fSurfaceArea; // Surface Area of PolyPhiFace |
---|
236 | G4PolyPhiFaceVertex *triangles; // Auxiliary pointer to 'corners' used for |
---|
237 | // triangulation. Copy structure, changing |
---|
238 | // the structure of 'corners' (ear removal) |
---|
239 | }; |
---|
240 | |
---|
241 | #include "G4PolyPhiFace.icc" |
---|
242 | |
---|
243 | #endif |
---|