Geant4  10.00.p02
UPolyPhiFace.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * This Software is part of the AIDA Unified Solids Library package *
4 // * See: https://aidasoft.web.cern.ch/USolids *
5 // ********************************************************************
6 //
7 // $Id:$
8 //
9 // --------------------------------------------------------------------
10 //
11 // UPolyPhiFace
12 //
13 // Class description:
14 //
15 // Definition of a face that bounds a polycone or polyhedra when
16 // it has a phi opening:
17 //
18 // UPolyPhiFace( const UReduciblePolygon *rz,
19 // double phi,
20 // double deltaPhi,
21 // double phiOther )
22 //
23 // Specifically: a face that lies on a plane that passes through
24 // the z axis. It has boundaries that are straight lines of arbitrary
25 // length and direction, but with corners aways on the same side of
26 // the z axis.
27 //
28 // 19.10.12 Marek Gayer
29 // Created from original implementation in Geant4
30 // --------------------------------------------------------------------
31 
32 #ifndef UPolyPhiFace_hh
33 #define UPolyPhiFace_hh
34 
35 #include "UVCSGface.hh"
36 #include "UVector2.hh"
37 
38 class UReduciblePolygon;
39 
41 {
42  double x, y, r, z; // position
43  double rNorm,
44  zNorm; // r/z normal
45  UVector3 norm3D; // 3D normal
46 
47  // Needed for Triangulation Algorithm
48  //
49  bool ear;
51 };
52 
54 {
55  UPolyPhiFaceEdge(): v0(0), v1(0), tr(.0), tz(0.), length(0.) {}
56  UPolyPhiFaceVertex* v0, *v1; // Corners
57  double tr, tz, // Unit vector along edge
58  length; // Length of edge
59  UVector3 norm3D; // 3D edge normal vector
60 };
61 
62 class UPolyPhiFace : public UVCSGface
63 {
64 
65  public: // with description
66 
68  double phi, double deltaPhi, double phiOther);
69  // Constructor.
70  // Points r,z should be supplied in clockwise order in r,z.
71  // For example:
72  // [1]---------[2] ^ R
73  // | | |
74  // | | +--> z
75  // [0]---------[3]
76 
77  virtual ~UPolyPhiFace();
78  // Destructor. Removes edges and corners.
79 
80  UPolyPhiFace(const UPolyPhiFace& source);
81  UPolyPhiFace& operator=(const UPolyPhiFace& source);
82  // Copy constructor and assgnment operator.
83 
84  bool Distance(const UVector3& p, const UVector3& v,
85  bool outgoing, double surfTolerance,
86  double& distance, double& distFromSurface,
87  UVector3& normal, bool& allBehind);
88 
89  double Safety(const UVector3& p, bool outgoing);
90 
91  VUSolid::EnumInside Inside(const UVector3& p, double tolerance,
92  double* bestDistance);
93 
94  UVector3 Normal(const UVector3& p, double* bestDistance);
95 
96  double Extent(const UVector3 axis);
97 
98  /*
99  void CalculateExtent( const EAxisType axis,
100  const UVoxelLimits &voxelLimit,
101  const UAffineTransform &tranform,
102  USolidExtentList &extentList );
103  */
104 
105  inline UVCSGface* Clone();
106  // Allocates on the heap a clone of this face.
107 
108  double SurfaceArea();
109  double SurfaceTriangle(UVector3 p1, UVector3 p2,
110  UVector3 p3, UVector3* p4);
112  // Auxiliary methods for determination of points on surface.
113 
114  public: // without description
115 
116  UPolyPhiFace(__void__&);
117  // Fake default constructor for usage restricted to direct object
118  // persistency for clients requiring preallocation of memory for
119  // persistifiable objects.
120 
121  void Diagnose(VUSolid* solid);
122  // Throw an exception if something is found inconsistent with
123  // the solid. For debugging purposes only
124 
125  protected:
126 
127  bool InsideEdgesExact(double r, double z, double normSign,
128  const UVector3& p, const UVector3& v);
129  // Decide if the point in r,z is inside the edges of our face,
130  // **but** do so consistently with other faces.
131 
132  bool InsideEdges(double r, double z);
133  bool InsideEdges(double r, double z, double* distRZ2,
134  UPolyPhiFaceVertex** base3Dnorm = 0,
135  UVector3** head3Dnorm = 0);
136  // Decide if the point in r,z is inside the edges of our face.
137 
138  inline double ExactZOrder(double z,
139  double qx, double qy, double qz,
140  const UVector3& v,
141  double normSign,
142  const UPolyPhiFaceVertex* vert) const;
143  // Decide precisely whether a trajectory passes to the left, right,
144  // or exactly passes through the z position of a vertex point in face.
145 
146  void CopyStuff(const UPolyPhiFace& source);
147 
148  protected:
149 
150  // Functions used for Triangulation in Case of generic Polygone.
151  // The triangulation is used for GetPointOnFace()
152 
153  double Area2(UVector2 a, UVector2 b, UVector2 c);
154  // Calculation of 2*Area of Triangle with Sign
155 
156  bool Left(UVector2 a, UVector2 b, UVector2 c);
157  bool LeftOn(UVector2 a, UVector2 b, UVector2 c);
158  bool Collinear(UVector2 a, UVector2 b, UVector2 c);
159  // Boolean functions for sign of Surface
160 
161  bool IntersectProp(UVector2 a, UVector2 b,
162  UVector2 c, UVector2 d);
163  // Boolean function for finding proper intersection of two
164  // line segments (a,b) and (c,d).
165 
166  bool Between(UVector2 a, UVector2 b, UVector2 c);
167  // Boolean function for determining if point c is between a and b
168  // where the three points (a,b,c) are on the same line.
169 
170  bool Intersect(UVector2 a, UVector2 b,
171  UVector2 c, UVector2 d);
172  // Boolean function for finding proper intersection or not
173  // of two line segments (a,b) and (c,d).
174 
176  // Boolean Diagonalie help to determine if diagonal s
177  // of segment (a,b) is convex or reflex.
178 
180  // Boolean function for determining if b is inside the cone (a0,a,a1)
181  // where a is the center of the cone.
182 
184  // Boolean function for determining if Diagonal is possible
185  // inside Polycone or PolyHedra.
186 
187  void EarInit();
188  // Initialisation for Triangulisation by ear tips.
189  // For details see "Computational Geometry in C" by Joseph O'Rourke.
190 
191  void Triangulate();
192  // Triangularisation by ear tips for Polycone or Polyhedra.
193  // For details see "Computational Geometry in C" by Joseph O'Rourke.
194  // NOTE: a copy of the shape is made and this copy is reordered in
195  // order to have a list of triangles. This list is used by the
196  // method GetPointOnFace().
197 
198  protected:
199 
200  int numEdges; // Number of edges
201  UPolyPhiFaceEdge* edges; // The edges of the face
202  UPolyPhiFaceVertex* corners; // And the corners
203  UVector3 normal; // Normal Unit vector
204  UVector3 radial; // Unit vector along radial direction
205  UVector3 surface; // Point on surface
206  UVector3 surface_point; // Auxiliary point on surface used for
207  // method GetPointOnFace()
208  double rMin, rMax, // Extent in r
209  zMin, zMax; // Extent in z
210  bool allBehind; // True if the polycone/polyhedra
211  // is behind the place of this face
212  double fTolerance;// Surface thickness
213  double fSurfaceArea; // Surface Area of PolyPhiFace
214  UPolyPhiFaceVertex* triangles; // Auxiliary pointer to 'corners' used for
215  // triangulation. Copy structure, changing
216  // the structure of 'corners' (ear removal)
217 };
218 
219 #include "UPolyPhiFace.icc"
220 
221 #endif
double SurfaceTriangle(UVector3 p1, UVector3 p2, UVector3 p3, UVector3 *p4)
bool InsideEdges(double r, double z)
UVector3 normal
UVCSGface * Clone()
VUSolid::EnumInside Inside(const UVector3 &p, double tolerance, double *bestDistance)
virtual ~UPolyPhiFace()
G4double z
Definition: TRTMaterials.hh:39
bool InCone(UPolyPhiFaceVertex *a, UPolyPhiFaceVertex *b)
double Area2(UVector2 a, UVector2 b, UVector2 c)
G4double a
Definition: TRTMaterials.hh:39
bool LeftOn(UVector2 a, UVector2 b, UVector2 c)
double ExactZOrder(double z, double qx, double qy, double qz, const UVector3 &v, double normSign, const UPolyPhiFaceVertex *vert) const
UPolyPhiFaceVertex * prev
Definition: UPolyPhiFace.hh:50
double Safety(const UVector3 &p, bool outgoing)
double fSurfaceArea
UPolyPhiFaceVertex * v0
Definition: UPolyPhiFace.hh:56
UPolyPhiFaceVertex * corners
double SurfaceArea()
UPolyPhiFace & operator=(const UPolyPhiFace &source)
UVector3 surface
bool Left(UVector2 a, UVector2 b, UVector2 c)
UPolyPhiFaceVertex * next
Definition: UPolyPhiFace.hh:50
bool Distance(const UVector3 &p, const UVector3 &v, bool outgoing, double surfTolerance, double &distance, double &distFromSurface, UVector3 &normal, bool &allBehind)
UPolyPhiFaceVertex * triangles
EnumInside
Definition: VUSolid.hh:23
UPolyPhiFaceEdge * edges
bool Diagonal(UPolyPhiFaceVertex *a, UPolyPhiFaceVertex *b)
bool IntersectProp(UVector2 a, UVector2 b, UVector2 c, UVector2 d)
double Extent(const UVector3 axis)
void CopyStuff(const UPolyPhiFace &source)
UVector3 GetPointOnFace()
UVector3 radial
UPolyPhiFaceVertex * v1
Definition: UPolyPhiFace.hh:56
bool Collinear(UVector2 a, UVector2 b, UVector2 c)
bool Between(UVector2 a, UVector2 b, UVector2 c)
double fTolerance
UVector3 Normal(const UVector3 &p, double *bestDistance)
bool InsideEdgesExact(double r, double z, double normSign, const UVector3 &p, const UVector3 &v)
bool Diagonalie(UPolyPhiFaceVertex *a, UPolyPhiFaceVertex *b)
UVector3 surface_point
UPolyPhiFace(const UReduciblePolygon *rz, double phi, double deltaPhi, double phiOther)
Definition: UPolyPhiFace.cc:35
bool Intersect(UVector2 a, UVector2 b, UVector2 c, UVector2 d)
void Triangulate()
void Diagnose(VUSolid *solid)