Creates user defined polyhedron. This function allows to the user to define arbitrary polyhedron. The faces of the polyhedron should be either triangles or planar quadrilateral. Nodes of a face are defined by indexes pointing to the elements in the xyz array. Numeration of the elements in the array starts from 1 (like in fortran). The indexes can be positive or negative. Negative sign means that the corresponding edge is invisible. The normal of the face should be directed to exterior of the polyhedron.
497 const G4int numSide =
504 typedef G4int int4[4];
511 std::vector<G4bool> chopped(
numCorner,
false);
512 std::vector<G4int*> triQuads;
515 while (remaining >= 3)
520 G4int iStepper = iStarter;
523 if (A < 0) { A = iStepper; }
524 else if (
B < 0) {
B = iStepper; }
525 else if (
C < 0) {
C = iStepper; }
528 if (++iStepper >=
numCorner) { iStepper = 0; }
530 while (chopped[iStepper]);
532 while (
C < 0 && iStepper != iStarter);
547 triQuads.push_back(tq);
555 if (++iStarter >=
numCorner) { iStarter = 0; }
557 while (chopped[iStarter]);
563 nFaces = numSide *
numCorner + 2 * triQuads.size();
564 faces_vec =
new int4[nFaces];
568 for (
G4int iEnd = 0; iEnd < 2; ++iEnd)
570 for (
size_t i = 0; i < triQuads.size(); ++i)
583 a = triQuads[i][0] + addition;
584 b = triQuads[i][2] + addition;
585 c = triQuads[i][1] + addition;
588 G4int bc = std::abs(c - b);
589 G4int ca = std::abs(a - c);
590 faces_vec[iface][0] = (ab == 1 || ab ==
d)? a: -a;
591 faces_vec[iface][1] = (bc == 1 || bc ==
d)? b: -b;
592 faces_vec[iface][2] = (ca == 1 || ca ==
d)? c: -c;
593 faces_vec[iface][3] = 0;
600 xyz =
new double3[nNodes];
604 for (
G4int iSide = 0; iSide < numSide; ++iSide)
608 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
609 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
613 if (iCorner < numCorner - 1)
615 faces_vec[iface][0] = ixyz + 1;
616 faces_vec[iface][1] = -(ixyz + numCorner + 1);
617 faces_vec[iface][2] = ixyz + numCorner + 2;
618 faces_vec[iface][3] = ixyz + 2;
622 faces_vec[iface][0] = ixyz + 1;
623 faces_vec[iface][1] = -(ixyz + numCorner + 1);
624 faces_vec[iface][2] = ixyz + 2;
625 faces_vec[iface][3] = ixyz - numCorner + 2;
628 else if (iSide == numSide - 1)
630 if (iCorner < numCorner - 1)
632 faces_vec[iface][0] = ixyz + 1;
633 faces_vec[iface][1] = ixyz + numCorner + 1;
634 faces_vec[iface][2] = ixyz + numCorner + 2;
635 faces_vec[iface][3] = -(ixyz + 2);
639 faces_vec[iface][0] = ixyz + 1;
640 faces_vec[iface][1] = ixyz + numCorner + 1;
641 faces_vec[iface][2] = ixyz + 2;
642 faces_vec[iface][3] = -(ixyz - numCorner + 2);
647 if (iCorner < numCorner - 1)
649 faces_vec[iface][0] = ixyz + 1;
650 faces_vec[iface][1] = -(ixyz + numCorner + 1);
651 faces_vec[iface][2] = ixyz + numCorner + 2;
652 faces_vec[iface][3] = -(ixyz + 2);
656 faces_vec[iface][0] = ixyz + 1;
657 faces_vec[iface][1] = -(ixyz + numCorner + 1);
658 faces_vec[iface][2] = ixyz + 2;
659 faces_vec[iface][3] = -(ixyz - numCorner + 2);
672 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
673 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
682 xyz =
new double3[nNodes];
683 faces_vec =
new int4[nFaces];
686 G4int ixyz = 0, iface = 0;
687 for (
G4int iSide = 0; iSide < numSide; ++iSide)
691 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
692 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
695 if (iSide < numSide - 1)
697 if (iCorner < numCorner - 1)
699 faces_vec[iface][0] = ixyz + 1;
700 faces_vec[iface][1] = -(ixyz + numCorner + 1);
701 faces_vec[iface][2] = ixyz + numCorner + 2;
702 faces_vec[iface][3] = -(ixyz + 2);
706 faces_vec[iface][0] = ixyz + 1;
707 faces_vec[iface][1] = -(ixyz + numCorner + 1);
708 faces_vec[iface][2] = ixyz + 2;
709 faces_vec[iface][3] = -(ixyz - numCorner + 2);
714 if (iCorner < numCorner - 1)
716 faces_vec[iface][0] = ixyz + 1;
717 faces_vec[iface][1] = -(ixyz + numCorner - nFaces + 1);
718 faces_vec[iface][2] = ixyz + numCorner - nFaces + 2;
719 faces_vec[iface][3] = -(ixyz + 2);
723 faces_vec[iface][0] = ixyz + 1;
724 faces_vec[iface][1] = -(ixyz - nFaces + numCorner + 1);
725 faces_vec[iface][2] = ixyz - nFaces + 2;
726 faces_vec[iface][3] = -(ixyz - numCorner + 2);
741 std::ostringstream message;
742 message <<
"Problem creating G4Polyhedron for: " <<
GetName();
743 G4Exception(
"G4GenericPolycone::CreatePolyhedron()",
"GeomSolids1002",
G4PolyconeSideRZ * corners
G4int createPolyhedron(G4int Nnodes, G4int Nfaces, const G4double xyz[][3], const G4int faces[][4])
double A(double temperature)
static const double twopi
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static G4int GetNumberOfRotationSteps()