00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id: G4PolyPhiFace.hh 67011 2013-01-29 16:17:41Z gcosmo $ 00028 // 00029 // 00030 // -------------------------------------------------------------------- 00031 // GEANT 4 class header file 00032 // 00033 // 00034 // G4PolyPhiFace 00035 // 00036 // Class description: 00037 // 00038 // Definition of a face that bounds a polycone or polyhedra when 00039 // it has a phi opening: 00040 // 00041 // G4PolyPhiFace( const G4ReduciblePolygon *rz, 00042 // G4double phi, 00043 // G4double deltaPhi, 00044 // G4double phiOther ) 00045 // 00046 // Specifically: a face that lies on a plane that passes through 00047 // the z axis. It has boundaries that are straight lines of arbitrary 00048 // length and direction, but with corners aways on the same side of 00049 // the z axis. 00050 00051 // Author: 00052 // David C. Williams (davidw@scipp.ucsc.edu) 00053 // -------------------------------------------------------------------- 00054 00055 #ifndef G4PolyPhiFace_hh 00056 #define G4PolyPhiFace_hh 00057 00058 #include "G4VCSGface.hh" 00059 #include "G4TwoVector.hh" 00060 00061 class G4ReduciblePolygon; 00062 00063 struct G4PolyPhiFaceVertex 00064 { 00065 G4double x, y, r, z; // position 00066 G4double rNorm, 00067 zNorm; // r/z normal 00068 G4ThreeVector norm3D; // 3D normal 00069 00070 // Needed for Triangulation Algorithm 00071 // 00072 G4bool ear; 00073 G4PolyPhiFaceVertex *next,*prev; 00074 }; 00075 00076 struct G4PolyPhiFaceEdge 00077 { 00078 G4PolyPhiFaceEdge(): v0(0), v1(0), tr(.0), tz(0.), length(0.) {} 00079 G4PolyPhiFaceVertex *v0, *v1; // Corners 00080 G4double tr, tz, // Unit vector along edge 00081 length; // Length of edge 00082 G4ThreeVector norm3D; // 3D edge normal vector 00083 }; 00084 00085 class G4PolyPhiFace : public G4VCSGface 00086 { 00087 00088 public: // with description 00089 00090 G4PolyPhiFace( const G4ReduciblePolygon *rz, 00091 G4double phi, G4double deltaPhi, G4double phiOther ); 00092 // Constructor. 00093 // Points r,z should be supplied in clockwise order in r,z. 00094 // For example: 00095 // [1]---------[2] ^ R 00096 // | | | 00097 // | | +--> z 00098 // [0]---------[3] 00099 00100 virtual ~G4PolyPhiFace(); 00101 // Destructor. Removes edges and corners. 00102 00103 G4PolyPhiFace( const G4PolyPhiFace &source ); 00104 G4PolyPhiFace& operator=( const G4PolyPhiFace &source ); 00105 // Copy constructor and assgnment operator. 00106 00107 G4bool Intersect( const G4ThreeVector &p, const G4ThreeVector &v, 00108 G4bool outgoing, G4double surfTolerance, 00109 G4double &distance, G4double &distFromSurface, 00110 G4ThreeVector &normal, G4bool &allBehind ); 00111 00112 G4double Distance( const G4ThreeVector &p, G4bool outgoing ); 00113 00114 EInside Inside( const G4ThreeVector &p, G4double tolerance, 00115 G4double *bestDistance ); 00116 00117 G4ThreeVector Normal( const G4ThreeVector &p, G4double *bestDistance ); 00118 00119 G4double Extent( const G4ThreeVector axis ); 00120 00121 void CalculateExtent( const EAxis axis, 00122 const G4VoxelLimits &voxelLimit, 00123 const G4AffineTransform &tranform, 00124 G4SolidExtentList &extentList ); 00125 00126 inline G4VCSGface *Clone(); 00127 // Allocates on the heap a clone of this face. 00128 00129 G4double SurfaceArea(); 00130 G4double SurfaceTriangle( G4ThreeVector p1, G4ThreeVector p2, 00131 G4ThreeVector p3, G4ThreeVector* p4); 00132 G4ThreeVector GetPointOnFace(); 00133 // Auxiliary methods for determination of points on surface. 00134 00135 public: // without description 00136 00137 G4PolyPhiFace(__void__&); 00138 // Fake default constructor for usage restricted to direct object 00139 // persistency for clients requiring preallocation of memory for 00140 // persistifiable objects. 00141 00142 void Diagnose( G4VSolid *solid ); 00143 // Throw an exception if something is found inconsistent with 00144 // the solid. For debugging purposes only 00145 00146 protected: 00147 00148 G4bool InsideEdgesExact( G4double r, G4double z, G4double normSign, 00149 const G4ThreeVector &p, const G4ThreeVector &v ); 00150 // Decide if the point in r,z is inside the edges of our face, 00151 // **but** do so consistently with other faces. 00152 00153 G4bool InsideEdges( G4double r, G4double z ); 00154 G4bool InsideEdges( G4double r, G4double z, G4double *distRZ2, 00155 G4PolyPhiFaceVertex **base3Dnorm=0, 00156 G4ThreeVector **head3Dnorm=0 ); 00157 // Decide if the point in r,z is inside the edges of our face. 00158 00159 inline G4double ExactZOrder( G4double z, 00160 G4double qx, G4double qy, G4double qz, 00161 const G4ThreeVector &v, 00162 G4double normSign, 00163 const G4PolyPhiFaceVertex *vert ) const; 00164 // Decide precisely whether a trajectory passes to the left, right, 00165 // or exactly passes through the z position of a vertex point in face. 00166 00167 void CopyStuff( const G4PolyPhiFace &source ); 00168 00169 protected: 00170 00171 // Functions used for Triangulation in Case of generic Polygone. 00172 // The triangulation is used for GetPointOnFace() 00173 00174 G4double Area2( G4TwoVector a, G4TwoVector b, G4TwoVector c); 00175 // Calculation of 2*Area of Triangle with Sign 00176 00177 G4bool Left( G4TwoVector a, G4TwoVector b, G4TwoVector c ); 00178 G4bool LeftOn( G4TwoVector a, G4TwoVector b, G4TwoVector c ); 00179 G4bool Collinear( G4TwoVector a, G4TwoVector b, G4TwoVector c ); 00180 // Boolean functions for sign of Surface 00181 00182 G4bool IntersectProp( G4TwoVector a, G4TwoVector b, 00183 G4TwoVector c, G4TwoVector d ); 00184 // Boolean function for finding proper intersection of two 00185 // line segments (a,b) and (c,d). 00186 00187 G4bool Between( G4TwoVector a, G4TwoVector b, G4TwoVector c ); 00188 // Boolean function for determining if point c is between a and b 00189 // where the three points (a,b,c) are on the same line. 00190 00191 G4bool Intersect( G4TwoVector a, G4TwoVector b, 00192 G4TwoVector c, G4TwoVector d ); 00193 // Boolean function for finding proper intersection or not 00194 // of two line segments (a,b) and (c,d). 00195 00196 G4bool Diagonalie( G4PolyPhiFaceVertex *a, G4PolyPhiFaceVertex *b ); 00197 // Boolean Diagonalie help to determine if diagonal s 00198 // of segment (a,b) is convex or reflex. 00199 00200 G4bool InCone( G4PolyPhiFaceVertex *a, G4PolyPhiFaceVertex *b ); 00201 // Boolean function for determining if b is inside the cone (a0,a,a1) 00202 // where a is the center of the cone. 00203 00204 G4bool Diagonal( G4PolyPhiFaceVertex *a, G4PolyPhiFaceVertex *b ); 00205 // Boolean function for determining if Diagonal is possible 00206 // inside Polycone or PolyHedra. 00207 00208 void EarInit(); 00209 // Initialisation for Triangulisation by ear tips. 00210 // For details see "Computational Geometry in C" by Joseph O'Rourke. 00211 00212 void Triangulate(); 00213 // Triangularisation by ear tips for Polycone or Polyhedra. 00214 // For details see "Computational Geometry in C" by Joseph O'Rourke. 00215 // NOTE: a copy of the shape is made and this copy is reordered in 00216 // order to have a list of triangles. This list is used by the 00217 // method GetPointOnFace(). 00218 00219 protected: 00220 00221 G4int numEdges; // Number of edges 00222 G4PolyPhiFaceEdge *edges; // The edges of the face 00223 G4PolyPhiFaceVertex *corners; // And the corners 00224 G4ThreeVector normal; // Normal unit vector 00225 G4ThreeVector radial; // Unit vector along radial direction 00226 G4ThreeVector surface; // Point on surface 00227 G4ThreeVector surface_point; // Auxiliary point on surface used for 00228 // method GetPointOnFace() 00229 G4double rMin, rMax, // Extent in r 00230 zMin, zMax; // Extent in z 00231 G4bool allBehind; // True if the polycone/polyhedra 00232 // is behind the place of this face 00233 G4double kCarTolerance;// Surface thickness 00234 G4double fSurfaceArea; // Surface Area of PolyPhiFace 00235 G4PolyPhiFaceVertex *triangles; // Auxiliary pointer to 'corners' used for 00236 // triangulation. Copy structure, changing 00237 // the structure of 'corners' (ear removal) 00238 }; 00239 00240 #include "G4PolyPhiFace.icc" 00241 00242 #endif