Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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.) {}
79 ZSection(G4double z, const G4TwoVector& offset, G4double scale)
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 G4VSolid* Clone() const override;
135
136 std::ostream& StreamInfo(std::ostream& os) const override;
137
138 G4ExtrudedSolid(__void__&);
139 // Fake default constructor for usage restricted to direct object
140 // persistency for clients requiring preallocation of memory for
141 // persistifiable objects.
142
145 // Copy constructor and assignment operator.
146
147 private:
148
149 void ComputeProjectionParameters();
150 void ComputeLateralPlanes();
151 inline G4bool PointInPolygon(const G4ThreeVector& p) const;
152 inline G4double DistanceToPolygonSqr(const G4ThreeVector& p) const;
153 G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
154
155 G4ThreeVector GetVertex(G4int iz, G4int ind) const;
156 G4TwoVector ProjectPoint(const G4ThreeVector& point) const;
157
158 G4bool IsSameLine(const G4TwoVector& p,
159 const G4TwoVector& l1,
160 const G4TwoVector& l2) const;
161 G4bool IsSameLineSegment(const G4TwoVector& p,
162 const G4TwoVector& l1,
163 const G4TwoVector& l2) const;
164 G4bool IsSameSide(const G4TwoVector& p1,
165 const G4TwoVector& p2,
166 const G4TwoVector& l1,
167 const G4TwoVector& l2) const;
168 G4bool IsPointInside(const G4TwoVector& a,
169 const G4TwoVector& b,
170 const G4TwoVector& c,
171 const G4TwoVector& p) const;
172 G4double GetAngle(const G4TwoVector& p0,
173 const G4TwoVector& pa,
174 const G4TwoVector& pb) const;
175
176 G4VFacet* MakeDownFacet(G4int ind1, G4int ind2, G4int ind3) const;
177 G4VFacet* MakeUpFacet(G4int ind1, G4int ind2, G4int ind3) const;
178
179 G4bool AddGeneralPolygonFacets();
180 G4bool MakeFacets();
181
182 private:
183
184 std::size_t fNv;
185 std::size_t fNz;
186 std::vector<G4TwoVector> fPolygon;
187 std::vector<ZSection> fZSections;
188 std::vector< std::vector<G4int> > fTriangles;
189 G4bool fIsConvex = false;
190 G4GeometryType fGeometryType;
191
192 G4int fSolidType = 0;
193 struct plane { G4double a,b,c,d; }; // a*x + b*y + c*z + d = 0
194 std::vector<plane> fPlanes;
195 struct line { G4double k,m; }; // x = k*y + m;
196 std::vector<line> fLines;
197 std::vector<G4double> fLengths; // edge lengths
198
199 std::vector<G4double> fKScales;
200 std::vector<G4double> fScale0s;
201 std::vector<G4TwoVector> fKOffsets;
202 std::vector<G4TwoVector> fOffset0s;
203};
204
205#include "G4ExtrudedSolid.icc"
206
207#endif
208
209#endif
CLHEP::Hep2Vector G4TwoVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
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
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67
ZSection(G4double z, const G4TwoVector &offset, G4double scale)