Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GenericTrap.hh
Go to the documentation of this file.
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#ifndef G4GENERICTRAP_HH
59#define G4GENERICTRAP_HH
60
61#include "G4GeomTypes.hh"
62
63#if defined(G4GEOM_USE_USOLIDS)
64#define G4GEOM_USE_UGENERICTRAP 1
65#endif
66
67#if defined(G4GEOM_USE_UGENERICTRAP)
68 #define G4UGenericTrap G4GenericTrap
69 #include "G4UGenericTrap.hh"
70#else
71
72#include <vector>
73
74#include "globals.hh"
75#include "G4TwoVector.hh"
76#include "G4VSolid.hh"
77#include "G4TessellatedSolid.hh"
78
79class G4GenericTrap : public G4VSolid
80{
81 public:
82
83 G4GenericTrap( const G4String& name, G4double halfZ,
84 const std::vector<G4TwoVector>& vertices );
85 // Constructor
86
87 ~G4GenericTrap() override;
88 // Destructor
89
90 // Accessors
91
92 inline G4double GetZHalfLength() const;
93 inline G4int GetNofVertices() const;
94 inline G4TwoVector GetVertex(G4int index) const;
95 inline const std::vector<G4TwoVector>& GetVertices() const;
96 inline G4double GetTwistAngle(G4int index) const;
97 inline G4bool IsTwisted() const;
98 inline G4int GetVisSubdivisions() const;
99 inline void SetVisSubdivisions(G4int subdiv);
100
101 // Solid methods
102
103 EInside Inside(const G4ThreeVector& p) const override;
104 G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
106 const G4ThreeVector& v) const override;
107 G4double DistanceToIn(const G4ThreeVector& p) const override;
109 const G4ThreeVector& v,
110 const G4bool calcNorm = false,
111 G4bool* validNorm = nullptr,
112 G4ThreeVector* n = nullptr) const override;
113 G4double DistanceToOut(const G4ThreeVector& p) const override;
114 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
115 G4bool CalculateExtent(const EAxis pAxis,
116 const G4VoxelLimits& pVoxelLimit,
117 const G4AffineTransform& pTransform,
118 G4double& pmin, G4double& pmax) const override;
119
120 G4GeometryType GetEntityType() const override;
121
122 G4VSolid* Clone() const override;
123
124 std::ostream& StreamInfo(std::ostream& os) const override;
125
126 G4ThreeVector GetPointOnSurface() const override ;
127
128 G4double GetCubicVolume() override;
129 G4double GetSurfaceArea() override;
130
131 // Visualisation functions
132
133 G4Polyhedron* GetPolyhedron () const override;
134 void DescribeYourselfTo(G4VGraphicsScene& scene) const override;
135 G4VisExtent GetExtent() const override;
136 G4Polyhedron* CreatePolyhedron() const override;
137
138 G4GenericTrap(__void__&);
139 // Fake default constructor for usage restricted to direct object
140 // persistency for clients requiring preallocation of memory for
141 // persistifiable objects.
142
143 G4GenericTrap(const G4GenericTrap& rhs);
145 // Copy constructor and assignment operator.
146
147 private:
148
149 // Internal methods
150
151 inline void SetTwistAngle(G4int index, G4double twist);
152 G4bool ComputeIsTwisted() ;
153 G4bool CheckOrder(const std::vector<G4TwoVector>& vertices) const;
154 G4bool IsSegCrossing(const G4TwoVector& a, const G4TwoVector& b,
155 const G4TwoVector& c, const G4TwoVector& d) const;
156 G4bool IsSegCrossingZ(const G4TwoVector& a, const G4TwoVector& b,
157 const G4TwoVector& c, const G4TwoVector& d) const;
158 void ReorderVertices(std::vector<G4ThreeVector>& vertices) const;
159 void ComputeBBox();
160 inline G4ThreeVector GetMinimumBBox() const;
161 inline G4ThreeVector GetMaximumBBox() const;
162
163 G4VFacet* MakeDownFacet(const std::vector<G4ThreeVector>& fromVertices,
164 G4int ind1, G4int ind2, G4int ind3) const;
165 G4VFacet* MakeUpFacet(const std::vector<G4ThreeVector>& fromVertices,
166 G4int ind1, G4int ind2, G4int ind3) const;
167 G4VFacet* MakeSideFacet(const G4ThreeVector& downVertex0,
168 const G4ThreeVector& downVertex1,
169 const G4ThreeVector& upVertex1,
170 const G4ThreeVector& upVertex0) const;
171 G4TessellatedSolid* CreateTessellatedSolid() const;
172
173 EInside InsidePolygone(const G4ThreeVector& p,
174 const std::vector<G4TwoVector>& poly) const;
175 G4double DistToPlane(const G4ThreeVector& p,
176 const G4ThreeVector& v, const G4int ipl) const ;
177 G4double DistToTriangle(const G4ThreeVector& p,
178 const G4ThreeVector& v, const G4int ipl) const;
179 G4ThreeVector NormalToPlane(const G4ThreeVector& p,
180 const G4int ipl) const;
181 G4double SafetyToFace(const G4ThreeVector& p, const G4int iseg) const;
182 G4double GetLateralFaceArea(G4int iface) const;
183
184 protected:
185
186 mutable G4bool fRebuildPolyhedron = false;
187 mutable G4Polyhedron* fpPolyhedron = nullptr;
188
189 private:
190
191 // static data members
192
193 static const G4int fgkNofVertices;
194 static const G4double fgkTolerance;
195
196 G4double halfCarTolerance;
197
198 // data members
199
200 G4double fDz;
201 std::vector<G4TwoVector> fVertices;
202 G4bool fIsTwisted = false;
203 G4double fTwist[4];
204 G4TessellatedSolid* fTessellatedSolid = nullptr;
205 G4ThreeVector fMinBBoxVector;
206 G4ThreeVector fMaxBBoxVector;
207 G4int fVisSubdivisions = 0;
208
209 enum ESide {kUndef,kXY0,kXY1,kXY2,kXY3,kMZ,kPZ};
210 // Codes for faces (kXY[num]=num of lateral face,kMZ= minus z face etc)
211
212 G4double fSurfaceArea = 0.0;
213 G4double fCubicVolume = 0.0;
214 // Surface and Volume
215};
216
217#include "G4GenericTrap.icc"
218
219#endif
220
221#endif
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4int GetNofVertices() const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
G4GenericTrap & operator=(const G4GenericTrap &rhs)
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
G4double GetZHalfLength() const
std::ostream & StreamInfo(std::ostream &os) const override
G4TwoVector GetVertex(G4int index) const
G4GeometryType GetEntityType() const override
G4Polyhedron * GetPolyhedron() const override
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
G4bool fRebuildPolyhedron
G4double GetTwistAngle(G4int index) const
G4double GetCubicVolume() override
G4VisExtent GetExtent() const override
const std::vector< G4TwoVector > & GetVertices() const
G4VSolid * Clone() const override
G4int GetVisSubdivisions() const
~G4GenericTrap() override
EInside Inside(const G4ThreeVector &p) const override
G4bool IsTwisted() const
G4Polyhedron * CreatePolyhedron() const override
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const override
void SetVisSubdivisions(G4int subdiv)
G4GenericTrap(const G4String &name, G4double halfZ, const std::vector< G4TwoVector > &vertices)
G4double GetSurfaceArea() override
G4ThreeVector GetPointOnSurface() const override
G4Polyhedron * fpPolyhedron
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67