Geant4-11
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(G4double z, const G4TwoVector& offset, G4double scale)
79 : fZ(z), fOffset(offset), fScale(scale) {}
80
84 };
85
86 public: // with description
87
88 G4ExtrudedSolid( const G4String& pName,
89 const std::vector<G4TwoVector>& polygon,
90 const std::vector<ZSection>& zsections);
91 // General constructor
92
93 G4ExtrudedSolid( const G4String& pName,
94 const std::vector<G4TwoVector>& polygon,
95 G4double halfZ,
96 const G4TwoVector& off1, G4double scale1,
97 const G4TwoVector& off2, G4double scale2 );
98 // Special constructor for solid with 2 z-sections
99
100 virtual ~G4ExtrudedSolid();
101 // Destructor
102
103 // Accessors
104
105 inline G4int GetNofVertices() const;
106 inline G4TwoVector GetVertex(G4int index) const;
107 inline std::vector<G4TwoVector> GetPolygon() const;
108
109 inline G4int GetNofZSections() const;
110 inline ZSection GetZSection(G4int index) const;
111 inline std::vector<ZSection> GetZSections() const;
112
113 // Solid methods
114
115 EInside Inside(const G4ThreeVector& p) const;
117 G4double DistanceToIn(const G4ThreeVector& p, const G4ThreeVector& v) const;
118 G4double DistanceToIn(const G4ThreeVector& p ) const;
120 const G4ThreeVector& v,
121 const G4bool calcNorm = false,
122 G4bool* validNorm = nullptr,
123 G4ThreeVector* n = nullptr) const;
124 G4double DistanceToOut(const G4ThreeVector& p) const;
125
127 G4bool CalculateExtent(const EAxis pAxis,
128 const G4VoxelLimits& pVoxelLimit,
129 const G4AffineTransform& pTransform,
130 G4double& pMin, G4double& pMax) const;
132 G4VSolid* Clone() const;
133
134 std::ostream& StreamInfo(std::ostream& os) const;
135
136 public: // without description
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
151 inline G4bool PointInPolygon(const G4ThreeVector& p) const;
154
155 G4ThreeVector GetVertex(G4int iz, G4int ind) const;
156 G4TwoVector ProjectPoint(const G4ThreeVector& point) const;
157
159 const G4TwoVector& l1,
160 const G4TwoVector& l2) const;
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;
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
181
182 private:
183
186 std::vector<G4TwoVector> fPolygon;
187 std::vector<ZSection> fZSections;
188 std::vector< std::vector<G4int> > fTriangles;
191
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
static const G4double pMax
static const G4double pMin
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4double DistanceToPolygonSqr(const G4ThreeVector &p) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
std::vector< G4TwoVector > GetPolygon() const
std::vector< G4double > fKScales
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()
G4double GetAngle(const G4TwoVector &p0, const G4TwoVector &pa, const G4TwoVector &pb) const
G4ExtrudedSolid & operator=(const G4ExtrudedSolid &rhs)
std::vector< ZSection > fZSections
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
G4GeometryType fGeometryType
G4bool IsSameLineSegment(const G4TwoVector &p, const G4TwoVector &l1, const G4TwoVector &l2) const
std::vector< G4TwoVector > fOffset0s
G4VFacet * MakeDownFacet(G4int ind1, G4int ind2, G4int ind3) const
std::vector< ZSection > GetZSections() const
G4TwoVector ProjectPoint(const G4ThreeVector &point) const
G4VFacet * MakeUpFacet(G4int ind1, G4int ind2, G4int ind3) const
G4bool IsSameSide(const G4TwoVector &p1, const G4TwoVector &p2, const G4TwoVector &l1, const G4TwoVector &l2) const
void ComputeProjectionParameters()
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
std::vector< G4double > fLengths
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector &p) const
G4GeometryType GetEntityType() const
G4bool PointInPolygon(const G4ThreeVector &p) const
G4bool IsSameLine(const G4TwoVector &p, const G4TwoVector &l1, const G4TwoVector &l2) const
G4bool IsPointInside(const G4TwoVector &a, const G4TwoVector &b, const G4TwoVector &c, const G4TwoVector &p) const
std::vector< G4double > fScale0s
G4bool AddGeneralPolygonFacets()
std::vector< G4TwoVector > fKOffsets
G4VSolid * Clone() const
ZSection GetZSection(G4int index) const
G4int GetNofZSections() const
std::vector< plane > fPlanes
G4int GetNofVertices() const
G4TwoVector GetVertex(G4int index) const
G4ExtrudedSolid(const G4String &pName, const std::vector< G4TwoVector > &polygon, const std::vector< ZSection > &zsections)
std::vector< line > fLines
std::vector< std::vector< G4int > > fTriangles
std::vector< G4TwoVector > fPolygon
EAxis
Definition: geomdefs.hh:54
EInside
Definition: geomdefs.hh:67
ZSection(G4double z, const G4TwoVector &offset, G4double scale)