Back to home page

EIC code displayed by LXR

 
 

    


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

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 // G4GenericTrap
0027 //
0028 // Class description:
0029 //
0030 // G4GenericTrap is a solid which represents an arbitrary trapezoid with
0031 // up to 8 vertices standing on two parallel planes perpendicular to Z axis.
0032 //
0033 // Parameters in the constructor:
0034 // - name               - solid name
0035 // - halfZ              - the solid half length in Z
0036 // - vertices           - the (x,y) coordinates of vertices:
0037 //                        o first four points: vertices[i], i<4
0038 //                          are the vertices sitting on the -halfZ plane;
0039 //                        o last four points: vertices[i], i>=4
0040 //                          are the vertices sitting on the +halfZ plane.
0041 //
0042 //   The order of defining the vertices of the solid is the following:
0043 //      - point 0 is connected with points 1,3,4
0044 //      - point 1 is connected with points 0,2,5
0045 //      - point 2 is connected with points 1,3,6
0046 //      - point 3 is connected with points 0,2,7
0047 //      - point 4 is connected with points 0,5,7
0048 //      - point 5 is connected with points 1,4,6
0049 //      - point 6 is connected with points 2,5,7
0050 //      - point 7 is connected with points 3,4,6
0051 // Points can be identical in order to create shapes with less than
0052 // 8 vertices.
0053 
0054 // Authors:
0055 //   Tatiana Nikitina, CERN; Ivana Hrivnacova, IPN Orsay
0056 //   Adapted from Root Arb8 implementation, author Andrei Gheata, CERN
0057 // -------------------------------------------------------------------
0058 #ifndef G4GENERICTRAP_HH
0059 #define G4GENERICTRAP_HH
0060 
0061 #include "G4GeomTypes.hh"
0062 
0063 #if defined(G4GEOM_USE_USOLIDS)
0064 #define G4GEOM_USE_UGENERICTRAP 1
0065 #endif
0066 
0067 #if defined(G4GEOM_USE_UGENERICTRAP)
0068   #define G4UGenericTrap G4GenericTrap
0069   #include "G4UGenericTrap.hh"
0070 #else
0071 
0072 #include <vector>
0073 
0074 #include "globals.hh"
0075 #include "G4TwoVector.hh"
0076 #include "G4VSolid.hh"
0077 #include "G4TessellatedSolid.hh"
0078 
0079 class G4GenericTrap : public G4VSolid
0080 {
0081   public:
0082 
0083     G4GenericTrap( const G4String& name, G4double halfZ,
0084                    const std::vector<G4TwoVector>& vertices );
0085       // Constructor
0086 
0087     ~G4GenericTrap() override;
0088       // Destructor
0089 
0090     // Accessors
0091 
0092     inline G4double    GetZHalfLength() const;
0093     inline G4int       GetNofVertices() const;
0094     inline G4TwoVector GetVertex(G4int index) const;
0095     inline const std::vector<G4TwoVector>& GetVertices() const;
0096     inline G4double    GetTwistAngle(G4int index) const;
0097     inline G4bool      IsTwisted() const;
0098     inline G4int       GetVisSubdivisions() const;
0099     inline void        SetVisSubdivisions(G4int subdiv);
0100 
0101     // Solid methods
0102 
0103     EInside Inside(const G4ThreeVector& p) const override;
0104     G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
0105     G4double DistanceToIn(const G4ThreeVector& p,
0106                           const G4ThreeVector& v) const override;
0107     G4double DistanceToIn(const G4ThreeVector& p) const override;
0108     G4double DistanceToOut(const G4ThreeVector& p,
0109                            const G4ThreeVector& v,
0110                            const G4bool calcNorm = false,
0111                                  G4bool* validNorm = nullptr,
0112                                  G4ThreeVector* n = nullptr) const override;
0113     G4double DistanceToOut(const G4ThreeVector& p) const override;
0114     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0115     G4bool CalculateExtent(const EAxis pAxis,
0116                            const G4VoxelLimits& pVoxelLimit,
0117                            const G4AffineTransform& pTransform,
0118                                  G4double& pmin, G4double& pmax) const override;
0119 
0120     G4GeometryType GetEntityType() const override;
0121 
0122     G4VSolid* Clone() const override;
0123 
0124     std::ostream& StreamInfo(std::ostream& os) const override;
0125 
0126     G4ThreeVector GetPointOnSurface() const override ;
0127 
0128     G4double GetCubicVolume() override;
0129     G4double GetSurfaceArea() override;
0130 
0131     // Visualisation functions
0132 
0133     G4Polyhedron* GetPolyhedron () const override;
0134     void DescribeYourselfTo(G4VGraphicsScene& scene) const override;
0135     G4VisExtent   GetExtent() const override;
0136     G4Polyhedron* CreatePolyhedron() const override;
0137 
0138     G4GenericTrap(__void__&);
0139       // Fake default constructor for usage restricted to direct object
0140       // persistency for clients requiring preallocation of memory for
0141       // persistifiable objects.
0142 
0143     G4GenericTrap(const G4GenericTrap& rhs);
0144     G4GenericTrap& operator=(const G4GenericTrap& rhs);
0145       // Copy constructor and assignment operator.
0146 
0147   private:
0148 
0149     // Internal methods
0150 
0151     inline void SetTwistAngle(G4int index, G4double twist);
0152     G4bool  ComputeIsTwisted() ;
0153     G4bool  CheckOrder(const std::vector<G4TwoVector>& vertices) const;
0154     G4bool  IsSegCrossing(const G4TwoVector& a, const G4TwoVector& b,
0155                           const G4TwoVector& c, const G4TwoVector& d) const;
0156     G4bool  IsSegCrossingZ(const G4TwoVector& a, const G4TwoVector& b,
0157                            const G4TwoVector& c, const G4TwoVector& d) const;
0158     void ReorderVertices(std::vector<G4ThreeVector>& vertices) const;
0159     void ComputeBBox();
0160     inline G4ThreeVector GetMinimumBBox() const;
0161     inline G4ThreeVector GetMaximumBBox() const;
0162 
0163     G4VFacet* MakeDownFacet(const std::vector<G4ThreeVector>& fromVertices,
0164                             G4int ind1, G4int ind2, G4int ind3) const;
0165     G4VFacet* MakeUpFacet(const std::vector<G4ThreeVector>& fromVertices,
0166                             G4int ind1, G4int ind2, G4int ind3) const;
0167     G4VFacet* MakeSideFacet(const G4ThreeVector& downVertex0,
0168                             const G4ThreeVector& downVertex1,
0169                             const G4ThreeVector& upVertex1,
0170                             const G4ThreeVector& upVertex0) const;
0171     G4TessellatedSolid* CreateTessellatedSolid() const;
0172 
0173     EInside InsidePolygone(const G4ThreeVector& p,
0174                            const std::vector<G4TwoVector>& poly) const;
0175     G4double DistToPlane(const G4ThreeVector& p,
0176                          const G4ThreeVector& v, const G4int ipl) const ;
0177     G4double DistToTriangle(const G4ThreeVector& p,
0178                             const G4ThreeVector& v, const G4int ipl) const;
0179     G4ThreeVector NormalToPlane(const G4ThreeVector& p,
0180                                 const G4int ipl) const;
0181     G4double SafetyToFace(const G4ThreeVector& p, const G4int iseg) const;
0182     G4double GetLateralFaceArea(G4int iface) const;
0183 
0184   protected:
0185 
0186      mutable G4bool fRebuildPolyhedron = false;
0187      mutable G4Polyhedron* fpPolyhedron = nullptr;
0188 
0189   private:
0190 
0191     // static data members
0192 
0193     static const G4int       fgkNofVertices;
0194     static const G4double    fgkTolerance;
0195 
0196     G4double halfCarTolerance;
0197 
0198     // data members
0199 
0200     G4double                 fDz;
0201     std::vector<G4TwoVector> fVertices;
0202     G4bool                   fIsTwisted = false;
0203     G4double                 fTwist[4];
0204     G4TessellatedSolid*      fTessellatedSolid = nullptr;
0205     G4ThreeVector            fMinBBoxVector;
0206     G4ThreeVector            fMaxBBoxVector;
0207     G4int                    fVisSubdivisions = 0;
0208 
0209     enum ESide {kUndef,kXY0,kXY1,kXY2,kXY3,kMZ,kPZ};
0210       // Codes for faces (kXY[num]=num of lateral face,kMZ= minus z face etc)
0211 
0212     G4double                 fSurfaceArea = 0.0;
0213     G4double                 fCubicVolume = 0.0;
0214       // Surface and Volume
0215 };
0216 
0217 #include "G4GenericTrap.icc"
0218 
0219 #endif
0220 
0221 #endif