Geant4 11.1.1
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: // without description
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 public: // with description
88
89 G4ExtrudedSolid( const G4String& pName,
90 const std::vector<G4TwoVector>& polygon,
91 const std::vector<ZSection>& zsections);
92 // General constructor
93
94 G4ExtrudedSolid( const G4String& pName,
95 const std::vector<G4TwoVector>& polygon,
96 G4double halfZ,
97 const G4TwoVector& off1 = G4TwoVector(0.,0.),
98 G4double scale1 = 1.,
99 const G4TwoVector& off2 = G4TwoVector(0.,0.),
100 G4double scale2 = 1. );
101 // Special constructor for solid with 2 z-sections
102
103 virtual ~G4ExtrudedSolid();
104 // Destructor
105
106 // Accessors
107
108 inline G4int GetNofVertices() const;
109 inline G4TwoVector GetVertex(G4int index) const;
110 inline std::vector<G4TwoVector> GetPolygon() const;
111
112 inline G4int GetNofZSections() const;
113 inline ZSection GetZSection(G4int index) const;
114 inline std::vector<ZSection> GetZSections() const;
115
116 // Solid methods
117
118 EInside Inside(const G4ThreeVector& p) const;
120 G4double DistanceToIn(const G4ThreeVector& p, const G4ThreeVector& v) const;
121 G4double DistanceToIn(const G4ThreeVector& p ) const;
123 const G4ThreeVector& v,
124 const G4bool calcNorm = false,
125 G4bool* validNorm = nullptr,
126 G4ThreeVector* n = nullptr) const;
127 G4double DistanceToOut(const G4ThreeVector& p) const;
128
129 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
130 G4bool CalculateExtent(const EAxis pAxis,
131 const G4VoxelLimits& pVoxelLimit,
132 const G4AffineTransform& pTransform,
133 G4double& pMin, G4double& pMax) const;
135 G4VSolid* Clone() const;
136
137 std::ostream& StreamInfo(std::ostream& os) const;
138
139 public: // without description
140
141 G4ExtrudedSolid(__void__&);
142 // Fake default constructor for usage restricted to direct object
143 // persistency for clients requiring preallocation of memory for
144 // persistifiable objects.
145
148 // Copy constructor and assignment operator.
149
150 private:
151
152 void ComputeProjectionParameters();
153 void ComputeLateralPlanes();
154 inline G4bool PointInPolygon(const G4ThreeVector& p) const;
155 inline G4double DistanceToPolygonSqr(const G4ThreeVector& p) const;
156 G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
157
158 G4ThreeVector GetVertex(G4int iz, G4int ind) const;
159 G4TwoVector ProjectPoint(const G4ThreeVector& point) const;
160
161 G4bool IsSameLine(const G4TwoVector& p,
162 const G4TwoVector& l1,
163 const G4TwoVector& l2) const;
164 G4bool IsSameLineSegment(const G4TwoVector& p,
165 const G4TwoVector& l1,
166 const G4TwoVector& l2) const;
167 G4bool IsSameSide(const G4TwoVector& p1,
168 const G4TwoVector& p2,
169 const G4TwoVector& l1,
170 const G4TwoVector& l2) const;
171 G4bool IsPointInside(const G4TwoVector& a,
172 const G4TwoVector& b,
173 const G4TwoVector& c,
174 const G4TwoVector& p) const;
175 G4double GetAngle(const G4TwoVector& p0,
176 const G4TwoVector& pa,
177 const G4TwoVector& pb) const;
178
179 G4VFacet* MakeDownFacet(G4int ind1, G4int ind2, G4int ind3) const;
180 G4VFacet* MakeUpFacet(G4int ind1, G4int ind2, G4int ind3) const;
181
182 G4bool AddGeneralPolygonFacets();
183 G4bool MakeFacets();
184
185 private:
186
187 std::size_t fNv;
188 std::size_t fNz;
189 std::vector<G4TwoVector> fPolygon;
190 std::vector<ZSection> fZSections;
191 std::vector< std::vector<G4int> > fTriangles;
192 G4bool fIsConvex = false;
193 G4GeometryType fGeometryType;
194
195 G4int fSolidType = 0;
196 struct plane { G4double a,b,c,d; }; // a*x + b*y + c*z + d = 0
197 std::vector<plane> fPlanes;
198 struct line { G4double k,m; }; // x = k*y + m;
199 std::vector<line> fLines;
200 std::vector<G4double> fLengths; // edge lengths
201
202 std::vector<G4double> fKScales;
203 std::vector<G4double> fScale0s;
204 std::vector<G4TwoVector> fKOffsets;
205 std::vector<G4TwoVector> fOffset0s;
206};
207
208#include "G4ExtrudedSolid.icc"
209
210#endif
211
212#endif
CLHEP::Hep2Vector G4TwoVector
Definition: G4TwoVector.hh:36
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
std::vector< G4TwoVector > GetPolygon() const
EInside Inside(const G4ThreeVector &p) const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const
std::ostream & StreamInfo(std::ostream &os) const
virtual ~G4ExtrudedSolid()
G4ExtrudedSolid & operator=(const G4ExtrudedSolid &rhs)
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
std::vector< ZSection > GetZSections() const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4GeometryType GetEntityType() const
G4VSolid * Clone() const
ZSection GetZSection(G4int index) const
G4int GetNofZSections() const
G4int GetNofVertices() const
G4TwoVector GetVertex(G4int index) const
EAxis
Definition: geomdefs.hh:54
EInside
Definition: geomdefs.hh:67
ZSection(G4double z, const G4TwoVector &offset, G4double scale)