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

Method FindClosestPointWithinRadius

Common/DataModel/vtkStaticCellLocator.cxx:1007–1125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1005// Return closest point (if any) AND the cell on which this closest point lies
1006template <typename T>
1007vtkIdType CellProcessor<T>::FindClosestPointWithinRadius(const double x[3], double radius,
1008 double closestPoint[3], vtkGenericCell* cell, vtkIdType& closestCellId, int& closestSubId,
1009 double& minDist2, int& inside)
1010{
1011 std::vector<bool> binHasBeenQueued(this->NumBins, false);
1012 std::vector<double> weights(this->MaxCellSize);
1013 double pcoords[3], point[3], bds[6], *bounds;
1014 double distance2ToCellBounds, dist2, binDist2;
1015 int subId, stat, ijk[3];
1016 vtkIdType retVal = 0;
1017 T numIds, j, cellId;
1018
1019 using node = std::pair<double, vtkIdType>;
1020 std::priority_queue<node, std::vector<node>, std::greater<>> queue;
1021
1022 // first get ijk containing point
1023 vtkIdType binId = this->Binner->GetBinIndex(x);
1024 queue.emplace(0.0, binId);
1025 binHasBeenQueued[binId] = true;
1026
1027 // minimum squared distance to the closest point
1028 minDist2 = radius * radius;
1029
1030 // Process the queue of candidate bins until the candidate bins are
1031 // further away than the current closest point.
1032 while (!queue.empty())
1033 {
1034 auto& top = queue.top();
1035 binId = top.second;
1036 binDist2 = top.first;
1037
1038 // stop if bounding box is further away than current closest point
1039 if (binDist2 > minDist2)
1040 {
1041 break;
1042 }
1043 // perform pop after ensuring that the bin is within the bounds
1044 queue.pop();
1045
1046 // compute distance to cells in bin, if any
1047 numIds = this->GetNumberOfIds(binId);
1048 if (numIds >= 1)
1049 {
1050 const CellFragments<T>* cellIds = this->GetIds(binId);
1051
1052 for (j = 0; j < numIds; j++)
1053 {
1054 cellId = cellIds[j].CellId;
1055
1056 // compute distance to cell bounding box
1057 bounds = this->CellBounds + 6 * cellId;
1058 distance2ToCellBounds = Distance2ToBounds(x, bounds);
1059
1060 // compute distance to cell only if distance to bounding box smaller than minDist2
1061 if (distance2ToCellBounds < minDist2)
1062 {
1063 this->DataSet->GetCell(cellId, cell);
1064

Callers

nothing calls this directly

Calls 14

GetNumberOfIdsMethod · 0.95
GetIdsMethod · 0.95
BuildLocatorMethod · 0.95
Distance2ToBoundsFunction · 0.85
popMethod · 0.80
maxFunction · 0.50
minFunction · 0.50
GetBinIndexMethod · 0.45
emplaceMethod · 0.45
emptyMethod · 0.45
GetCellMethod · 0.45
EvaluatePositionMethod · 0.45

Tested by

no test coverage detected