Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
HepPolyhedronTetMesh Class Reference

#include <HepPolyhedron.h>

+ Inheritance diagram for HepPolyhedronTetMesh:

Public Member Functions

 HepPolyhedronTetMesh (const std::vector< G4ThreeVector > &tetrahedra)
 
 ~HepPolyhedronTetMesh () override
 
- Public Member Functions inherited from HepPolyhedron
 HepPolyhedron ()
 
 HepPolyhedron (G4int Nvert, G4int Nface)
 
 HepPolyhedron (const HepPolyhedron &from)
 
 HepPolyhedron (HepPolyhedron &&from)
 
virtual ~HepPolyhedron ()
 
HepPolyhedronoperator= (const HepPolyhedron &from)
 
HepPolyhedronoperator= (HepPolyhedron &&from)
 
G4int GetNoVertices () const
 
G4int GetNoVerteces () const
 
G4int GetNoFacets () const
 
HepPolyhedronTransform (const G4Transform3D &t)
 
G4bool GetNextVertexIndex (G4int &index, G4int &edgeFlag) const
 
G4Point3D GetVertex (G4int index) const
 
G4bool GetNextVertex (G4Point3D &vertex, G4int &edgeFlag) const
 
G4bool GetNextVertex (G4Point3D &vertex, G4int &edgeFlag, G4Normal3D &normal) const
 
G4bool GetNextEdgeIndices (G4int &i1, G4int &i2, G4int &edgeFlag, G4int &iface1, G4int &iface2) const
 
G4bool GetNextEdgeIndeces (G4int &i1, G4int &i2, G4int &edgeFlag, G4int &iface1, G4int &iface2) const
 
G4bool GetNextEdgeIndices (G4int &i1, G4int &i2, G4int &edgeFlag) const
 
G4bool GetNextEdgeIndeces (G4int &i1, G4int &i2, G4int &edgeFlag) const
 
