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 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 // G4GenericTrap
 27 //
 28 // Class description:
 29 //
 30 // G4GenericTrap is a solid which represents an arbitrary trapezoid with
 31 // up to 8 vertices standing on two parallel planes perpendicular to Z axis.
 32 //
 33 // Parameters in the constructor:
 34 // - name               - solid name
 35 // - halfZ              - the solid half length in Z
 36 // - vertices           - the (x,y) coordinates of vertices:
 37 //                        o first four points: vertices[i], i<4
 38 //                          are the vertices sitting on the -halfZ plane;
 39 //                        o last four points: vertices[i], i>=4
 40 //                          are the vertices sitting on the +halfZ plane.
 41 //
 42 //   The order of defining the vertices of the solid is the following:
 43 //      - point 0 is connected with points 1,3,4
 44 //      - point 1 is connected with points 0,2,5
 45 //      - point 2 is connected with points 1,3,6
 46 //      - point 3 is connected with points 0,2,7
 47 //      - point 4 is connected with points 0,5,7
 48 //      - point 5 is connected with points 1,4,6
 49 //      - point 6 is connected with points 2,5,7
 50 //      - point 7 is connected with points 3,4,6
 51 // Points can be identical in order to create shapes with less than
 52 // 8 vertices.
 53 
 54 // Authors:
 55 //   Tatiana Nikitina, CERN; Ivana Hrivnacova, IPN Orsay
 56 //   Adapted from Root Arb8 implementation, author Andrei Gheata, CERN
 57 //
 58 //   27.05.2024 - Evgueni Tcherniaev, complete revision, speed up
 59 // -------------------------------------------------------------------
 60 #ifndef G4GENERICTRAP_HH
 61 #define G4GENERICTRAP_HH
 62 
 63 #include "G4GeomTypes.hh"
 64 
 65 #if defined(G4GEOM_USE_USOLIDS)
 66 #define G4GEOM_USE_UGENERICTRAP 1
 67 #endif
 68 
 69 #if defined(G4GEOM_USE_UGENERICTRAP)
 70   #define G4UGenericTrap G4GenericTrap
 71   #include "G4UGenericTrap.hh"
 72 #else
 73 
 74 #include <vector>
 75 
 76 #include "globals.hh"
 77 #include "G4TwoVector.hh"
 78 #include "G4VSolid.hh"
 79 
 80 class G4GenericTrap : public G4VSolid
 81 {
 82   public:
 83 
 84     // Constructor
 85     G4GenericTrap(const G4String& name, G4double halfZ,
 86                   const std::vector<G4TwoVector>& vertices);
 87 
 88     // Fake default constructor for usage restricted to direct object
 89     // persistency for clients requiring preallocation of memory for
 90     // persistifiable objects.
 91     G4GenericTrap(__void__&);
 92 
 93     // Copy constructor and assignment operator
 94     G4GenericTrap(const G4GenericTrap& rhs);
 95     G4GenericTrap& operator=(const G4GenericTrap& rhs);
 96 
 97     // Destructor
 98     ~G4GenericTrap() override;
 99 
100     // Accessors
101     inline G4double    GetZHalfLength() const;
102     inline G4int       GetNofVertices() const;
103     inline G4TwoVector GetVertex(G4int index) const;
104     inline const std::vector<G4TwoVector>& GetVertices() const;
105     inline G4double    GetTwistAngle(G4int index) const;
106     inline G4bool      IsTwisted() const;
107     inline G4int       GetVisSubdivisions() const;
108     inline void        SetVisSubdivisions(G4int subdiv);
109 
110     // Solid methods
111     EInside Inside(const G4ThreeVector& p) const override;
112     G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
113     G4double DistanceToIn(const G4ThreeVector& p,
114                           const G4ThreeVector& v) const override;
115     G4double DistanceToIn(const G4ThreeVector& p) const override;
116     G4double DistanceToOut(const G4ThreeVector& p,
117                            const G4ThreeVector& v,
118                            const G4bool calcNorm = false,
119                                  G4bool* validNorm = nullptr,
120                                  G4ThreeVector* n = nullptr) const override;
121     G4double DistanceToOut(const G4ThreeVector& p) const override;
122     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
123     G4bool CalculateExtent(const EAxis pAxis,
124                            const G4VoxelLimits& pVoxelLimit,
125                            const G4AffineTransform& pTransform,
126                                  G4double& pmin, G4double& pmax) const override;
127 
128     G4GeometryType GetEntityType() const override;
129 
130     G4bool IsFaceted () const override;
131 
132     G4VSolid* Clone() const override;
133 
134     std::ostream& StreamInfo(std::ostream& os) const override;
135 
136     G4ThreeVector GetPointOnSurface() const override ;
137 
138     G4double GetCubicVolume() override;
139     G4double GetSurfaceArea() override;
140 
141     // Visualisation functions
142     void DescribeYourselfTo(G4VGraphicsScene& scene) const override;
143     G4VisExtent GetExtent() const override;
144     G4Polyhedron* CreatePolyhedron() const override;
145     G4Polyhedron* GetPolyhedron () const override;
146 
147   private:
148 
149     // Internal methods
150     void CheckParameters(G4double halfZ, const std::vector<G4TwoVector>& vertices);
151     void ComputeLateralSurfaces();
152     void ComputeBoundingBox();
153     void ComputeScratchLength();
154     G4double GetLateralFaceArea(G4int iface) const;
155     G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
156 
157     void WarningSignA(const G4String& method, const G4String& icase, G4double A,
158                       const G4ThreeVector& p, const G4ThreeVector& v) const;
159     void WarningSignB(const G4String& method, const G4String& icase, G4double f, G4double B,
160                       const G4ThreeVector& p, const G4ThreeVector& v) const;
161     void WarningDistanceToIn(G4int k, const G4ThreeVector& p, const G4ThreeVector& v,
162                              G4double tmin, G4double tmax,
163                              const G4double ttin[2], const G4double ttout[2]) const;
164     void WarningDistanceToOut(const G4ThreeVector& p,
165                               const G4ThreeVector& v,
166                               G4double tout) const;
167 
168   private:
169 
170   struct G4GenericTrapPlane // Ax + By + Cz + D = 0
171     {
172       G4double A = 0.;
173       G4double B = 0.;
174       G4double C = 0.;
175       G4double D = 0.;
176     };
177     struct G4GenericTrapSurface // Axz + Byz + Czz + Dx + Ey + Fz + G = 0
178     {
179       G4double A = 0.;
180       G4double B = 0.;
181       G4double C = 0.;
182       G4double D = 0.;
183       G4double E = 0.;
184       G4double F = 0.;
185       G4double G = 0.;
186     };
187 
188     // Data members
189     G4double                 halfTolerance = 0.;
190     G4double                 fScratch = 0.;
191     G4double                 fDz = 0.;
192     std::vector<G4TwoVector> fVertices = {0.,0.,0.,0.,0.,0.,0.,0.};
193     G4TwoVector              fDelta[4];
194     G4bool                   fIsTwisted = false;
195     G4double                 fTwist[5] = {0.};
196     G4ThreeVector            fMinBBox{0.};
197     G4ThreeVector            fMaxBBox{0.};
198     G4int                    fVisSubdivisions = 0;
199     G4GenericTrapPlane       fPlane[8];
200     G4GenericTrapSurface     fSurf[4];
201     mutable G4double         fArea[4] = {0.};
202     mutable G4bool           fRebuildPolyhedron = false;
203     mutable G4Polyhedron*    fpPolyhedron = nullptr;
204 
205     // Surface and Volume
206     G4double                 fSurfaceArea = 0.;
207     G4double                 fCubicVolume = 0.;
208 };
209 
210 #include "G4GenericTrap.icc"
211 
212 #endif // defined(G4GEOM_USE_UGENERICTRAP)
213 
214 #endif // G4GENERICTRAP_HH
215