44 const searchableSurface& surf,
46 const scalar initDistSqr
51 List<pointIndexHit> oneHit(1);
52 surf.findNearest(onePoint, oneDist, oneHit);
58 Foam::scalar Foam::searchableSurfacesQueries::sumDistSqr
60 const PtrList<searchableSurface>& allSurfaces,
62 const scalar initDistSqr,
68 forAll(surfacesToTest, testI)
70 label surfI = surfacesToTest[testI];
74 tempFindNearest(allSurfaces[surfI], pt, initDistSqr)
78 sum +=
magSqr(hit.hitPoint()-pt);
87 Foam::scalar Foam::searchableSurfacesQueries::tryMorphTet
89 const PtrList<searchableSurface>& allSurfaces,
91 const scalar initDistSqr,
100 scalar fac2 = fac1-fac;
102 vector ptry = pSum*fac1-p[ihi]*fac2;
104 scalar ytry = sumDistSqr(allSurfaces, surfacesToTest, initDistSqr, ptry);
109 pSum += ptry - p[ihi];
116 bool Foam::searchableSurfacesQueries::morphTet
118 const PtrList<searchableSurface>& allSurfaces,
120 const scalar initDistSqr,
121 const scalar convergenceDistSqr,
129 autoPtr<OFstream> str;
133 wordList names(surfacesToTest.size());
136 names[i] = allSurfaces[surfacesToTest[i]].name();
138 Pout<<
"searchableSurfacesQueries::morphTet : intersection of " 139 << names <<
" starting from points:" << p <<
endl;
140 str.reset(
new OFstream(
"track.obj"));
145 for (
label iter = 0; iter < maxIter; iter++)
148 label ilo, ihi, inhi;
152 ilo = sortedIndices[0];
153 ihi = sortedIndices[sortedIndices.size()-1];
154 inhi = sortedIndices[sortedIndices.size()-2];
159 Pout<<
"Iteration:" << iter
160 <<
" lowest:" << y[ilo] <<
" highest:" << y[ihi]
161 <<
" points:" << p <<
endl;
165 str()<<
"l " << vertI-1 <<
' ' << vertI <<
nl;
168 if (y[ihi] < convergenceDistSqr)
177 scalar ytry = tryMorphTet
204 else if (ytry >= y[inhi])
208 scalar ysave = y[ihi];
229 p[i] = 0.5*(p[i] + p[ilo]);
248 str()<<
"l " << vertI-1 <<
' ' << vertI <<
nl;
324 void Foam::searchableSurfacesQueries::mergeHits
329 const List<pointIndexHit>& surfHits,
332 List<pointIndexHit>& allInfo,
340 surfDistSqr[i] =
magSqr(surfHits[i].hitPoint() - start);
359 label next = index + 1;
361 if (next < allDistSqr.size())
371 label sz = allSurfaces.size();
372 allSurfaces.setSize(sz+1);
373 allInfo.setSize(allSurfaces.size());
374 allDistSqr.setSize(allSurfaces.size());
376 for (
label j = sz-1; j > index; --j)
378 allSurfaces[j+1] = allSurfaces[j];
379 allInfo[j+1] = allInfo[j];
380 allDistSqr[j+1] = allDistSqr[j];
383 allSurfaces[index+1] = testI;
384 allInfo[index+1] = surfHits[i];
385 allDistSqr[index+1] = surfDistSqr[i];
415 forAll(surfacesToTest, testI)
418 allSurfaces[surfacesToTest[testI]].findLineAny(p0, p1, intersectInfo);
424 if (intersectInfo[i].hit())
426 hitInfo[hitMap[i]] = intersectInfo[i];
427 hitSurfaces[hitMap[i]] = testI;
433 hitMap[newI] = hitMap[i];
451 intersectInfo.setSize(newI);
476 if (surfacesToTest.
empty())
482 allSurfaces[surfacesToTest[0]].findLineAll(start, end, hitInfo);
490 labelList& pSurfaces = hitSurfaces[pointI];
498 pDistSqr[i] =
magSqr(pHits[i].hitPoint() - start[pointI]);
503 if (surfacesToTest.
size() > 1)
506 for (
label testI = 1; testI < surfacesToTest.
size(); testI++)
509 allSurfaces[surfacesToTest[testI]].findLineAll
561 forAll(surfacesToTest, testI)
564 allSurfaces[surfacesToTest[testI]].findLine
571 forAll(nearestInfo, pointI)
573 if (nearestInfo[pointI].hit())
575 hit1[pointI] = nearestInfo[pointI];
576 surface1[pointI] = testI;
577 nearest[pointI] = hit1[pointI].hitPoint();
594 if (hit1[pointI].hit())
596 nearest[pointI] = hit1[pointI].hitPoint();
601 nearest[pointI] = end[pointI];
605 forAll(surfacesToTest, testI)
608 allSurfaces[surfacesToTest[testI]].findLine(end, nearest, nearestInfo);
610 forAll(nearestInfo, pointI)
612 if (nearestInfo[pointI].hit())
614 hit2[pointI] = nearestInfo[pointI];
615 surface2[pointI] = testI;
616 nearest[pointI] = hit2[pointI].hitPoint();
636 nearestSurfaces = -1;
643 forAll(surfacesToTest, testI)
645 allSurfaces[surfacesToTest[testI]].findNearest
655 if (hitInfo[pointI].hit())
657 minDistSqr[pointI] =
magSqr 659 hitInfo[pointI].hitPoint()
662 nearestInfo[pointI] = hitInfo[pointI];
663 nearestSurfaces[pointI] = testI;
682 if (regionIndices.
empty())
697 nearestSurfaces = -1;
704 forAll(surfacesToTest, testI)
706 allSurfaces[surfacesToTest[testI]].findNearest
717 if (hitInfo[pointI].hit())
719 minDistSqr[pointI] =
magSqr 721 hitInfo[pointI].hitPoint()
724 nearestInfo[pointI] = hitInfo[pointI];
725 nearestSurfaces[pointI] = testI;
763 forAll(surfacesToTest, testI)
768 forAll(nearestSurfaces, i)
770 if (nearestSurfaces[i] == testI)
772 surfPoints.append(samples[i]);
773 surfIndices.append(i);
779 allSurfaces[surfacesToTest[testI]].getVolumeType(surfPoints, volType);
784 label pointI = surfIndices[i];
785 scalar dist =
mag(samples[pointI] - nearestInfo[pointI].hitPoint());
791 distance[pointI] = dist;
799 switch (illegalHandling)
803 distance[pointI] = dist;
808 distance[pointI] = -dist;
814 <<
"getVolumeType failure," 815 <<
" neither INSIDE or OUTSIDE." 816 <<
" point:" << surfPoints[i]
818 << allSurfaces[surfacesToTest[testI]].name()
839 forAll(surfacesToTest, testI)
843 bbPoints[2*testI] = surface.
bounds().
min();
845 bbPoints[2*testI + 1] = surface.
bounds().
max();
857 const scalar initDistSqr,
858 const scalar convergenceDistSqr,
872 tempFindNearest(allSurfaces[surfacesToTest[i]], start, initDistSqr)
878 sumNearest += nearest[i];
884 "searchableSurfacesQueries::facesIntersection" 885 "(const labelList&, const scalar, const scalar, const point&)" 886 ) <<
"Did not find point within distance " 887 << initDistSqr <<
" of starting point " << start
889 << allSurfaces[surfacesToTest[i]].IOobject::name()
894 nearest.last() = sumNearest / surfacesToTest.
size();
902 nearestDist[i] = sumDistSqr
914 bool converged = morphTet
931 intersection = tempFindNearest
933 allSurfaces[surfacesToTest[0]],
static void findNearest(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &, const scalarField &nearestDistSqr, labelList &surfaces, List< pointIndexHit > &)
Find nearest. Return -1 (and a miss()) or surface and nearest.
const point & min() const
Minimum describing the bounding box.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
vector point
Point is a vector.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
dimensioned< scalar > mag(const dimensioned< Type > &)
bool empty() const
Return true if the UList is empty (ie, size() is zero).
static boundBox bounds(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest)
Find the boundBox of the selected surfaces.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void size(const label)
Override size to be inconsistent with allocated storage.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const boundBox & bounds() const
Return const reference to boundBox.
Various functions to operate on Lists.
PointIndexHit< point > pointIndexHit
bool hit() const
Is there a hit.
static void signedDistance(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const pointField &samples, const scalarField &nearestDistSqr, const volumeType illegalHandling, labelList &nearestSurfaces, scalarField &distance)
Find signed distance to nearest surface. Outside is positive.
static void findAllIntersections(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelListList &surfaces, List< List< pointIndexHit > > &surfaceHits)
Find all intersections in order from start to end. Returns for.
vectorField pointField
pointField is a vectorField.
static const NamedEnum< volumeType, 4 > names
const Point & hitPoint() const
Return hit point.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Number of components in this vector space.
void setSize(const label)
Reset size of List.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static void findNearestIntersection(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelList &surface1, List< pointIndexHit > &hit1, labelList &surface2, List< pointIndexHit > &hit2)
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
const point & max() const
Maximum describing the bounding box.
label findLower(const ListType &, typename ListType::const_reference, const label stary, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
List< scalar > scalarList
A List of scalars.
errorManip< error > abort(error &err)
label findMin(const ListType &, const label start=0)
Find index of min element (and less than given element).
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
A bounding box defined in terms of the points at its extremities.
List< word > wordList
A List of words.
List< label > labelList
A List of labels.
Vector< scalar > vector
A scalar version of the templated Vector.
static pointIndexHit facesIntersection(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const scalar initDistSqr, const scalar convergenceDistSqr, const point &start)
Calculate point which is on a set of surfaces. WIP.
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
static void findAnyIntersection(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelList &surfaces, List< pointIndexHit > &)
Find any intersection. Return hit point information and.
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout,"Pout")