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",
260 if ( (phiTotal <= 0) || (phiTotal > twopi*(1-
DBL_EPSILON)) )
272 endPhi = phiStart+phiTotal;
296 next->
r = iterRZ.
GetA();
297 next->
z = iterRZ.
GetB();
298 }
while( ++next, iterRZ.
Next() );
350 }
while( prev=corner, corner=next, corner >
corners );
380 phiIsOpen(false), genericPgon(false), numCorner(0), corners(0),
381 original_parameters(0), enclosingCylinder(0)
413 if (
this == &source)
return *
this;
484 std::ostringstream message;
485 message <<
"Solid " <<
GetName() <<
" built using generic construct."
486 <<
G4endl <<
"Not applicable to the generic construct !";
487 G4Exception(
"G4Polyhedra::Reset()",
"GeomSolids1001",
601 G4int oldprc = os.precision(16);
602 os <<
"-----------------------------------------------------------\n"
603 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
604 <<
" ===================================================\n"
605 <<
" Solid type: G4Polyhedra\n"
608 <<
" ending phi angle : " <<
endPhi/
degree <<
" degrees \n"
609 <<
" number of sides : " <<
numSide <<
" \n";
614 os <<
" number of Z planes: " << numPlanes <<
"\n"
616 for (i=0; i<numPlanes; i++)
618 os <<
" Z plane " << i <<
": "
621 os <<
" Tangent distances to inner surface (Rmin): \n";
622 for (i=0; i<numPlanes; i++)
624 os <<
" Z plane " << i <<
": "
627 os <<
" Tangent distances to outer surface (Rmax): \n";
628 for (i=0; i<numPlanes; i++)
630 os <<
" Z plane " << i <<
": "
634 os <<
" number of RZ points: " <<
numCorner <<
"\n"
635 <<
" RZ values (corners): \n";
641 os <<
"-----------------------------------------------------------\n";
642 os.precision(oldprc);
656 G4double lambda1, lambda2, chose,aOne,aTwo;
667 if( (chose>=0.) && (chose < aOne) )
671 return (p2+lambda1*v+lambda2*w);
676 return (p0+lambda1*t+lambda2*u);
695 return (p2 + lambda1*w + lambda2*v);
707 G4double chose, totArea=0., Achose1, Achose2,
708 rad1, rad2, sinphi1, sinphi2, cosphi1, cosphi2;
710 area, aTop=0., aBottom=0., zVal=0.;
713 std::vector<G4double> aVector1;
714 std::vector<G4double> aVector2;
715 std::vector<G4double> aVector3;
723 for(j=0; j<numPlanes-1; j++)
729 area = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
730 aVector1.push_back(area);
733 for(j=0; j<numPlanes-1; j++)
739 area = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
740 aVector2.push_back(area);
743 for(j=0; j<numPlanes-1; j++)
754 else { aVector3.push_back(0.); }
757 for(j=0; j<numPlanes-1; j++)
759 totArea +=
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
769 aTop = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
777 aBottom = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+b)*cosksi;
781 Achose2 =
numSide*(aVector1[0]+aVector2[0])+2.*aVector3[0];
784 if( (chose >= 0.) && (chose < aTop + aBottom) )
787 rang = std::floor((chose-
startPhi)/ksi-0.01);
788 if(rang<0) { rang=0; }
789 rang = std::fabs(rang);
790 sinphi1 = std::sin(
startPhi+rang*ksi);
791 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
792 cosphi1 = std::cos(
startPhi+rang*ksi);
793 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
795 if(chose>=0. && chose<aTop)
815 for (j=0; j<numPlanes-1; j++)
817 if( ((chose >= Achose1) && (chose < Achose2)) || (j == numPlanes-2) )
821 Achose1 +=
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
822 Achose2 = Achose1 +
numSide*(aVector1[j+1]+aVector2[j+1])
832 totArea =
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
835 if( (chose>=0.) && (chose<
numSide*aVector1[j]) )
838 rang = std::floor((chose-
startPhi)/ksi-0.01);
839 if(rang<0) { rang=0; }
840 rang = std::fabs(rang);
843 sinphi1 = std::sin(
startPhi+rang*ksi);
844 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
845 cosphi1 = std::cos(
startPhi+rang*ksi);
846 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
858 else if ( (chose >=
numSide*aVector1[j])
859 && (chose <=
numSide*(aVector1[j]+aVector2[j])) )
862 rang = std::floor((chose-
startPhi)/ksi-0.01);
863 if(rang<0) { rang=0; }
864 rang = std::fabs(rang);
867 sinphi1 = std::sin(
startPhi+rang*ksi);
868 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
869 cosphi1 = std::cos(
startPhi+rang*ksi);
870 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
884 if( (chose>=0.) && (chose < 1.) )
959 typedef G4int int4[4];
966 std::vector<G4bool> chopped(
numCorner,
false);
967 std::vector<G4int*> triQuads;
970 while (remaining >= 3)
974 G4int A = -1, B = -1, C = -1;
975 G4int iStepper = iStarter;
978 if (A < 0) { A = iStepper; }
979 else if (B < 0) { B = iStepper; }
980 else if (C < 0) { C = iStepper; }
983 if (++iStepper >=
numCorner) iStepper = 0;
985 while (chopped[iStepper]);
987 while (C < 0 && iStepper != iStarter);
1002 triQuads.push_back(tq);
1010 if (++iStarter >=
numCorner) { iStarter = 0; }
1012 while (chopped[iStarter]);
1020 faces_vec =
new int4[nFaces];
1024 for (
G4int iEnd = 0; iEnd < 2; ++iEnd)
1026 for (
size_t i = 0; i < triQuads.size(); ++i)
1039 a = triQuads[i][0] + addition;
1040 b = triQuads[i][2] + addition;
1041 c = triQuads[i][1] + addition;
1044 G4int bc = std::abs(c - b);
1045 G4int ca = std::abs(a - c);
1046 faces_vec[iface][0] = (ab == 1 || ab == d)? a: -a;
1047 faces_vec[iface][1] = (bc == 1 || bc == d)? b: -b;
1048 faces_vec[iface][2] = (ca == 1 || ca == d)? c: -c;
1049 faces_vec[iface][3] = 0;
1056 xyz =
new double3[nNodes];
1064 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1065 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1067 if (iCorner < numCorner - 1)
1069 faces_vec[iface][0] = ixyz + 1;
1070 faces_vec[iface][1] = ixyz + numCorner + 1;
1071 faces_vec[iface][2] = ixyz + numCorner + 2;
1072 faces_vec[iface][3] = ixyz + 2;
1076 faces_vec[iface][0] = ixyz + 1;
1077 faces_vec[iface][1] = ixyz + numCorner + 1;
1078 faces_vec[iface][2] = ixyz + 2;
1079 faces_vec[iface][3] = ixyz - numCorner + 2;
1091 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1092 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1101 xyz =
new double3[nNodes];
1102 faces_vec =
new int4[nFaces];
1106 G4int ixyz = 0, iface = 0;
1111 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1112 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1114 if (iSide < numSide - 1)
1116 if (iCorner < numCorner - 1)
1118 faces_vec[iface][0] = ixyz + 1;
1119 faces_vec[iface][1] = ixyz + numCorner + 1;
1120 faces_vec[iface][2] = ixyz + numCorner + 2;
1121 faces_vec[iface][3] = ixyz + 2;
1125 faces_vec[iface][0] = ixyz + 1;
1126 faces_vec[iface][1] = ixyz + numCorner + 1;
1127 faces_vec[iface][2] = ixyz + 2;
1128 faces_vec[iface][3] = ixyz - numCorner + 2;
1133 if (iCorner < numCorner - 1)
1135 faces_vec[iface][0] = ixyz + 1;
1136 faces_vec[iface][1] = ixyz + numCorner - nFaces + 1;
1137 faces_vec[iface][2] = ixyz + numCorner - nFaces + 2;
1138 faces_vec[iface][3] = ixyz + 2;
1142 faces_vec[iface][0] = ixyz + 1;
1143 faces_vec[iface][1] = ixyz - nFaces + numCorner + 1;
1144 faces_vec[iface][2] = ixyz - nFaces + 2;
1145 faces_vec[iface][3] = ixyz - numCorner + 2;
1155 G4int problem = polyhedron->createPolyhedron(nNodes, nFaces, xyz, faces_vec);
1156 delete [] faces_vec;
1160 std::ostringstream message;
1161 message <<
"Problem creating G4Polyhedron for: " <<
GetName();
1162 G4Exception(
"G4Polyhedra::CreatePolyhedron()",
"GeomSolids1002",
1178 G4bool isConvertible=
true;
1184 std::vector<G4double> Z;
1185 std::vector<G4double> Rmin;
1186 std::vector<G4double> Rmax;
1188 G4int countPlanes=1;
1199 Rmax.push_back (
corners[1].r);icurr=1;
1201 else if (Zprev ==
corners[numPlanes-1].z)
1203 Rmin.push_back(
corners[numPlanes-1].r);
1204 Rmax.push_back (
corners[0].r);
1210 Rmax.push_back (
corners[0].r);
1215 G4int inextr=0, inextl=0;
1216 for (
G4int i=0; i < numPlanes-2; i++)
1219 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1221 if((
corners[inextr].z >= Zmax) & (
corners[inextl].
z >= Zmax)) {
break; }
1236 Rmin.push_back(
corners[inextl].r);
1237 Rmax.push_back(
corners[icurr].r);
1241 Rmin.push_back(
corners[inextl].r);
1250 Rmin.push_back(
corners[icurl].r);
1251 Rmax.push_back(
corners[icurr].r);
1255 Rmin.push_back(
corners[icurl].r);
1262 isConvertible=
false;
break;
1264 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1272 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1274 Rmin.push_back(
corners[inextl].r);
1275 Rmax.push_back (
corners[inextr].r);
1279 Z.push_back(Zright);
1288 Rmax.push_back(
corners[inextr].r);
1289 Rmin.push_back(
corners[icurr].r);
1293 Rmin.push_back(
corners[icurl].r + (Zright-
corners[icurl].z)/difZl
1295 Rmax.push_back(
corners[inextr].r);
1303 Rmax.push_back(
corners[inextr].r);
1304 Rmin.push_back (
corners[icurr].r);
1308 Rmax.push_back(
corners[inextr].r);
1316 isConvertible=
false;
break;
1326 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1328 Rmax.push_back(
corners[inextr].r);
1329 Rmin.push_back(
corners[inextl].r);
1341 for(
G4int j=0; j < countPlanes; j++)
1355 std::ostringstream message;
1357 <<
"cannot be converted to Polyhedra with (Rmin,Rmaz,Z) parameters!";
1358 G4Exception(
"G4Polyhedra::SetOriginalParameters()",
1367 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[])