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

Method FindClosestPoint

Common/DataModel/vtkStaticPointLocator.cxx:296–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294// Given a position x, return the id of the point closest to it.
295template <typename TIds>
296vtkIdType BucketList<TIds>::FindClosestPoint(const double x[3])
297{
298 int i, j;
299 double minDist2;
300 double dist2 = VTK_DOUBLE_MAX;
301 double pt[3];
302 int closest, level;
303 vtkIdType ptId, cno, numIds;
304 int ijk[3], *nei;
305 NeighborBuckets buckets;
306 const vtkLocatorTuple<TIds>* ids;
307
308 // Find bucket point is in.
309 //
310 this->GetBucketIndices(x, ijk);
311
312 // Need to search this bucket for the closest point. If there are no
313 // points in this bucket, search 1st level neighbors, and so on, until
314 // closest point found.
315 //
316 for (closest = (-1), minDist2 = VTK_DOUBLE_MAX, level = 0; (closest == -1) &&
317 (level < this->Divisions[0] || level < this->Divisions[1] || level < this->Divisions[2]);
318 level++)
319 {
320 this->GetBucketNeighbors(&buckets, ijk, this->Divisions, level);
321
322 for (i = 0; i < buckets.GetNumberOfNeighbors(); i++)
323 {
324 nei = buckets.GetPoint(i);
325 cno = nei[0] + nei[1] * this->xD + nei[2] * this->xyD;
326
327 if ((numIds = this->GetNumberOfIds(cno)) > 0)
328 {
329 ids = this->GetIds(cno);
330 for (j = 0; j < numIds; j++)
331 {
332 ptId = ids[j].PtId;
333 this->DataSet->GetPoint(ptId, pt);
334 if ((dist2 = vtkMath::Distance2BetweenPoints(x, pt)) < minDist2)
335 {
336 closest = ptId;
337 minDist2 = dist2;
338 }
339 }
340 }
341 }
342 }
343
344 //
345 // Because of the relative location of the points in the buckets, the
346 // point found previously may not be the closest point. We have to
347 // search those bucket neighbors that might also contain the point.
348 //
349 if (minDist2 > 0.0)
350 {
351 this->GetOverlappingBuckets(&buckets, x, ijk, sqrt(minDist2), 0);
352 for (i = 0; i < buckets.GetNumberOfNeighbors(); i++)
353 {

Callers

nothing calls this directly

Calls 9

GetNumberOfIdsMethod · 0.95
GetIdsMethod · 0.95
GetOverlappingBucketsMethod · 0.95
BuildLocatorMethod · 0.95
sqrtFunction · 0.50
GetBucketIndicesMethod · 0.45
GetBucketNeighborsMethod · 0.45
GetNumberOfNeighborsMethod · 0.45
GetPointMethod · 0.45

Tested by

no test coverage detected