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

Method FindClosestPoint

Common/DataModel/vtkPointLocator.cxx:167–250  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Given a position x, return the id of the point closest to it.

Source from the content-addressed store, hash-verified

165//------------------------------------------------------------------------------
166// Given a position x, return the id of the point closest to it.
167vtkIdType vtkPointLocator::FindClosestPoint(const double x[3])
168{
169 this->BuildLocator();
170 if (this->HashTable == nullptr)
171 {
172 return -1;
173 }
174 int i, j;
175 double minDist2;
176 double dist2 = VTK_DOUBLE_MAX;
177 double pt[3];
178 int level;
179 vtkIdType ptId, closest, cno, nids;
180 vtkIdList* ptIds;
181 int ijk[3], *nei;
182 vtkNeighborPoints buckets;
183
184 // Find bucket point is in.
185 this->GetBucketIndices(x, ijk);
186
187 //
188 // Need to search this bucket for closest point. If there are no
189 // points in this bucket, search 1st level neighbors, and so on,
190 // until closest point found.
191 //
192 for (closest = (-1), minDist2 = VTK_DOUBLE_MAX, level = 0; (closest == -1) &&
193 (level < this->Divisions[0] || level < this->Divisions[1] || level < this->Divisions[2]);
194 level++)
195 {
196 this->GetBucketNeighbors(&buckets, ijk, this->Divisions, level);
197
198 for (i = 0; i < buckets.GetNumberOfNeighbors(); i++)
199 {
200 nei = buckets.GetPoint(i);
201 cno = nei[0] + nei[1] * this->XD + nei[2] * this->SliceSize;
202
203 if ((ptIds = this->HashTable[cno]) != nullptr)
204 {
205 nids = ptIds->GetNumberOfIds();
206 for (j = 0; j < nids; j++)
207 {
208 ptId = ptIds->GetId(j);
209 this->DataSet->GetPoint(ptId, pt);
210 if ((dist2 = vtkMath::Distance2BetweenPoints(x, pt)) < minDist2)
211 {
212 closest = ptId;
213 minDist2 = dist2;
214 }
215 }
216 }
217 }
218 }
219 //
220 // Because of the relative location of the points in the buckets, the
221 // point found previously may not be the closest point. Have to
222 // search those bucket neighbors that might also contain point.
223 //
224 if (minDist2 > 0.0)

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected