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

Method FindClosestPointInSphere

Common/DataModel/vtkKdTree.cxx:2338–2387  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2336
2337//------------------------------------------------------------------------------
2338int vtkKdTree::FindClosestPointInSphere(
2339 double x, double y, double z, double radius, int skipRegion, double& dist2)
2340{
2341 if (!this->LocatorPoints)
2342 {
2343 vtkErrorMacro(<< "vtkKdTree::FindClosestPointInSphere - must build locator first");
2344 return -1;
2345 }
2346 int* regionIds = new int[this->NumberOfRegions];
2347
2348 this->BSPCalculator->ComputeIntersectionsUsingDataBoundsOn();
2349
2350 int nRegions = this->BSPCalculator->IntersectsSphere2(
2351 regionIds, this->NumberOfRegions, x, y, z, radius * radius);
2352
2353 this->BSPCalculator->ComputeIntersectionsUsingDataBoundsOff();
2354
2355 double minDistance2 = 4 * this->MaxWidth * this->MaxWidth;
2356 int localCloseId = -1;
2357
2358 bool recheck = false; // used to flag that we should recheck the distance
2359 for (int reg = 0; reg < nRegions; reg++)
2360 {
2361 if (regionIds[reg] == skipRegion)
2362 {
2363 continue;
2364 }
2365
2366 int neighbor = regionIds[reg];
2367
2368 // recheck that the bin is closer than the current minimum distance
2369 if (!recheck || this->RegionList[neighbor]->GetDistance2ToBoundary(x, y, z, 1) < minDistance2)
2370 {
2371 double newDistance2;
2372 int newLocalCloseId = this->FindClosestPointInRegion_(neighbor, x, y, z, newDistance2);
2373
2374 if (newDistance2 < minDistance2 && newDistance2 <= radius * radius)
2375 {
2376 minDistance2 = newDistance2;
2377 localCloseId = newLocalCloseId;
2378 recheck = true; // changed the minimum distance so mark to check subsequent bins
2379 }
2380 }
2381 }
2382
2383 delete[] regionIds;
2384
2385 dist2 = minDistance2;
2386 return localCloseId;
2387}
2388
2389//------------------------------------------------------------------------------
2390void vtkKdTree::FindPointsWithinRadius(double R, const double x[3], vtkIdList* result)

Callers 2

FindClosestPointMethod · 0.95

Tested by

no test coverage detected