Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
HepPolyhedron.h
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//
27//
28//
29// Class Description:
30// HepPolyhedron is an intermediate class between description of a shape
31// and visualization systems. It is intended to provide some service like:
32// - polygonization of shapes with triangulization (quadrilaterization)
33// of complex polygons;
34// - calculation of normals for faces and vertices;
35// - finding result of boolean operation on polyhedra;
36//
37// Public constructors:
38//
39// HepPolyhedronBox (dx,dy,dz)
40// - create polyhedron for Box;
41// HepPolyhedronTrd1 (dx1,dx2,dy,dz)
42// - create polyhedron for Trd1;
43// HepPolyhedronTrd2 (dx1,dx2,dy1,dy2,dz)
44// - create polyhedron for Trd2;
45// HepPolyhedronTrap (dz,theta,phi, h1,bl1,tl1,alp1, h2,bl2,tl2,alp2)
46// - create polyhedron for Trap;
47// HepPolyhedronPara (dx,dy,dz,alpha,theta,phi)
48// - create polyhedron for Para;
49// HepPolyhedronTube (rmin,rmax,dz)
50// - create polyhedron for Tube;
51// HepPolyhedronTubs (rmin,rmax,dz,phi1,dphi)
52// - create polyhedron for Tubs;
53// HepPolyhedronCone (rmin1,rmax1,rmin2,rmax2,dz)
54// - create polyhedron for Cone;
55// HepPolyhedronCons (rmin1,rmax1,rmin2,rmax2,dz,phi1,dphi)
56// - create polyhedron for Cons;
57// HepPolyhedronPgon (phi,dphi,npdv,nz, z(*),rmin(*),rmax(*))
58// - create polyhedron for Pgon;
59// HepPolyhedronPcon (phi,dphi,nz, z(*),rmin(*),rmax(*))
60// - create polyhedron for Pcon;
61// HepPolyhedronSphere (rmin,rmax,phi,dphi,the,dthe)
62// - create polyhedron for Sphere;
63// HepPolyhedronTorus (rmin,rmax,rtor,phi,dphi)
64// - create polyhedron for Torus;
65// HepPolyhedronTet (p0[3],p1[3],p2[3],p3[3])
66// - create polyhedron for Tet;
67// HepPolyhedronEllipsoid (dx,dy,dz,zcut1,zcut2)
68// - create polyhedron for Ellipsoid;
69// HepPolyhedronEllipticalCone(dx,dy,z,zcut1)
70// - create polyhedron for Elliptical cone;
71// HepPolyhedronParaboloid (r1,r2,dz,phi,dphi)
72// - create polyhedron for Paraboloid;
73// HepPolyhedronHype (r1,r2,tan1,tan2,halfz)
74// - create polyhedron for Hype;
75// HepPolyhedronHyperbolicMirror (a,h,r)
76// - create polyhedron for Hyperbolic mirror;
77// Public functions:
78//
79// GetNoVertices () - returns number of vertices;
80// GetNoFacets () - returns number of faces;
81// GetNextVertexIndex (index,edgeFlag) - get vertex indices of the
82// quadrilaterals in order;
83// returns false when finished each face;
84// GetVertex (index) - returns vertex by index;
85// GetNextVertex (vertex,edgeFlag) - get vertices with edge visibility
86// of the quadrilaterals in order;
87// returns false when finished each face;
88// GetNextVertex (vertex,edgeFlag,normal) - get vertices with edge
89// visibility and normal of the quadrilaterals
90// in order; returns false when finished each face;
91// GetNextEdgeIndices (i1,i2,edgeFlag) - get indices of the next edge;
92// returns false for the last edge;
93// GetNextEdgeIndices (i1,i2,edgeFlag,iface1,iface2) - get indices of
94// the next edge with indices of the faces
95// to which the edge belongs;
96// returns false for the last edge;
97// GetNextEdge (p1,p2,edgeFlag) - get next edge;
98// returns false for the last edge;
99// GetNextEdge (p1,p2,edgeFlag,iface1,iface2) - get next edge with indices
100// of the faces to which the edge belongs;
101// returns false for the last edge;
102// GetFacet (index,n,nodes,edgeFlags=0,normals=0) - get face by index;
103// GetNextFacet (n,nodes,edgeFlags=0,normals=0) - get next face with normals
104// at the nodes; returns false for the last face;
105// GetNormal (index) - get normal of face given by index;
106// GetUnitNormal (index) - get unit normal of face given by index;
107// GetNextNormal (normal) - get normals of each face in order;
108// returns false when finished all faces;
109// GetNextUnitNormal (normal) - get normals of unit length of each face
110// in order; returns false when finished all faces;
111// GetSurfaceArea() - get surface area of the polyhedron;
112// GetVolume() - get volume of the polyhedron;
113// GetNumberOfRotationSteps() - get number of steps for whole circle;
114// SetNumberOfRotationSteps (n) - set number of steps for whole circle;
115// ResetNumberOfRotationSteps() - reset number of steps for whole circle
116// to default value;
117// History:
118//
119// 20.06.96 Evgeni Chernyaev <[email protected]> - initial version
120//
121// 23.07.96 John Allison
122// - added GetNoVertices, GetNoFacets, GetNextVertex, GetNextNormal
123//
124// 30.09.96 E.Chernyaev
125// - added GetNextVertexIndex, GetVertex by Yasuhide Sawada
126// - added GetNextUnitNormal, GetNextEdgeIndices, GetNextEdge
127// - improvements: angles now expected in radians
128// int -> G4int, double -> G4double
129// - G4ThreeVector replaced by either G4Point3D or G4Normal3D
130//
131// 15.12.96 E.Chernyaev
132// - private functions G4PolyhedronAlloc, G4PolyhedronPrism renamed
133// to AllocateMemory and CreatePrism
134// - added private functions GetNumberOfRotationSteps, RotateEdge,
135// RotateAroundZ, SetReferences
136// - rewritten G4PolyhedronCons;
137// - added G4PolyhedronPara, ...Trap, ...Pgon, ...Pcon, ...Sphere, ...Torus,
138// so full List of implemented shapes now looks like:
139// BOX, TRD1, TRD2, TRAP, TUBE, TUBS, CONE, CONS, PARA, PGON, PCON,
140// SPHERE, TORUS
141//
142// 01.06.97 E.Chernyaev
143// - RotateAroundZ modified and SetSideFacets added to allow Rmin=Rmax
144// in bodies of revolution
145//
146// 24.06.97 J.Allison
147// - added static private member fNumberOfRotationSteps and static public
148// functions void SetNumberOfRotationSteps (G4int n) and
149// void ResetNumberOfRotationSteps (). Modified
150// GetNumberOfRotationSteps() appropriately. Made all three functions
151// inline (at end of this .hh file).
152// Usage:
153// G4Polyhedron::SetNumberOfRotationSteps
154// (fpView -> GetViewParameters ().GetNoOfSides ());
155// pPolyhedron = solid.CreatePolyhedron ();
156// G4Polyhedron::ResetNumberOfRotationSteps ();
157//
158// 19.03.00 E.Chernyaev
159// - added boolean operations (add, subtract, intersect) on polyhedra;
160//
161// 25.05.01 E.Chernyaev
162// - added GetSurfaceArea() and GetVolume();
163//
164// 05.11.02 E.Chernyaev
165// - added createTwistedTrap() and createPolyhedron();
166//
167// 06.03.05 J.Allison
168// - added IsErrorBooleanProcess
169//
170// 20.06.05 G.Cosmo
171// - added HepPolyhedronEllipsoid
172//
173// 21.10.09 J.Allison
174// - removed IsErrorBooleanProcess (now error is returned through argument)
175//
176
177#ifndef HEP_POLYHEDRON_HH
178#define HEP_POLYHEDRON_HH
179
180#include "G4Types.hh"
181#include "G4Point3D.hh"
182#include "G4Normal3D.hh"
183#include "G4Transform3D.hh"
184
185#ifndef DEFAULT_NUMBER_OF_STEPS
186#define DEFAULT_NUMBER_OF_STEPS 24
187#endif
188
189class G4Facet {
190 friend class HepPolyhedron;
191 friend std::ostream& operator<<(std::ostream&, const G4Facet &facet);
192
193 private:
194 struct G4Edge { G4int v,f; };
195 G4Edge edge[4];
196
197 public:
198 G4Facet(G4int v1=0, G4int f1=0, G4int v2=0, G4int f2=0,
199 G4int v3=0, G4int f3=0, G4int v4=0, G4int f4=0)
200 { edge[0].v=v1; edge[0].f=f1; edge[1].v=v2; edge[1].f=f2;
201 edge[2].v=v3; edge[2].f=f3; edge[3].v=v4; edge[3].f=f4; }
202};
203
205 friend std::ostream& operator<<(std::ostream&, const HepPolyhedron &ph);
206
207 protected:
212
213 // Re-allocate memory for HepPolyhedron
214 void AllocateMemory(G4int Nvert, G4int Nface);
215
216 // Find neighbouring facet
217 G4int FindNeighbour(G4int iFace, G4int iNode, G4int iOrder) const;
218
219 // Find normal at node
220 G4Normal3D FindNodeNormal(G4int iFace, G4int iNode) const;
221
222 // Create HepPolyhedron for prism with quadrilateral base
223 void CreatePrism();
224
225 // Generate facets by revolving an edge around Z-axis
226 void RotateEdge(G4int k1, G4int k2, G4double r1, G4double r2,
227 G4int v1, G4int v2, G4int vEdge,
228 G4bool ifWholeCircle, G4int ns, G4int &kface);
229
230 // Set side facets for the case of incomplete rotation
231 void SetSideFacets(G4int ii[4], G4int vv[4],
232 G4int *kk, G4double *r,
233 G4double dphi, G4int ns, G4int &kface);
234
235 // Create HepPolyhedron for body of revolution around Z-axis
236 void RotateAroundZ(G4int nstep, G4double phi, G4double dphi,
237 G4int np1, G4int np2,
238 const G4double *z, G4double *r,
239 G4int nodeVis, G4int edgeVis);
240
241 // For each edge set reference to neighbouring facet
242 void SetReferences();
243
244 // Invert the order on nodes in facets
245 void InvertFacets();
246
247 public:
248 // Constructor
249 HepPolyhedron() : nvert(0), nface(0), pV(0), pF(0) {}
250
251 // Copy constructor
252 HepPolyhedron(const HepPolyhedron & from);
253
254 // Move constructor
256
257 // Destructor
258 virtual ~HepPolyhedron() { delete [] pV; delete [] pF; }
259
260 // Assignment
261 HepPolyhedron & operator=(const HepPolyhedron & from);
262
263 // Move assignment
265
266 // Get number of vertices
267 G4int GetNoVertices() const { return nvert; }
268 G4int GetNoVerteces() const { return nvert; } // Old spelling.
269
270 // Get number of facets
271 G4int GetNoFacets() const { return nface; }
272
273 // Transform the polyhedron
275
276 // Get next vertex index of the quadrilateral
277 G4bool GetNextVertexIndex(G4int & index, G4int & edgeFlag) const;
278
279 // Get vertex by index
280 G4Point3D GetVertex(G4int index) const;
281
282 // Get next vertex + edge visibility of the quadrilateral
283 G4bool GetNextVertex(G4Point3D & vertex, G4int & edgeFlag) const;
284
285 // Get next vertex + edge visibility + normal of the quadrilateral
286 G4bool GetNextVertex(G4Point3D & vertex, G4int & edgeFlag,
287 G4Normal3D & normal) const;
288
289 // Get indices of the next edge with indices of the faces
290 G4bool GetNextEdgeIndices(G4int & i1, G4int & i2, G4int & edgeFlag,
291 G4int & iface1, G4int & iface2) const;
292 G4bool GetNextEdgeIndeces(G4int & i1, G4int & i2, G4int & edgeFlag,
293 G4int & iface1, G4int & iface2) const
294 {return GetNextEdgeIndices(i1,i2,edgeFlag,iface1,iface2);} // Old spelling
295
296 // Get indices of the next edge
297 G4bool GetNextEdgeIndices(G4int & i1, G4int & i2, G4int & edgeFlag) const;
298 G4bool GetNextEdgeIndeces(G4int & i1, G4int & i2, G4int & edgeFlag) const
299 {return GetNextEdgeIndices(i1,i2,edgeFlag);} // Old spelling.
300
301 // Get next edge
302 G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const;
303
304 // Get next edge
305 G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag,
306 G4int &iface1, G4int &iface2) const;
307
308 // Get face by index
309 void GetFacet(G4int iFace, G4int &n, G4int *iNodes,
310 G4int *edgeFlags = 0, G4int *iFaces = 0) const;
311
312 // Get face by index
313 void GetFacet(G4int iFace, G4int &n, G4Point3D *nodes,
314 G4int *edgeFlags=0, G4Normal3D *normals=0) const;
315
316 // Get next face with normals at the nodes
317 G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0,
318 G4Normal3D *normals=0) const;
319
320 // Get normal of the face given by index
321 G4Normal3D GetNormal(G4int iFace) const;
322
323 // Get unit normal of the face given by index
324 G4Normal3D GetUnitNormal(G4int iFace) const;
325
326 // Get normal of the next face
327 G4bool GetNextNormal(G4Normal3D &normal) const;
328
329 // Get normal of unit length of the next face
330 G4bool GetNextUnitNormal(G4Normal3D &normal) const;
331
332 // Boolean operations
333 HepPolyhedron add(const HepPolyhedron &p) const;
334 HepPolyhedron subtract(const HepPolyhedron &p) const;
335 HepPolyhedron intersect(const HepPolyhedron &p) const;
336
337 // Get area of the surface of the polyhedron
338 G4double GetSurfaceArea() const;
339
340 // Get volume of the polyhedron
341 G4double GetVolume() const;
342
343 // Get number of steps for whole circle
345
346 // Set number of steps for whole circle
347 static void SetNumberOfRotationSteps(G4int n);
348
349 // Reset number of steps for whole circle to default value
350 static void ResetNumberOfRotationSteps();
351
352 /**
353 * Creates polyhedron for twisted trapezoid.
354 * The trapezoid is given by two bases perpendicular to the z-axis.
355 *
356 * @param Dz half length in z
357 * @param xy1 1st base (at z = -Dz)
358 * @param xy2 2nd base (at z = +Dz)
359 * @return status of the operation - is non-zero in case of problem
360 */
362 const G4double xy1[][2], const G4double xy2[][2]);
363
364 /**
365 * Creates user defined polyhedron.
366 * This function allows to the user to define arbitrary polyhedron.
367 * The faces of the polyhedron should be either triangles or planar
368 * quadrilateral. Nodes of a face are defined by indexes pointing to
369 * the elements in the xyz array. Numeration of the elements in the
370 * array starts from 1 (like in fortran). The indexes can be positive
371 * or negative. Negative sign means that the corresponding edge is
372 * invisible. The normal of the face should be directed to exterior
373 * of the polyhedron.
374 *
375 * @param Nnodes number of nodes
376 * @param Nfaces number of faces
377 * @param xyz nodes
378 * @param faces faces (quadrilaterals or triangles)
379 * @return status of the operation - is non-zero in case of problem
380 */
381 G4int createPolyhedron(G4int Nnodes, G4int Nfaces,
382 const G4double xyz[][3], const G4int faces[][4]);
383};
384
386{
387 public:
389 G4double Dy1, G4double Dy2, G4double Dz);
390 virtual ~HepPolyhedronTrd2();
391};
392
394{
395 public:
397 G4double Dy, G4double Dz);
398 virtual ~HepPolyhedronTrd1();
399};
400
402{
403 public:
405 virtual ~HepPolyhedronBox();
406};
407
409{
410 public:
412 G4double Dy1,
413 G4double Dx1, G4double Dx2, G4double Alp1,
414 G4double Dy2,
415 G4double Dx3, G4double Dx4, G4double Alp2);
416 virtual ~HepPolyhedronTrap();
417};
418
420{
421 public:
423 G4double Alpha, G4double Theta, G4double Phi);
424 virtual ~HepPolyhedronPara();
425};
426
428{
429 public:
431 G4double r2,
432 G4double dz,
433 G4double Phi1,
434 G4double Dphi);
435 virtual ~HepPolyhedronParaboloid();
436};
437
439{
440 public:
442 G4double r2,
443 G4double tan1,
444 G4double tan2,
445 G4double halfZ);
446 virtual ~HepPolyhedronHype();
447};
448
450{
451 public:
453 G4double Rmn2, G4double Rmx2, G4double Dz,
454 G4double Phi1, G4double Dphi);
455 virtual ~HepPolyhedronCons();
456};
457
459{
460 public:
462 G4double Rmn2, G4double Rmx2, G4double Dz);
463 virtual ~HepPolyhedronCone();
464};
465
467{
468 public:
470 G4double Phi1, G4double Dphi);
471 virtual ~HepPolyhedronTubs();
472};
473
475{
476 public:
478 virtual ~HepPolyhedronTube();
479};
480
482{
483 public:
484 HepPolyhedronPgon(G4double phi, G4double dphi, G4int npdv, G4int nz,
485 const G4double *z,
486 const G4double *rmin,
487 const G4double *rmax);
488 virtual ~HepPolyhedronPgon();
489};
490
492{
493 public:
495 const G4double *z,
496 const G4double *rmin,
497 const G4double *rmax);
498 virtual ~HepPolyhedronPcon();
499};
500
502{
503 public:
505 G4double phi, G4double dphi,
506 G4double the, G4double dthe);
507 virtual ~HepPolyhedronSphere();
508};
509
511{
512 public:
514 G4double phi, G4double dphi);
515 virtual ~HepPolyhedronTorus();
516};
517
519{
520 public:
521 HepPolyhedronTet(const G4double p0[3],
522 const G4double p1[3],
523 const G4double p2[3],
524 const G4double p3[3]);
525 virtual ~HepPolyhedronTet();
526};
527
529{
530 public:
532 G4double zcut1, G4double zcut2);
533 virtual ~HepPolyhedronEllipsoid();
534};
535
537{
538 public:
540 G4double zcut1);
542};
543
545{
546 public:
549};
550
551#endif /* HEP_POLYHEDRON_HH */
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
friend std::ostream & operator<<(std::ostream &, const G4Facet &facet)
G4Facet(G4int v1=0, G4int f1=0, G4int v2=0, G4int f2=0, G4int v3=0, G4int f3=0, G4int v4=0, G4int f4=0)
virtual ~HepPolyhedronBox()
virtual ~HepPolyhedronCone()
virtual ~HepPolyhedronCons()
virtual ~HepPolyhedronHype()
virtual ~HepPolyhedronPara()
virtual ~HepPolyhedronPcon()
virtual ~HepPolyhedronPgon()
virtual ~HepPolyhedronSphere()
virtual ~HepPolyhedronTet()
virtual ~HepPolyhedronTorus()
virtual ~HepPolyhedronTrap()
virtual ~HepPolyhedronTrd1()
virtual ~HepPolyhedronTrd2()
virtual ~HepPolyhedronTube()
virtual ~HepPolyhedronTubs()
G4bool GetNextEdgeIndeces(G4int &i1, G4int &i2, G4int &edgeFlag, G4int &iface1, G4int &iface2) const
G4int GetNoVerteces() const
friend std::ostream & operator<<(std::ostream &, const HepPolyhedron &ph)
static void SetNumberOfRotationSteps(G4int n)
void RotateAroundZ(G4int nstep, G4double phi, G4double dphi, G4int np1, G4int np2, const G4double *z, G4double *r, G4int nodeVis, G4int edgeVis)
G4bool GetNextEdgeIndices(G4int &i1, G4int &i2, G4int &edgeFlag, G4int &iface1, G4int &iface2) const
G4Normal3D GetUnitNormal(G4int iFace) const
void GetFacet(G4int iFace, G4int &n, G4int *iNodes, G4int *edgeFlags=0, G4int *iFaces=0) const
G4int createTwistedTrap(G4double Dz, const G4double xy1[][2], const G4double xy2[][2])
G4Point3D * pV
void SetReferences()
G4bool GetNextNormal(G4Normal3D &normal) const
HepPolyhedron & operator=(const HepPolyhedron &from)
G4Normal3D FindNodeNormal(G4int iFace, G4int iNode) const
static G4int GetNumberOfRotationSteps()
G4Normal3D GetNormal(G4int iFace) const
G4int FindNeighbour(G4int iFace, G4int iNode, G4int iOrder) const
G4bool GetNextEdgeIndeces(G4int &i1, G4int &i2, G4int &edgeFlag) const
G4Point3D GetVertex(G4int index) const
G4double GetSurfaceArea() const
HepPolyhedron subtract(const HepPolyhedron &p) const
G4bool GetNextVertex(G4Point3D &vertex, G4int &edgeFlag) const
G4double GetVolume() const
HepPolyhedron intersect(const HepPolyhedron &p) const
HepPolyhedron & Transform(const G4Transform3D &t)
G4int createPolyhedron(G4int Nnodes, G4int Nfaces, const G4double xyz[][3], const G4int faces[][4])
void AllocateMemory(G4int Nvert, G4int Nface)
G4int GetNoFacets() const
G4bool GetNextUnitNormal(G4Normal3D &normal) const
static void ResetNumberOfRotationSteps()
void RotateEdge(G4int k1, G4int k2, G4double r1, G4double r2, G4int v1, G4int v2, G4int vEdge, G4bool ifWholeCircle, G4int ns, G4int &kface)
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0, G4Normal3D *normals=0) const
static G4ThreadLocal G4int fNumberOfRotationSteps
G4bool GetNextVertexIndex(G4int &index, G4int &edgeFlag) const
G4Facet * pF
HepPolyhedron add(const HepPolyhedron &p) const
virtual ~HepPolyhedron()
G4int GetNoVertices() const
G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const
void SetSideFacets(G4int ii[4], G4int vv[4], G4int *kk, G4double *r, G4double dphi, G4int ns, G4int &kface)
#define G4ThreadLocal
Definition: tls.hh:77
#define ns
Definition: xmlparse.cc:614