G4bool GetNextEdge (G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const
 
G4bool GetNextEdge (G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag, G4int &iface1, G4int &iface2) const
 
void GetFacet (G4int iFace, G4int &n, G4int *iNodes, G4int *edgeFlags=nullptr, G4int *iFaces=nullptr) const
 
void GetFacet (G4int iFace, G4int &n, G4Point3D *nodes, G4int *edgeFlags=nullptr, G4Normal3D *normals=nullptr) const
 
G4bool GetNextFacet (G4int &n, G4Point3D *nodes, G4int *edgeFlags=nullptr, G4Normal3D *normals=nullptr) const
 
G4Normal3D GetNormal (G4int iFace) const
 
G4Normal3D GetUnitNormal (G4int iFace) const
 
G4bool GetNextNormal (G4Normal3D &normal) const
 
G4bool GetNextUnitNormal (G4Normal3D &normal) const
 
HepPolyhedron add (const HepPolyhedron &p) const
 
HepPolyhedron subtract (const HepPolyhedron &p) const
 
HepPolyhedron intersect (const HepPolyhedron &p) const
 
G4double GetSurfaceArea () const
 
G4double GetVolume () const
 
void SetVertex (G4int index, const G4Point3D &v)
 
void SetFacet (G4int index, G4int iv1, G4int iv2, G4int iv3, G4int iv4=0)
 
void SetReferences ()
 
void JoinCoplanarFacets (G4double tolerance)
 
void InvertFacets ()
 
G4int createTwistedTrap (G4double Dz, const G4double xy1[][2], const G4double xy2[][2])
 
G4int createPolyhedron (G4int Nnodes, G4int Nfaces, const G4double xyz[][3], const G4int faces[][4])
 
G4Point3D vertexUnweightedMean () const
 

Additional Inherited Members

- Static Public Member Functions inherited from HepPolyhedron
static G4int GetNumberOfRotationSteps ()
 
static void SetNumberOfRotationSteps (G4int n)
 
static void ResetNumberOfRotationSteps ()
 
- Protected Member Functions inherited from HepPolyhedron
void AllocateMemory (G4int Nvert, G4int Nface)
 
G4int FindNeighbour (G4int iFace, G4int iNode, G4int iOrder) const
 
G4Normal3D FindNodeNormal (G4int iFace, G4int iNode) const
 
void CreatePrism ()
 
void RotateEdge (G4int k1, G4int k2, G4double r1, G4double r2, G4int v1, G4int v2, G4int vEdge, G4bool ifWholeCircle, G4int ns, G4int &kface)
 
void SetSideFacets (G4int ii[4], G4int vv[4], G4int *kk, G4double *r, G4double dphi, G4int ns, G4int &kface)
 
void RotateAroundZ (G4int nstep, G4double phi, G4double dphi, G4int np1, G4int np2, const G4double *z, G4double *r, G4int nodeVis, G4int edgeVis)
 
void RotateContourAroundZ (G4int nstep, G4double phi, G4double dphi, const std::vector< G4TwoVector > &rz, G4int nodeVis, G4int edgeVis)
 
G4bool TriangulatePolygon (const std::vector< G4TwoVector > &polygon, std::vector< G4int > &result)
 
G4bool CheckSnip (const std::vector< G4TwoVector > &contour, G4int a, G4int b, G4int c, G4int n, const G4int *V)
 
- Protected Attributes inherited from HepPolyhedron
G4int nvert
 
G4int nface
 
G4Point3DpV
 
G4FacetpF
 
- Static Protected Attributes inherited from HepPolyhedron
static G4ThreadLocal G4int fNumberOfRotationSteps = DEFAULT_NUMBER_OF_STEPS
 

Detailed Description

Definition at line 617 of file HepPolyhedron.h.

Constructor & Destructor Documentation

◆ HepPolyhedronTetMesh()

HepPolyhedronTetMesh::HepPolyhedronTetMesh ( const std::vector< G4ThreeVector > & tetrahedra)

Definition at line 2920 of file HepPolyhedron.cc.

2933{
2934 // Check size of input vector
2935 G4int nnodes = (G4int)tetrahedra.size();
2936 if (nnodes == 0)
2937 {
2938 std::cerr
2939 << "HepPolyhedronTetMesh: Empty tetrahedron mesh" << std::endl;
2940 return;
2941 }
2942 G4int ntet = nnodes/4;
2943 if (nnodes != ntet*4)
2944 {
2945 std::cerr << "HepPolyhedronTetMesh: Number of nodes = " << nnodes
2946 << " in tetrahedron mesh is NOT multiple of 4"
2947 << std::endl;
2948 return;
2949 }
2950
2951 // Find coincident vertices using hash table techniques.
2952 // This could be done using std::unordered_map, but the code
2953 // below runs faster.
2954 std::vector<G4int> iheads(nnodes, -1);
2955 std::vector<std::pair<G4int,G4int>> ipairs(nnodes,std::pair(-1,-1));
2956 for (G4int i = 0; i < nnodes; ++i)
2957 {
2958 // Generate hash key
2959 G4ThreeVector point = tetrahedra[i];
2960 auto key = std::hash<G4double>()(point.x());
2961 key ^= std::hash<G4double>()(point.y());
2962 key ^= std::hash<G4double>()(point.z());
2963 key %= nnodes;
2964 // Check head of the list
2965 if (iheads[key] < 0)
2966 {
2967 iheads[key] = i;
2968 ipairs[i].first = i;
2969 continue;
2970 }
2971 // Loop along the list
2972 for (G4int icur = iheads[key], iprev = 0;;)
2973 {
2974 G4int icheck = ipairs[icur].first;
2975 if (tetrahedra[icheck] == point)
2976 {
2977 ipairs[i].first = icheck; // coincident vertex
2978 break;
2979 }
2980 iprev = icur;
2981 icur = ipairs[icur].second;
2982 // Append vertex to the list
2983 if (icur < 0)
2984 {
2985 ipairs[i].first = i;
2986 ipairs[iprev].second = i;
2987 break;
2988 }
2989 }
2990 }
2991
2992 // Create vector of original facets
2993 struct facet
2994 {
2995 G4int i1, i2, i3;
2996 facet() : i1(0), i2(0), i3(0) {};
2997 facet(G4int k1, G4int k2, G4int k3) : i1(k1), i2(k2), i3(k3) {};
2998 };
2999 G4int nfacets = nnodes;
3000 std::vector<facet> ifacets(nfacets);
3001 for (G4int i = 0; i < nfacets; i += 4)
3002 {
3003 G4int i0 = ipairs[i + 0].first;
3004 G4int i1 = ipairs[i + 1].first;
3005 G4int i2 = ipairs[i + 2].first;
3006 G4int i3 = ipairs[i + 3].first;
3007 if (i0 > i1) std::swap(i0, i1);
3008 if (i0 > i2) std::swap(i0, i2);
3009 if (i0 > i3) std::swap(i0, i3);
3010 if (i1 > i2) std::swap(i1, i2);
3011 if (i1 > i3) std::swap(i1, i3);
3012 G4ThreeVector e1 = tetrahedra[i1] - tetrahedra[i0];
3013 G4ThreeVector e2 = tetrahedra[i2] - tetrahedra[i0];
3014 G4ThreeVector e3 = tetrahedra[i3] - tetrahedra[i0];
3015 G4double volume = (e1.cross(e2)).dot(e3);
3016 if (volume > 0.) std::swap(i2, i3);
3017 ifacets[i + 0] = facet(i0, i1, i2);
3018 ifacets[i + 1] = facet(i0, i2, i3);
3019 ifacets[i + 2] = facet(i0, i3, i1);
3020 ifacets[i + 3] = facet(i1, i3, i2);
3021 }
3022
3023 // Find shared facets
3024 std::fill(iheads.begin(), iheads.end(), -1);
3025 std::fill(ipairs.begin(), ipairs.end(), std::pair(-1,-1));
3026 for (G4int i = 0; i < nfacets; ++i)
3027 {
3028 // Check head of the list
3029 G4int key = ifacets[i].i1;
3030 if (iheads[key] < 0)
3031 {
3032 iheads[key] = i;
3033 ipairs[i].first = i;
3034 continue;
3035 }
3036 // Loop along the list
3037 G4int i2 = ifacets[i].i2, i3 = ifacets[i].i3;
3038 for (G4int icur = iheads[key], iprev = -1;;)
3039 {
3040 G4int icheck = ipairs[icur].first;
3041 if (ifacets[icheck].i2 == i3 && ifacets[icheck].i3 == i2)
3042 {
3043 if (iprev < 0)
3044 {
3045 iheads[key] = ipairs[icur].second;
3046 }
3047 else
3048 {
3049 ipairs[iprev].second = ipairs[icur].second;
3050 }
3051 ipairs[icur].first = -1; // shared facet
3052 ipairs[icur].second = -1;
3053 break;
3054 }
3055 iprev = icur;
3056 icur = ipairs[icur].second;
3057 // Append facet to the list
3058 if (icur < 0)
3059 {
3060 ipairs[i].first = i;
3061 ipairs[iprev].second = i;
3062 break;
3063 }
3064 }
3065 }
3066
3067 // Count vertices and facets skipping shared facets
3068 std::fill(iheads.begin(), iheads.end(), -1);
3069 G4int nver = 0, nfac = 0;
3070 for (G4int i = 0; i < nfacets; ++i)
3071 {
3072 if (ipairs[i].first < 0) continue;
3073 G4int i1 = ifacets[i].i1;
3074 G4int i2 = ifacets[i].i2;
3075 G4int i3 = ifacets[i].i3;
3076 if (iheads[i1] < 0) iheads[i1] = nver++;
3077 if (iheads[i2] < 0) iheads[i2] = nver++;
3078 if (iheads[i3] < 0) iheads[i3] = nver++;
3079 nfac++;
3080 }
3081
3082 // Construct polyhedron
3083 AllocateMemory(nver, nfac);
3084 for (G4int i = 0; i < nnodes; ++i)
3085 {
3086 G4int k = iheads[i];
3087 if (k >= 0) SetVertex(k + 1, tetrahedra[i]);
3088 }
3089 for (G4int i = 0, k = 0; i < nfacets; ++i)
3090 {
3091 if (ipairs[i].first < 0) continue;
3092 G4int i1 = iheads[ifacets[i].i1] + 1;
3093 G4int i2 = iheads[ifacets[i].i2] + 1;
3094 G4int i3 = iheads[ifacets[i].i3] + 1;
3095 SetFacet(++k, i1, i2, i3);
3096 }
3097 SetReferences();
3098}
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
double z() const
double x() const
double y() const
Hep3Vector cross(const Hep3Vector &) const
double dot(const Hep3Vector &) const
void SetVertex(G4int index, const G4Point3D &v)
void SetFacet(G4int index, G4int iv1, G4int iv2, G4int iv3, G4int iv4=0)
void AllocateMemory(G4int Nvert, G4int Nface)

◆ ~HepPolyhedronTetMesh()

HepPolyhedronTetMesh::~HepPolyhedronTetMesh ( )
overridedefault

The documentation for this class was generated from the following files: