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

#include <HepPolyhedron.h>

+ Inheritance diagram for HepPolyhedronBoxMesh:

Public Member Functions

 HepPolyhedronBoxMesh (G4double sizeX, G4double sizeY, G4double sizeZ, const std::vector< G4ThreeVector > &positions)
 
 ~HepPolyhedronBoxMesh () 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 617 of file HepPolyhedron.h.

Constructor & Destructor Documentation

◆ HepPolyhedronBoxMesh()

HepPolyhedronBoxMesh::HepPolyhedronBoxMesh ( G4double  sizeX,
G4double  sizeY,
G4double  sizeZ,
const std::vector< G4ThreeVector > &  positions 
)

Definition at line 3083 of file HepPolyhedron.cc.

3097{
3098 G4int nbox = (G4int)positions.size();
3099 if (nbox == 0)
3100 {
3101 std::cerr << "HepPolyhedronBoxMesh: Empty box mesh" << std::endl;
3102 return;
3103 }
3104 // compute inverse dimensions
3105 G4double invx = 1./sizeX, invy = 1./sizeY, invz = 1./sizeZ;
3106 // find mesh bounding box
3107 G4ThreeVector pmin = positions[0], pmax = positions[0];
3108 for (const auto& p: positions)
3109 {
3110 if (pmin.x() > p.x()) pmin.setX(p.x());
3111 if (pmin.y() > p.y()) pmin.setY(p.y());
3112 if (pmin.z() > p.z()) pmin.setZ(p.z());
3113 if (pmax.x() < p.x()) pmax.setX(p.x());
3114 if (pmax.y() < p.y()) pmax.setY(p.y());
3115 if (pmax.z() < p.z()) pmax.setZ(p.z());
3116 }
3117 // find number of voxels
3118 G4int nx = (pmax.x() - pmin.x())*invx + 1.5;
3119 G4int ny = (pmax.y() - pmin.y())*invy + 1.5;
3120 G4int nz = (pmax.z() - pmin.z())*invz + 1.5;
3121 // create structures for voxels and node indices
3122 std::vector<char> voxels(nx*ny*nz, 0);
3123 std::vector<G4int> indices((nx+1)*(ny+1)*(nz+1), 0);
3124 // mark voxels listed in positions
3125 G4int kx = ny*nz, ky = nz;
3126 for (const auto& p: positions)
3127 {
3128 G4int ix = (p.x() - pmin.x())*invx + 0.5;
3129 G4int iy = (p.y() - pmin.y())*invy + 0.5;
3130 G4int iz = (p.z() - pmin.z())*invz + 0.5;
3131 G4int i = ix*kx + iy*ky + iz;
3132 voxels[i] = 1;
3133 }
3134 // count number of vertices and facets
3135 // set indices
3136 G4int kvx = (ny + 1)*(nz + 1), kvy = nz + 1;
3137 G4int nver = 0, nfac = 0;
3138 for (const auto& p: positions)
3139 {
3140 G4int ix = (p.x() - pmin.x())*invx + 0.5;
3141 G4int iy = (p.y() - pmin.y())*invy + 0.5;
3142 G4int iz = (p.z() - pmin.z())*invz + 0.5;
3143 //
3144 // 011 111
3145 // +---–---+
3146 // | 001 | 101
3147 // | +---–---+
3148 // | | | |
3149 // +---|---+ |
3150 // 010 | 110 |
3151 // +-------+
3152 // 000 100
3153 //
3154 G4int vcheck = 0;
3155 // check (ix - 1) side
3156 vcheck = (ix == 0) ? 0 : voxels[(ix-1)*kx + iy*ky + iz];
3157 if (vcheck == 0)
3158 {
3159 nfac++;
3160 G4int i1 = (ix+0)*kvx + (iy+0)*kvy + (iz+0); // 000
3161 G4int i2 = (ix+0)*kvx + (iy+0)*kvy + (iz+1); // 001
3162 G4int i3 = (ix+0)*kvx + (iy+1)*kvy + (iz+1); // 011
3163 G4int i4 = (ix+0)*kvx + (iy+1)*kvy + (iz+0); // 010
3164 if (indices[i1] == 0) indices[i1] = ++nver;
3165 if (indices[i2] == 0) indices[i2] = ++nver;
3166 if (indices[i3] == 0) indices[i3] = ++nver;
3167 if (indices[i4] == 0) indices[i4] = ++nver;
3168 }
3169 // check (ix + 1) side
3170 vcheck = (ix == nx - 1) ? 0 : voxels[(ix+1)*kx + iy*ky + iz];
3171 if (vcheck == 0)
3172 {
3173 nfac++;
3174 G4int i1 = (ix+1)*kvx + (iy+1)*kvy + (iz+0); // 110
3175 G4int i2 = (ix+1)*kvx + (iy+1)*kvy + (iz+1); // 111
3176 G4int i3 = (ix+1)*kvx + (iy+0)*kvy + (iz+1); // 101
3177 G4int i4 = (ix+1)*kvx + (iy+0)*kvy + (iz+0); // 100
3178 if (indices[i1] == 0) indices[i1] = ++nver;
3179 if (indices[i2] == 0) indices[i2] = ++nver;
3180 if (indices[i3] == 0) indices[i3] = ++nver;
3181 if (indices[i4] == 0) indices[i4] = ++nver;
3182 }
3183 // check (iy - 1) side
3184 vcheck = (iy == 0) ? 0 : voxels[ix*kx + (iy-1)*ky + iz];
3185 if (vcheck == 0)
3186 {
3187 nfac++;
3188 G4int i1 = (ix+0)*kvx + (iy+0)*kvy + (iz+0); // 000
3189 G4int i2 = (ix+1)*kvx + (iy+0)*kvy + (iz+0); // 100
3190 G4int i3 = (ix+1)*kvx + (iy+0)*kvy + (iz+1); // 101
3191 G4int i4 = (ix+0)*kvx + (iy+0)*kvy + (iz+1); // 001
3192 if (indices[i1] == 0) indices[i1] = ++nver;
3193 if (indices[i2] == 0) indices[i2] = ++nver;
3194 if (indices[i3] == 0) indices[i3] = ++nver;
3195 if (indices[i4] == 0) indices[i4] = ++nver;
3196 }
3197 // check (iy + 1) side
3198 vcheck = (iy == ny - 1) ? 0 : voxels[ix*kx + (iy+1)*ky + iz];
3199 if (vcheck == 0)
3200 {
3201 nfac++;
3202 G4int i1 = (ix+0)*kvx + (iy+1)*kvy + (iz+0); // 010
3203 G4int i2 = (ix+0)*kvx + (iy+1)*kvy + (iz+1); // 011
3204 G4int i3 = (ix+1)*kvx + (iy+1)*kvy + (iz+1); // 111
3205 G4int i4 = (ix+1)*kvx + (iy+1)*kvy + (iz+0); // 110
3206 if (indices[i1] == 0) indices[i1] = ++nver;
3207 if (indices[i2] == 0) indices[i2] = ++nver;
3208 if (indices[i3] == 0) indices[i3] = ++nver;
3209 if (indices[i4] == 0) indices[i4] = ++nver;
3210 }
3211 // check (iz - 1) side
3212 vcheck = (iz == 0) ? 0 : voxels[ix*kx + iy*ky + (iz-1)];
3213 if (vcheck == 0)
3214 {
3215 nfac++;
3216 G4int i1 = (ix+0)*kvx + (iy+0)*kvy + (iz+0); // 000
3217 G4int i2 = (ix+0)*kvx + (iy+1)*kvy + (iz+0); // 010
3218 G4int i3 = (ix+1)*kvx + (iy+1)*kvy + (iz+0); // 110
3219 G4int i4 = (ix+1)*kvx + (iy+0)*kvy + (iz+0); // 100
3220 if (indices[i1] == 0) indices[i1] = ++nver;
3221 if (indices[i2] == 0) indices[i2] = ++nver;
3222 if (indices[i3] == 0) indices[i3] = ++nver;
3223 if (indices[i4] == 0) indices[i4] = ++nver;
3224 }
3225 // check (iz + 1) side
3226 vcheck = (iz == nz - 1) ? 0 : voxels[ix*kx + iy*ky + (iz+1)];
3227 if (vcheck == 0)
3228 {
3229 nfac++;
3230 G4int i1 = (ix+0)*kvx + (iy+0)*kvy + (iz+1); // 001
3231 G4int i2 = (ix+1)*kvx + (iy+0)*kvy + (iz+1); // 101
3232 G4int i3 = (ix+1)*kvx + (iy+1)*kvy + (iz+1); // 111
3233 G4int i4 = (ix+0)*kvx + (iy+1)*kvy + (iz+1); // 011
3234 if (indices[i1] == 0) indices[i1] = ++nver;
3235 if (indices[i2] == 0) indices[i2] = ++nver;
3236 if (indices[i3] == 0) indices[i3] = ++nver;
3237 if (indices[i4] == 0) indices[i4] = ++nver;
3238 }
3239 }
3240 // Construct polyhedron
3241 AllocateMemory(nver, nfac);
3242 G4ThreeVector p0(pmin.x() - 0.5*sizeX, pmin.y() - 0.5*sizeY, pmin.z() - 0.5*sizeZ);
3243 for (G4int ix = 0; ix <= nx; ++ix)
3244 {
3245 for (G4int iy = 0; iy <= ny; ++iy)
3246 {
3247 for (G4int iz = 0; iz <= nz; ++iz)
3248 {
3249 G4int i = ix*kvx + iy*kvy + iz;
3250 if (indices[i] == 0) continue;
3251 SetVertex(indices[i], p0 + G4ThreeVector(ix*sizeX, iy*sizeY, iz*sizeZ));
3252 }
3253 }
3254 }
3255 nfac = 0;
3256 for (const auto& p: positions)
3257 {
3258 G4int ix = (p.x() - pmin.x())*invx + 0.5;
3259 G4int iy = (p.y() - pmin.y())*invy + 0.5;
3260 G4int iz = (p.z() - pmin.z())*invz + 0.5;
3261 G4int vcheck = 0;
3262 // check (ix - 1) side
3263 vcheck = (ix == 0) ? 0 : voxels[(ix-1)*kx + iy*ky + iz];
3264 if (vcheck == 0)
3265 {
3266 G4int i1 = (ix+0)*kvx + (iy+0)*kvy + (iz+0); // 000
3267 G4int i2 = (ix+0)*kvx + (iy+0)*kvy + (iz+1); // 001
3268 G4int i3 = (ix+0)*kvx + (iy+1)*kvy + (iz+1); // 011
3269 G4int i4 = (ix+0)*kvx + (iy+1)*kvy + (iz+0); // 010
3270 SetFacet(++nfac, indices[i1], indices[i2], indices[i3], indices[i4]);
3271 }
3272 // check (ix + 1) side
3273 vcheck = (ix == nx - 1) ? 0 : voxels[(ix+1)*kx + iy*ky + iz];
3274 if (vcheck == 0)
3275 {
3276 G4int i1 = (ix+1)*kvx + (iy+1)*kvy + (iz+0); // 110
3277 G4int i2 = (ix+1)*kvx + (iy+1)*kvy + (iz+1); // 111
3278 G4int i3 = (ix+1)*kvx + (iy+0)*kvy + (iz+1); // 101
3279 G4int i4 = (ix+1)*kvx + (iy+0)*kvy + (iz+0); // 100
3280 SetFacet(++nfac, indices[i1], indices[i2], indices[i3], indices[i4]);
3281
3282 }
3283 // check (iy - 1) side
3284 vcheck = (iy == 0) ? 0 : voxels[ix*kx + (iy-1)*ky + iz];
3285 if (vcheck == 0)
3286 {
3287 G4int i1 = (ix+0)*kvx + (iy+0)*kvy + (iz+0); // 000
3288 G4int i2 = (ix+1)*kvx + (iy+0)*kvy + (iz+0); // 100
3289 G4int i3 = (ix+1)*kvx + (iy+0)*kvy + (iz+1); // 101
3290 G4int i4 = (ix+0)*kvx + (iy+0)*kvy + (iz+1); // 001
3291 SetFacet(++nfac, indices[i1], indices[i2], indices[i3], indices[i4]);
3292 }
3293 // check (iy + 1) side
3294 vcheck = (iy == ny - 1) ? 0 : voxels[ix*kx + (iy+1)*ky + iz];
3295 if (vcheck == 0)
3296 {
3297 G4int i1 = (ix+0)*kvx + (iy+1)*kvy + (iz+0); // 010
3298 G4int i2 = (ix+0)*kvx + (iy+1)*kvy + (iz+1); // 011
3299 G4int i3 = (ix+1)*kvx + (iy+1)*kvy + (iz+1); // 111
3300 G4int i4 = (ix+1)*kvx + (iy+1)*kvy + (iz+0); // 110
3301 SetFacet(++nfac, indices[i1], indices[i2], indices[i3], indices[i4]);
3302 }
3303 // check (iz - 1) side
3304 vcheck = (iz == 0) ? 0 : voxels[ix*kx + iy*ky + (iz-1)];
3305 if (vcheck == 0)
3306 {
3307 G4int i1 = (ix+0)*kvx + (iy+0)*kvy + (iz+0); // 000
3308 G4int i2 = (ix+0)*kvx + (iy+1)*kvy + (iz+0); // 010
3309 G4int i3 = (ix+1)*kvx + (iy+1)*kvy + (iz+0); // 110
3310 G4int i4 = (ix+1)*kvx + (iy+0)*kvy + (iz+0); // 100
3311 SetFacet(++nfac, indices[i1], indices[i2], indices[i3], indices[i4]);
3312 }
3313 // check (iz + 1) side
3314 vcheck = (iz == nz - 1) ? 0 : voxels[ix*kx + iy*ky + (iz+1)];
3315 if (vcheck == 0)
3316 {
3317 G4int i1 = (ix+0)*kvx + (iy+0)*kvy + (iz+1); // 001
3318 G4int i2 = (ix+1)*kvx + (iy+0)*kvy + (iz+1); // 101
3319 G4int i3 = (ix+1)*kvx + (iy+1)*kvy + (iz+1); // 111
3320 G4int i4 = (ix+0)*kvx + (iy+1)*kvy + (iz+1); // 011
3321 SetFacet(++nfac, indices[i1], indices[i2], indices[i3], indices[i4]);
3322 }
3323 }
3324 SetReferences();
3325}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
double z() const
double x() const
void setY(double)
double y() const
void setZ(double)
void setX(double)
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)

◆ ~HepPolyhedronBoxMesh()

HepPolyhedronBoxMesh::~HepPolyhedronBoxMesh ( )
overridedefault

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