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

Method FindClosestPoint

Common/DataModel/vtkStaticPointLocator2D.cxx:243–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241// Given a position x, return the id of the point closest to it.
242template <typename TIds>
243vtkIdType BucketList2D<TIds>::FindClosestPoint(const double x[3])
244{
245 int i, j;
246 double minDist2;
247 double dist2 = VTK_DOUBLE_MAX;
248 double pt[3];
249 int closest, level;
250 vtkIdType ptId, cno, numIds;
251 int ij[2], *nei;
252 NeighborBuckets2D buckets;
253 const vtkLocatorTuple<TIds>* ids;
254
255 // Find bucket point is in.
256 //
257 this->GetBucketIndices(x, ij);
258
259 // Need to search this bucket for the closest point. If there are no
260 // points in this bucket, search 1st level neighbors, and so on, until
261 // closest point found.
262 //
263 for (closest = (-1), minDist2 = VTK_DOUBLE_MAX, level = 0;
264 (closest == -1) && (level < this->Divisions[0] || level < this->Divisions[1]); level++)
265 {
266 this->GetBucketNeighbors(&buckets, ij, this->Divisions, level);
267
268 for (i = 0; i < buckets.GetNumberOfNeighbors(); i++)
269 {
270 nei = buckets.GetPoint(i);
271 cno = nei[0] + nei[1] * this->xD;
272
273 if ((numIds = this->GetNumberOfIds(cno)) > 0)
274 {
275 ids = this->GetIds(cno);
276 for (j = 0; j < numIds; j++)
277 {
278 ptId = ids[j].PtId;
279 this->DataSet->GetPoint(ptId, pt);
280 if ((dist2 = Distance2BetweenPoints2D(x, pt)) < minDist2)
281 {
282 closest = ptId;
283 minDist2 = dist2;
284 }
285 }
286 }
287 }
288 }
289
290 //
291 // Because of the relative location of the points in the buckets, the
292 // point found previously may not be the closest point. We have to
293 // search those bucket neighbors that might also contain the point.
294 //
295 if (minDist2 > 0.0)
296 {
297 this->GetOverlappingBuckets(&buckets, x, ij, sqrt(minDist2), 0);
298 for (i = 0; i < buckets.GetNumberOfNeighbors(); i++)
299 {
300 nei = buckets.GetPoint(i);

Callers 1

IntersectWithLineMethod · 0.95

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