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

Method FindClosestPointWithinRadius

Common/DataModel/vtkStaticPointLocator2D.cxx:325–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323//------------------------------------------------------------------------------
324template <typename TIds>
325vtkIdType BucketList2D<TIds>::FindClosestPointWithinRadius(
326 double radius, const double x[3], double inputDataLength, double& dist2)
327{
328 int i, j;
329 double pt[3];
330 vtkIdType ptId, closest = -1;
331 int ij[2], *nei;
332 double minDist2;
333
334 double refinedRadius, radius2, refinedRadius2;
335 double currentRadius;
336 double distance2ToDataBounds, maxDistance;
337 int ii, radiusLevels[2], radiusLevel, prevMinLevel[2], prevMaxLevel[2];
338 NeighborBuckets2D buckets;
339 const vtkLocatorTuple<TIds>* ids;
340
341 // Initialize
342 dist2 = -1.0;
343 radius2 = radius * radius;
344 minDist2 = 1.01 * radius2; // something slightly bigger....
345
346 vtkDataArray* pointData = static_cast<vtkPointSet*>(this->DataSet)->GetPoints()->GetData();
347
348 // Find the bucket the point is in.
349 //
350 this->GetBucketIndices(x, ij);
351
352 // Start by searching the bucket that the point is in.
353 //
354 vtkIdType numIds;
355 vtkIdType cno = ij[0] + ij[1] * this->xD;
356 if ((numIds = this->GetNumberOfIds(cno)) > 0)
357 {
358 ids = this->GetIds(cno);
359 for (j = 0; j < numIds; j++)
360 {
361 ptId = ids[j].PtId;
362 pointData->GetTuple(ptId, pt);
363 if ((dist2 = Distance2BetweenPoints2D(x, pt)) < minDist2)
364 {
365 closest = ptId;
366 minDist2 = dist2;
367 }
368 }
369 }
370
371 // Now, search only those buckets that are within a radius. The radius used
372 // is the smaller of sqrt(minDist2) and the radius that is passed in. To avoid
373 // checking a large number of buckets unnecessarily, if the radius is
374 // larger than the dimensions of a bucket, we search outward using a
375 // simple heuristic of rings. This heuristic ends up collecting inner
376 // buckets multiple times, but this only happens in the case where these
377 // buckets are empty, so they are discarded quickly.
378 //
379 if (minDist2 < radius2)
380 {
381 refinedRadius = sqrt(minDist2);
382 refinedRadius2 = dist2;

Callers

nothing calls this directly

Calls 15

GetNumberOfIdsMethod · 0.95
GetIdsMethod · 0.95
GetOverlappingBucketsMethod · 0.95
BuildLocatorMethod · 0.95
sqrtFunction · 0.50
maxFunction · 0.50
GetDataMethod · 0.45
GetPointsMethod · 0.45
GetBucketIndicesMethod · 0.45
GetTupleMethod · 0.45
Distance2ToBoundsMethod · 0.45
GetNumberOfNeighborsMethod · 0.45

Tested by

no test coverage detected