59 #if !defined(G4GEOM_USE_UPOLYHEDRA)
72 using namespace CLHEP;
91 std::ostringstream message;
92 message <<
"Solid must have at least one side - " <<
GetName() <<
G4endl
93 <<
" No sides specified !";
94 G4Exception(
"G4Polyhedra::G4Polyhedra()",
"GeomSolids0002",
102 if ( (phiTotal <=0) || (phiTotal >= twopi*(1-
DBL_EPSILON)) )
103 { phiTotal = twopi; }
104 G4double convertRad = std::cos(0.5*phiTotal/theNumSide);
120 for (i=0; i<numZPlanes; i++)
122 if (( i < numZPlanes-1) && ( zPlane[i] == zPlane[i+1] ))
124 if( (rInner[i] > rOuter[i+1])
125 ||(rInner[i+1] > rOuter[i]) )
128 std::ostringstream message;
129 message <<
"Cannot create a Polyhedra with no contiguous segments."
131 <<
" Segments are not contiguous !" <<
G4endl
132 <<
" rMin[" << i <<
"] = " << rInner[i]
133 <<
" -- rMax[" << i+1 <<
"] = " << rOuter[i+1] <<
G4endl
134 <<
" rMin[" << i+1 <<
"] = " << rInner[i+1]
135 <<
" -- rMax[" << i <<
"] = " << rOuter[i];
136 G4Exception(
"G4Polyhedra::G4Polyhedra()",
"GeomSolids0002",
151 rz->
ScaleA( 1/convertRad );
156 Create( phiStart, phiTotal, theNumSide, rz );
176 std::ostringstream message;
177 message <<
"Solid must have at least one side - " <<
GetName() <<
G4endl
178 <<
" No sides specified !";
179 G4Exception(
"G4Polyhedra::G4Polyhedra()",
"GeomSolids0002",
185 Create( phiStart, phiTotal, theNumSide, rz );
209 if (rz->
Amin() < 0.0)
211 std::ostringstream message;
212 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl
213 <<
" All R values must be >= 0 !";
214 G4Exception(
"G4Polyhedra::Create()",
"GeomSolids0002",
224 std::ostringstream message;
225 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl
226 <<
" R/Z cross section is zero or near zero: " << rzArea;
227 G4Exception(
"G4Polyhedra::Create()",
"GeomSolids0002",
234 std::ostringstream message;
235 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl
236 <<
" Too few unique R/Z values !";
237 G4Exception(
"G4Polyhedra::Create()",
"GeomSolids0002",
243 std::ostringstream message;
244 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl
245 <<
" R/Z segments cross !";
246 G4Exception(
"G4Polyhedra::Create()",
"GeomSolids0002",
259 if ( (phiTotal <= 0) || (phiTotal > twopi*(1-
DBL_EPSILON)) )
271 endPhi = phiStart+phiTotal;
294 next->
r = iterRZ.
GetA();
295 next->
z = iterRZ.
GetB();
296 }
while( ++next, iterRZ.
Next() );
348 }
while( prev=corner, corner=next, corner >
corners );
378 phiIsOpen(false), genericPgon(false), numCorner(0), corners(0),
379 original_parameters(0), enclosingCylinder(0)
411 if (
this == &source)
return *
this;
482 std::ostringstream message;
483 message <<
"Solid " <<
GetName() <<
" built using generic construct."
484 <<
G4endl <<
"Not applicable to the generic construct !";
485 G4Exception(
"G4Polyhedra::Reset()",
"GeomSolids1001",
599 G4int oldprc = os.precision(16);
600 os <<
"-----------------------------------------------------------\n"
601 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
602 <<
" ===================================================\n"
603 <<
" Solid type: G4Polyhedra\n"
606 <<
" ending phi angle : " <<
endPhi/
degree <<
" degrees \n"
607 <<
" number of sides : " <<
numSide <<
" \n";
612 os <<
" number of Z planes: " << numPlanes <<
"\n"
614 for (i=0; i<numPlanes; i++)
616 os <<
" Z plane " << i <<
": "
619 os <<
" Tangent distances to inner surface (Rmin): \n";
620 for (i=0; i<numPlanes; i++)
622 os <<
" Z plane " << i <<
": "
625 os <<
" Tangent distances to outer surface (Rmax): \n";
626 for (i=0; i<numPlanes; i++)
628 os <<
" Z plane " << i <<
": "
632 os <<
" number of RZ points: " <<
numCorner <<
"\n"
633 <<
" RZ values (corners): \n";
639 os <<
"-----------------------------------------------------------\n";
640 os.precision(oldprc);
654 G4double lambda1, lambda2, chose,aOne,aTwo;
665 if( (chose>=0.) && (chose < aOne) )
669 return (p2+lambda1*v+lambda2*w);
674 return (p0+lambda1*t+lambda2*u);
693 return (p2 + lambda1*w + lambda2*v);
705 G4double chose, totArea=0., Achose1, Achose2,
706 rad1, rad2, sinphi1, sinphi2, cosphi1, cosphi2;
708 area, aTop=0., aBottom=0., zVal=0.;
711 std::vector<G4double> aVector1;
712 std::vector<G4double> aVector2;
713 std::vector<G4double> aVector3;
721 for(j=0; j<numPlanes-1; j++)
727 area = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
728 aVector1.push_back(area);
731 for(j=0; j<numPlanes-1; j++)
737 area = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
738 aVector2.push_back(area);
741 for(j=0; j<numPlanes-1; j++)
752 else { aVector3.push_back(0.); }
755 for(j=0; j<numPlanes-1; j++)
757 totArea +=
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
767 aTop = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
775 aBottom = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
779 Achose2 =
numSide*(aVector1[0]+aVector2[0])+2.*aVector3[0];
782 if( (chose >= 0.) && (chose < aTop + aBottom) )
785 rang = std::floor((chose-
startPhi)/ksi-0.01);
786 if(rang<0) { rang=0; }
787 rang = std::fabs(rang);
788 sinphi1 = std::sin(
startPhi+rang*ksi);
789 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
790 cosphi1 = std::cos(
startPhi+rang*ksi);
791 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
793 if(chose>=0. && chose<aTop)
813 for (j=0; j<numPlanes-1; j++)
815 if( ((chose >= Achose1) && (chose < Achose2)) || (j == numPlanes-2) )
819 Achose1 +=
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
820 Achose2 = Achose1 +
numSide*(aVector1[j+1]+aVector2[j+1])
830 totArea =
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
833 if( (chose>=0.) && (chose<
numSide*aVector1[j]) )
836 rang = std::floor((chose-
startPhi)/ksi-0.01);
837 if(rang<0) { rang=0; }
838 rang = std::fabs(rang);
841 sinphi1 = std::sin(
startPhi+rang*ksi);
842 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
843 cosphi1 = std::cos(
startPhi+rang*ksi);
844 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
856 else if ( (chose >=
numSide*aVector1[j])
857 && (chose <=
numSide*(aVector1[j]+aVector2[j])) )
860 rang = std::floor((chose-
startPhi)/ksi-0.01);
861 if(rang<0) { rang=0; }
862 rang = std::fabs(rang);
865 sinphi1 = std::sin(
startPhi+rang*ksi);
866 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
867 cosphi1 = std::cos(
startPhi+rang*ksi);
868 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
882 if( (chose>=0.) && (chose < 1.) )
957 typedef G4int int4[4];
964 std::vector<G4bool> chopped(
numCorner,
false);
965 std::vector<G4int*> triQuads;
968 while (remaining >= 3)
972 G4int A = -1, B = -1, C = -1;
973 G4int iStepper = iStarter;
976 if (A < 0) { A = iStepper; }
977 else if (B < 0) { B = iStepper; }
978 else if (C < 0) { C = iStepper; }
981 if (++iStepper >=
numCorner) iStepper = 0;
983 while (chopped[iStepper]);
985 while (C < 0 && iStepper != iStarter);
1000 triQuads.push_back(tq);
1008 if (++iStarter >=
numCorner) { iStarter = 0; }
1010 while (chopped[iStarter]);
1018 faces_vec =
new int4[nFaces];
1022 for (
G4int iEnd = 0; iEnd < 2; ++iEnd)
1024 for (
size_t i = 0; i < triQuads.size(); ++i)
1037 a = triQuads[i][0] + addition;
1038 b = triQuads[i][2] + addition;
1039 c = triQuads[i][1] + addition;
1042 G4int bc = std::abs(c - b);
1043 G4int ca = std::abs(a - c);
1044 faces_vec[iface][0] = (ab == 1 || ab == d)? a: -a;
1045 faces_vec[iface][1] = (bc == 1 || bc == d)? b: -b;
1046 faces_vec[iface][2] = (ca == 1 || ca == d)? c: -c;
1047 faces_vec[iface][3] = 0;
1054 xyz =
new double3[nNodes];
1062 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1063 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1065 if (iCorner < numCorner - 1)
1067 faces_vec[iface][0] = ixyz + 1;
1068 faces_vec[iface][1] = ixyz + numCorner + 1;
1069 faces_vec[iface][2] = ixyz + numCorner + 2;
1070 faces_vec[iface][3] = ixyz + 2;
1074 faces_vec[iface][0] = ixyz + 1;
1075 faces_vec[iface][1] = ixyz + numCorner + 1;
1076 faces_vec[iface][2] = ixyz + 2;
1077 faces_vec[iface][3] = ixyz - numCorner + 2;
1089 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1090 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1099 xyz =
new double3[nNodes];
1100 faces_vec =
new int4[nFaces];
1104 G4int ixyz = 0, iface = 0;
1109 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1110 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1112 if (iSide < numSide - 1)
1114 if (iCorner < numCorner - 1)
1116 faces_vec[iface][0] = ixyz + 1;
1117 faces_vec[iface][1] = ixyz + numCorner + 1;
1118 faces_vec[iface][2] = ixyz + numCorner + 2;
1119 faces_vec[iface][3] = ixyz + 2;
1123 faces_vec[iface][0] = ixyz + 1;
1124 faces_vec[iface][1] = ixyz + numCorner + 1;
1125 faces_vec[iface][2] = ixyz + 2;
1126 faces_vec[iface][3] = ixyz - numCorner + 2;
1131 if (iCorner < numCorner - 1)
1133 faces_vec[iface][0] = ixyz + 1;
1134 faces_vec[iface][1] = ixyz + numCorner - nFaces + 1;
1135 faces_vec[iface][2] = ixyz + numCorner - nFaces + 2;
1136 faces_vec[iface][3] = ixyz + 2;
1140 faces_vec[iface][0] = ixyz + 1;
1141 faces_vec[iface][1] = ixyz - nFaces + numCorner + 1;
1142 faces_vec[iface][2] = ixyz - nFaces + 2;
1143 faces_vec[iface][3] = ixyz - numCorner + 2;
1153 G4int problem = polyhedron->createPolyhedron(nNodes, nFaces, xyz, faces_vec);
1154 delete [] faces_vec;
1158 std::ostringstream message;
1159 message <<
"Problem creating G4Polyhedron for: " <<
GetName();
1160 G4Exception(
"G4Polyhedra::CreatePolyhedron()",
"GeomSolids1002",
1176 G4bool isConvertible=
true;
1182 std::vector<G4double> Z;
1183 std::vector<G4double> Rmin;
1184 std::vector<G4double> Rmax;
1186 G4int countPlanes=1;
1197 Rmax.push_back (
corners[1].r);icurr=1;
1199 else if (Zprev ==
corners[numPlanes-1].z)
1201 Rmin.push_back(
corners[numPlanes-1].r);
1202 Rmax.push_back (
corners[0].r);
1208 Rmax.push_back (
corners[0].r);
1213 G4int inextr=0, inextl=0;
1214 for (
G4int i=0; i < numPlanes-2; i++)
1217 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1219 if((
corners[inextr].z >= Zmax) & (
corners[inextl].
z >= Zmax)) {
break; }
1234 Rmin.push_back(
corners[inextl].r);
1235 Rmax.push_back(
corners[icurr].r);
1239 Rmin.push_back(
corners[inextl].r);
1248 Rmin.push_back(
corners[icurl].r);
1249 Rmax.push_back(
corners[icurr].r);
1253 Rmin.push_back(
corners[icurl].r);
1260 isConvertible=
false;
break;
1262 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1270 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1272 Rmin.push_back(
corners[inextl].r);
1273 Rmax.push_back (
corners[inextr].r);
1277 Z.push_back(Zright);
1286 Rmax.push_back(
corners[inextr].r);
1287 Rmin.push_back(
corners[icurr].r);
1291 Rmin.push_back(
corners[icurl].r + (Zright-
corners[icurl].z)/difZl
1293 Rmax.push_back(
corners[inextr].r);
1301 Rmax.push_back(
corners[inextr].r);
1302 Rmin.push_back (
corners[icurr].r);
1306 Rmax.push_back(
corners[inextr].r);
1314 isConvertible=
false;
break;
1324 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1328 Rmax.push_back(
corners[inextr].r);
1329 Rmin.push_back(
corners[inextl].r);
1333 Rmax.push_back(
corners[inextr].r);
1334 Rmin.push_back(
corners[inextl].r);
1347 for(
G4int j=0; j < countPlanes; j++)
1361 std::ostringstream message;
1363 <<
"cannot be converted to Polyhedra with (Rmin,Rmaz,Z) parameters!";
1364 G4Exception(
"G4Polyhedra::SetOriginalParameters()",
1373 for(
G4int j=0; j < numPlanes; j++)
void CopyStuff(const G4Polyhedra &source)
G4bool CrossesItself(G4double tolerance)
ThreeVector shoot(const G4int Ap, const G4int Af)
G4VCSGfaceted & operator=(const G4VCSGfaceted &source)
G4bool fRebuildPolyhedron
G4Polyhedron * fpPolyhedron
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
G4GeometryType GetEntityType() const
G4PolyhedraHistorical * original_parameters
G4ThreeVector GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, G4ThreeVector p2, G4ThreeVector p3) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4PolyhedraSideRZ * corners
G4bool MustBeOutside(const G4ThreeVector &p) const
void Create(G4double phiStart, G4double phiTotal, G4int numSide, G4ReduciblePolygon *rz)
G4ThreeVector GetPointOnSurface() const
static double normal(HepRandomEngine *eptr)
G4bool RemoveDuplicateVertices(G4double tolerance)
G4EnclosingCylinder * enclosingCylinder
G4bool RemoveRedundantVertices(G4double tolerance)
G4ThreeVector GetPointOnSurfaceGeneric() const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
G4int NumVertices() const
void ScaleA(G4double scale)
static const G4double A[nN]
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
EInside Inside(const G4ThreeVector &p) const
G4Polyhedron * CreatePolyhedron() const
static const double degree
G4Polyhedra & operator=(const G4Polyhedra &source)
void SetOriginalParameters(G4PolyhedraHistorical *pars)
G4ThreeVector GetPointOnTriangle(G4ThreeVector p0, G4ThreeVector p1, G4ThreeVector p2) const
virtual EInside Inside(const G4ThreeVector &p) const
G4bool ShouldMiss(const G4ThreeVector &p, const G4ThreeVector &v) const
std::ostream & StreamInfo(std::ostream &os) const
G4Polyhedra(const G4String &name, G4double phiStart, G4double phiTotal, G4int numSide, G4int numZPlanes, const G4double zPlane[], const G4double rInner[], const G4double rOuter[])