39 const searchableSurface& surf,
41 const scalar initDistSqr
46 List<pointIndexHit> oneHit(1);
47 surf.findNearest(onePoint, oneDist, oneHit);
53 Foam::scalar Foam::searchableSurfacesQueries::sumDistSqr
55 const PtrList<searchableSurface>& allSurfaces,
57 const scalar initDistSqr,
63 forAll(surfacesToTest, testI)
65 label surfI = surfacesToTest[testI];
69 tempFindNearest(allSurfaces[surfI], pt, initDistSqr)
73 sum +=
magSqr(hit.hitPoint()-pt);
82 Foam::scalar Foam::searchableSurfacesQueries::tryMorphTet
84 const PtrList<searchableSurface>& allSurfaces,
86 const scalar initDistSqr,
95 scalar fac2 = fac1-fac;
97 vector ptry = pSum*fac1-p[ihi]*fac2;
99 scalar ytry = sumDistSqr(allSurfaces, surfacesToTest, initDistSqr, ptry);
104 pSum += ptry - p[ihi];
111 bool Foam::searchableSurfacesQueries::morphTet
113 const PtrList<searchableSurface>& allSurfaces,
115 const scalar initDistSqr,
116 const scalar convergenceDistSqr,
124 autoPtr<OFstream> str;
128 wordList names(surfacesToTest.size());
131 names[i] = allSurfaces[surfacesToTest[i]].name();
133 Pout<<
"searchableSurfacesQueries::morphTet : intersection of "
134 << names <<
" starting from points:" << p <<
endl;
135 str.reset(
new OFstream(
"track.obj"));
140 for (label iter = 0; iter < maxIter; iter++)
143 label ilo, ihi, inhi;
147 ilo = sortedIndices[0];
148 ihi = sortedIndices[sortedIndices.size()-1];
149 inhi = sortedIndices[sortedIndices.size()-2];
154 Pout<<
"Iteration:" << iter
155 <<
" lowest:" << y[ilo] <<
" highest:" << y[ihi]
156 <<
" points:" << p <<
endl;
160 str()<<
"l " << vertI-1 <<
' ' << vertI <<
nl;
163 if (y[ihi] < convergenceDistSqr)
172 scalar ytry = tryMorphTet
199 else if (ytry >= y[inhi])
203 scalar ysave = y[ihi];
224 p[i] = 0.5*(p[i] + p[ilo]);
243 str()<<
"l " << vertI-1 <<
' ' << vertI <<
nl;
319 void Foam::searchableSurfacesQueries::mergeHits
322 const scalar mergeDist,
325 const List<pointIndexHit>& surfHits,
328 List<pointIndexHit>& allInfo,
336 surfDistSqr[i] =
magSqr(surfHits[i].hitPoint()-start);
341 label index =
findLower(allDistSqr, surfDistSqr[i]);
347 && (
mag(allDistSqr[index]-surfDistSqr[i]) < mergeDist)
359 label next = index+1;
362 next < allDistSqr.size()
363 && (
mag(allDistSqr[next]-surfDistSqr[i]) < mergeDist)
374 label sz = allSurfaces.size();
375 allSurfaces.setSize(sz+1);
376 allInfo.setSize(allSurfaces.size());
377 allDistSqr.setSize(allSurfaces.size());
379 for (label j = sz-1; j > index; --j)
381 allSurfaces[j+1] = allSurfaces[j];
382 allInfo[j+1] = allInfo[j];
383 allDistSqr[j+1] = allDistSqr[j];
386 allSurfaces[index+1] = testI;
387 allInfo[index+1] = surfHits[i];
388 allDistSqr[index+1] = surfDistSqr[i];
418 forAll(surfacesToTest, testI)
421 allSurfaces[surfacesToTest[testI]].findLineAny(p0, p1, intersectInfo);
427 if (intersectInfo[i].hit())
429 hitInfo[hitMap[i]] = intersectInfo[i];
430 hitSurfaces[hitMap[i]] = testI;
436 hitMap[newI] = hitMap[i];
454 intersectInfo.setSize(newI);
479 if (surfacesToTest.
empty())
485 allSurfaces[surfacesToTest[0]].findLineAll(start, end, hitInfo);
493 labelList& pSurfaces = hitSurfaces[pointI];
501 pDistSqr[i] =
magSqr(pHits[i].hitPoint() - start[pointI]);
506 if (surfacesToTest.
size() > 1)
514 1E2*SMALL*(end-start)
515 +
vector(ROOTVSMALL,ROOTVSMALL,ROOTVSMALL)
524 for (label testI = 1; testI < surfacesToTest.
size(); testI++)
527 allSurfaces[surfacesToTest[testI]].findLineAll
656 nearestSurfaces = -1;
663 forAll(surfacesToTest, testI)
665 allSurfaces[surfacesToTest[testI]].findNearest
675 if (hitInfo[pointI].hit())
677 minDistSqr[pointI] =
magSqr
679 hitInfo[pointI].hitPoint()
682 nearestInfo[pointI] = hitInfo[pointI];
683 nearestSurfaces[pointI] = testI;
695 const scalar initDistSqr,
696 const scalar convergenceDistSqr,
710 tempFindNearest(allSurfaces[surfacesToTest[i]], start, initDistSqr)
716 sumNearest += nearest[i];
722 "searchableSurfacesQueries::facesIntersection"
723 "(const labelList&, const scalar, const scalar, const point&)"
724 ) <<
"Did not find point within distance "
725 << initDistSqr <<
" of starting point " << start
727 << allSurfaces[surfacesToTest[i]].IOobject::name()
732 nearest[nearest.size()-1] = sumNearest / surfacesToTest.
size();
740 nearestDist[i] = sumDistSqr
752 bool converged = morphTet
769 intersection = tempFindNearest
771 allSurfaces[surfacesToTest[0]],