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

Method FindClosestNPoints

Common/DataModel/vtkKdTree.cxx:2511–2675  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2509
2510//------------------------------------------------------------------------------
2511void vtkKdTree::FindClosestNPoints(int N, const double x[3], vtkIdList* result)
2512{
2513 result->Reset();
2514 if (N <= 0)
2515 {
2516 return;
2517 }
2518 if (!this->LocatorPoints)
2519 {
2520 vtkErrorMacro(<< "vtkKdTree::FindClosestNPoints - must build locator first");
2521 return;
2522 }
2523
2524 int numTotalPoints = this->Top->GetNumberOfPoints();
2525 if (numTotalPoints < N)
2526 {
2527 vtkWarningMacro("Number of requested points is greater than total number of points in KdTree");
2528 N = numTotalPoints;
2529 }
2530 result->SetNumberOfIds(N);
2531
2532 // now we want to go about finding a region that contains at least N points
2533 // but not many more -- hopefully the region contains X as well but we
2534 // can't depend on that
2535 vtkKdNode* node = this->Top;
2536 vtkKdNode* startingNode = nullptr;
2537 if (!node->ContainsPoint(x[0], x[1], x[2], 0))
2538 {
2539 // point is not in the region
2540 int numPoints = node->GetNumberOfPoints();
2541 vtkKdNode* prevNode = node;
2542 while (node->GetLeft() && numPoints > N)
2543 {
2544 prevNode = node;
2545 double leftDist2 = node->GetLeft()->GetDistance2ToBoundary(x[0], x[1], x[2], 1);
2546 double rightDist2 = node->GetRight()->GetDistance2ToBoundary(x[0], x[1], x[2], 1);
2547 if (leftDist2 < rightDist2)
2548 {
2549 node = node->GetLeft();
2550 }
2551 else
2552 {
2553 node = node->GetRight();
2554 }
2555 numPoints = node->GetNumberOfPoints();
2556 }
2557 if (numPoints < N)
2558 {
2559 startingNode = prevNode;
2560 }
2561 else
2562 {
2563 startingNode = node;
2564 }
2565 }
2566 else
2567 {
2568 int numPoints = node->GetNumberOfPoints();

Callers 15

RunFunction · 0.45
FindCellMethod · 0.45
TimePointLocatorsFunction · 0.45
ComparePointLocatorsFunction · 0.45
RequestDataMethod · 0.45
operator()Method · 0.45
operator()Method · 0.45
FindPointsFunction · 0.45
ComputeBasisMethod · 0.45

Calls 13

SetNumberOfIdsMethod · 0.80
popMethod · 0.80
ResetMethod · 0.45
GetNumberOfPointsMethod · 0.45
ContainsPointMethod · 0.45
InsertPointMethod · 0.45
GetLargestDist2Method · 0.45
pushMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45
GetDataBoundsMethod · 0.45

Tested by 3

RunFunction · 0.36
ComparePointLocatorsFunction · 0.36