Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:57

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4PolyPhiFace
0027 //
0028 // Class description:
0029 //
0030 //   Definition of a face that bounds a polycone or polyhedra when
0031 //   it has a phi opening:
0032 //
0033 //   G4PolyPhiFace( const G4ReduciblePolygon* rz,
0034 //                        G4double phi,
0035 //                        G4double deltaPhi,
0036 //                        G4double phiOther )
0037 //
0038 //   Specifically: a face that lies on a plane that passes through
0039 //   the z axis. It has boundaries that are straight lines of arbitrary
0040 //   length and direction, but with corners aways on the same side of
0041 //   the z axis.
0042 
0043 // Author: David C. Williams (davidw@scipp.ucsc.edu)
0044 // --------------------------------------------------------------------
0045 #ifndef G4POLYPHIFACE_HH
0046 #define G4POLYPHIFACE_HH 1
0047 
0048 #include "G4VCSGface.hh"
0049 #include "G4TwoVector.hh"
0050 
0051 class G4ReduciblePolygon;
0052 
0053 struct G4PolyPhiFaceVertex
0054 {
0055   G4double x, y, r, z;   // position
0056   G4double rNorm, 
0057            zNorm;        // r/z normal
0058   G4ThreeVector norm3D;  // 3D normal
0059 
0060   // Needed for Triangulation Algorithm
0061   //
0062   G4bool ear;
0063   G4PolyPhiFaceVertex *next,*prev;
0064 };
0065 
0066 struct G4PolyPhiFaceEdge
0067 {
0068   G4PolyPhiFaceEdge() = default;
0069   G4PolyPhiFaceVertex  *v0{nullptr}, *v1{nullptr};  // Corners
0070   G4double tr{.0}, tz{0.},        // Unit vector along edge
0071            length{0.};            // Length of edge
0072   G4ThreeVector norm3D;           // 3D edge normal vector
0073 };
0074 
0075 class G4PolyPhiFace : public G4VCSGface
0076 {
0077 
0078   public:
0079 
0080     G4PolyPhiFace( const G4ReduciblePolygon* rz,
0081                          G4double phi, G4double deltaPhi, G4double phiOther );
0082       // Constructor.
0083       // Points r,z should be supplied in clockwise order in r,z.
0084       // For example:
0085       //                [1]---------[2]         ^ R
0086       //                 |           |          |
0087       //                 |           |          +--> z
0088       //                [0]---------[3]
0089 
0090     ~G4PolyPhiFace() override;
0091       // Destructor. Removes edges and corners.
0092 
0093     G4PolyPhiFace( const G4PolyPhiFace &source );
0094     G4PolyPhiFace& operator=( const G4PolyPhiFace &source );
0095       // Copy constructor and assgnment operator.
0096 
0097     G4bool Intersect( const G4ThreeVector& p, const G4ThreeVector& v,
0098                             G4bool outgoing, G4double surfTolerance,
0099                             G4double& distance, G4double& distFromSurface,
0100                             G4ThreeVector& normal, G4bool& allBehind ) override;
0101 
0102     G4double Distance( const G4ThreeVector& p, G4bool outgoing ) override;
0103   
0104     EInside Inside( const G4ThreeVector& p, G4double tolerance, 
0105                           G4double* bestDistance ) override;
0106     
0107     G4ThreeVector Normal( const G4ThreeVector& p,
0108                                 G4double* bestDistance ) override;
0109 
0110     G4double Extent( const G4ThreeVector axis ) override;
0111   
0112     void CalculateExtent( const EAxis axis, 
0113                           const G4VoxelLimits &voxelLimit,
0114                           const G4AffineTransform& tranform,
0115                                 G4SolidExtentList& extentList ) override;
0116 
0117     inline G4VCSGface* Clone() override;
0118       // Allocates on the heap a clone of this face.
0119 
0120     G4double SurfaceArea() override;
0121     G4double SurfaceTriangle( const G4ThreeVector& p1, const G4ThreeVector& p2,
0122                               const G4ThreeVector& p3, G4ThreeVector* p4);
0123     G4ThreeVector GetPointOnFace() override;
0124       // Auxiliary methods for determination of points on surface.
0125 
0126     G4PolyPhiFace(__void__&);
0127       // Fake default constructor for usage restricted to direct object
0128       // persistency for clients requiring preallocation of memory for
0129       // persistifiable objects.
0130 
0131     void Diagnose( G4VSolid* solid );
0132       // Throw an exception if something is found inconsistent with
0133       // the solid. For debugging purposes only
0134 
0135   protected:
0136 
0137     G4bool InsideEdgesExact( G4double r, G4double z, G4double normSign,
0138                              const G4ThreeVector& p, const G4ThreeVector& v );
0139       // Decide if the point in r,z is inside the edges of our face,
0140       // **but** do so consistently with other faces.
0141 
0142     G4bool InsideEdges( G4double r, G4double z );
0143     G4bool InsideEdges( G4double r, G4double z, G4double* distRZ2,
0144                         G4PolyPhiFaceVertex** base3Dnorm = nullptr,
0145                         G4ThreeVector** head3Dnorm = nullptr );
0146       // Decide if the point in r,z is inside the edges of our face.
0147 
0148     inline G4double ExactZOrder( G4double z, 
0149                                  G4double qx, G4double qy, G4double qz, 
0150                            const G4ThreeVector& v, 
0151                                  G4double normSign,
0152                            const G4PolyPhiFaceVertex* vert ) const;
0153       // Decide precisely whether a trajectory passes to the left, right,
0154       // or exactly passes through the z position of a vertex point in face.
0155 
0156     void CopyStuff( const G4PolyPhiFace& source );
0157 
0158     // Functions used for Triangulation in Case of generic Polygone.
0159     // The triangulation is used for GetPointOnFace()
0160 
0161     G4double Area2( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c);
0162       // Calculation of 2*Area of Triangle with Sign
0163 
0164     G4bool Left( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c );
0165     G4bool LeftOn( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c );
0166     G4bool Collinear( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c );
0167       // Boolean functions for sign of Surface
0168 
0169     G4bool IntersectProp( const G4TwoVector& a, const G4TwoVector& b,
0170                           const G4TwoVector& c, const G4TwoVector& d );
0171       // Boolean function for finding proper intersection of two
0172       // line segments (a,b) and (c,d).
0173 
0174     G4bool Between( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c );
0175       // Boolean function for determining if point c is between a and b
0176       // where the three points (a,b,c) are on the same line.
0177 
0178     G4bool Intersect( const G4TwoVector& a, const G4TwoVector& b,
0179                       const G4TwoVector& c, const G4TwoVector& d );
0180       // Boolean function for finding proper intersection or not
0181       // of two line segments (a,b) and (c,d).
0182 
0183     G4bool Diagonalie( G4PolyPhiFaceVertex* a, G4PolyPhiFaceVertex* b );
0184       // Boolean Diagonalie help to determine if diagonal s
0185       // of segment (a,b) is convex or reflex.
0186 
0187     G4bool InCone( G4PolyPhiFaceVertex *a, G4PolyPhiFaceVertex *b );
0188       // Boolean function for determining if b is inside the cone (a0,a,a1)
0189       // where a is the center of the cone.
0190 
0191     G4bool Diagonal( G4PolyPhiFaceVertex* a, G4PolyPhiFaceVertex* b );
0192       // Boolean function for determining if Diagonal is possible
0193       // inside Polycone or PolyHedra.
0194 
0195     void EarInit();
0196       // Initialisation for Triangulisation by ear tips.
0197       // For details see "Computational Geometry in C" by Joseph O'Rourke.
0198 
0199     void Triangulate();
0200       // Triangularisation by ear tips for Polycone or Polyhedra.
0201       // For details see "Computational Geometry in C" by Joseph O'Rourke.
0202       // NOTE: a copy of the shape is made and this copy is reordered in
0203       //       order to have a list of triangles. This list is used by the
0204       //       method GetPointOnFace().
0205 
0206   protected:
0207 
0208     G4int numEdges = 0;  // Number of edges
0209     G4PolyPhiFaceEdge* edges = nullptr;       // The edges of the face
0210     G4PolyPhiFaceVertex* corners = nullptr;   // And the corners
0211     G4ThreeVector normal;        // Normal unit vector
0212     G4ThreeVector radial;        // Unit vector along radial direction
0213     G4ThreeVector surface;       // Point on surface
0214     G4ThreeVector surface_point; // Auxiliary point on surface used for
0215                                  // method GetPointOnFace() 
0216     G4double rMin, rMax, // Extent in r
0217              zMin, zMax; // Extent in z
0218     G4bool allBehind = false; // True if the polycone/polyhedra
0219                               // is behind the place of this face
0220     G4double kCarTolerance;      // Surface thickness
0221     G4double fSurfaceArea = 0.0; // Surface Area of PolyPhiFace 
0222     G4PolyPhiFaceVertex* triangles = nullptr;
0223       // Auxiliary pointer to 'corners' used for triangulation.
0224       // Copy structure, changing the structure of 'corners' (ear removal)
0225 };
0226 
0227 #include "G4PolyPhiFace.icc"
0228 
0229 #endif