Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // Class Description: 26 // Class Description: 27 // HepPolyhedron is an intermediate class betw 27 // HepPolyhedron is an intermediate class between description of a shape 28 // and visualization systems. It is intended t 28 // and visualization systems. It is intended to provide some service like: 29 // - polygonization of shapes with trianguli 29 // - polygonization of shapes with triangulization (quadrilaterization) 30 // of complex polygons; 30 // of complex polygons; 31 // - calculation of normals for faces and ve 31 // - calculation of normals for faces and vertices; 32 // - finding result of boolean operation on 32 // - finding result of boolean operation on polyhedra; 33 // 33 // 34 // Public constructors: 34 // Public constructors: 35 // 35 // 36 // HepPolyhedronBox (dx,dy,dz) 36 // HepPolyhedronBox (dx,dy,dz) 37 // - cr 37 // - create polyhedron for Box; 38 // HepPolyhedronTrd1 (dx1,dx2,dy,dz) 38 // HepPolyhedronTrd1 (dx1,dx2,dy,dz) 39 // - cr 39 // - create polyhedron for Trd1; 40 // HepPolyhedronTrd2 (dx1,dx2,dy1,dy2,dz) 40 // HepPolyhedronTrd2 (dx1,dx2,dy1,dy2,dz) 41 // - cr 41 // - create polyhedron for Trd2; 42 // HepPolyhedronTrap (dz,theta,phi, h1,bl1,t 42 // HepPolyhedronTrap (dz,theta,phi, h1,bl1,tl1,alp1, h2,bl2,tl2,alp2) 43 // - cr 43 // - create polyhedron for Trap; 44 // HepPolyhedronPara (dx,dy,dz,alpha,theta,p 44 // HepPolyhedronPara (dx,dy,dz,alpha,theta,phi) 45 // - cr 45 // - create polyhedron for Para; 46 // HepPolyhedronTube (rmin,rmax,dz) 46 // HepPolyhedronTube (rmin,rmax,dz) 47 // - cr 47 // - create polyhedron for Tube; 48 // HepPolyhedronTubs (rmin,rmax,dz,phi1,dphi 48 // HepPolyhedronTubs (rmin,rmax,dz,phi1,dphi) 49 // - cr 49 // - create polyhedron for Tubs; 50 // HepPolyhedronCone (rmin1,rmax1,rmin2,rmax 50 // HepPolyhedronCone (rmin1,rmax1,rmin2,rmax2,dz) 51 // - cr 51 // - create polyhedron for Cone; 52 // HepPolyhedronCons (rmin1,rmax1,rmin2,rmax 52 // HepPolyhedronCons (rmin1,rmax1,rmin2,rmax2,dz,phi1,dphi) 53 // - cr 53 // - create polyhedron for Cons; 54 // HepPolyhedronPgon (phi,dphi,npdv,nz, z(*) 54 // HepPolyhedronPgon (phi,dphi,npdv,nz, z(*),rmin(*),rmax(*)) 55 // - cr 55 // - create polyhedron for Pgon; 56 // HepPolyhedronPcon (phi,dphi,nz, z(*),rmin 56 // HepPolyhedronPcon (phi,dphi,nz, z(*),rmin(*),rmax(*)) 57 // - cr 57 // - create polyhedron for Pcon; 58 // HepPolyhedronSphere (rmin,rmax,phi,dphi,t 58 // HepPolyhedronSphere (rmin,rmax,phi,dphi,the,dthe) 59 // - cr 59 // - create polyhedron for Sphere; 60 // HepPolyhedronTorus (rmin,rmax,rtor,phi,dp 60 // HepPolyhedronTorus (rmin,rmax,rtor,phi,dphi) 61 // - cr 61 // - create polyhedron for Torus; 62 // HepPolyhedronTet (p0[3],p1[3],p2[3],p3[3] 62 // HepPolyhedronTet (p0[3],p1[3],p2[3],p3[3]) 63 // - cr 63 // - create polyhedron for Tet; 64 // HepPolyhedronEllipsoid (dx,dy,dz,zcut1,zc 64 // HepPolyhedronEllipsoid (dx,dy,dz,zcut1,zcut2) 65 // - cr 65 // - create polyhedron for Ellipsoid; 66 // HepPolyhedronEllipticalCone(dx,dy,z,zcut1 66 // HepPolyhedronEllipticalCone(dx,dy,z,zcut1) 67 // - cr 67 // - create polyhedron for Elliptical cone; 68 // HepPolyhedronParaboloid (r1,r2,dz,phi,dph 68 // HepPolyhedronParaboloid (r1,r2,dz,phi,dphi) 69 // - cr 69 // - create polyhedron for Paraboloid; 70 // HepPolyhedronHype (r1,r2,tan1,tan2,halfz) 70 // HepPolyhedronHype (r1,r2,tan1,tan2,halfz) 71 // - cr 71 // - create polyhedron for Hype; 72 // HepPolyhedronHyperbolicMirror (a,h,r) 72 // HepPolyhedronHyperbolicMirror (a,h,r) 73 // - cr 73 // - create polyhedron for Hyperbolic mirror; 74 // HepPolyhedronTetMesh (vector<p>) 74 // HepPolyhedronTetMesh (vector<p>) 75 // - cr 75 // - create polyhedron for tetrahedron mesh; 76 // HepPolyhedronBoxMesh (sx,sy,sz,vector<p>) 76 // HepPolyhedronBoxMesh (sx,sy,sz,vector<p>) 77 // - cr 77 // - create polyhedron for box mesh; 78 // Public functions: 78 // Public functions: 79 // 79 // 80 // GetNoVertices () - returns number o 80 // GetNoVertices () - returns number of vertices; 81 // GetNoFacets () - returns number o 81 // GetNoFacets () - returns number of faces; 82 // GetNextVertexIndex (index,edgeFlag) - get 82 // GetNextVertexIndex (index,edgeFlag) - get vertex indices of the 83 // quadrilaterals i 83 // quadrilaterals in order; 84 // returns false wh 84 // returns false when finished each face; 85 // GetVertex (index) - returns vertex b 85 // GetVertex (index) - returns vertex by index; 86 // GetNextVertex (vertex,edgeFlag) - get ver 86 // GetNextVertex (vertex,edgeFlag) - get vertices with edge visibility 87 // of the quadrilat 87 // of the quadrilaterals in order; 88 // returns false wh 88 // returns false when finished each face; 89 // GetNextVertex (vertex,edgeFlag,normal) - 89 // GetNextVertex (vertex,edgeFlag,normal) - get vertices with edge 90 // visibility and n 90 // visibility and normal of the quadrilaterals 91 // in order; return 91 // in order; returns false when finished each face; 92 // GetNextEdgeIndices (i1,i2,edgeFlag) - get 92 // GetNextEdgeIndices (i1,i2,edgeFlag) - get indices of the next edge; 93 // returns false fo 93 // returns false for the last edge; 94 // GetNextEdgeIndices (i1,i2,edgeFlag,iface1 94 // GetNextEdgeIndices (i1,i2,edgeFlag,iface1,iface2) - get indices of 95 // the next edge wi 95 // the next edge with indices of the faces 96 // to which the edg 96 // to which the edge belongs; 97 // returns false fo 97 // returns false for the last edge; 98 // GetNextEdge (p1,p2,edgeFlag) - get next e 98 // GetNextEdge (p1,p2,edgeFlag) - get next edge; 99 // returns false fo 99 // returns false for the last edge; 100 // GetNextEdge (p1,p2,edgeFlag,iface1,iface2 100 // GetNextEdge (p1,p2,edgeFlag,iface1,iface2) - get next edge with indices 101 // of the faces to 101 // of the faces to which the edge belongs; 102 // returns false fo 102 // returns false for the last edge; 103 // GetFacet (index,n,nodes,edgeFlags=0,norma 103 // GetFacet (index,n,nodes,edgeFlags=0,normals=0) - get face by index; 104 // GetNextFacet (n,nodes,edgeFlags=0,normals 104 // GetNextFacet (n,nodes,edgeFlags=0,normals=0) - get next face with normals 105 // at the nodes; re 105 // at the nodes; returns false for the last face; 106 // GetNormal (index) - get normal of fa 106 // GetNormal (index) - get normal of face given by index; 107 // GetUnitNormal (index) - get unit normal 107 // GetUnitNormal (index) - get unit normal of face given by index; 108 // GetNextNormal (normal) - get normals of e 108 // GetNextNormal (normal) - get normals of each face in order; 109 // returns false wh 109 // returns false when finished all faces; 110 // GetNextUnitNormal (normal) - get normals 110 // GetNextUnitNormal (normal) - get normals of unit length of each face 111 // in order; return 111 // in order; returns false when finished all faces; 112 // GetSurfaceArea() - get surface area 112 // GetSurfaceArea() - get surface area of the polyhedron; 113 // GetVolume() - get volume of th 113 // GetVolume() - get volume of the polyhedron; 114 // GetNumberOfRotationSteps() - get number o 114 // GetNumberOfRotationSteps() - get number of steps for whole circle; 115 // SetVertex(index, v) - set vertex; 115 // SetVertex(index, v) - set vertex; 116 // SetFacet(index,iv1,iv2,iv3,iv4) - set fac 116 // SetFacet(index,iv1,iv2,iv3,iv4) - set facet; 117 // SetReferences() - set references t 117 // SetReferences() - set references to neighbouring facets; 118 // JoinCoplanarFacets(tolerance) - join copl 118 // JoinCoplanarFacets(tolerance) - join coplanar facets where it is possible 119 // InvertFacets() - invert the order 119 // InvertFacets() - invert the order on nodes in facets; 120 // SetNumberOfRotationSteps (n) - set number 120 // SetNumberOfRotationSteps (n) - set number of steps for whole circle; 121 // ResetNumberOfRotationSteps() - reset numb 121 // ResetNumberOfRotationSteps() - reset number of steps for whole circle 122 // to default value 122 // to default value; 123 // History: 123 // History: 124 // 124 // 125 // 20.06.96 Evgeni Chernyaev <Evgueni.Tchernia 125 // 20.06.96 Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch> - initial version 126 // 126 // 127 // 23.07.96 John Allison 127 // 23.07.96 John Allison 128 // - added GetNoVertices, GetNoFacets, GetNext 128 // - added GetNoVertices, GetNoFacets, GetNextVertex, GetNextNormal 129 // 129 // 130 // 30.09.96 E.Chernyaev 130 // 30.09.96 E.Chernyaev 131 // - added GetNextVertexIndex, GetVertex by Ya 131 // - added GetNextVertexIndex, GetVertex by Yasuhide Sawada 132 // - added GetNextUnitNormal, GetNextEdgeIndic 132 // - added GetNextUnitNormal, GetNextEdgeIndices, GetNextEdge 133 // - improvements: angles now expected in radi 133 // - improvements: angles now expected in radians 134 // int -> G4int, double -> G4d 134 // int -> G4int, double -> G4double 135 // - G4ThreeVector replaced by either G4Point3 135 // - G4ThreeVector replaced by either G4Point3D or G4Normal3D 136 // 136 // 137 // 15.12.96 E.Chernyaev 137 // 15.12.96 E.Chernyaev 138 // - private functions G4PolyhedronAlloc, G4Po 138 // - private functions G4PolyhedronAlloc, G4PolyhedronPrism renamed 139 // to AllocateMemory and CreatePrism 139 // to AllocateMemory and CreatePrism 140 // - added private functions GetNumberOfRotati 140 // - added private functions GetNumberOfRotationSteps, RotateEdge, 141 // RotateAroundZ, SetReferences 141 // RotateAroundZ, SetReferences 142 // - rewritten G4PolyhedronCons; 142 // - rewritten G4PolyhedronCons; 143 // - added G4PolyhedronPara, ...Trap, ...Pgon, 143 // - added G4PolyhedronPara, ...Trap, ...Pgon, ...Pcon, ...Sphere, ...Torus, 144 // so full List of implemented shapes now lo 144 // so full List of implemented shapes now looks like: 145 // BOX, TRD1, TRD2, TRAP, TUBE, TUBS, CONE, 145 // BOX, TRD1, TRD2, TRAP, TUBE, TUBS, CONE, CONS, PARA, PGON, PCON, 146 // SPHERE, TORUS 146 // SPHERE, TORUS 147 // 147 // 148 // 01.06.97 E.Chernyaev 148 // 01.06.97 E.Chernyaev 149 // - RotateAroundZ modified and SetSideFacets 149 // - RotateAroundZ modified and SetSideFacets added to allow Rmin=Rmax 150 // in bodies of revolution 150 // in bodies of revolution 151 // 151 // 152 // 24.06.97 J.Allison 152 // 24.06.97 J.Allison 153 // - added static private member fNumberOfRota 153 // - added static private member fNumberOfRotationSteps and static public 154 // functions void SetNumberOfRotationSteps ( 154 // functions void SetNumberOfRotationSteps (G4int n) and 155 // void ResetNumberOfRotationSteps (). Modi 155 // void ResetNumberOfRotationSteps (). Modified 156 // GetNumberOfRotationSteps() appropriately. 156 // GetNumberOfRotationSteps() appropriately. Made all three functions 157 // inline (at end of this .hh file). 157 // inline (at end of this .hh file). 158 // Usage: 158 // Usage: 159 // G4Polyhedron::SetNumberOfRotationSteps 159 // G4Polyhedron::SetNumberOfRotationSteps 160 // (fpView -> GetViewParameters ().GetNoOf 160 // (fpView -> GetViewParameters ().GetNoOfSides ()); 161 // pPolyhedron = solid.CreatePolyhedron (); 161 // pPolyhedron = solid.CreatePolyhedron (); 162 // G4Polyhedron::ResetNumberOfRotationSteps 162 // G4Polyhedron::ResetNumberOfRotationSteps (); 163 // 163 // 164 // 19.03.00 E.Chernyaev 164 // 19.03.00 E.Chernyaev 165 // - added boolean operations (add, subtract, 165 // - added boolean operations (add, subtract, intersect) on polyhedra; 166 // 166 // 167 // 25.05.01 E.Chernyaev 167 // 25.05.01 E.Chernyaev 168 // - added GetSurfaceArea() and GetVolume(); 168 // - added GetSurfaceArea() and GetVolume(); 169 // 169 // 170 // 05.11.02 E.Chernyaev 170 // 05.11.02 E.Chernyaev 171 // - added createTwistedTrap() and createPolyh 171 // - added createTwistedTrap() and createPolyhedron(); 172 // 172 // 173 // 06.03.05 J.Allison 173 // 06.03.05 J.Allison 174 // - added IsErrorBooleanProcess 174 // - added IsErrorBooleanProcess 175 // 175 // 176 // 20.06.05 G.Cosmo 176 // 20.06.05 G.Cosmo 177 // - added HepPolyhedronEllipsoid 177 // - added HepPolyhedronEllipsoid 178 // 178 // 179 // 18.07.07 T.Nikitina 179 // 18.07.07 T.Nikitina 180 // - added HepPolyhedronParaboloid; 180 // - added HepPolyhedronParaboloid; 181 // 181 // 182 // 21.10.09 J.Allison 182 // 21.10.09 J.Allison 183 // - removed IsErrorBooleanProcess (now error 183 // - removed IsErrorBooleanProcess (now error is returned through argument) 184 // 184 // 185 // 22.02.20 E.Chernyaev 185 // 22.02.20 E.Chernyaev 186 // - added HepPolyhedronTet, HepPolyhedronHybe 186 // - added HepPolyhedronTet, HepPolyhedronHyberbolicMirror 187 // 187 // 188 // 12.05.21 E.Chernyaev 188 // 12.05.21 E.Chernyaev 189 // - added TriangulatePolygon(), RotateContour 189 // - added TriangulatePolygon(), RotateContourAroundZ() 190 // - added HepPolyhedronPgon, HepPolyhedronPco 190 // - added HepPolyhedronPgon, HepPolyhedronPcon given by rz-countour 191 // 191 // 192 // 26.03.22 E.Chernyaev 192 // 26.03.22 E.Chernyaev 193 // - added HepPolyhedronTetMesh 193 // - added HepPolyhedronTetMesh 194 // 194 // 195 // 04.04.22 E.Chernyaev 195 // 04.04.22 E.Chernyaev 196 // - added JoinCoplanarFacets() 196 // - added JoinCoplanarFacets() 197 // 197 // 198 // 07.04.22 E.Chernyaev 198 // 07.04.22 E.Chernyaev 199 // - added HepPolyhedronBoxMesh 199 // - added HepPolyhedronBoxMesh 200 200 201 #ifndef HEP_POLYHEDRON_HH 201 #ifndef HEP_POLYHEDRON_HH 202 #define HEP_POLYHEDRON_HH 202 #define HEP_POLYHEDRON_HH 203 203 204 #include <vector> 204 #include <vector> 205 #include "G4Types.hh" 205 #include "G4Types.hh" 206 #include "G4TwoVector.hh" 206 #include "G4TwoVector.hh" 207 #include "G4ThreeVector.hh" 207 #include "G4ThreeVector.hh" 208 #include "G4Point3D.hh" 208 #include "G4Point3D.hh" 209 #include "G4Normal3D.hh" 209 #include "G4Normal3D.hh" 210 #include "G4Transform3D.hh" 210 #include "G4Transform3D.hh" 211 211 212 #ifndef DEFAULT_NUMBER_OF_STEPS 212 #ifndef DEFAULT_NUMBER_OF_STEPS 213 #define DEFAULT_NUMBER_OF_STEPS 24 213 #define DEFAULT_NUMBER_OF_STEPS 24 214 #endif 214 #endif 215 215 216 class G4Facet { 216 class G4Facet { 217 friend class HepPolyhedron; 217 friend class HepPolyhedron; 218 friend std::ostream& operator<<(std::ostream 218 friend std::ostream& operator<<(std::ostream&, const G4Facet &facet); 219 219 220 private: 220 private: 221 struct G4Edge { G4int v,f; }; 221 struct G4Edge { G4int v,f; }; 222 G4Edge edge[4]; 222 G4Edge edge[4]; 223 223 224 public: 224 public: 225 G4Facet(G4int v1=0, G4int f1=0, G4int v2=0, 225 G4Facet(G4int v1=0, G4int f1=0, G4int v2=0, G4int f2=0, 226 G4int v3=0, G4int f3=0, G4int v4=0, 226 G4int v3=0, G4int f3=0, G4int v4=0, G4int f4=0) 227 { edge[0].v=v1; edge[0].f=f1; edge[1].v=v2; 227 { edge[0].v=v1; edge[0].f=f1; edge[1].v=v2; edge[1].f=f2; 228 edge[2].v=v3; edge[2].f=f3; edge[3].v=v4; 228 edge[2].v=v3; edge[2].f=f3; edge[3].v=v4; edge[3].f=f4; } 229 }; 229 }; 230 230 231 class HepPolyhedron { 231 class HepPolyhedron { 232 friend std::ostream& operator<<(std::ostream 232 friend std::ostream& operator<<(std::ostream&, const HepPolyhedron &ph); 233 233 234 protected: 234 protected: 235 static G4ThreadLocal G4int fNumberOfRotation 235 static G4ThreadLocal G4int fNumberOfRotationSteps; 236 G4int nvert, nface; 236 G4int nvert, nface; 237 G4Point3D *pV; 237 G4Point3D *pV; 238 G4Facet *pF; 238 G4Facet *pF; 239 239 240 // Re-allocate memory for HepPolyhedron 240 // Re-allocate memory for HepPolyhedron 241 void AllocateMemory(G4int Nvert, G4int Nface 241 void AllocateMemory(G4int Nvert, G4int Nface); 242 242 243 // Find neighbouring facet 243 // Find neighbouring facet 244 G4int FindNeighbour(G4int iFace, G4int iNode 244 G4int FindNeighbour(G4int iFace, G4int iNode, G4int iOrder) const; 245 245 246 // Find normal at node 246 // Find normal at node 247 G4Normal3D FindNodeNormal(G4int iFace, G4int 247 G4Normal3D FindNodeNormal(G4int iFace, G4int iNode) const; 248 248 249 // Create HepPolyhedron for prism with quadr 249 // Create HepPolyhedron for prism with quadrilateral base 250 void CreatePrism(); 250 void CreatePrism(); 251 251 252 // Generate facets by revolving an edge arou 252 // Generate facets by revolving an edge around Z-axis 253 void RotateEdge(G4int k1, G4int k2, G4double 253 void RotateEdge(G4int k1, G4int k2, G4double r1, G4double r2, 254 G4int v1, G4int v2, G4int vE 254 G4int v1, G4int v2, G4int vEdge, 255 G4bool ifWholeCircle, G4int 255 G4bool ifWholeCircle, G4int ns, G4int &kface); 256 256 257 // Set side facets for the case of incomplet 257 // Set side facets for the case of incomplete rotation 258 void SetSideFacets(G4int ii[4], G4int vv[4], 258 void SetSideFacets(G4int ii[4], G4int vv[4], 259 G4int *kk, G4double *r, 259 G4int *kk, G4double *r, 260 G4double dphi, G4int ns, 260 G4double dphi, G4int ns, G4int &kface); 261 261 262 // Create HepPolyhedron for body of revoluti 262 // Create HepPolyhedron for body of revolution around Z-axis 263 void RotateAroundZ(G4int nstep, G4double phi 263 void RotateAroundZ(G4int nstep, G4double phi, G4double dphi, 264 G4int np1, G4int np2, 264 G4int np1, G4int np2, 265 const G4double *z, G4doub 265 const G4double *z, G4double *r, 266 G4int nodeVis, G4int edge 266 G4int nodeVis, G4int edgeVis); 267 267 268 // Create HepPolyhedron for body of revoluti 268 // Create HepPolyhedron for body of revolution around Z-axis 269 void RotateContourAroundZ(G4int nstep, G4dou 269 void RotateContourAroundZ(G4int nstep, G4double phi, G4double dphi, 270 const std::vector< 270 const std::vector<G4TwoVector> &rz, 271 G4int nodeVis, G4i 271 G4int nodeVis, G4int edgeVis); 272 272 273 // Triangulate closed polygon (contour) 273 // Triangulate closed polygon (contour) 274 G4bool TriangulatePolygon(const std::vector< 274 G4bool TriangulatePolygon(const std::vector<G4TwoVector> &polygon, 275 std::vector<G4int> 275 std::vector<G4int> &result); 276 276 277 // Helper function for TriangulatePolygon() 277 // Helper function for TriangulatePolygon() 278 G4bool CheckSnip(const std::vector<G4TwoVect 278 G4bool CheckSnip(const std::vector<G4TwoVector> &contour, 279 G4int a, G4int b, G4int c, 279 G4int a, G4int b, G4int c, 280 G4int n, const G4int* V); 280 G4int n, const G4int* V); 281 281 282 public: 282 public: 283 // Default constructor 283 // Default constructor 284 HepPolyhedron() : nvert(0), nface(0), pV(nul 284 HepPolyhedron() : nvert(0), nface(0), pV(nullptr), pF(nullptr) {} 285 285 286 // Constructor with allocation of memory 286 // Constructor with allocation of memory 287 HepPolyhedron(G4int Nvert, G4int Nface); 287 HepPolyhedron(G4int Nvert, G4int Nface); 288 288 289 // Copy constructor 289 // Copy constructor 290 HepPolyhedron(const HepPolyhedron & from); 290 HepPolyhedron(const HepPolyhedron & from); 291 291 292 // Move constructor 292 // Move constructor 293 HepPolyhedron(HepPolyhedron && from); 293 HepPolyhedron(HepPolyhedron && from); 294 294 295 // Destructor 295 // Destructor 296 virtual ~HepPolyhedron() { delete [] pV; del 296 virtual ~HepPolyhedron() { delete [] pV; delete [] pF; } 297 297 298 // Assignment 298 // Assignment 299 HepPolyhedron & operator=(const HepPolyhedro 299 HepPolyhedron & operator=(const HepPolyhedron & from); 300 300 301 // Move assignment 301 // Move assignment 302 HepPolyhedron & operator=(HepPolyhedron && f 302 HepPolyhedron & operator=(HepPolyhedron && from); 303 303 304 // Get number of vertices 304 // Get number of vertices 305 G4int GetNoVertices() const { return nvert; 305 G4int GetNoVertices() const { return nvert; } 306 G4int GetNoVerteces() const { return nvert; 306 G4int GetNoVerteces() const { return nvert; } // Old spelling. 307 307 308 // Get number of facets 308 // Get number of facets 309 G4int GetNoFacets() const { return nface; } 309 G4int GetNoFacets() const { return nface; } 310 310 311 // Transform the polyhedron 311 // Transform the polyhedron 312 HepPolyhedron & Transform(const G4Transform3 312 HepPolyhedron & Transform(const G4Transform3D & t); 313 313 314 // Get next vertex index of the quadrilatera 314 // Get next vertex index of the quadrilateral 315 G4bool GetNextVertexIndex(G4int & index, G4i 315 G4bool GetNextVertexIndex(G4int & index, G4int & edgeFlag) const; 316 316 317 // Get vertex by index 317 // Get vertex by index 318 G4Point3D GetVertex(G4int index) const; 318 G4Point3D GetVertex(G4int index) const; 319 319 320 // Get next vertex + edge visibility of the 320 // Get next vertex + edge visibility of the quadrilateral 321 G4bool GetNextVertex(G4Point3D & vertex, G4i 321 G4bool GetNextVertex(G4Point3D & vertex, G4int & edgeFlag) const; 322 322 323 // Get next vertex + edge visibility + norma 323 // Get next vertex + edge visibility + normal of the quadrilateral 324 G4bool GetNextVertex(G4Point3D & vertex, G4i 324 G4bool GetNextVertex(G4Point3D & vertex, G4int & edgeFlag, 325 G4Normal3D & normal) co 325 G4Normal3D & normal) const; 326 326 327 // Get indices of the next edge with indices 327 // Get indices of the next edge with indices of the faces 328 G4bool GetNextEdgeIndices(G4int & i1, G4int 328 G4bool GetNextEdgeIndices(G4int & i1, G4int & i2, G4int & edgeFlag, 329 G4int & iface1, G4 329 G4int & iface1, G4int & iface2) const; 330 G4bool GetNextEdgeIndeces(G4int & i1, G4int 330 G4bool GetNextEdgeIndeces(G4int & i1, G4int & i2, G4int & edgeFlag, 331 G4int & iface1, G4 331 G4int & iface1, G4int & iface2) const 332 {return GetNextEdgeIndices(i1,i2,edgeFlag,if 332 {return GetNextEdgeIndices(i1,i2,edgeFlag,iface1,iface2);} // Old spelling 333 333 334 // Get indices of the next edge 334 // Get indices of the next edge 335 G4bool GetNextEdgeIndices(G4int & i1, G4int 335 G4bool GetNextEdgeIndices(G4int & i1, G4int & i2, G4int & edgeFlag) const; 336 G4bool GetNextEdgeIndeces(G4int & i1, G4int 336 G4bool GetNextEdgeIndeces(G4int & i1, G4int & i2, G4int & edgeFlag) const 337 {return GetNextEdgeIndices(i1,i2,edgeFlag);} 337 {return GetNextEdgeIndices(i1,i2,edgeFlag);} // Old spelling. 338 338 339 // Get next edge 339 // Get next edge 340 G4bool GetNextEdge(G4Point3D &p1, G4Point3D 340 G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const; 341 341 342 // Get next edge 342 // Get next edge 343 G4bool GetNextEdge(G4Point3D &p1, G4Point3D 343 G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag, 344 G4int &iface1, G4int &ifa 344 G4int &iface1, G4int &iface2) const; 345 345 346 // Get face by index 346 // Get face by index 347 void GetFacet(G4int iFace, G4int &n, G4int * 347 void GetFacet(G4int iFace, G4int &n, G4int *iNodes, 348 G4int *edgeFlags = nullptr, G4 348 G4int *edgeFlags = nullptr, G4int *iFaces = nullptr) const; 349 349 350 // Get face by index 350 // Get face by index 351 void GetFacet(G4int iFace, G4int &n, G4Point 351 void GetFacet(G4int iFace, G4int &n, G4Point3D *nodes, 352 G4int *edgeFlags=nullptr, G4No 352 G4int *edgeFlags=nullptr, G4Normal3D *normals=nullptr) const; 353 353 354 // Get next face with normals at the nodes 354 // Get next face with normals at the nodes 355 G4bool GetNextFacet(G4int &n, G4Point3D *nod 355 G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=nullptr, 356 G4Normal3D *normals=null 356 G4Normal3D *normals=nullptr) const; 357 357 358 // Get normal of the face given by index 358 // Get normal of the face given by index 359 G4Normal3D GetNormal(G4int iFace) const; 359 G4Normal3D GetNormal(G4int iFace) const; 360 360 361 // Get unit normal of the face given by inde 361 // Get unit normal of the face given by index 362 G4Normal3D GetUnitNormal(G4int iFace) const; 362 G4Normal3D GetUnitNormal(G4int iFace) const; 363 363 364 // Get normal of the next face 364 // Get normal of the next face 365 G4bool GetNextNormal(G4Normal3D &normal) con 365 G4bool GetNextNormal(G4Normal3D &normal) const; 366 366 367 // Get normal of unit length of the next fac 367 // Get normal of unit length of the next face 368 G4bool GetNextUnitNormal(G4Normal3D &normal) 368 G4bool GetNextUnitNormal(G4Normal3D &normal) const; 369 369 370 // Boolean operations 370 // Boolean operations 371 HepPolyhedron add(const HepPolyhedron &p) co 371 HepPolyhedron add(const HepPolyhedron &p) const; 372 HepPolyhedron subtract(const HepPolyhedron & 372 HepPolyhedron subtract(const HepPolyhedron &p) const; 373 HepPolyhedron intersect(const HepPolyhedron 373 HepPolyhedron intersect(const HepPolyhedron &p) const; 374 374 375 // Get area of the surface of the polyhedron 375 // Get area of the surface of the polyhedron 376 G4double GetSurfaceArea() const; 376 G4double GetSurfaceArea() const; 377 377 378 // Get volume of the polyhedron 378 // Get volume of the polyhedron 379 G4double GetVolume() const; 379 G4double GetVolume() const; 380 380 381 // Get number of steps for whole circle 381 // Get number of steps for whole circle 382 static G4int GetNumberOfRotationSteps(); 382 static G4int GetNumberOfRotationSteps(); 383 383 384 // Set vertex (1 <= index <= Nvert) 384 // Set vertex (1 <= index <= Nvert) 385 void SetVertex(G4int index, const G4Point3D& 385 void SetVertex(G4int index, const G4Point3D& v); 386 386 387 // Set facet (1 <= index <= Nface) 387 // Set facet (1 <= index <= Nface) 388 void SetFacet(G4int index, G4int iv1, G4int 388 void SetFacet(G4int index, G4int iv1, G4int iv2, G4int iv3, G4int iv4 = 0); 389 389 390 // For each edge set reference to neighbouri 390 // For each edge set reference to neighbouring facet, 391 // call this after all vertices and facets h 391 // call this after all vertices and facets have been set 392 void SetReferences(); 392 void SetReferences(); 393 393 394 // Join couples of triangular facets to quad 394 // Join couples of triangular facets to quadrangular facets 395 // where it is possible 395 // where it is possible 396 void JoinCoplanarFacets(G4double tolerance); 396 void JoinCoplanarFacets(G4double tolerance); 397 397 398 // Invert the order on nodes in facets 398 // Invert the order on nodes in facets 399 void InvertFacets(); 399 void InvertFacets(); 400 400 401 // Set number of steps for whole circle 401 // Set number of steps for whole circle 402 static void SetNumberOfRotationSteps(G4int n 402 static void SetNumberOfRotationSteps(G4int n); 403 403 404 // Reset number of steps for whole circle to 404 // Reset number of steps for whole circle to default value 405 static void ResetNumberOfRotationSteps(); 405 static void ResetNumberOfRotationSteps(); 406 406 407 /** 407 /** 408 * Creates polyhedron for twisted trapezoid. 408 * Creates polyhedron for twisted trapezoid. 409 * The trapezoid is given by two bases perpe 409 * The trapezoid is given by two bases perpendicular to the z-axis. 410 * 410 * 411 * @param Dz half length in z 411 * @param Dz half length in z 412 * @param xy1 1st base (at z = -Dz) 412 * @param xy1 1st base (at z = -Dz) 413 * @param xy2 2nd base (at z = +Dz) 413 * @param xy2 2nd base (at z = +Dz) 414 * @return status of the operation - is non- 414 * @return status of the operation - is non-zero in case of problem 415 */ 415 */ 416 G4int createTwistedTrap(G4double Dz, 416 G4int createTwistedTrap(G4double Dz, 417 const G4double xy1[][2 417 const G4double xy1[][2], const G4double xy2[][2]); 418 418 419 /** 419 /** 420 * Creates user defined polyhedron. 420 * Creates user defined polyhedron. 421 * This function allows to the user to defin 421 * This function allows to the user to define arbitrary polyhedron. 422 * The faces of the polyhedron should be eit 422 * The faces of the polyhedron should be either triangles or planar 423 * quadrilateral. Nodes of a face are define 423 * quadrilateral. Nodes of a face are defined by indexes pointing to 424 * the elements in the xyz array. Numeration 424 * the elements in the xyz array. Numeration of the elements in the 425 * array starts from 1 (like in fortran). Th 425 * array starts from 1 (like in fortran). The indexes can be positive 426 * or negative. Negative sign means that the 426 * or negative. Negative sign means that the corresponding edge is 427 * invisible. The normal of the face should 427 * invisible. The normal of the face should be directed to exterior 428 * of the polyhedron. 428 * of the polyhedron. 429 * 429 * 430 * @param Nnodes number of nodes 430 * @param Nnodes number of nodes 431 * @param Nfaces number of faces 431 * @param Nfaces number of faces 432 * @param xyz nodes 432 * @param xyz nodes 433 * @param faces faces (quadrilaterals or t 433 * @param faces faces (quadrilaterals or triangles) 434 * @return status of the operation - is non- 434 * @return status of the operation - is non-zero in case of problem 435 */ 435 */ 436 G4int createPolyhedron(G4int Nnodes, G4int N 436 G4int createPolyhedron(G4int Nnodes, G4int Nfaces, 437 const G4double xyz[][ 437 const G4double xyz[][3], const G4int faces[][4]); 438 << 439 /** << 440 * Calculate the unweighted mean of all the << 441 * confused with the polyhedron centre or ce << 442 * @return G4Point3D of the unweighted mean << 443 */ << 444 G4Point3D vertexUnweightedMean() const; << 445 }; 438 }; 446 439 447 class HepPolyhedronTrd2 : public HepPolyhedron 440 class HepPolyhedronTrd2 : public HepPolyhedron 448 { 441 { 449 public: 442 public: 450 HepPolyhedronTrd2(G4double Dx1, G4double Dx2 443 HepPolyhedronTrd2(G4double Dx1, G4double Dx2, 451 G4double Dy1, G4double Dy2 444 G4double Dy1, G4double Dy2, G4double Dz); 452 ~HepPolyhedronTrd2() override; 445 ~HepPolyhedronTrd2() override; 453 }; 446 }; 454 447 455 class HepPolyhedronTrd1 : public HepPolyhedron 448 class HepPolyhedronTrd1 : public HepPolyhedronTrd2 456 { 449 { 457 public: 450 public: 458 HepPolyhedronTrd1(G4double Dx1, G4double Dx2 451 HepPolyhedronTrd1(G4double Dx1, G4double Dx2, 459 G4double Dy, G4double Dz); 452 G4double Dy, G4double Dz); 460 ~HepPolyhedronTrd1() override; 453 ~HepPolyhedronTrd1() override; 461 }; 454 }; 462 455 463 class HepPolyhedronBox : public HepPolyhedronT 456 class HepPolyhedronBox : public HepPolyhedronTrd2 464 { 457 { 465 public: 458 public: 466 HepPolyhedronBox(G4double Dx, G4double Dy, G 459 HepPolyhedronBox(G4double Dx, G4double Dy, G4double Dz); 467 ~HepPolyhedronBox() override; 460 ~HepPolyhedronBox() override; 468 }; 461 }; 469 462 470 class HepPolyhedronTrap : public HepPolyhedron 463 class HepPolyhedronTrap : public HepPolyhedron 471 { 464 { 472 public: 465 public: 473 HepPolyhedronTrap(G4double Dz, G4double Thet 466 HepPolyhedronTrap(G4double Dz, G4double Theta, G4double Phi, 474 G4double Dy1, 467 G4double Dy1, 475 G4double Dx1, G4double Dx2 468 G4double Dx1, G4double Dx2, G4double Alp1, 476 G4double Dy2, 469 G4double Dy2, 477 G4double Dx3, G4double Dx4 470 G4double Dx3, G4double Dx4, G4double Alp2); 478 ~HepPolyhedronTrap() override; 471 ~HepPolyhedronTrap() override; 479 }; 472 }; 480 473 481 class HepPolyhedronPara : public HepPolyhedron 474 class HepPolyhedronPara : public HepPolyhedronTrap 482 { 475 { 483 public: 476 public: 484 HepPolyhedronPara(G4double Dx, G4double Dy, 477 HepPolyhedronPara(G4double Dx, G4double Dy, G4double Dz, 485 G4double Alpha, G4double T 478 G4double Alpha, G4double Theta, G4double Phi); 486 ~HepPolyhedronPara() override; 479 ~HepPolyhedronPara() override; 487 }; 480 }; 488 481 489 class HepPolyhedronParaboloid : public HepPoly 482 class HepPolyhedronParaboloid : public HepPolyhedron 490 { 483 { 491 public: 484 public: 492 HepPolyhedronParaboloid(G4double r1, 485 HepPolyhedronParaboloid(G4double r1, 493 G4double r2, 486 G4double r2, 494 G4double dz, 487 G4double dz, 495 G4double Phi1, 488 G4double Phi1, 496 G4double Dphi); 489 G4double Dphi); 497 ~HepPolyhedronParaboloid() override; 490 ~HepPolyhedronParaboloid() override; 498 }; 491 }; 499 492 500 class HepPolyhedronHype : public HepPolyhedron 493 class HepPolyhedronHype : public HepPolyhedron 501 { 494 { 502 public: 495 public: 503 HepPolyhedronHype(G4double r1, 496 HepPolyhedronHype(G4double r1, 504 G4double r2, 497 G4double r2, 505 G4double tan1, 498 G4double tan1, 506 G4double tan2, 499 G4double tan2, 507 G4double halfZ); 500 G4double halfZ); 508 ~HepPolyhedronHype() override; 501 ~HepPolyhedronHype() override; 509 }; 502 }; 510 503 511 class HepPolyhedronCons : public HepPolyhedron 504 class HepPolyhedronCons : public HepPolyhedron 512 { 505 { 513 public: 506 public: 514 HepPolyhedronCons(G4double Rmn1, G4double Rm 507 HepPolyhedronCons(G4double Rmn1, G4double Rmx1, 515 G4double Rmn2, G4double Rm 508 G4double Rmn2, G4double Rmx2, G4double Dz, 516 G4double Phi1, G4double Dp 509 G4double Phi1, G4double Dphi); 517 ~HepPolyhedronCons() override; 510 ~HepPolyhedronCons() override; 518 }; 511 }; 519 512 520 class HepPolyhedronCone : public HepPolyhedron 513 class HepPolyhedronCone : public HepPolyhedronCons 521 { 514 { 522 public: 515 public: 523 HepPolyhedronCone(G4double Rmn1, G4double Rm 516 HepPolyhedronCone(G4double Rmn1, G4double Rmx1, 524 G4double Rmn2, G4double Rm 517 G4double Rmn2, G4double Rmx2, G4double Dz); 525 ~HepPolyhedronCone() override; 518 ~HepPolyhedronCone() override; 526 }; 519 }; 527 520 528 class HepPolyhedronTubs : public HepPolyhedron 521 class HepPolyhedronTubs : public HepPolyhedronCons 529 { 522 { 530 public: 523 public: 531 HepPolyhedronTubs(G4double Rmin, G4double Rm 524 HepPolyhedronTubs(G4double Rmin, G4double Rmax, G4double Dz, 532 G4double Phi1, G4double Dp 525 G4double Phi1, G4double Dphi); 533 ~HepPolyhedronTubs() override; 526 ~HepPolyhedronTubs() override; 534 }; 527 }; 535 528 536 class HepPolyhedronTube : public HepPolyhedron 529 class HepPolyhedronTube : public HepPolyhedronCons 537 { 530 { 538 public: 531 public: 539 HepPolyhedronTube (G4double Rmin, G4double R 532 HepPolyhedronTube (G4double Rmin, G4double Rmax, G4double Dz); 540 ~HepPolyhedronTube() override; 533 ~HepPolyhedronTube() override; 541 }; 534 }; 542 535 543 class HepPolyhedronPgon : public HepPolyhedron 536 class HepPolyhedronPgon : public HepPolyhedron 544 { 537 { 545 public: 538 public: 546 HepPolyhedronPgon(G4double phi, G4double dph 539 HepPolyhedronPgon(G4double phi, G4double dphi, G4int npdv, G4int nz, 547 const G4double *z, 540 const G4double *z, 548 const G4double *rmin, 541 const G4double *rmin, 549 const G4double *rmax); 542 const G4double *rmax); 550 HepPolyhedronPgon(G4double phi, G4double dph 543 HepPolyhedronPgon(G4double phi, G4double dphi, G4int npdv, 551 const std::vector<G4TwoVec 544 const std::vector<G4TwoVector> &rz); 552 ~HepPolyhedronPgon() override; 545 ~HepPolyhedronPgon() override; 553 }; 546 }; 554 547 555 class HepPolyhedronPcon : public HepPolyhedron 548 class HepPolyhedronPcon : public HepPolyhedronPgon 556 { 549 { 557 public: 550 public: 558 HepPolyhedronPcon(G4double phi, G4double dph 551 HepPolyhedronPcon(G4double phi, G4double dphi, G4int nz, 559 const G4double *z, 552 const G4double *z, 560 const G4double *rmin, 553 const G4double *rmin, 561 const G4double *rmax); 554 const G4double *rmax); 562 HepPolyhedronPcon(G4double phi, G4double dph 555 HepPolyhedronPcon(G4double phi, G4double dphi, 563 const std::vector<G4TwoVec 556 const std::vector<G4TwoVector> &rz); 564 ~HepPolyhedronPcon() override; 557 ~HepPolyhedronPcon() override; 565 }; 558 }; 566 559 567 class HepPolyhedronSphere : public HepPolyhedr 560 class HepPolyhedronSphere : public HepPolyhedron 568 { 561 { 569 public: 562 public: 570 HepPolyhedronSphere(G4double rmin, G4double 563 HepPolyhedronSphere(G4double rmin, G4double rmax, 571 G4double phi, G4double d 564 G4double phi, G4double dphi, 572 G4double the, G4double d 565 G4double the, G4double dthe); 573 ~HepPolyhedronSphere() override; 566 ~HepPolyhedronSphere() override; 574 }; 567 }; 575 568 576 class HepPolyhedronTorus : public HepPolyhedro 569 class HepPolyhedronTorus : public HepPolyhedron 577 { 570 { 578 public: 571 public: 579 HepPolyhedronTorus(G4double rmin, G4double r 572 HepPolyhedronTorus(G4double rmin, G4double rmax, G4double rtor, 580 G4double phi, G4double dp 573 G4double phi, G4double dphi); 581 ~HepPolyhedronTorus() override; 574 ~HepPolyhedronTorus() override; 582 }; 575 }; 583 576 584 class HepPolyhedronTet : public HepPolyhedron 577 class HepPolyhedronTet : public HepPolyhedron 585 { 578 { 586 public: 579 public: 587 HepPolyhedronTet(const G4double p0[3], 580 HepPolyhedronTet(const G4double p0[3], 588 const G4double p1[3], 581 const G4double p1[3], 589 const G4double p2[3], 582 const G4double p2[3], 590 const G4double p3[3]); 583 const G4double p3[3]); 591 ~HepPolyhedronTet() override; 584 ~HepPolyhedronTet() override; 592 }; 585 }; 593 586 594 class HepPolyhedronEllipsoid : public HepPolyh 587 class HepPolyhedronEllipsoid : public HepPolyhedron 595 { 588 { 596 public: 589 public: 597 HepPolyhedronEllipsoid(G4double dx, G4double 590 HepPolyhedronEllipsoid(G4double dx, G4double dy, G4double dz, 598 G4double zcut1, G4dou 591 G4double zcut1, G4double zcut2); 599 ~HepPolyhedronEllipsoid() override; 592 ~HepPolyhedronEllipsoid() override; 600 }; 593 }; 601 594 602 class HepPolyhedronEllipticalCone : public Hep 595 class HepPolyhedronEllipticalCone : public HepPolyhedron 603 { 596 { 604 public: 597 public: 605 HepPolyhedronEllipticalCone(G4double dx, G4d 598 HepPolyhedronEllipticalCone(G4double dx, G4double dy, G4double z, 606 G4double zcut1); 599 G4double zcut1); 607 ~HepPolyhedronEllipticalCone() override; 600 ~HepPolyhedronEllipticalCone() override; 608 }; 601 }; 609 602 610 class HepPolyhedronHyperbolicMirror : public H 603 class HepPolyhedronHyperbolicMirror : public HepPolyhedron 611 { 604 { 612 public: 605 public: 613 HepPolyhedronHyperbolicMirror(G4double a, G4 606 HepPolyhedronHyperbolicMirror(G4double a, G4double h, G4double r); 614 ~HepPolyhedronHyperbolicMirror() override; 607 ~HepPolyhedronHyperbolicMirror() override; 615 }; 608 }; 616 609 617 class HepPolyhedronTetMesh : public HepPolyhed 610 class HepPolyhedronTetMesh : public HepPolyhedron 618 { 611 { 619 public: 612 public: 620 HepPolyhedronTetMesh(const std::vector<G4Thr 613 HepPolyhedronTetMesh(const std::vector<G4ThreeVector>& tetrahedra); 621 ~HepPolyhedronTetMesh() override; 614 ~HepPolyhedronTetMesh() override; 622 }; 615 }; 623 616 624 class HepPolyhedronBoxMesh : public HepPolyhed 617 class HepPolyhedronBoxMesh : public HepPolyhedron 625 { 618 { 626 public: 619 public: 627 HepPolyhedronBoxMesh(G4double sizeX, G4doubl 620 HepPolyhedronBoxMesh(G4double sizeX, G4double sizeY, G4double sizeZ, 628 const std::vector<G4Thr 621 const std::vector<G4ThreeVector>& positions); 629 ~HepPolyhedronBoxMesh() override; 622 ~HepPolyhedronBoxMesh() override; 630 }; 623 }; 631 624 632 #endif /* HEP_POLYHEDRON_HH */ 625 #endif /* HEP_POLYHEDRON_HH */ 633 626