------------------------------------------------------------------------------ Given a position x, return the id of the point closest to it. This method is used when performing incremental point insertion.
| 1314 | // Given a position x, return the id of the point closest to it. This method |
| 1315 | // is used when performing incremental point insertion. |
| 1316 | vtkIdType vtkPointLocator::FindClosestInsertedPoint(const double x[3]) |
| 1317 | { |
| 1318 | int i; |
| 1319 | double minDist2, dist2; |
| 1320 | double pt[3]; |
| 1321 | int level; |
| 1322 | vtkIdType closest, j; |
| 1323 | vtkIdType ptId, nids, cno; |
| 1324 | vtkIdList* ptIds; |
| 1325 | int ijk[3], *nei; |
| 1326 | int MULTIPLES; |
| 1327 | double diff; |
| 1328 | vtkNeighborPoints buckets; |
| 1329 | |
| 1330 | // |
| 1331 | // Make sure candidate point is in bounds. If not, it is outside. |
| 1332 | // |
| 1333 | for (i = 0; i < 3; i++) |
| 1334 | { |
| 1335 | if (x[i] < this->Bounds[2 * i] || x[i] > this->Bounds[2 * i + 1]) |
| 1336 | { |
| 1337 | return -1; |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | // Find bucket point is in. |
| 1342 | // |
| 1343 | this->GetBucketIndices(x, ijk); |
| 1344 | |
| 1345 | // Need to search this bucket for closest point. If there are no |
| 1346 | // points in this bucket, search 1st level neighbors, and so on, |
| 1347 | // until closest point found. |
| 1348 | // |
| 1349 | for (closest = -1, minDist2 = VTK_DOUBLE_MAX, level = 0; (closest == -1) && |
| 1350 | (level < this->Divisions[0] || level < this->Divisions[1] || level < this->Divisions[2]); |
| 1351 | level++) |
| 1352 | { |
| 1353 | this->GetBucketNeighbors(&buckets, ijk, this->Divisions, level); |
| 1354 | |
| 1355 | for (i = 0; i < buckets.GetNumberOfNeighbors(); i++) |
| 1356 | { |
| 1357 | nei = buckets.GetPoint(i); |
| 1358 | cno = nei[0] + nei[1] * this->XD + nei[2] * this->SliceSize; |
| 1359 | |
| 1360 | if ((ptIds = this->HashTable[cno]) != nullptr) |
| 1361 | { |
| 1362 | nids = ptIds->GetNumberOfIds(); |
| 1363 | for (j = 0; j < nids; j++) |
| 1364 | { |
| 1365 | ptId = ptIds->GetId(j); |
| 1366 | this->Points->GetPoint(ptId, pt); |
| 1367 | if ((dist2 = vtkMath::Distance2BetweenPoints(x, pt)) < minDist2) |
| 1368 | { |
| 1369 | closest = ptId; |
| 1370 | minDist2 = dist2; |
| 1371 | } |
| 1372 | } |
| 1373 | } |
no test coverage detected