Geant4 11.1.1
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])
 

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 610 of file HepPolyhedron.h.

Constructor & Destructor Documentation

◆ HepPolyhedronTetMesh()

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

Definition at line 2901 of file HepPolyhedron.cc.

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