Geant4 11.2.2
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])
 
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 624 of file HepPolyhedron.h.

Constructor & Destructor Documentation

◆ HepPolyhedronBoxMesh()

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

Definition at line 3102 of file HepPolyhedron.cc.

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