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",
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",
225 std::ostringstream message;
226 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl 227 <<
" R/Z cross section is zero or near zero: " << rzArea;
228 G4Exception(
"G4Polyhedra::Create()",
"GeomSolids0002",
235 std::ostringstream message;
236 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl 237 <<
" Too few unique R/Z values !";
238 G4Exception(
"G4Polyhedra::Create()",
"GeomSolids0002",
244 std::ostringstream message;
245 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl 246 <<
" R/Z segments cross !";
247 G4Exception(
"G4Polyhedra::Create()",
"GeomSolids0002",
273 endPhi = phiStart+phiTotal;
297 next->
r = iterRZ.
GetA();
298 next->
z = iterRZ.
GetB();
299 }
while( ++next, iterRZ.
Next() );
351 }
while( prev=corner, corner=next, corner >
corners );
414 if (
this == &source)
return *
this;
485 std::ostringstream message;
486 message <<
"Solid " <<
GetName() <<
" built using generic construct." 487 <<
G4endl <<
"Not applicable to the generic construct !";
488 G4Exception(
"G4Polyhedra::Reset()",
"GeomSolids1001",
602 G4int oldprc = os.precision(16);
603 os <<
"-----------------------------------------------------------\n" 604 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n" 605 <<
" ===================================================\n" 606 <<
" Solid type: G4Polyhedra\n" 609 <<
" ending phi angle : " <<
endPhi/
degree <<
" degrees \n" 610 <<
" number of sides : " <<
numSide <<
" \n";
615 os <<
" number of Z planes: " << numPlanes <<
"\n" 617 for (i=0; i<numPlanes; i++)
619 os <<
" Z plane " << i <<
": " 622 os <<
" Tangent distances to inner surface (Rmin): \n";
623 for (i=0; i<numPlanes; i++)
625 os <<
" Z plane " << i <<
": " 628 os <<
" Tangent distances to outer surface (Rmax): \n";
629 for (i=0; i<numPlanes; i++)
631 os <<
" Z plane " << i <<
": " 635 os <<
" number of RZ points: " <<
numCorner <<
"\n" 636 <<
" RZ values (corners): \n";
642 os <<
"-----------------------------------------------------------\n";
643 os.precision(oldprc);
657 G4double lambda1, lambda2, chose,aOne,aTwo;
668 if( (chose>=0.) && (chose < aOne) )
672 return (p2+lambda1*v+lambda2*w);
677 return (p0+lambda1*t+lambda2*u);
696 return (p2 + lambda1*w + lambda2*v);
708 G4double chose, totArea=0., Achose1, Achose2,
709 rad1, rad2, sinphi1, sinphi2, cosphi1, cosphi2;
711 area, aTop=0., aBottom=0., zVal=0.;
714 std::vector<G4double> aVector1;
715 std::vector<G4double> aVector2;
716 std::vector<G4double> aVector3;
724 for(j=0; j<numPlanes-1; j++)
730 area = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+
b)*cosksi;
731 aVector1.push_back(area);
734 for(j=0; j<numPlanes-1; j++)
740 area = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+
b)*cosksi;
741 aVector2.push_back(area);
744 for(j=0; j<numPlanes-1; j++)
755 else { aVector3.push_back(0.); }
758 for(j=0; j<numPlanes-1; j++)
760 totArea +=
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
770 aTop = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+
b)*cosksi;
778 aBottom = std::sqrt(l2-
sqr((a-b)*cosksi))*(a+
b)*cosksi;
782 Achose2 =
numSide*(aVector1[0]+aVector2[0])+2.*aVector3[0];
785 if( (chose >= 0.) && (chose < aTop + aBottom) )
788 rang = std::floor((chose-
startPhi)/ksi-0.01);
789 if(rang<0) { rang=0; }
790 rang = std::fabs(rang);
791 sinphi1 = std::sin(
startPhi+rang*ksi);
792 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
793 cosphi1 = std::cos(
startPhi+rang*ksi);
794 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
796 if(chose>=0. && chose<aTop)
816 for (j=0; j<numPlanes-1; j++)
818 if( ((chose >= Achose1) && (chose < Achose2)) || (j == numPlanes-2) )
822 Achose1 +=
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
823 Achose2 = Achose1 +
numSide*(aVector1[j+1]+aVector2[j+1])
833 totArea =
numSide*(aVector1[j]+aVector2[j])+2.*aVector3[j];
836 if( (chose>=0.) && (chose<
numSide*aVector1[j]) )
839 rang = std::floor((chose-
startPhi)/ksi-0.01);
840 if(rang<0) { rang=0; }
841 rang = std::fabs(rang);
844 sinphi1 = std::sin(
startPhi+rang*ksi);
845 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
846 cosphi1 = std::cos(
startPhi+rang*ksi);
847 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
859 else if ( (chose >=
numSide*aVector1[j])
860 && (chose <=
numSide*(aVector1[j]+aVector2[j])) )
863 rang = std::floor((chose-
startPhi)/ksi-0.01);
864 if(rang<0) { rang=0; }
865 rang = std::fabs(rang);
868 sinphi1 = std::sin(
startPhi+rang*ksi);
869 sinphi2 = std::sin(
startPhi+(rang+1)*ksi);
870 cosphi1 = std::cos(
startPhi+rang*ksi);
871 cosphi2 = std::cos(
startPhi+(rang+1)*ksi);
885 if( (chose>=0.) && (chose < 1.) )
960 typedef G4int int4[4];
967 std::vector<G4bool> chopped(
numCorner,
false);
968 std::vector<G4int*> triQuads;
971 while (remaining >= 3)
976 G4int iStepper = iStarter;
979 if (A < 0) { A = iStepper; }
980 else if (
B < 0) {
B = iStepper; }
981 else if (
C < 0) {
C = iStepper; }
984 if (++iStepper >=
numCorner) iStepper = 0;
986 while (chopped[iStepper]);
988 while (
C < 0 && iStepper != iStarter);
1003 triQuads.push_back(tq);
1011 if (++iStarter >=
numCorner) { iStarter = 0; }
1013 while (chopped[iStarter]);
1021 faces_vec =
new int4[nFaces];
1025 for (
G4int iEnd = 0; iEnd < 2; ++iEnd)
1027 for (
size_t i = 0; i < triQuads.size(); ++i)
1040 a = triQuads[i][0] + addition;
1041 b = triQuads[i][2] + addition;
1042 c = triQuads[i][1] + addition;
1045 G4int bc = std::abs(c - b);
1046 G4int ca = std::abs(a - c);
1047 faces_vec[iface][0] = (ab == 1 || ab ==
d)? a: -a;
1048 faces_vec[iface][1] = (bc == 1 || bc ==
d)? b: -b;
1049 faces_vec[iface][2] = (ca == 1 || ca ==
d)? c: -c;
1050 faces_vec[iface][3] = 0;
1057 xyz =
new double3[nNodes];
1065 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1066 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1068 if (iCorner < numCorner - 1)
1070 faces_vec[iface][0] = ixyz + 1;
1071 faces_vec[iface][1] = ixyz + numCorner + 1;
1072 faces_vec[iface][2] = ixyz + numCorner + 2;
1073 faces_vec[iface][3] = ixyz + 2;
1077 faces_vec[iface][0] = ixyz + 1;
1078 faces_vec[iface][1] = ixyz + numCorner + 1;
1079 faces_vec[iface][2] = ixyz + 2;
1080 faces_vec[iface][3] = ixyz - numCorner + 2;
1092 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1093 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1102 xyz =
new double3[nNodes];
1103 faces_vec =
new int4[nFaces];
1107 G4int ixyz = 0, iface = 0;
1112 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1113 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1115 if (iSide < numSide - 1)
1117 if (iCorner < numCorner - 1)
1119 faces_vec[iface][0] = ixyz + 1;
1120 faces_vec[iface][1] = ixyz + numCorner + 1;
1121 faces_vec[iface][2] = ixyz + numCorner + 2;
1122 faces_vec[iface][3] = ixyz + 2;
1126 faces_vec[iface][0] = ixyz + 1;
1127 faces_vec[iface][1] = ixyz + numCorner + 1;
1128 faces_vec[iface][2] = ixyz + 2;
1129 faces_vec[iface][3] = ixyz - numCorner + 2;
1134 if (iCorner < numCorner - 1)
1136 faces_vec[iface][0] = ixyz + 1;
1137 faces_vec[iface][1] = ixyz + numCorner - nFaces + 1;
1138 faces_vec[iface][2] = ixyz + numCorner - nFaces + 2;
1139 faces_vec[iface][3] = ixyz + 2;
1143 faces_vec[iface][0] = ixyz + 1;
1144 faces_vec[iface][1] = ixyz - nFaces + numCorner + 1;
1145 faces_vec[iface][2] = ixyz - nFaces + 2;
1146 faces_vec[iface][3] = ixyz - numCorner + 2;
1157 delete [] faces_vec;
1161 std::ostringstream message;
1162 message <<
"Problem creating G4Polyhedron for: " <<
GetName();
1163 G4Exception(
"G4Polyhedra::CreatePolyhedron()",
"GeomSolids1002",
1179 G4bool isConvertible=
true;
1185 std::vector<G4double>
Z;
1186 std::vector<G4double> Rmin;
1187 std::vector<G4double> Rmax;
1189 G4int countPlanes=1;
1200 Rmax.push_back (
corners[1].r);icurr=1;
1202 else if (Zprev ==
corners[numPlanes-1].z)
1204 Rmin.push_back(
corners[numPlanes-1].
r);
1211 Rmax.push_back (
corners[0].r);
1216 G4int inextr=0, inextl=0;
1217 for (
G4int i=0; i < numPlanes-2; i++)
1220 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1238 Rmax.push_back(
corners[icurr].r);
1252 Rmax.push_back(
corners[icurr].r);
1263 isConvertible=
false;
break;
1265 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1273 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1276 Rmax.push_back (
corners[inextr].r);
1280 Z.push_back(Zright);
1290 Rmin.push_back(
corners[icurr].r);
1296 Rmax.push_back(
corners[inextr].r);
1305 Rmin.push_back (
corners[icurr].r);
1317 isConvertible=
false;
break;
1327 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1330 Rmin.push_back(
corners[inextl].r);
1342 for(
G4int j=0; j < countPlanes; j++)
1356 std::ostringstream message;
1358 <<
"cannot be converted to Polyhedra with (Rmin,Rmaz,Z) parameters!";
1359 G4Exception(
"G4Polyhedra::SetOriginalParameters()",
1368 for(
G4int j=0; j < numPlanes; j++)
std::ostream & StreamInfo(std::ostream &os) const
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
G4int createPolyhedron(G4int Nnodes, G4int Nfaces, const G4double xyz[][3], const G4int faces[][4])
G4PolyhedraHistorical * original_parameters
G4bool ShouldMiss(const G4ThreeVector &p, const G4ThreeVector &v) const
G4Polyhedron * CreatePolyhedron() const
G4PolyhedraSideRZ * corners
void Create(G4double phiStart, G4double phiTotal, G4int numSide, G4ReduciblePolygon *rz)
G4ThreeVector GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, G4ThreeVector p2, G4ThreeVector p3) const
static double normal(HepRandomEngine *eptr)
G4bool RemoveDuplicateVertices(G4double tolerance)
virtual EInside Inside(const G4ThreeVector &p) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4EnclosingCylinder * enclosingCylinder
G4bool RemoveRedundantVertices(G4double tolerance)
double A(double temperature)
G4bool MustBeOutside(const G4ThreeVector &p) const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
void ScaleA(G4double scale)
static const double twopi
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4ThreeVector GetPointOnSurfaceGeneric() const
G4GeometryType GetEntityType() const
G4ThreeVector GetPointOnTriangle(G4ThreeVector p0, G4ThreeVector p1, G4ThreeVector p2) const
G4int NumVertices() const
static const double degree
G4Polyhedra & operator=(const G4Polyhedra &source)
void SetOriginalParameters(G4PolyhedraHistorical *pars)
G4ThreeVector GetPointOnSurface() const
EInside Inside(const G4ThreeVector &p) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4Polyhedra(const G4String &name, G4double phiStart, G4double phiTotal, G4int numSide, G4int numZPlanes, const G4double zPlane[], const G4double rInner[], const G4double rOuter[])
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const