Geant4 11.3.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ExtrudedSolid.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// G4ExtrudedSolid
27//
28// Class description:
29//
30// G4ExtrudedSolid is a solid which represents the extrusion of an arbitrary
31// polygon with fixed outline in the defined Z sections.
32// The z-sides of the solid are the scaled versions of the same polygon.
33// The solid is implemented as a specification of G4TessellatedSolid.
34//
35// Parameters in the constructor:
36// const G4String& pName - solid name
37// std::vector<G4TwoVector> polygon - the vertices of the outlined polygon
38// defined in clockwise or anti-clockwise order
39// std::vector<ZSection> - the z-sections defined by
40// z position, offset and scale
41// in increasing z-position order
42//
43// Parameters in the special constructor (for solid with 2 z-sections:
44// G4double halfZ - the solid half length in Z
45// G4TwoVector off1 - offset of the side in -halfZ
46// G4double scale1 - scale of the side in -halfZ
47// G4TwoVector off2 - offset of the side in +halfZ
48// G4double scale2 - scale of the side in -halfZ
49
50// Author: Ivana Hrivnacova, IPN Orsay
51// --------------------------------------------------------------------
52#ifndef G4EXTRUDEDSOLID_HH
53#define G4EXTRUDEDSOLID_HH
54
55#include "G4GeomTypes.hh"
56
57#if defined(G4GEOM_USE_USOLIDS)
58#define G4GEOM_USE_UEXTRUDEDSOLID 1
59#endif
60
61#if defined(G4GEOM_USE_UEXTRUDEDSOLID)
62 #define G4UExtrudedSolid G4ExtrudedSolid
63 #include "G4UExtrudedSolid.hh"
64#else
65
66#include <vector>
67
68#include "G4TwoVector.hh"
69#include "G4TessellatedSolid.hh"
70
72{
73
74 public:
75
76 struct ZSection
77 {
78 ZSection() : fZ(0.), fOffset(0.,0.), fScale(1.) {}
80 : fZ(z), fOffset(offset), fScale(scale) {}
81
85 };
86
87 G4ExtrudedSolid( const G4String& pName,
88 const std::vector<G4TwoVector>& polygon,
89 const std::vector<ZSection>& zsections);
90 // General constructor
91
92 G4ExtrudedSolid( const G4String& pName,
93 const std::vector<G4TwoVector>& polygon,
94 G4double halfZ,
95 const G4TwoVector& off1 = G4TwoVector(0.,0.),
96 G4double scale1 = 1.,
97 const G4TwoVector& off2 = G4TwoVector(0.,0.),
98 G4double scale2 = 1. );
99 // Special constructor for solid with 2 z-sections
100
101 ~G4ExtrudedSolid() override;
102 // Destructor
103
104 // Accessors
105
106 inline G4int GetNofVertices() const;
107 inline G4TwoVector GetVertex(G4int index) const;
108 inline std::vector<G4TwoVector> GetPolygon() const;
109
110 inline G4int GetNofZSections() const;
111 inline ZSection GetZSection(G4int index) const;
112 inline std::vector<ZSection> GetZSections() const;
113
114 // Solid methods
115
116 EInside Inside(const G4ThreeVector& p) const override;
117 G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
119 const G4ThreeVector& v) const override;
120 G4double DistanceToIn(const G4ThreeVector& p ) const override;
122 const G4ThreeVector& v,
123 const G4bool calcNorm = false,
124 G4bool* validNorm = nullptr,
125 G4ThreeVector* n = nullptr) const override;
126 G4double DistanceToOut(const G4ThreeVector& p) const override;
127
128 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
129 G4bool CalculateExtent(const EAxis pAxis,
130 const G4VoxelLimits& pVoxelLimit,
131 const G4AffineTransform& pTransform,
132 G4double& pMin, G4double& pMax) const override;
133 G4GeometryType GetEntityType () const override;
134 G4bool IsFaceted () const override;
135 G4VSolid* Clone() const override;
136
137 std::ostream& StreamInfo(std::ostream& os) const override;
138
139 G4ExtrudedSolid(__void__&);
140 // Fake default constructor for usage restricted to direct object
141 // persistency for clients requiring preallocation of memory for
142 // persistifiable objects.
143
146 // Copy constructor and assignment operator.
147
148 private:
149
150 void ComputeProjectionParameters();
151 void ComputeLateralPlanes();
152 inline G4bool PointInPolygon(const G4ThreeVector& p) const;
153 inline G4double DistanceToPolygonSqr(const G4ThreeVector& p) const;
154 G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
155
156 G4ThreeVector GetVertex(G4int iz, G4int ind) const;
157 G4TwoVector ProjectPoint(const G4ThreeVector& point) const;
158
159 G4bool IsSameLine(const G4TwoVector& p,
160 const G4TwoVector& l1,
161 const G4TwoVector& l2) const;
162 G4bool IsSameLineSegment(const G4TwoVector& p,
163 const G4TwoVector& l1,
164 const G4TwoVector& l2) const;
165 G4bool IsSameSide(const G4TwoVector& p1,
166 const G4TwoVector& p2,
167 const G4TwoVector& l1,
168 const G4TwoVector& l2) const;
169 G4bool IsPointInside(const G4TwoVector& a,
170 const G4TwoVector& b,
171 const G4TwoVector& c,
172 const G4TwoVector& p) const;
173 G4double GetAngle(const G4TwoVector& p0,
174 const G4TwoVector& pa,
175 const G4TwoVector& pb) const;
176
177 G4VFacet* MakeDownFacet(G4int ind1, G4int ind2, G4int ind3) const;
178 G4VFacet* MakeUpFacet(G4int ind1, G4int ind2, G4int ind3) const;
179
180 G4bool AddGeneralPolygonFacets();
181 G4bool MakeFacets();
182
183 private:
184
185 std::size_t fNv;
186 std::size_t fNz;
187 std::vector<G4TwoVector> fPolygon;
188 std::vector<ZSection> fZSections;
189 std::vector< std::vector<G4int> > fTriangles;
190 G4bool fIsConvex = false;
191 G4GeometryType fGeometryType;
192
193 G4int fSolidType = 0;
194 struct plane { G4double a,b,c,d; }; // a*x + b*y + c*z + d = 0
195 std::vector<plane> fPlanes;
196 struct line { G4double k,m; }; // x = k*y + m;
197 std::vector<line> fLines;
198 std::vector<G4double> fLengths; // edge lengths
199
200 std::vector<G4double> fKScales;
201 std::vector<G4double> fScale0s;
202 std::vector<G4TwoVector> fKOffsets;
203 std::vector<G4TwoVector> fOffset0s;
204};
205
206#include "G4ExtrudedSolid.icc"
207
208#endif
209
210#endif
G4ThreadLocal T * G4GeomSplitter< T >::offset
CLHEP::Hep3Vector G4ThreeVector
CLHEP::Hep2Vector G4TwoVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4String G4GeometryType
Definition G4VSolid.hh:80
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const override
G4GeometryType GetEntityType() const override
std::vector< G4TwoVector > GetPolygon() const
G4ExtrudedSolid & operator=(const G4ExtrudedSolid &rhs)
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
~G4ExtrudedSolid() override
std::vector< ZSection > GetZSections() const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
EInside Inside(const G4ThreeVector &p) const override
ZSection GetZSection(G4int index) const
G4int GetNofZSections() const
G4int GetNofVertices() const
G4VSolid * Clone() const override
G4ExtrudedSolid(const G4ExtrudedSolid &rhs)
G4TwoVector GetVertex(G4int index) const
G4ExtrudedSolid(const G4String &pName, const std::vector< G4TwoVector > &polygon, const std::vector< ZSection > &zsections)
std::ostream & StreamInfo(std::ostream &os) const override
G4bool IsFaceted() const override
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
G4VSolid(const G4String &name)
Definition G4VSolid.cc:57
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67
ZSection(G4double z, const G4TwoVector &offset, G4double scale)