ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepPolyhedron.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HepPolyhedron.h
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 // HepPolyhedronEllipsoid (dx,dy,dz,zcut1,zcut2)
66 // - create polyhedron for Ellipsoid;
67 // Public functions:
68 //
69 // GetNoVertices () - returns number of vertices;
70 // GetNoFacets () - returns number of faces;
71 // GetNextVertexIndex (index,edgeFlag) - get vertex indices of the
72 // quadrilaterals in order;
73 // returns false when finished each face;
74 // GetVertex (index) - returns vertex by index;
75 // GetNextVertex (vertex,edgeFlag) - get vertices with edge visibility
76 // of the quadrilaterals in order;
77 // returns false when finished each face;
78 // GetNextVertex (vertex,edgeFlag,normal) - get vertices with edge
79 // visibility and normal of the quadrilaterals
80 // in order; returns false when finished each face;
81 // GetNextEdgeIndices (i1,i2,edgeFlag) - get indices of the next edge;
82 // returns false for the last edge;
83 // GetNextEdgeIndices (i1,i2,edgeFlag,iface1,iface2) - get indices of
84 // the next edge with indices of the faces
85 // to which the edge belongs;
86 // returns false for the last edge;
87 // GetNextEdge (p1,p2,edgeFlag) - get next edge;
88 // returns false for the last edge;
89 // GetNextEdge (p1,p2,edgeFlag,iface1,iface2) - get next edge with indices
90 // of the faces to which the edge belongs;
91 // returns false for the last edge;
92 // GetFacet (index,n,nodes,edgeFlags=0,normals=0) - get face by index;
93 // GetNextFacet (n,nodes,edgeFlags=0,normals=0) - get next face with normals
94 // at the nodes; returns false for the last face;
95 // GetNormal (index) - get normal of face given by index;
96 // GetUnitNormal (index) - get unit normal of face given by index;
97 // GetNextNormal (normal) - get normals of each face in order;
98 // returns false when finished all faces;
99 // GetNextUnitNormal (normal) - get normals of unit length of each face
100 // in order; returns false when finished all faces;
101 // GetSurfaceArea() - get surface area of the polyhedron;
102 // GetVolume() - get volume of the polyhedron;
103 // GetNumberOfRotationSteps() - get number of steps for whole circle;
104 // SetNumberOfRotationSteps (n) - set number of steps for whole circle;
105 // ResetNumberOfRotationSteps() - reset number of steps for whole circle
106 // to default value;
107 // History:
108 //
109 // 20.06.96 Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch> - initial version
110 //
111 // 23.07.96 John Allison
112 // - added GetNoVertices, GetNoFacets, GetNextVertex, GetNextNormal
113 //
114 // 30.09.96 E.Chernyaev
115 // - added GetNextVertexIndex, GetVertex by Yasuhide Sawada
116 // - added GetNextUnitNormal, GetNextEdgeIndices, GetNextEdge
117 // - improvements: angles now expected in radians
118 // int -> G4int, double -> G4double
119 // - G4ThreeVector replaced by either G4Point3D or G4Normal3D
120 //
121 // 15.12.96 E.Chernyaev
122 // - private functions G4PolyhedronAlloc, G4PolyhedronPrism renamed
123 // to AllocateMemory and CreatePrism
124 // - added private functions GetNumberOfRotationSteps, RotateEdge,
125 // RotateAroundZ, SetReferences
126 // - rewritten G4PolyhedronCons;
127 // - added G4PolyhedronPara, ...Trap, ...Pgon, ...Pcon, ...Sphere, ...Torus,
128 // so full List of implemented shapes now looks like:
129 // BOX, TRD1, TRD2, TRAP, TUBE, TUBS, CONE, CONS, PARA, PGON, PCON,
130 // SPHERE, TORUS
131 //
132 // 01.06.97 E.Chernyaev
133 // - RotateAroundZ modified and SetSideFacets added to allow Rmin=Rmax
134 // in bodies of revolution
135 //
136 // 24.06.97 J.Allison
137 // - added static private member fNumberOfRotationSteps and static public
138 // functions void SetNumberOfRotationSteps (G4int n) and
139 // void ResetNumberOfRotationSteps (). Modified
140 // GetNumberOfRotationSteps() appropriately. Made all three functions
141 // inline (at end of this .hh file).
142 // Usage:
143 // G4Polyhedron::SetNumberOfRotationSteps
144 // (fpView -> GetViewParameters ().GetNoOfSides ());
145 // pPolyhedron = solid.CreatePolyhedron ();
146 // G4Polyhedron::ResetNumberOfRotationSteps ();
147 //
148 // 19.03.00 E.Chernyaev
149 // - added boolean operations (add, subtract, intersect) on polyhedra;
150 //
151 // 25.05.01 E.Chernyaev
152 // - added GetSurfaceArea() and GetVolume();
153 //
154 // 05.11.02 E.Chernyaev
155 // - added createTwistedTrap() and createPolyhedron();
156 //
157 // 06.03.05 J.Allison
158 // - added IsErrorBooleanProcess
159 //
160 // 20.06.05 G.Cosmo
161 // - added HepPolyhedronEllipsoid
162 //
163 // 21.10.09 J.Allison
164 // - removed IsErrorBooleanProcess (now error is returned through argument)
165 //
166 
167 #ifndef HEP_POLYHEDRON_HH
168 #define HEP_POLYHEDRON_HH
169 
170 #include "G4Types.hh"
171 #include "G4Point3D.hh"
172 #include "G4Normal3D.hh"
173 #include "G4Transform3D.hh"
174 
175 #ifndef DEFAULT_NUMBER_OF_STEPS
176 #define DEFAULT_NUMBER_OF_STEPS 24
177 #endif
178 
179 class G4Facet {
180  friend class HepPolyhedron;
181  friend std::ostream& operator<<(std::ostream&, const G4Facet &facet);
182 
183  private:
184  struct G4Edge { G4int v,f; };
186 
187  public:
189  G4int v3=0, G4int f3=0, G4int v4=0, G4int f4=0)
190  { edge[0].v=v1; edge[0].f=f1; edge[1].v=v2; edge[1].f=f2;
191  edge[2].v=v3; edge[2].f=f3; edge[3].v=v4; edge[3].f=f4; }
192 };
193 
195  friend std::ostream& operator<<(std::ostream&, const HepPolyhedron &ph);
196 
197  protected:
202 
203  // Re-allocate memory for HepPolyhedron
204  void AllocateMemory(G4int Nvert, G4int Nface);
205 
206  // Find neighbouring facet
207  G4int FindNeighbour(G4int iFace, G4int iNode, G4int iOrder) const;
208 
209  // Find normal at node
210  G4Normal3D FindNodeNormal(G4int iFace, G4int iNode) const;
211 
212  // Create HepPolyhedron for prism with quadrilateral base
213  void CreatePrism();
214 
215  // Generate facets by revolving an edge around Z-axis
217  G4int v1, G4int v2, G4int vEdge,
218  G4bool ifWholeCircle, G4int ns, G4int &kface);
219 
220  // Set side facets for the case of incomplete rotation
221  void SetSideFacets(G4int ii[4], G4int vv[4],
222  G4int *kk, G4double *r,
223  G4double dphi, G4int ns, G4int &kface);
224 
225  // Create HepPolyhedron for body of revolution around Z-axis
226  void RotateAroundZ(G4int nstep, G4double phi, G4double dphi,
227  G4int np1, G4int np2,
228  const G4double *z, G4double *r,
229  G4int nodeVis, G4int edgeVis);
230 
231  // For each edge set reference to neighbouring facet
232  void SetReferences();
233 
234  // Invert the order on nodes in facets
235  void InvertFacets();
236 
237  public:
238  // Constructor
239  HepPolyhedron() : nvert(0), nface(0), pV(0), pF(0) {}
240 
241  // Copy constructor
242  HepPolyhedron(const HepPolyhedron & from);
243 
244  // Move constructor
245  HepPolyhedron(HepPolyhedron && from);
246 
247  // Destructor
248  virtual ~HepPolyhedron() { delete [] pV; delete [] pF; }
249 
250  // Assignment
251  HepPolyhedron & operator=(const HepPolyhedron & from);
252 
253  // Move assignment
255 
256  // Get number of vertices
257  G4int GetNoVertices() const { return nvert; }
258  G4int GetNoVerteces() const { return nvert; } // Old spelling.
259 
260  // Get number of facets
261  G4int GetNoFacets() const { return nface; }
262 
263  // Transform the polyhedron
265 
266  // Get next vertex index of the quadrilateral
267  G4bool GetNextVertexIndex(G4int & index, G4int & edgeFlag) const;
268 
269  // Get vertex by index
270  G4Point3D GetVertex(G4int index) const;
271 
272  // Get next vertex + edge visibility of the quadrilateral
273  G4bool GetNextVertex(G4Point3D & vertex, G4int & edgeFlag) const;
274 
275  // Get next vertex + edge visibility + normal of the quadrilateral
276  G4bool GetNextVertex(G4Point3D & vertex, G4int & edgeFlag,
277  G4Normal3D & normal) const;
278 
279  // Get indices of the next edge with indices of the faces
280  G4bool GetNextEdgeIndices(G4int & i1, G4int & i2, G4int & edgeFlag,
281  G4int & iface1, G4int & iface2) const;
282  G4bool GetNextEdgeIndeces(G4int & i1, G4int & i2, G4int & edgeFlag,
283  G4int & iface1, G4int & iface2) const
284  {return GetNextEdgeIndices(i1,i2,edgeFlag,iface1,iface2);} // Old spelling
285 
286  // Get indices of the next edge
287  G4bool GetNextEdgeIndices(G4int & i1, G4int & i2, G4int & edgeFlag) const;
288  G4bool GetNextEdgeIndeces(G4int & i1, G4int & i2, G4int & edgeFlag) const
289  {return GetNextEdgeIndices(i1,i2,edgeFlag);} // Old spelling.
290 
291  // Get next edge
292  G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const;
293 
294  // Get next edge
295  G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag,
296  G4int &iface1, G4int &iface2) const;
297 
298  // Get face by index
299  void GetFacet(G4int iFace, G4int &n, G4int *iNodes,
300  G4int *edgeFlags = 0, G4int *iFaces = 0) const;
301 
302  // Get face by index
303  void GetFacet(G4int iFace, G4int &n, G4Point3D *nodes,
304  G4int *edgeFlags=0, G4Normal3D *normals=0) const;
305 
306  // Get next face with normals at the nodes
307  G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0,
308  G4Normal3D *normals=0) const;
309 
310  // Get normal of the face given by index
311  G4Normal3D GetNormal(G4int iFace) const;
312 
313  // Get unit normal of the face given by index
314  G4Normal3D GetUnitNormal(G4int iFace) const;
315 
316  // Get normal of the next face
318 
319  // Get normal of unit length of the next face
321 
322  // Boolean operations
323  HepPolyhedron add(const HepPolyhedron &p) const;
324  HepPolyhedron subtract(const HepPolyhedron &p) const;
325  HepPolyhedron intersect(const HepPolyhedron &p) const;
326 
327  // Get area of the surface of the polyhedron
328  G4double GetSurfaceArea() const;
329 
330  // Get volume of the polyhedron
331  G4double GetVolume() const;
332 
333  // Get number of steps for whole circle
335 
336  // Set number of steps for whole circle
337  static void SetNumberOfRotationSteps(G4int n);
338 
339  // Reset number of steps for whole circle to default value
340  static void ResetNumberOfRotationSteps();
341 
352  const G4double xy1[][2], const G4double xy2[][2]);
353 
371  G4int createPolyhedron(G4int Nnodes, G4int Nfaces,
372  const G4double xyz[][3], const G4int faces[][4]);
373 };
374 
376 {
377  public:
379  G4double Dy1, G4double Dy2, G4double Dz);
380  virtual ~HepPolyhedronTrd2();
381 };
382 
384 {
385  public:
388  virtual ~HepPolyhedronTrd1();
389 };
390 
392 {
393  public:
395  virtual ~HepPolyhedronBox();
396 };
397 
399 {
400  public:
402  G4double Dy1,
403  G4double Dx1, G4double Dx2, G4double Alp1,
404  G4double Dy2,
405  G4double Dx3, G4double Dx4, G4double Alp2);
406  virtual ~HepPolyhedronTrap();
407 };
408 
410 {
411  public:
413  G4double Alpha, G4double Theta, G4double Phi);
414  virtual ~HepPolyhedronPara();
415 };
416 
418 {
419  public:
421  G4double r2,
422  G4double dz,
423  G4double Phi1,
424  G4double Dphi);
425  virtual ~HepPolyhedronParaboloid();
426 };
427 
429 {
430  public:
432  G4double r2,
433  G4double tan1,
434  G4double tan2,
435  G4double halfZ);
436  virtual ~HepPolyhedronHype();
437 };
438 
440 {
441  public:
442  HepPolyhedronCons(G4double Rmn1, G4double Rmx1,
443  G4double Rmn2, G4double Rmx2, G4double Dz,
444  G4double Phi1, G4double Dphi);
445  virtual ~HepPolyhedronCons();
446 };
447 
449 {
450  public:
451  HepPolyhedronCone(G4double Rmn1, G4double Rmx1,
452  G4double Rmn2, G4double Rmx2, G4double Dz);
453  virtual ~HepPolyhedronCone();
454 };
455 
457 {
458  public:
460  G4double Phi1, G4double Dphi);
461  virtual ~HepPolyhedronTubs();
462 };
463 
465 {
466  public:
468  virtual ~HepPolyhedronTube();
469 };
470 
472 {
473  public:
475  const G4double *z,
476  const G4double *rmin,
477  const G4double *rmax);
478  virtual ~HepPolyhedronPgon();
479 };
480 
482 {
483  public:
485  const G4double *z,
486  const G4double *rmin,
487  const G4double *rmax);
488  virtual ~HepPolyhedronPcon();
489 };
490 
492 {
493  public:
495  G4double phi, G4double dphi,
496  G4double the, G4double dthe);
497  virtual ~HepPolyhedronSphere();
498 };
499 
501 {
502  public:
504  G4double phi, G4double dphi);
505  virtual ~HepPolyhedronTorus();
506 };
507 
509 {
510  public:
512  G4double zcut1, G4double zcut2);
513  virtual ~HepPolyhedronEllipsoid();
514 };
515 
517 {
518  public:
520  G4double zcut1);
522 };
523 
524 #endif /* HEP_POLYHEDRON_HH */