MCPcopy Create free account
hub / github.com/Kitware/VTK / FindClosestNPoints

Method FindClosestNPoints

Common/DataModel/vtkPointLocator.cxx:642–751  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

640
641//------------------------------------------------------------------------------
642void vtkPointLocator::FindClosestNPoints(int N, const double x[3], vtkIdList* result)
643{
644 this->BuildLocator();
645 if (this->HashTable == nullptr)
646 {
647 return;
648 }
649 int i, j;
650 double dist2;
651 double pt[3];
652 int level;
653 vtkIdType ptId, nids, cno;
654 vtkIdList* ptIds;
655 int ijk[3], *nei;
656 vtkNeighborPoints buckets;
657
658 // clear out the result
659 result->Reset();
660
661 // Find bucket point is in.
662 this->GetBucketIndices(x, ijk);
663
664 // there are two steps, first a simple expanding wave of buckets until
665 // we have enough points. Then a refinement to make sure we have the
666 // N closest points.
667 level = 0;
668 double maxDistance = 0.0;
669 int currentCount = 0;
670 IdTuple* res = new IdTuple[N];
671
672 this->GetBucketNeighbors(&buckets, ijk, this->Divisions, level);
673 while (buckets.GetNumberOfNeighbors() && currentCount < N)
674 {
675 for (i = 0; i < buckets.GetNumberOfNeighbors(); i++)
676 {
677 nei = buckets.GetPoint(i);
678 cno = nei[0] + nei[1] * this->XD + nei[2] * this->SliceSize;
679
680 if ((ptIds = this->HashTable[cno]) != nullptr)
681 {
682 nids = ptIds->GetNumberOfIds();
683 for (j = 0; j < nids; j++)
684 {
685 ptId = ptIds->GetId(j);
686 this->DataSet->GetPoint(ptId, pt);
687 dist2 = vtkMath::Distance2BetweenPoints(x, pt);
688 if (currentCount < N)
689 {
690 res[currentCount].Dist2 = dist2;
691 res[currentCount].PtId = ptId;
692 maxDistance = std::max(dist2, maxDistance);
693 currentCount++;
694 if (currentCount == N)
695 {
696 std::sort(res, res + currentCount);
697 }
698 }
699 else if (dist2 < maxDistance)

Callers

nothing calls this directly

Calls 14

BuildLocatorMethod · 0.95
GetBucketNeighborsMethod · 0.95
GetOverlappingBucketsMethod · 0.95
SetNumberOfIdsMethod · 0.80
maxFunction · 0.50
sortFunction · 0.50
sqrtFunction · 0.50
ResetMethod · 0.45
GetBucketIndicesMethod · 0.45
GetNumberOfNeighborsMethod · 0.45
GetPointMethod · 0.45
GetNumberOfIdsMethod · 0.45

Tested by

no test coverage detected