GeoModel - GeoModelCore
GeoPolyhedron.h
1 #ifndef GeoPolyhedron_h
2 #define GeoPolyhedron_h
3 //--------------------------------------------------------------------//
4 // JFB: //
5 // GeoPolyhedron was HepPolyhedron, retrofitted to GeoModel //
6 // infrastructure: //
7 //--------------------------------------------------------------------//
8 
9 
10 // ********************************************************************
11 // * DISCLAIMER *
12 // * *
13 // * The following disclaimer summarizes all the specific disclaimers *
14 // * of contributors to this software. The specific disclaimers,which *
15 // * govern, are listed with their locations in: *
16 // * http://cern.ch/geant4/license *
17 // * *
18 // * Neither the authors of this software system, nor their employing *
19 // * institutes,nor the agencies providing financial support for this *
20 // * work make any representation or warranty, express or implied, *
21 // * regarding this software system or assume any liability for its *
22 // * use. *
23 // * *
24 // * This code implementation is the intellectual property of the *
25 // * GEANT4 collaboration. *
26 // * By copying, distributing or modifying the Program (or any work *
27 // * based on the Program) you indicate your acceptance of this *
28 // * statement, and all its terms. *
29 // ********************************************************************
30 //
31 //
32 // Class Description:
33 // GeoPolyhedron is an intermediate class between description of a shape
34 // and visualization systems. It is intended to provide some service like:
35 // - polygonization of shapes with triangulization (quadrilaterization)
36 // of complex polygons;
37 // - calculation of normals for faces and vertices;
38 // - finding result of boolean operation on polyhedra;
39 //
40 // Public constructors:
41 //
42 // GeoPolyhedronBox (dx,dy,dz)
43 // - create polyhedron for Box;
44 // GeoPolyhedronTrd1 (dx1,dx2,dy,dz)
45 // - create polyhedron for G3 Trd1;
46 // GeoPolyhedronTrd2 (dx1,dx2,dy1,dy2,dz)
47 // - create polyhedron for G3 Trd2;
48 // GeoPolyhedronTrap (dz,theta,phi, h1,bl1,tl1,alp1, h2,bl2,tl2,alp2)
49 // - create polyhedron for G3 Trap;
50 // GeoPolyhedronPara (dx,dy,dz,alpha,theta,phi)
51 // - create polyhedron for G3 Para;
52 // GeoPolyhedronTube (rmin,rmax,dz)
53 // - create polyhedron for G3 Tube;
54 // GeoPolyhedronTubs (rmin,rmax,dz,phi1,dphi)
55 // - create polyhedron for G3 Tubs;
56 // GeoPolyhedronCone (rmin1,rmax1,rmin2,rmax2,dz)
57 // - create polyhedron for G3 Cone;
58 // GeoPolyhedronCons (rmin1,rmax1,rmin2,rmax2,dz,phi1,dphi)
59 // - create polyhedron for G3 Cons;
60 // GeoPolyhedronPgon (phi,dphi,npdv,nz, z(*),rmin(*),rmax(*))
61 // - create polyhedron for G3 Pgon;
62 // GeoPolyhedronPcon (phi,dphi,nz, z(*),rmin(*),rmax(*))
63 // - create polyhedron for G3 Pcon;
64 // GeoPolyhedronSphere (rmin,rmax,phi,dphi,the,dthe)
65 // - create polyhedron for Sphere;
66 // GeoPolyhedronTorus (rmin,rmax,rtor,phi,dphi)
67 // - create polyhedron for Torus;
68 // Public functions:
69 //
70 // GetNoVertices () - returns number of vertices;
71 // GetNoFacets () - returns number of faces;
72 // GetNextVertexIndex (index,edgeFlag) - get vertex indeces of the
73 // quadrilaterals in order;
74 // returns false when finished each face;
75 // GetVertex (index) - returns vertex by index;
76 // GetNextVertex (vertex,edgeFlag) - get vertices with edge visibility
77 // of the quadrilaterals in order;
78 // returns false when finished each face;
79 // GetNextVertex (vertex,edgeFlag,normal) - get vertices with edge
80 // visibility and normal of the quadrilaterals
81 // in order; returns false when finished each face;
82 // GetNextEdgeIndeces (i1,i2,edgeFlag) - get indeces of the next edge;
83 // returns false for the last edge;
84 // GetNextEdgeIndeces (i1,i2,edgeFlag,iface1,iface2) - get indeces of
85 // the next edge with indeces of the faces
86 // to which the edge belongs;
87 // returns false for the last edge;
88 // GetNextEdge (p1,p2,edgeFlag) - get next edge;
89 // returns false for the last edge;
90 // GetNextEdge (p1,p2,edgeFlag,iface1,iface2) - get next edge with indeces
91 // of the faces to which the edge belongs;
92 // returns false for the last edge;
93 // GetFacet (index,n,nodes,edgeFlags=0,normals=0) - get face by index;
94 // GetNextFacet (n,nodes,edgeFlags=0,normals=0) - get next face with normals
95 // at the nodes; returns false for the last face;
96 // GetNormal (index) - get normal of face given by index;
97 // GetUnitNormal (index) - get unit normal of face given by index;
98 // GetNextNormal (normal) - get normals of each face in order;
99 // returns false when finished all faces;
100 // GetNextUnitNormal (normal) - get normals of unit length of each face
101 // in order; returns false when finished all faces;
102 // GetSurfaceArea() - get surface area of the polyhedron;
103 // GetVolume() - get volume of the polyhedron;
104 // GetNumberOfRotationSteps() - get number of steps for whole circle;
105 // SetNumberOfRotationSteps (n) - set number of steps for whole circle;
106 // ResetNumberOfRotationSteps() - reset number of steps for whole circle
107 // to default value;
108 // History:
109 //
110 // 20.06.96 Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch> - initial version
111 //
112 // 23.07.96 John Allison
113 // - added GetNoVertices, GetNoFacets, GetNextVertex, GetNextNormal
114 //
115 // 30.09.96 E.Chernyaev
116 // - added GetNextVertexIndex, GetVertex by Yasuhide Sawada
117 // - added GetNextUnitNormal, GetNextEdgeIndeces, GetNextEdge
118 // - improvements: angles now expected in radians
119 // int -> G4int, double -> G4double
120 // - G4ThreeVector replaced by either G4Point3D or G4Normal3D
121 //
122 // 15.12.96 E.Chernyaev
123 // - private functions G4PolyhedronAlloc, G4PolyhedronPrism renamed
124 // to AllocateMemory and CreatePrism
125 // - added private functions GetNumberOfRotationSteps, RotateEdge,
126 // RotateAroundZ, SetReferences
127 // - rewritten G4PolyhedronCons;
128 // - added G4PolyhedronPara, ...Trap, ...Pgon, ...Pcon, ...Sphere, ...Torus,
129 // so full List of implemented shapes now looks like:
130 // BOX, TRD1, TRD2, TRAP, TUBE, TUBS, CONE, CONS, PARA, PGON, PCON,
131 // SPHERE, TORUS
132 //
133 // 01.06.97 E.Chernyaev
134 // - RotateAroundZ modified and SetSideFacets added to allow Rmin=Rmax
135 // in bodies of revolution
136 //
137 // 24.06.97 J.Allison
138 // - added static private member fNumberOfRotationSteps and static public
139 // functions void SetNumberOfRotationSteps (G4int n) and
140 // void ResetNumberOfRotationSteps (). Modified
141 // GetNumberOfRotationSteps() appropriately. Made all three functions
142 // inline (at end of this .hh file).
143 // Usage:
144 // G4Polyhedron::SetNumberOfRotationSteps
145 // (fpView -> GetViewParameters ().GetNoOfSides ());
146 // pPolyhedron = solid.CreatePolyhedron ();
147 // G4Polyhedron::ResetNumberOfRotationSteps ();
148 //
149 // 19.03.00 E.Chernyaev
150 // - added boolean operations (add, subtract, intersect) on polyhedra;
151 //
152 // 25.05.01 E.Chernyaev
153 // - added GetSurfaceArea() and GetVolume();
154 //
155 #include "GeoModelKernel/GeoDefinitions.h"
156 #include <iostream>
157 
158 #ifndef DEFAULT_NUMBER_OF_STEPS
159 #define DEFAULT_NUMBER_OF_STEPS 24
160 #endif
161 
162 class GeoFacet
163 {
164  friend class GeoPolyhedron;
165  friend std::ostream & operator<< (std::ostream &, const GeoFacet & facet);
166 
167 private:
168  struct
169  {
170  int v, f;
171  }
172  m_edge[4];
173 
174 public:
175  GeoFacet (int v1 = 0, int f1 = 0, int v2 = 0, int f2 = 0,
176  int v3 = 0, int f3 = 0, int v4 = 0, int f4 = 0)
177  {
178  m_edge[0].v = v1;
179  m_edge[0].f = f1;
180  m_edge[1].v = v2;
181  m_edge[1].f = f2;
182  m_edge[2].v = v3;
183  m_edge[2].f = f3;
184  m_edge[3].v = v4;
185  m_edge[3].f = f4;
186  }
187 };
188 
190 {
191  friend std::ostream & operator<< (std::ostream &, const GeoPolyhedron & ph);
192 
193 private:
194  static int s_fNumberOfRotationSteps;
195 
196 protected:
197  int m_nvert, m_nface;
198  GeoTrf::Vector3D *m_pV;
199  GeoFacet *m_pF;
200 
201  // Allocate memory for GeoPolyhedron
202  void AllocateMemory (int Nvert, int Nface);
203 
204  // Find neighbouring facet
205  int FindNeighbour (int iFace, int iNode, int iOrder) const;
206 
207  // Find normal at node
208  GeoTrf::Vector3D FindNodeNormal (int iFace, int iNode) const;
209 
210  // Create GeoPolyhedron for prism with quadrilateral base
211  void CreatePrism ();
212 
213  // Generate facets by revolving an edge around Z-axis
214  void RotateEdge (int k1, int k2, double r1, double r2,
215  int v1, int v2, int vEdge,
216  bool ifWholeCircle, int ns, int &kface);
217 
218  // Set side facets for the case of incomplete rotation
219  void SetSideFacets (int ii[4], int vv[4],
220  int *kk, double *r, double dphi, int ns, int &kface);
221 
222  // Create GeoPolyhedron for body of revolution around Z-axis
223  void RotateAroundZ (int nstep, double phi, double dphi,
224  int np1, int np2,
225  const double *z, double *r, int nodeVis, int edgeVis);
226 
227  // For each edge set reference to neighbouring facet
228  void SetReferences ();
229 
230  // Invert the order on nodes in facets
231  void InvertFacets ();
232 
233 public:
234  // Constructor
235  GeoPolyhedron (int Nvert = 0, int Nface = 0):m_nvert (Nvert), m_nface (Nface),
236  m_pV (Nvert ? new GeoTrf::Vector3D[Nvert + 1] : 0),
237  m_pF (Nface ? new GeoFacet[Nface + 1] : 0)
238  {
239  }
240 
241  // Copy constructor
242  GeoPolyhedron (const GeoPolyhedron & from);
243 
244  // Destructor
245  virtual ~ GeoPolyhedron ()
246  {
247  delete[]m_pV;
248  delete[]m_pF;
249  }
250 
251  // Assignment
252  virtual GeoPolyhedron & operator= (const GeoPolyhedron & from);
253 
254  // Get number of vertices
255  int GetNoVertices () const
256  {
257  return m_nvert;
258  }
259 
260  // Get number of facets
261  int GetNoFacets () const
262  {
263  return m_nface;
264  }
265 
266  // Transform the polyhedron
267  GeoPolyhedron & Transform (const GeoTrf::RotationMatrix3D & rot,
268  const GeoTrf::Vector3D & trans);
269 
270  // Get next vertex index of the quadrilateral
271  bool GetNextVertexIndex (int &index, int &edgeFlag) const;
272 
273  // Get vertex by index
274  GeoTrf::Vector3D GetVertex (int index) const;
275 
276  // Get next vertex + edge visibility of the quadrilateral
277  bool GetNextVertex (GeoTrf::Vector3D & vertex, int &edgeFlag) const;
278 
279  // Get next vertex + edge visibility + normal of the quadrilateral
280  bool GetNextVertex (GeoTrf::Vector3D & vertex, int &edgeFlag,
281  GeoTrf::Vector3D & normal) const;
282 
283  // Get indeces of the next edge with indeces of the faces
284  bool GetNextEdgeIndeces (int &i1, int &i2, int &edgeFlag,
285  int &iface1, int &iface2) const;
286 
287  // Get indeces of the next edge
288  bool GetNextEdgeIndeces (int &i1, int &i2, int &edgeFlag) const;
289 
290  // Get next edge
291  bool GetNextEdge (GeoTrf::Vector3D & p1, GeoTrf::Vector3D & p2, int &edgeFlag) const;
292 
293  // Get next edge
294  bool GetNextEdge (GeoTrf::Vector3D & p1, GeoTrf::Vector3D & p2, int &edgeFlag,
295  int &iface1, int &iface2) const;
296 
297  // Get face by index
298  void GetFacet (int iFace, int &n, int *iNodes,
299  int *edgeFlags = 0, int *iFaces = 0) const;
300 
301  // Get face by index
302  void GetFacet (int iFace, int &n, GeoTrf::Vector3D * nodes,
303  int *edgeFlags = 0, GeoTrf::Vector3D * normals = 0) const;
304 
305  // Get next face with normals at the nodes
306  bool GetNextFacet (int &n, GeoTrf::Vector3D * nodes,
307  int *edgeFlags = 0, GeoTrf::Vector3D * normals = 0) const;
308 
309  // Get normal of the face given by index
310  GeoTrf::Vector3D GetNormal (int iFace) const;
311 
312  // Get unit normal of the face given by index
313  GeoTrf::Vector3D GetUnitNormal (int iFace) const;
314 
315  // Get normal of the next face
316  bool GetNextNormal (GeoTrf::Vector3D & normal) const;
317 
318  // Get normal of unit length of the next face
319  bool GetNextUnitNormal (GeoTrf::Vector3D & normal) const;
320 
321  // Boolean operations
322  GeoPolyhedron add (const GeoPolyhedron & p) const;
323  GeoPolyhedron subtract (const GeoPolyhedron & p) const;
324  GeoPolyhedron intersect (const GeoPolyhedron & p) const;
325 
326  // Get area of the surface of the polyhedron
327  double GetSurfaceArea () const;
328 
329  // Get volume of the polyhedron
330  double GetVolume () const;
331 
332  // Get number of steps for whole circle
333  static int GetNumberOfRotationSteps ()
334  {
335  return s_fNumberOfRotationSteps;
336  }
337 
338  // Set number of steps for whole circle
339  static void SetNumberOfRotationSteps (int n);
340 
341  // Reset number of steps for whole circle to default value
342  static void ResetNumberOfRotationSteps ()
343  {
344  s_fNumberOfRotationSteps = DEFAULT_NUMBER_OF_STEPS;
345  }
346 
347 
348 
349 };
350 
352 {
353 public:
354  GeoPolyhedronTrd2 (double Dx1, double Dx2,
355  double Dy1, double Dy2, double Dz);
356  virtual ~ GeoPolyhedronTrd2 ();
357  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
358  {
359  return GeoPolyhedron::operator = (from);
360  }
361 };
362 
364 {
365 public:
366  GeoPolyhedronTrd1 (double Dx1, double Dx2, double Dy, double Dz);
367  virtual ~ GeoPolyhedronTrd1 ();
368  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
369  {
370  return GeoPolyhedron::operator = (from);
371  }
372 };
373 
375 {
376 public:
377  GeoPolyhedronBox (double Dx, double Dy, double Dz);
378  virtual ~ GeoPolyhedronBox ();
379  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
380  {
381  return GeoPolyhedron::operator = (from);
382  }
383 };
384 
386 {
387 public:
388  GeoPolyhedronTrap (double Dz, double Theta, double Phi,
389  double Dy1,
390  double Dx1, double Dx2, double Alp1,
391  double Dy2, double Dx3, double Dx4, double Alp2);
392  virtual ~ GeoPolyhedronTrap ();
393  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
394  {
395  return GeoPolyhedron::operator = (from);
396  }
397 };
398 
400 {
401 public:
402  GeoPolyhedronPara (double Dx, double Dy, double Dz,
403  double Alpha, double Theta, double Phi);
404  virtual ~ GeoPolyhedronPara ();
405  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
406  {
407  return GeoPolyhedron::operator = (from);
408  }
409 };
410 
412 {
413 public:
414  GeoPolyhedronCons (double Rmn1, double Rmx1,
415  double Rmn2, double Rmx2, double Dz,
416  double Phi1, double Dphi);
417  virtual ~ GeoPolyhedronCons ();
418  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
419  {
420  return GeoPolyhedron::operator = (from);
421  }
422 };
423 
425 {
426 public:
427  GeoPolyhedronCone (double Rmn1, double Rmx1,
428  double Rmn2, double Rmx2, double Dz);
429  virtual ~ GeoPolyhedronCone ();
430  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
431  {
432  return GeoPolyhedron::operator = (from);
433  }
434 };
435 
437 {
438 public:
439  GeoPolyhedronTubs (double Rmin, double Rmax, double Dz,
440  double Phi1, double Dphi);
441  virtual ~ GeoPolyhedronTubs ();
442  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
443  {
444  return GeoPolyhedron::operator = (from);
445  }
446 };
447 
449 {
450 public:
451  GeoPolyhedronTube (double Rmin, double Rmax, double Dz);
452  virtual ~ GeoPolyhedronTube ();
453  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
454  {
455  return GeoPolyhedron::operator = (from);
456  }
457 };
458 
460 {
461 public:
462  GeoPolyhedronPgon (double phi, double dphi, int npdv, int nz,
463  const double *z, const double *rmin, const double *rmax);
464  virtual ~ GeoPolyhedronPgon ();
465  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
466  {
467  return GeoPolyhedron::operator = (from);
468  }
469 };
470 
472 {
473 public:
474  GeoPolyhedronPcon (double phi, double dphi, int nz,
475  const double *z, const double *rmin, const double *rmax);
476  virtual ~ GeoPolyhedronPcon ();
477  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
478  {
479  return GeoPolyhedron::operator = (from);
480  }
481 };
482 
484 {
485 public:
486  GeoPolyhedronSphere (double rmin, double rmax,
487  double phi, double dphi, double the, double dthe);
488  virtual ~ GeoPolyhedronSphere ();
489  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
490  {
491  return GeoPolyhedron::operator = (from);
492  }
493 };
494 
496 {
497 public:
498  GeoPolyhedronTorus (double rmin, double rmax, double rtor,
499  double phi, double dphi);
500  virtual ~ GeoPolyhedronTorus ();
501  virtual GeoPolyhedron & operator = (const GeoPolyhedron & from)
502  {
503  return GeoPolyhedron::operator = (from);
504  }
505 };
506 
507 
508 #endif
Base class for GeoModel Facets Two implementations exist:
Definition: GeoFacet.h:24