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";
611 os <<
" number of Z planes: " << numPlanes <<
"\n"
613 for (i=0; i<numPlanes; i++)
615 os <<
" Z plane " << i <<
": "
618 os <<
" Tangent distances to inner surface (Rmin): \n";
619 for (i=0; i<numPlanes; i++)
621 os <<
" Z plane " << i <<
": "
624 os <<
" Tangent distances to outer surface (Rmax): \n";
625 for (i=0; i<numPlanes; i++)
627 os <<
" Z plane " << i <<
": "
631 os <<
" number of RZ points: " <<
numCorner <<
"\n"
632 <<
" RZ values (corners): \n";
638 os <<
"-----------------------------------------------------------\n";
639 os.precision(oldprc);
653 G4double lambda1, lambda2, chose,aOne,aTwo;
664 if( (chose>=0.) && (chose < aOne) )
668 return (p2+lambda1*v+lambda2*w);
673 return (p0+lambda1*t+lambda2*u);
692 return (p2 + lambda1*w + lambda2*v);
704 G4double chose, totArea=0., Achose1, Achose2,
705 rad1, rad2, sinphi1, sinphi2, cosphi1, cosphi2;
707 area, aTop=0., aBottom=0., zVal=0.;
710 std::vector<G4double> aVector1;
711 std::vector<G4double> aVector2;
712 std::vector<G4double> aVector3;
720 for(j=0; j<numPlanes-1; j++)
726 area = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
727 aVector1.push_back(area);
730 for(j=0; j<numPlanes-1; j++)
736 area = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
737 aVector2.push_back(area);
740 for(j=0; j<numPlanes-1; j++)
751 else { aVector3.push_back(0.); }
754 for(j=0; j<numPlanes-1; j++)
756 totArea +=
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
766 aTop = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
774 aBottom = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
778 Achose2 =
numSide*(aVector1[0]+aVector2[0])+2.*aVector3[0];
781 if( (chose >= 0.) && (chose < aTop + aBottom) )
784 rang = std::floor((chose-
startPhi)/ksi-0.01);
785 if(rang<0) { rang=0; }
786 rang = std::fabs(rang);
787 sinphi1 = std::sin(
startPhi+rang*ksi);
788 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
789 cosphi1 = std::cos(
startPhi+rang*ksi);
790 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
792 if(chose>=0. && chose<aTop)
812 for (j=0; j<numPlanes-1; j++)
814 if( ((chose >= Achose1) && (chose < Achose2)) || (j == numPlanes-2) )
818 Achose1 +=
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
819 Achose2 = Achose1 +
numSide*(aVector1[j+1]+aVector2[j+1])
829 totArea =
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
832 if( (chose>=0.) && (chose<
numSide*aVector1[j]) )
835 rang = std::floor((chose-
startPhi)/ksi-0.01);
836 if(rang<0) { rang=0; }
837 rang = std::fabs(rang);
840 sinphi1 = std::sin(
startPhi+rang*ksi);
841 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
842 cosphi1 = std::cos(
startPhi+rang*ksi);
843 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
855 else if ( (chose >=
numSide*aVector1[j])
856 && (chose <=
numSide*(aVector1[j]+aVector2[j])) )
859 rang = std::floor((chose-
startPhi)/ksi-0.01);
860 if(rang<0) { rang=0; }
861 rang = std::fabs(rang);
864 sinphi1 = std::sin(
startPhi+rang*ksi);
865 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
866 cosphi1 = std::cos(
startPhi+rang*ksi);
867 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
881 if( (chose>=0.) && (chose < 1.) )
956 typedef G4int int4[4];
963 std::vector<G4bool> chopped(
numCorner,
false);
964 std::vector<G4int*> triQuads;
967 while (remaining >= 3)
971 G4int A = -1, B = -1, C = -1;
972 G4int iStepper = iStarter;
975 if (A < 0) { A = iStepper; }
976 else if (B < 0) { B = iStepper; }
977 else if (C < 0) { C = iStepper; }
980 if (++iStepper >=
numCorner) iStepper = 0;
982 while (chopped[iStepper]);
984 while (C < 0 && iStepper != iStarter);
999 triQuads.push_back(tq);
1007 if (++iStarter >=
numCorner) { iStarter = 0; }
1009 while (chopped[iStarter]);
1017 faces_vec =
new int4[nFaces];
1021 for (
G4int iEnd = 0; iEnd < 2; ++iEnd)
1023 for (
size_t i = 0; i < triQuads.size(); ++i)
1036 a = triQuads[i][0] + addition;
1037 b = triQuads[i][2] + addition;
1038 c = triQuads[i][1] + addition;
1041 G4int bc = std::abs(c - b);
1042 G4int ca = std::abs(a - c);
1043 faces_vec[iface][0] = (ab == 1 || ab == d)? a: -a;
1044 faces_vec[iface][1] = (bc == 1 || bc == d)? b: -b;
1045 faces_vec[iface][2] = (ca == 1 || ca == d)? c: -c;
1046 faces_vec[iface][3] = 0;
1053 xyz =
new double3[nNodes];
1061 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1062 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1064 if (iCorner < numCorner - 1)
1066 faces_vec[iface][0] = ixyz + 1;
1067 faces_vec[iface][1] = ixyz + numCorner + 1;
1068 faces_vec[iface][2] = ixyz + numCorner + 2;
1069 faces_vec[iface][3] = ixyz + 2;
1073 faces_vec[iface][0] = ixyz + 1;
1074 faces_vec[iface][1] = ixyz + numCorner + 1;
1075 faces_vec[iface][2] = ixyz + 2;
1076 faces_vec[iface][3] = ixyz - numCorner + 2;
1088 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1089 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1098 xyz =
new double3[nNodes];
1099 faces_vec =
new int4[nFaces];
1103 G4int ixyz = 0, iface = 0;
1108 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1109 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1111 if (iSide < numSide - 1)
1113 if (iCorner < numCorner - 1)
1115 faces_vec[iface][0] = ixyz + 1;
1116 faces_vec[iface][1] = ixyz + numCorner + 1;
1117 faces_vec[iface][2] = ixyz + numCorner + 2;
1118 faces_vec[iface][3] = ixyz + 2;
1122 faces_vec[iface][0] = ixyz + 1;
1123 faces_vec[iface][1] = ixyz + numCorner + 1;
1124 faces_vec[iface][2] = ixyz + 2;
1125 faces_vec[iface][3] = ixyz - numCorner + 2;
1130 if (iCorner < numCorner - 1)
1132 faces_vec[iface][0] = ixyz + 1;
1133 faces_vec[iface][1] = ixyz + numCorner - nFaces + 1;
1134 faces_vec[iface][2] = ixyz + numCorner - nFaces + 2;
1135 faces_vec[iface][3] = ixyz + 2;
1139 faces_vec[iface][0] = ixyz + 1;
1140 faces_vec[iface][1] = ixyz - nFaces + numCorner + 1;
1141 faces_vec[iface][2] = ixyz - nFaces + 2;
1142 faces_vec[iface][3] = ixyz - numCorner + 2;
1152 G4int problem = polyhedron->createPolyhedron(nNodes, nFaces, xyz, faces_vec);
1153 delete [] faces_vec;
1157 std::ostringstream message;
1158 message <<
"Problem creating G4Polyhedron for: " <<
GetName();
1159 G4Exception(
"G4Polyhedra::CreatePolyhedron()",
"GeomSolids1002",
1175 G4bool isConvertible=
true;
1181 std::vector<G4double> Z;
1182 std::vector<G4double> Rmin;
1183 std::vector<G4double> Rmax;
1185 G4int countPlanes=1;
1196 Rmax.push_back (
corners[1].r);icurr=1;
1198 else if (Zprev ==
corners[numPlanes-1].z)
1200 Rmin.push_back(
corners[numPlanes-1].r);
1201 Rmax.push_back (
corners[0].r);
1207 Rmax.push_back (
corners[0].r);
1212 G4int inextr=0, inextl=0;
1213 for (
G4int i=0; i < numPlanes-2; i++)
1216 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1218 if((
corners[inextr].z >= Zmax) & (
corners[inextl].
z >= Zmax)) {
break; }
1233 Rmin.push_back(
corners[icurl].r);
1234 Rmax.push_back(Rmax[countPlanes-2]);
1235 Rmax[countPlanes-2]=
corners[icurl].
r;
1239 Rmin.push_back(
corners[inextl].r);
1240 Rmax.push_back(
corners[icurl].r);
1245 Rmin.push_back(
corners[inextl].r);
1246 Rmax.push_back (
corners[icurr].r + (Zleft-
corners[icurr].z)/difZr
1251 isConvertible=
false;
break;
1253 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1261 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1263 Rmin.push_back(
corners[inextl].r);
1264 Rmax.push_back (
corners[inextr].r);
1268 Z.push_back(Zright);
1277 Rmin.push_back(
corners[icurr].r);
1278 Rmax.push_back(
corners[inextr].r);
1282 Rmin.push_back(
corners[inextr].r);
1283 Rmax.push_back(
corners[icurr].r);
1284 Rmax[countPlanes-2]=
corners[inextr].
r;
1292 Rmax.push_back(
corners[inextr].r);
1293 Rmin.push_back (
corners[icurr].r);
1297 Rmax.push_back(
corners[inextr].r);
1305 isConvertible=
false;
break;
1315 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1319 Rmax.push_back(
corners[inextr].r);
1320 Rmin.push_back(
corners[inextl].r);
1324 Rmax.push_back(
corners[inextr].r);
1325 Rmin.push_back(
corners[inextl].r);
1338 for(
G4int j=0; j < countPlanes; j++)
1352 std::ostringstream message;
1354 <<
"cannot be converted to Polyhedra with (Rmin,Rmaz,Z) parameters!";
1355 G4Exception(
"G4Polyhedra::SetOriginalParameters()",
1364 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[])