Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4ExtrudedSolid.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 // G4ExtrudedSolid
0027 //
0028 // Class description:
0029 //
0030 // G4ExtrudedSolid is a solid which represents the extrusion of an arbitrary
0031 // polygon with fixed outline in the defined Z sections.
0032 // The z-sides of the solid are the scaled versions of the same polygon.
0033 // The solid is implemented as a specification of G4TessellatedSolid.
0034 //
0035 // Parameters in the constructor:
0036 // const G4String& pName             - solid name
0037 // std::vector<G4TwoVector> polygon  - the vertices of the outlined polygon
0038 //                                     defined in clockwise or anti-clockwise order
0039 // std::vector<ZSection>             - the z-sections defined by
0040 //                                     z position, offset and scale
0041 //                                     in increasing z-position order
0042 //
0043 // Parameters in the special constructor (for solid with 2 z-sections:
0044 // G4double halfZ                    - the solid half length in Z
0045 // G4TwoVector off1                  - offset of the side in -halfZ
0046 // G4double scale1                   - scale of the side in -halfZ
0047 // G4TwoVector off2                  - offset of the side in +halfZ
0048 // G4double scale2                   - scale of the side in -halfZ
0049 
0050 // Author: Ivana Hrivnacova, IPN Orsay
0051 // --------------------------------------------------------------------
0052 #ifndef G4EXTRUDEDSOLID_HH
0053 #define G4EXTRUDEDSOLID_HH
0054 
0055 #include "G4GeomTypes.hh"
0056 
0057 #if defined(G4GEOM_USE_USOLIDS)
0058 #define G4GEOM_USE_UEXTRUDEDSOLID 1
0059 #endif
0060 
0061 #if defined(G4GEOM_USE_UEXTRUDEDSOLID)
0062   #define G4UExtrudedSolid G4ExtrudedSolid
0063   #include "G4UExtrudedSolid.hh"
0064 #else
0065 
0066 #include <vector>
0067 
0068 #include "G4TwoVector.hh"
0069 #include "G4TessellatedSolid.hh"
0070 
0071 class G4ExtrudedSolid : public G4TessellatedSolid
0072 {
0073 
0074   public:
0075 
0076     struct ZSection
0077     {
0078       ZSection() : fZ(0.), fOffset(0.,0.), fScale(1.) {}
0079       ZSection(G4double z, const G4TwoVector& offset, G4double scale)
0080         : fZ(z), fOffset(offset), fScale(scale) {}
0081 
0082       G4double    fZ;
0083       G4TwoVector fOffset;
0084       G4double    fScale;
0085     };
0086 
0087     G4ExtrudedSolid( const G4String&                 pName,
0088                      const std::vector<G4TwoVector>& polygon,
0089                      const std::vector<ZSection>&    zsections);
0090       // General constructor
0091 
0092     G4ExtrudedSolid( const G4String&                 pName,
0093                      const std::vector<G4TwoVector>& polygon,
0094                            G4double                  halfZ,
0095                      const G4TwoVector& off1 = G4TwoVector(0.,0.),
0096                            G4double scale1 = 1.,
0097                      const G4TwoVector& off2 = G4TwoVector(0.,0.),
0098                            G4double scale2 = 1. );
0099       // Special constructor for solid with 2 z-sections
0100 
0101     ~G4ExtrudedSolid() override;
0102       // Destructor
0103 
0104     // Accessors
0105 
0106     inline G4int       GetNofVertices() const;
0107     inline G4TwoVector GetVertex(G4int index) const;
0108     inline std::vector<G4TwoVector> GetPolygon() const;
0109 
0110     inline G4int       GetNofZSections() const;
0111     inline ZSection    GetZSection(G4int index) const;
0112     inline std::vector<ZSection> GetZSections() const;
0113 
0114     // Solid methods
0115 
0116     EInside  Inside(const G4ThreeVector& p) const override;
0117     G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
0118     G4double DistanceToIn(const G4ThreeVector& p,
0119                           const G4ThreeVector& v) const override;
0120     G4double DistanceToIn(const G4ThreeVector& p ) const override;
0121     G4double DistanceToOut(const G4ThreeVector& p,
0122                            const G4ThreeVector& v,
0123                            const G4bool calcNorm = false,
0124                                  G4bool* validNorm = nullptr,
0125                                  G4ThreeVector* n = nullptr) const override;
0126     G4double DistanceToOut(const G4ThreeVector& p) const override;
0127 
0128     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0129     G4bool CalculateExtent(const EAxis pAxis,
0130                            const G4VoxelLimits& pVoxelLimit,
0131                            const G4AffineTransform& pTransform,
0132                                  G4double& pMin, G4double& pMax) const override;
0133     G4GeometryType GetEntityType () const override;
0134     G4VSolid* Clone() const override;
0135 
0136     std::ostream& StreamInfo(std::ostream& os) const override;
0137 
0138     G4ExtrudedSolid(__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     G4ExtrudedSolid(const G4ExtrudedSolid& rhs);
0144     G4ExtrudedSolid& operator=(const G4ExtrudedSolid& rhs);
0145       // Copy constructor and assignment operator.
0146 
0147   private:
0148 
0149     void ComputeProjectionParameters();
0150     void ComputeLateralPlanes();
0151     inline G4bool PointInPolygon(const G4ThreeVector& p) const;
0152     inline G4double DistanceToPolygonSqr(const G4ThreeVector& p) const;
0153     G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
0154 
0155     G4ThreeVector GetVertex(G4int iz, G4int ind) const;
0156     G4TwoVector ProjectPoint(const G4ThreeVector& point) const;
0157 
0158     G4bool IsSameLine(const G4TwoVector& p,
0159                       const G4TwoVector& l1,
0160                       const G4TwoVector& l2) const;
0161     G4bool IsSameLineSegment(const G4TwoVector& p,
0162                              const G4TwoVector& l1,
0163                              const G4TwoVector& l2) const;
0164     G4bool IsSameSide(const G4TwoVector& p1,
0165                       const G4TwoVector& p2,
0166                       const G4TwoVector& l1,
0167                       const G4TwoVector& l2) const;
0168     G4bool IsPointInside(const G4TwoVector& a,
0169                          const G4TwoVector& b,
0170                          const G4TwoVector& c,
0171                          const G4TwoVector& p) const;
0172     G4double GetAngle(const G4TwoVector& p0,
0173                       const G4TwoVector& pa,
0174                       const G4TwoVector& pb) const;
0175 
0176     G4VFacet* MakeDownFacet(G4int ind1, G4int ind2, G4int ind3) const;
0177     G4VFacet* MakeUpFacet(G4int ind1, G4int ind2, G4int ind3) const;
0178 
0179     G4bool AddGeneralPolygonFacets();
0180     G4bool MakeFacets();
0181 
0182   private:
0183 
0184     std::size_t    fNv;
0185     std::size_t    fNz;
0186     std::vector<G4TwoVector> fPolygon;
0187     std::vector<ZSection>    fZSections;
0188     std::vector< std::vector<G4int> > fTriangles;
0189     G4bool         fIsConvex = false;
0190     G4GeometryType fGeometryType;
0191 
0192     G4int fSolidType = 0;
0193     struct plane { G4double a,b,c,d; }; // a*x + b*y + c*z + d = 0
0194     std::vector<plane> fPlanes;
0195     struct line { G4double k,m; };      // x = k*y + m;
0196     std::vector<line> fLines;
0197     std::vector<G4double> fLengths;     // edge lengths
0198 
0199     std::vector<G4double>      fKScales;
0200     std::vector<G4double>      fScale0s;
0201     std::vector<G4TwoVector>   fKOffsets;
0202     std::vector<G4TwoVector>   fOffset0s;
0203 };
0204 
0205 #include "G4ExtrudedSolid.icc"
0206 
0207 #endif
0208 
0209 #endif