File indexing completed on 2025-01-18 09:59:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 #ifndef HEP_POLYHEDRON_HH
0202 #define HEP_POLYHEDRON_HH
0203
0204 #include <vector>
0205 #include "G4Types.hh"
0206 #include "G4TwoVector.hh"
0207 #include "G4ThreeVector.hh"
0208 #include "G4Point3D.hh"
0209 #include "G4Normal3D.hh"
0210 #include "G4Transform3D.hh"
0211
0212 #ifndef DEFAULT_NUMBER_OF_STEPS
0213 #define DEFAULT_NUMBER_OF_STEPS 24
0214 #endif
0215
0216 class G4Facet {
0217 friend class HepPolyhedron;
0218 friend std::ostream& operator<<(std::ostream&, const G4Facet &facet);
0219
0220 private:
0221 struct G4Edge { G4int v,f; };
0222 G4Edge edge[4];
0223
0224 public:
0225 G4Facet(G4int v1=0, G4int f1=0, G4int v2=0, G4int f2=0,
0226 G4int v3=0, G4int f3=0, G4int v4=0, G4int f4=0)
0227 { edge[0].v=v1; edge[0].f=f1; edge[1].v=v2; edge[1].f=f2;
0228 edge[2].v=v3; edge[2].f=f3; edge[3].v=v4; edge[3].f=f4; }
0229 };
0230
0231 class HepPolyhedron {
0232 friend std::ostream& operator<<(std::ostream&, const HepPolyhedron &ph);
0233
0234 protected:
0235 static G4ThreadLocal G4int fNumberOfRotationSteps;
0236 G4int nvert, nface;
0237 G4Point3D *pV;
0238 G4Facet *pF;
0239
0240
0241 void AllocateMemory(G4int Nvert, G4int Nface);
0242
0243
0244 G4int FindNeighbour(G4int iFace, G4int iNode, G4int iOrder) const;
0245
0246
0247 G4Normal3D FindNodeNormal(G4int iFace, G4int iNode) const;
0248
0249
0250 void CreatePrism();
0251
0252
0253 void RotateEdge(G4int k1, G4int k2, G4double r1, G4double r2,
0254 G4int v1, G4int v2, G4int vEdge,
0255 G4bool ifWholeCircle, G4int ns, G4int &kface);
0256
0257
0258 void SetSideFacets(G4int ii[4], G4int vv[4],
0259 G4int *kk, G4double *r,
0260 G4double dphi, G4int ns, G4int &kface);
0261
0262
0263 void RotateAroundZ(G4int nstep, G4double phi, G4double dphi,
0264 G4int np1, G4int np2,
0265 const G4double *z, G4double *r,
0266 G4int nodeVis, G4int edgeVis);
0267
0268
0269 void RotateContourAroundZ(G4int nstep, G4double phi, G4double dphi,
0270 const std::vector<G4TwoVector> &rz,
0271 G4int nodeVis, G4int edgeVis);
0272
0273
0274 G4bool TriangulatePolygon(const std::vector<G4TwoVector> &polygon,
0275 std::vector<G4int> &result);
0276
0277
0278 G4bool CheckSnip(const std::vector<G4TwoVector> &contour,
0279 G4int a, G4int b, G4int c,
0280 G4int n, const G4int* V);
0281
0282 public:
0283
0284 HepPolyhedron() : nvert(0), nface(0), pV(nullptr), pF(nullptr) {}
0285
0286
0287 HepPolyhedron(G4int Nvert, G4int Nface);
0288
0289
0290 HepPolyhedron(const HepPolyhedron & from);
0291
0292
0293 HepPolyhedron(HepPolyhedron && from);
0294
0295
0296 virtual ~HepPolyhedron() { delete [] pV; delete [] pF; }
0297
0298
0299 HepPolyhedron & operator=(const HepPolyhedron & from);
0300
0301
0302 HepPolyhedron & operator=(HepPolyhedron && from);
0303
0304
0305 G4int GetNoVertices() const { return nvert; }
0306 G4int GetNoVerteces() const { return nvert; }
0307
0308
0309 G4int GetNoFacets() const { return nface; }
0310
0311
0312 HepPolyhedron & Transform(const G4Transform3D & t);
0313
0314
0315 G4bool GetNextVertexIndex(G4int & index, G4int & edgeFlag) const;
0316
0317
0318 G4Point3D GetVertex(G4int index) const;
0319
0320
0321 G4bool GetNextVertex(G4Point3D & vertex, G4int & edgeFlag) const;
0322
0323
0324 G4bool GetNextVertex(G4Point3D & vertex, G4int & edgeFlag,
0325 G4Normal3D & normal) const;
0326
0327
0328 G4bool GetNextEdgeIndices(G4int & i1, G4int & i2, G4int & edgeFlag,
0329 G4int & iface1, G4int & iface2) const;
0330 G4bool GetNextEdgeIndeces(G4int & i1, G4int & i2, G4int & edgeFlag,
0331 G4int & iface1, G4int & iface2) const
0332 {return GetNextEdgeIndices(i1,i2,edgeFlag,iface1,iface2);}
0333
0334
0335 G4bool GetNextEdgeIndices(G4int & i1, G4int & i2, G4int & edgeFlag) const;
0336 G4bool GetNextEdgeIndeces(G4int & i1, G4int & i2, G4int & edgeFlag) const
0337 {return GetNextEdgeIndices(i1,i2,edgeFlag);}
0338
0339
0340 G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const;
0341
0342
0343 G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag,
0344 G4int &iface1, G4int &iface2) const;
0345
0346
0347 void GetFacet(G4int iFace, G4int &n, G4int *iNodes,
0348 G4int *edgeFlags = nullptr, G4int *iFaces = nullptr) const;
0349
0350
0351 void GetFacet(G4int iFace, G4int &n, G4Point3D *nodes,
0352 G4int *edgeFlags=nullptr, G4Normal3D *normals=nullptr) const;
0353
0354
0355 G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=nullptr,
0356 G4Normal3D *normals=nullptr) const;
0357
0358
0359 G4Normal3D GetNormal(G4int iFace) const;
0360
0361
0362 G4Normal3D GetUnitNormal(G4int iFace) const;
0363
0364
0365 G4bool GetNextNormal(G4Normal3D &normal) const;
0366
0367
0368 G4bool GetNextUnitNormal(G4Normal3D &normal) const;
0369
0370
0371 HepPolyhedron add(const HepPolyhedron &p) const;
0372 HepPolyhedron subtract(const HepPolyhedron &p) const;
0373 HepPolyhedron intersect(const HepPolyhedron &p) const;
0374
0375
0376 G4double GetSurfaceArea() const;
0377
0378
0379 G4double GetVolume() const;
0380
0381
0382 static G4int GetNumberOfRotationSteps();
0383
0384
0385 void SetVertex(G4int index, const G4Point3D& v);
0386
0387
0388 void SetFacet(G4int index, G4int iv1, G4int iv2, G4int iv3, G4int iv4 = 0);
0389
0390
0391
0392 void SetReferences();
0393
0394
0395
0396 void JoinCoplanarFacets(G4double tolerance);
0397
0398
0399 void InvertFacets();
0400
0401
0402 static void SetNumberOfRotationSteps(G4int n);
0403
0404
0405 static void ResetNumberOfRotationSteps();
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416 G4int createTwistedTrap(G4double Dz,
0417 const G4double xy1[][2], const G4double xy2[][2]);
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436 G4int createPolyhedron(G4int Nnodes, G4int Nfaces,
0437 const G4double xyz[][3], const G4int faces[][4]);
0438
0439
0440
0441
0442
0443
0444 G4Point3D vertexUnweightedMean() const;
0445 };
0446
0447 class HepPolyhedronTrd2 : public HepPolyhedron
0448 {
0449 public:
0450 HepPolyhedronTrd2(G4double Dx1, G4double Dx2,
0451 G4double Dy1, G4double Dy2, G4double Dz);
0452 ~HepPolyhedronTrd2() override;
0453 };
0454
0455 class HepPolyhedronTrd1 : public HepPolyhedronTrd2
0456 {
0457 public:
0458 HepPolyhedronTrd1(G4double Dx1, G4double Dx2,
0459 G4double Dy, G4double Dz);
0460 ~HepPolyhedronTrd1() override;
0461 };
0462
0463 class HepPolyhedronBox : public HepPolyhedronTrd2
0464 {
0465 public:
0466 HepPolyhedronBox(G4double Dx, G4double Dy, G4double Dz);
0467 ~HepPolyhedronBox() override;
0468 };
0469
0470 class HepPolyhedronTrap : public HepPolyhedron
0471 {
0472 public:
0473 HepPolyhedronTrap(G4double Dz, G4double Theta, G4double Phi,
0474 G4double Dy1,
0475 G4double Dx1, G4double Dx2, G4double Alp1,
0476 G4double Dy2,
0477 G4double Dx3, G4double Dx4, G4double Alp2);
0478 ~HepPolyhedronTrap() override;
0479 };
0480
0481 class HepPolyhedronPara : public HepPolyhedronTrap
0482 {
0483 public:
0484 HepPolyhedronPara(G4double Dx, G4double Dy, G4double Dz,
0485 G4double Alpha, G4double Theta, G4double Phi);
0486 ~HepPolyhedronPara() override;
0487 };
0488
0489 class HepPolyhedronParaboloid : public HepPolyhedron
0490 {
0491 public:
0492 HepPolyhedronParaboloid(G4double r1,
0493 G4double r2,
0494 G4double dz,
0495 G4double Phi1,
0496 G4double Dphi);
0497 ~HepPolyhedronParaboloid() override;
0498 };
0499
0500 class HepPolyhedronHype : public HepPolyhedron
0501 {
0502 public:
0503 HepPolyhedronHype(G4double r1,
0504 G4double r2,
0505 G4double tan1,
0506 G4double tan2,
0507 G4double halfZ);
0508 ~HepPolyhedronHype() override;
0509 };
0510
0511 class HepPolyhedronCons : public HepPolyhedron
0512 {
0513 public:
0514 HepPolyhedronCons(G4double Rmn1, G4double Rmx1,
0515 G4double Rmn2, G4double Rmx2, G4double Dz,
0516 G4double Phi1, G4double Dphi);
0517 ~HepPolyhedronCons() override;
0518 };
0519
0520 class HepPolyhedronCone : public HepPolyhedronCons
0521 {
0522 public:
0523 HepPolyhedronCone(G4double Rmn1, G4double Rmx1,
0524 G4double Rmn2, G4double Rmx2, G4double Dz);
0525 ~HepPolyhedronCone() override;
0526 };
0527
0528 class HepPolyhedronTubs : public HepPolyhedronCons
0529 {
0530 public:
0531 HepPolyhedronTubs(G4double Rmin, G4double Rmax, G4double Dz,
0532 G4double Phi1, G4double Dphi);
0533 ~HepPolyhedronTubs() override;
0534 };
0535
0536 class HepPolyhedronTube : public HepPolyhedronCons
0537 {
0538 public:
0539 HepPolyhedronTube (G4double Rmin, G4double Rmax, G4double Dz);
0540 ~HepPolyhedronTube() override;
0541 };
0542
0543 class HepPolyhedronPgon : public HepPolyhedron
0544 {
0545 public:
0546 HepPolyhedronPgon(G4double phi, G4double dphi, G4int npdv, G4int nz,
0547 const G4double *z,
0548 const G4double *rmin,
0549 const G4double *rmax);
0550 HepPolyhedronPgon(G4double phi, G4double dphi, G4int npdv,
0551 const std::vector<G4TwoVector> &rz);
0552 ~HepPolyhedronPgon() override;
0553 };
0554
0555 class HepPolyhedronPcon : public HepPolyhedronPgon
0556 {
0557 public:
0558 HepPolyhedronPcon(G4double phi, G4double dphi, G4int nz,
0559 const G4double *z,
0560 const G4double *rmin,
0561 const G4double *rmax);
0562 HepPolyhedronPcon(G4double phi, G4double dphi,
0563 const std::vector<G4TwoVector> &rz);
0564 ~HepPolyhedronPcon() override;
0565 };
0566
0567 class HepPolyhedronSphere : public HepPolyhedron
0568 {
0569 public:
0570 HepPolyhedronSphere(G4double rmin, G4double rmax,
0571 G4double phi, G4double dphi,
0572 G4double the, G4double dthe);
0573 ~HepPolyhedronSphere() override;
0574 };
0575
0576 class HepPolyhedronTorus : public HepPolyhedron
0577 {
0578 public:
0579 HepPolyhedronTorus(G4double rmin, G4double rmax, G4double rtor,
0580 G4double phi, G4double dphi);
0581 ~HepPolyhedronTorus() override;
0582 };
0583
0584 class HepPolyhedronTet : public HepPolyhedron
0585 {
0586 public:
0587 HepPolyhedronTet(const G4double p0[3],
0588 const G4double p1[3],
0589 const G4double p2[3],
0590 const G4double p3[3]);
0591 ~HepPolyhedronTet() override;
0592 };
0593
0594 class HepPolyhedronEllipsoid : public HepPolyhedron
0595 {
0596 public:
0597 HepPolyhedronEllipsoid(G4double dx, G4double dy, G4double dz,
0598 G4double zcut1, G4double zcut2);
0599 ~HepPolyhedronEllipsoid() override;
0600 };
0601
0602 class HepPolyhedronEllipticalCone : public HepPolyhedron
0603 {
0604 public:
0605 HepPolyhedronEllipticalCone(G4double dx, G4double dy, G4double z,
0606 G4double zcut1);
0607 ~HepPolyhedronEllipticalCone() override;
0608 };
0609
0610 class HepPolyhedronHyperbolicMirror : public HepPolyhedron
0611 {
0612 public:
0613 HepPolyhedronHyperbolicMirror(G4double a, G4double h, G4double r);
0614 ~HepPolyhedronHyperbolicMirror() override;
0615 };
0616
0617 class HepPolyhedronTetMesh : public HepPolyhedron
0618 {
0619 public:
0620 HepPolyhedronTetMesh(const std::vector<G4ThreeVector>& tetrahedra);
0621 ~HepPolyhedronTetMesh() override;
0622 };
0623
0624 class HepPolyhedronBoxMesh : public HepPolyhedron
0625 {
0626 public:
0627 HepPolyhedronBoxMesh(G4double sizeX, G4double sizeY, G4double sizeZ,
0628 const std::vector<G4ThreeVector>& positions);
0629 ~HepPolyhedronBoxMesh() override;
0630 };
0631
0632 #endif