50 #if !defined(G4GEOM_USE_UTESSELLATEDSOLID)
140 if (&ts ==
this)
return *
this;
194 for (
G4int i = 0; i <
n; ++i)
213 G4Exception(
"G4TessellatedSolid::AddFacet()",
"GeomSolids1002",
214 JustWarning,
"Attempt to add facets when solid is closed.");
219 set<G4VertexInfo,G4VertexComparator>::iterator begin
224 value.
mag2 = p.
x() + p.
y() + p.
z();
233 while (!found && it != end)
238 if ((found = (facet == aFacet)))
break;
240 if (dif > kCarTolerance3)
break;
247 while (!found && it != begin)
253 found = (facet == aFacet);
256 if (dif > kCarTolerance3)
break;
270 G4Exception(
"G4TessellatedSolid::AddFacet()",
"GeomSolids1002",
271 JustWarning,
"Attempt to add facet not properly defined.");
280 const std::vector<G4int>&
max,
283 vector<G4int> xyz = voxel;
284 stack<vector<G4int> >
pos;
287 G4int cc = 0, nz = 0;
289 vector<G4int> candidates;
307 for (
auto i = 0; i <= 2; ++i)
309 if (xyz[i] < max[i] - 1)
337 vector<G4int> voxel(3), maxVoxels(3);
339 G4int size = maxVoxels[0] * maxVoxels[1] * maxVoxels[2];
346 for (voxel[2] = 0; voxel[2] < maxVoxels[2] - 1; ++voxel[2])
348 for (voxel[1] = 0; voxel[1] < maxVoxels[1] - 1; ++voxel[1])
350 for (voxel[0] = 0; voxel[0] < maxVoxels[0] - 1; ++voxel[0])
355 for (
auto i = 0; i <= 2; ++i)
401 for (
G4int j = 0; j < size; ++j)
407 for (
G4int i=0; i < vsize; ++i)
433 set<G4VertexInfo,G4VertexComparator> vertexListSorted;
434 set<G4VertexInfo,G4VertexComparator>::iterator begin
435 = vertexListSorted.begin(), end = vertexListSorted.end(),
pos,
it;
444 vector<G4int> newIndex(100);
455 value.
mag2 = p.
x() + p.
y() + p.
z();
461 pos = vertexListSorted.lower_bound(value);
468 found = (dif < kCarTolerance24);
470 dif = q.
x() + q.
y() + q.
z() - value.
mag2;
471 if (dif > kCarTolerance3)
break;
484 found = (dif < kCarTolerance24);
486 dif = value.
mag2 - (q.
x() + q.
y() + q.
z());
487 if (dif > kCarTolerance3)
break;
496 G4cout <<
"Adding new vertex #" << i <<
" of facet " <<
k
501 vertexListSorted.insert(value);
502 begin = vertexListSorted.begin();
503 end = vertexListSorted.end();
504 newIndex[i] = value.
id;
523 G4cout <<
"Vertex #" << i <<
" of facet " <<
k
524 <<
" found, redirecting to " <<
id <<
G4endl;
540 for (
auto res=vertexListSorted.cbegin(); res!=vertexListSorted.cend(); ++res)
542 G4int id = (*res).id;
545 if (previousValue && (previousValue - 1
e-9 > mvalue))
546 G4cout <<
"Error in CreateVertexList: previousValue " << previousValue
547 <<
" is smaller than mvalue " << mvalue <<
G4endl;
548 previousValue = mvalue;
560 G4cout <<
"G4TessellatedSolid - Allocated memory without voxel overhead "
561 << without <<
"; with " << with <<
"; ratio: " << ratio <<
G4endl;
617 for (
G4int i = 0; i < size; ++i)
643 vector<G4int> startingVoxel(3);
646 const G4double dirTolerance = 1.0E-14;
648 const vector<G4int> &startingCandidates =
650 G4int limit = startingCandidates.size();
660 for(
G4int i = 0; i < limit; ++i)
662 G4int candidate = startingCandidates[i];
665 if (dist < minDist) minDist = dist;
692 G4bool nearParallel =
false;
712 vector<G4int> curVoxel(3);
713 curVoxel = startingVoxel;
721 const vector<G4int> &candidates =
724 if (
G4int candidatesCount = candidates.size())
726 for (
G4int i = 0 ; i < candidatesCount; ++i)
728 G4int candidate = candidates[i];
732 crossingO = facet.
Intersect(p,v,
true,distO,distFromSurfaceO,normalO);
733 crossingI = facet.
Intersect(p,v,
false,distI,distFromSurfaceI,normalI);
735 if (crossingO || crossingI)
739 nearParallel = (crossingO
740 && std::fabs(normalO.
dot(v))<dirTolerance)
741 || (crossingI && std::fabs(normalI.
dot(v))<dirTolerance);
744 if (crossingO && distO > 0.0 && distO < distOut)
746 if (crossingI && distI > 0.0 && distI < distIn)
752 if (nearParallel)
break;
768 currentPoint += direction * (shift + shiftBonus);
788 G4int oldprc = message.precision(16);
789 message <<
"Cannot determine whether point is inside or outside volume!"
795 <<
"p.x() = " << p.
x()/
mm <<
" mm" <<
G4endl
796 <<
"p.y() = " << p.
y()/
mm <<
" mm" <<
G4endl
797 <<
"p.z() = " << p.
z()/
mm <<
" mm";
798 message.precision(oldprc);
834 const G4double dirTolerance = 1.0E-14;
841 for (
G4int i = 0; i < size; ++i)
845 if (dist < minDist) minDist = dist;
881 for (
G4int i=0; i<nTry; ++i)
883 G4bool nearParallel =
false;
895 vector<G4VFacet*>::const_iterator
f =
fFacets.begin();
904 crossingO = ((*f)->Intersect(p,v,
true,distO,distFromSurfaceO,normalO));
905 crossingI = ((*f)->Intersect(p,v,
false,distI,distFromSurfaceI,normalI));
906 if (crossingO || crossingI)
908 nearParallel = (crossingO && std::fabs(normalO.
dot(v))<dirTolerance)
909 || (crossingI && std::fabs(normalI.
dot(v))<dirTolerance);
912 if (crossingO && distO > 0.0 && distO < distOut) distOut = distO;
913 if (crossingI && distI > 0.0 && distI < distIn) distIn = distI;
916 }
while (!nearParallel && ++f !=
fFacets.end());
917 }
while (nearParallel && sm !=
fMaxTries);
928 G4int oldprc = message.precision(16);
929 message <<
"Cannot determine whether point is inside or outside volume!"
935 <<
"p.x() = " << p.
x()/
mm <<
" mm" <<
G4endl
936 <<
"p.y() = " << p.
y()/
mm <<
" mm" <<
G4endl
937 <<
"p.z() = " << p.
z()/
mm <<
" mm";
938 message.precision(oldprc);
960 if (i == 0) location = locationprime;
979 vector<G4int> curVoxel(3);
984 if (
G4int limit = candidates.size())
987 for(
G4int i = 0 ; i < limit ; ++i)
989 G4int candidate = candidates[i];
992 if (dist < minDist) minDist = dist;
1006 for (
G4int i = 0; i < size; ++i)
1027 message <<
"Point p is not on surface !?" <<
G4endl
1028 <<
" No facets found for point: " << p <<
" !" <<
G4endl
1029 <<
" Returning approximated value for normal.";
1031 G4Exception(
"G4TessellatedSolid::SurfaceNormal(p)",
1063 G4int oldprc = message.precision(16) ;
1064 message <<
"Point p is already inside!?" <<
G4endl
1066 <<
" p.x() = " << p.
x()/
mm <<
" mm" <<
G4endl
1067 <<
" p.y() = " << p.
y()/
mm <<
" mm" <<
G4endl
1068 <<
" p.z() = " << p.
z()/
mm <<
" mm" <<
G4endl
1070 message.precision(oldprc) ;
1071 G4Exception(
"G4TriangularFacet::DistanceToIn(p,v)",
1077 for (
G4int i = 0; i < size; ++i)
1080 if (facet.
Intersect(p,v,
false,dist,distFromSurface,normal))
1131 G4int oldprc = message.precision(16) ;
1132 message <<
"Point p is already outside!?" <<
G4endl
1134 <<
" p.x() = " << p.
x()/
mm <<
" mm" <<
G4endl
1135 <<
" p.y() = " << p.
y()/
mm <<
" mm" <<
G4endl
1136 <<
" p.z() = " << p.
z()/
mm <<
" mm" <<
G4endl
1138 message.precision(oldprc) ;
1139 G4Exception(
"G4TriangularFacet::DistanceToOut(p)",
1144 G4bool isExtreme =
false;
1146 for (
G4int i = 0; i < size; ++i)
1149 if (facet.
Intersect(p,v,
true,dist,distFromSurface,normal))
1161 if (dist >= 0.0 && dist < minDist)
1171 aNormalVector = minNormal;
1172 aConvex = isExtreme;
1179 Normal(p, aNormalVector);
1191 G4int& minCandidate )
const
1193 G4int candidatesCount = candidates.size();
1198 for (
G4int i = 0 ; i < candidatesCount; ++i)
1200 G4int candidate = candidates[i];
1202 if (facet.
Intersect(aPoint,direction,
true,dist,distFromSurface,normal))
1211 minCandidate = candidate;
1214 if (dist >= 0.0 && dist < minDist)
1218 minCandidate = candidate;
1242 vector<G4int> curVoxel(3);
1249 const vector<G4int>* old =
nullptr;
1251 G4int minCandidate = -1;
1255 if (old == &candidates)
1257 if (old != &candidates && candidates.size())
1260 aNormalVector, minCandidate);
1261 if (minDistance <= totalShift)
break;
1267 totalShift += shift;
1268 if (minDistance <= totalShift)
break;
1270 currentPoint += direction * (shift + shiftBonus);
1276 if (minCandidate < 0)
1281 Normal(aPoint, aNormalVector);
1304 G4int candidatesCount = candidates.size();
1310 for (
G4int i = 0 ; i < candidatesCount; ++i)
1312 G4int candidate = candidates[i];
1314 if (facet.
Intersect(aPoint,direction,
false,dist,distFromSurface,normal))
1324 && (dist >= 0.0) && (dist < minDistance))
1363 currentPoint += direction * (shift + shiftBonus);
1368 vector<G4int> curVoxel(3);
1374 if (candidates.size())
1377 if (minDistance > distance) minDistance = distance;
1378 if (distance < totalShift)
break;
1384 totalShift += shift;
1385 if (minDistance < totalShift)
break;
1387 currentPoint += direction * (shift + shiftBonus);
1403 const std::pair<G4int, G4double>&
r)
1405 return l.second < r.second;
1418 vector<pair<G4int, G4double> > voxelsSorted(size);
1420 pair<G4int, G4double>
info;
1422 for (
G4int i = 0; i < size; ++i)
1429 info.second = safety;
1430 voxelsSorted[i] =
info;
1433 std::sort(voxelsSorted.begin(), voxelsSorted.end(),
1436 for (
G4int i = 0; i < size; ++i)
1438 const pair<G4int,G4double>&
inf = voxelsSorted[i];
1440 if (dist > minDist)
break;
1443 G4int csize = candidates.size();
1444 for (
G4int j = 0; j < csize; ++j)
1446 G4int candidate = candidates[j];
1448 dist = simple ? facet.
Distance(p,minDist)
1469 G4int oldprc = message.precision(16) ;
1470 message <<
"Point p is already inside!?" <<
G4endl
1472 <<
"p.x() = " << p.
x()/
mm <<
" mm" <<
G4endl
1473 <<
"p.y() = " << p.
y()/
mm <<
" mm" <<
G4endl
1474 <<
"p.z() = " << p.
z()/
mm <<
" mm" <<
G4endl
1476 message.precision(oldprc) ;
1491 vector<G4int> startingVoxel(3);
1508 for (
G4int i = 0; i < size; ++i)
1512 if (dist < minDist) minDist = dist;
1527 G4int oldprc = message.precision(16) ;
1528 message <<
"Point p is already outside!?" <<
G4endl
1530 <<
"p.x() = " << p.
x()/
mm <<
" mm" <<
G4endl
1531 <<
"p.y() = " << p.
y()/
mm <<
" mm" <<
G4endl
1532 <<
"p.z() = " << p.
z()/
mm <<
" mm" <<
G4endl
1534 message.precision(oldprc) ;
1535 G4Exception(
"G4TriangularFacet::DistanceToOut(p)",
1554 for (
G4int i = 0; i < size; ++i)
1558 if (dist < minDist) minDist = dist;
1585 for (
G4int i = 0; i < size; ++i)
1587 os <<
"FACET # = " << i + 1 <<
G4endl;
1663 message <<
"Invalid response from facet in solid '" <<
GetName() <<
"',"
1665 <<
"at point: " << p <<
"and direction: " <<
v;
1666 G4Exception(
"G4TessellatedSolid::DistanceToIn(p,v)",
1725 message <<
"Invalid response from facet in solid '" <<
GetName() <<
"',"
1727 <<
"at point: " << p <<
"and direction: " <<
v;
1728 G4Exception(
"G4TessellatedSolid::DistanceToOut(p,v,..)",
1757 for (
G4int i = 0; i < size; ++i)
1763 for (
G4int j=0; j<
n; ++j)
1768 polyhedron->
AddFacet(v[0],v[1],v[2],v[3]);
1807 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
1810 message <<
"Bad bounding box (min >= max) for solid: "
1812 <<
"\npMin = " << pMin
1813 <<
"\npMax = " <<
pMax;
1814 G4Exception(
"G4TessellatedSolid::BoundingLimits()",
1846 return (pMin < pMax) ?
true :
false;
1857 std::vector<const G4ThreeVectorList *> pyramid(2);
1860 apex[0] = (bmin+bmax)*0.5;
1877 if (!benv.
CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
1878 if (emin < pMin) pMin =
emin;
1879 if (emax > pMax) pMax =
emax;
1880 if (eminlim > pMin && emaxlim < pMax)
break;
1882 return (pMin < pMax);
1948 for (
G4int i = 0; i < size; ++i)
1966 for (
G4int i = 0; i < size; ++i)
1981 return fFacets[i]->GetPointOnFace();
1997 G4ThreeVector(-0.9577428892113370, 0.2732676269591740, 0.0897405271949221);
1999 G4ThreeVector(-0.8331264504940770,-0.5162067214954600,-0.1985722492445700);
2001 G4ThreeVector(-0.1516671651108820, 0.9666292616127460, 0.2064580868390110);
2003 G4ThreeVector( 0.6570250350323190,-0.6944539025883300, 0.2933460081893360);
2005 G4ThreeVector(-0.4820456281280320,-0.6331060000098690,-0.6056474264406270);
2007 G4ThreeVector( 0.7629032554236800 , 0.1016854697539910,-0.6384658864065180);
2009 G4ThreeVector( 0.7689540409061150, 0.5034929891988220, 0.3939600142169160);
2011 G4ThreeVector( 0.5765188359255740, 0.5997271636278330,-0.5549354566343150);
2013 G4ThreeVector( 0.6660632777862070,-0.6362809868288380, 0.3892379937580790);
2015 G4ThreeVector( 0.3824415020414780, 0.6541792713761380,-0.6525243125110690);
2017 G4ThreeVector(-0.5107726564526760, 0.6020905056811610, 0.6136760679616570);
2019 G4ThreeVector( 0.7459135439578050, 0.6618796061649330, 0.0743530220183488);
2021 G4ThreeVector( 0.1536405855311580, 0.8117477913978260,-0.5634359711967240);
2023 G4ThreeVector( 0.0744395301705579,-0.8707110101772920,-0.4861286795736560);
2025 G4ThreeVector(-0.1665874645185400, 0.6018553940549240,-0.7810369397872780);
2027 G4ThreeVector( 0.7766902003633100, 0.6014617505959970,-0.1870724331097450);
2029 G4ThreeVector(-0.8710128685847430,-0.1434320216603030,-0.4698551243971010);
2031 G4ThreeVector( 0.8901082092766820,-0.4388411398893870, 0.1229871120030100);
2033 G4ThreeVector(-0.6430417431544370,-0.3295938228697690, 0.6912779675984150);
2035 G4ThreeVector( 0.6331124368380410, 0.6306211461665000, 0.4488714875425340);
2049 for (
G4int i = 0; i < limit; ++i)
2070 size += sizeInsides + sizeVoxels;