Geant4 11.4.0
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), 09.02.2007 - First implementation
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
71/**
72 * @brief G4ExtrudedSolid is a is a solid which represents the extrusion
73 * of an arbitrary polygon with fixed outline in the defined Z sections.
74 * The z-sides of the solid are the scaled versions of the same polygon.
75 * The solid is implemented as a specification of a G4TessellatedSolid.
76 */
77
79{
80 public:
81
82 /**
83 * Structure defining a Z section composing the solid.
84 */
85 struct ZSection
86 {
87 ZSection() : fZ(0.), fOffset(0.,0.), fScale(1.) {}
89 : fZ(z), fOffset(offset), fScale(scale) {}
90
94 };
95
96 /**
97 * General constructor for an extruded polygon, through contour and polyline.
98 * @param[in] pName The solid name.
99 * @param[in] polygon The 2D polygonal contour, i.e. the vertices of the
100 * outlined polygon defined in clock-wise order.
101 * @param[in] zsections The 3D polyline with scale factors, i.e. the
102 * Z-sections defined by Z position in increasing order.
103 */
104 G4ExtrudedSolid( const G4String& pName,
105 const std::vector<G4TwoVector>& polygon,
106 const std::vector<ZSection>& zsections);
107
108 /**
109 * Special constructor for an extruded polygon with 2 Z-sections.
110 * @param[in] pName The solid name.
111 * @param[in] polygon The 2D polygonal contour, i.e. the vertices of the
112 * outlined polygon defined in clock-wise order.
113 * @param[in] halfZ Half length in Z, i.e. the distance from the origin
114 * to the sections.
115 * @param[in] off1 (X, Y) position of the first polygon in -halfZ.
116 * @param[in] scale1 Scale factor at -halfZ.
117 * @param[in] off2 (X, Y) position of the second polygon in +halfZ.
118 * @param[in] scale2 Scale factor at +halfZ.
119 */
120 G4ExtrudedSolid( const G4String& pName,
121 const std::vector<G4TwoVector>& polygon,
122 G4double halfZ,
123 const G4TwoVector& off1 = G4TwoVector(0.,0.),
124 G4double scale1 = 1.,
125 const G4TwoVector& off2 = G4TwoVector(0.,0.),
126 G4double scale2 = 1. );
127
128 /**
129 * Default Destructor.
130 */
131 ~G4ExtrudedSolid() override = default;
132
133 /**
134 * Accessors.
135 */
136 inline G4int GetNofVertices() const;
137 inline G4TwoVector GetVertex(G4int index) const;
138 inline std::vector<G4TwoVector> GetPolygon() const;
139 inline G4int GetNofZSections() const;
140 inline ZSection GetZSection(G4int index) const;
141 inline std::vector<ZSection> GetZSections() const;
142
143 /**
144 * Concrete implementations of the expected query interfaces for
145 * solids, as defined in the base class G4VSolid.
146 */
147 EInside Inside(const G4ThreeVector& p) const override;
148 G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
150 const G4ThreeVector& v) const override;
151 G4double DistanceToIn(const G4ThreeVector& p ) const override;
153 const G4ThreeVector& v,
154 const G4bool calcNorm = false,
155 G4bool* validNorm = nullptr,
156 G4ThreeVector* n = nullptr) const override;
157 G4double DistanceToOut(const G4ThreeVector& p) const override;
158
159 /**
160 * Computes the bounding limits of the solid.
161 * @param[out] pMin The minimum bounding limit point.
162 * @param[out] pMax The maximum bounding limit point.
163 */
164 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
165
166 /**
167 * Calculates the minimum and maximum extent of the solid, when under the
168 * specified transform, and within the specified limits.
169 * @param[in] pAxis The axis along which compute the extent.
170 * @param[in] pVoxelLimit The limiting space dictated by voxels.
171 * @param[in] pTransform The internal transformation applied to the solid.
172 * @param[out] pMin The minimum extent value.
173 * @param[out] pMax The maximum extent value.
174 * @returns True if the solid is intersected by the extent region.
175 */
176 G4bool CalculateExtent(const EAxis pAxis,
177 const G4VoxelLimits& pVoxelLimit,
178 const G4AffineTransform& pTransform,
179 G4double& pMin, G4double& pMax) const override;
180
181 /**
182 * Returns the type ID, "G4ExtrudedSolid" of the solid.
183 */
184 G4GeometryType GetEntityType () const override;
185
186 /**
187 * Returns true as the solid has only planar faces.
188 */
189 G4bool IsFaceted () const override;
190
191 /**
192 * Makes a clone of the object for use in multi-treading.
193 * @returns A pointer to the new cloned allocated solid.
194 */
195 G4VSolid* Clone() const override;
196
197 /**
198 * Streams the object contents to an output stream.
199 */
200 std::ostream& StreamInfo(std::ostream& os) const override;
201
202 /**
203 * Fake default constructor for usage restricted to direct object
204 * persistency for clients requiring preallocation of memory for
205 * persistifiable objects.
206 */
207 G4ExtrudedSolid(__void__&);
208
209 /**
210 * Copy constructor and assignment operator.
211 */
212 G4ExtrudedSolid(const G4ExtrudedSolid& rhs) = default;
214
215 private:
216
217 /**
218 * Algorithm for SurfaceNormal() following the original
219 * specification for points not on the surface.
220 */
221 G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
222
223 /**
224 * Computes parameters for point projections p(z)
225 * to the polygon scale & offset.
226 */
227 void ComputeProjectionParameters();
228
229 /**
230 * Computes the lateral planes: a*x + b*y + c*z + d = 0.
231 */
232 void ComputeLateralPlanes();
233
234 /**
235 * Returns if point 'p' is within the polygon.
236 */
237 inline G4bool PointInPolygon(const G4ThreeVector& p) const;
238
239 /**
240 * Returns the square distance of point 'p' from the polygon.
241 */
242 inline G4double DistanceToPolygonSqr(const G4ThreeVector& p) const;
243
244 /**
245 * Returns the vertex coordinates, given the indeces for the
246 * polygons and Z sections.
247 * @param[in] iz Index for the Z section.
248 * @param[in] ind Index for the polygon.
249 * @returns The shifted and scaled coordinates of the vertex.
250 */
251 G4ThreeVector GetVertex(G4int iz, G4int ind) const;
252
253 /**
254 * Returns the projected point of 'p' in the polygon scale.
255 */
256 G4TwoVector ProjectPoint(const G4ThreeVector& point) const;
257
258 /**
259 * Returns true if 'p' is on the line through 'l1', 'l2'.
260 */
261 G4bool IsSameLine(const G4TwoVector& p,
262 const G4TwoVector& l1,
263 const G4TwoVector& l2) const;
264 /**
265 * Returns true if 'p' is on the line through 'l1', 'l2'
266 * and lies between 'l1' and 'l2'.
267 */
268 G4bool IsSameLineSegment(const G4TwoVector& p,
269 const G4TwoVector& l1,
270 const G4TwoVector& l2) const;
271 /**
272 * Returns true if 'p1' and 'p2' are on the same side of the line
273 * through 'l1', 'l2'.
274 */
275 G4bool IsSameSide(const G4TwoVector& p1,
276 const G4TwoVector& p2,
277 const G4TwoVector& l1,
278 const G4TwoVector& l2) const;
279 /**
280 * Returns true if 'p' is inside of triangle abc or on its edges.
281 */
282 G4bool IsPointInside(const G4TwoVector& a,
283 const G4TwoVector& b,
284 const G4TwoVector& c,
285 const G4TwoVector& p) const;
286 /**
287 * Returns the angle of the vertex in 'p0'.
288 */
289 G4double GetAngle(const G4TwoVector& p0,
290 const G4TwoVector& pa,
291 const G4TwoVector& pb) const;
292
293 /**
294 * Returns a pointer to a triangular facet from the polygon points
295 * given by indices forming the down side ( the normal goes in -z).
296 */
297 G4VFacet* MakeDownFacet(G4int ind1, G4int ind2, G4int ind3) const;
298
299 /**
300 * Returns a pointer to a triangular facet from the polygon points
301 * given by indices forming the upper side ( z>0 ).
302 */
303 G4VFacet* MakeUpFacet(G4int ind1, G4int ind2, G4int ind3) const;
304
305 /**
306 * Decomposes polygonal sides in triangular facets.
307 * @returns false if failing to define a facet.
308 */
309 G4bool AddGeneralPolygonFacets();
310
311 /**
312 * Generates the tessellated structure of the solid creating the
313 * triangular or quadrangular facets from the vertices.
314 * @returns false if failing to define a facet.
315 */
316 G4bool MakeFacets();
317
318 private:
319
320 std::size_t fNv;
321 std::size_t fNz;
322 std::vector<G4TwoVector> fPolygon;
323 std::vector<ZSection> fZSections;
324 std::vector< std::vector<G4int> > fTriangles;
325 G4bool fIsConvex = false;
326 G4GeometryType fGeometryType;
327
328 G4int fSolidType = 0;
329 struct plane { G4double a,b,c,d; }; // a*x + b*y + c*z + d = 0
330 std::vector<plane> fPlanes;
331 struct line { G4double k,m; }; // x = k*y + m;
332 std::vector<line> fLines;
333 std::vector<G4double> fLengths; // edge lengths
334
335 std::vector<G4double> fKScales;
336 std::vector<G4double> fScale0s;
337 std::vector<G4TwoVector> fKOffsets;
338 std::vector<G4TwoVector> fOffset0s;
339};
340
341#include "G4ExtrudedSolid.icc"
342
343#endif
344
345#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:70
G4AffineTransform is a class for geometric affine transformations. It supports efficient arbitrary ro...
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
G4ExtrudedSolid(const G4ExtrudedSolid &rhs)=default
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
std::vector< ZSection > GetZSections() const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
~G4ExtrudedSolid() override=default
EInside Inside(const G4ThreeVector &p) const override
ZSection GetZSection(G4int index) const
G4int GetNofZSections() const
G4int GetNofVertices() const
G4VSolid * Clone() const override
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
G4VFacet is a base class defining the facets which are components of a G4TessellatedSolid shape.
Definition G4VFacet.hh:56
G4VSolid(const G4String &name)
Definition G4VSolid.cc:59
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67
ZSection(G4double z, const G4TwoVector &offset, G4double scale)