Skip to content

Commit

Permalink
ENH: Add distances of returned ids in PointsLocator
Browse files Browse the repository at this point in the history
Needed when additional filtering based on distance might be needed.
Also the Search method which has same functionality as FindClosestNPoints
and FindPointsWithinRadius has been removed from the codebase.
  • Loading branch information
PranjalSahu authored and dzenanz committed Aug 15, 2022
1 parent 2568e72 commit 7782feb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
8 changes: 2 additions & 6 deletions Modules/Registration/Common/include/itkPointsLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,13 @@ class ITK_TEMPLATE_EXPORT PointsLocator : public Object
PointIdentifier
FindClosestPoint(const PointType & query) const;

/** Find the k-nearest neighbors. Returns the point ids. */
void
Search(const PointType &, unsigned int, NeighborsIdentifierType &) const;

/** Find the closest N points. Returns the point ids. */
void
FindClosestNPoints(const PointType &, unsigned int, NeighborsIdentifierType &) const;

/** Find all the points within a specified radius. Returns the point ids. */
/** Find the closest N points. Returns the point ids and save the distances */
void
Search(const PointType &, double, NeighborsIdentifierType &) const;
FindClosestNPoints(const PointType &, unsigned int, NeighborsIdentifierType &, std::vector<double> &) const;

/** Find all the points within a specified radius. Returns the point ids. */
void
Expand Down
21 changes: 7 additions & 14 deletions Modules/Registration/Common/include/itkPointsLocator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ PointsLocator<TPointsContainer>::FindClosestPoint(const PointType & query) const
return identifiers[0];
}


template <typename TPointsContainer>
void
PointsLocator<TPointsContainer>::Search(const PointType & query,
unsigned int numberOfNeighborsRequested,
NeighborsIdentifierType & identifiers) const
PointsLocator<TPointsContainer>::FindClosestNPoints(const PointType & query,
unsigned int numberOfNeighborsRequested,
NeighborsIdentifierType & identifiers) const
{
unsigned int N = numberOfNeighborsRequested;
if (N > this->m_Points->Size())
Expand All @@ -88,7 +89,8 @@ template <typename TPointsContainer>
void
PointsLocator<TPointsContainer>::FindClosestNPoints(const PointType & query,
unsigned int numberOfNeighborsRequested,
NeighborsIdentifierType & identifiers) const
NeighborsIdentifierType & identifiers,
std::vector<double> & distances) const
{
unsigned int N = numberOfNeighborsRequested;
if (N > this->m_Points->Size())
Expand All @@ -98,16 +100,7 @@ PointsLocator<TPointsContainer>::FindClosestNPoints(const PointType & qu
itkWarningMacro("The number of requested neighbors is greater than the "
<< "total number of points. Only returning " << N << " points.");
}
this->m_Tree->Search(query, N, identifiers);
}

template <typename TPointsContainer>
void
PointsLocator<TPointsContainer>::Search(const PointType & query,
double radius,
NeighborsIdentifierType & identifiers) const
{
this->m_Tree->Search(query, radius, identifiers);
this->m_Tree->Search(query, N, identifiers, distances);
}

template <typename TPointsContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ManifoldParzenWindowsPointSetFunction<TPointSet, TOutput, TCoordRep>::SetInputPo
Cout.Fill(0);

typename PointsLocatorType::NeighborsIdentifierType neighbors;
this->m_PointsLocator->Search(point, this->m_CovarianceKNeighborhood, neighbors);
this->m_PointsLocator->FindClosestNPoints(point, this->m_CovarianceKNeighborhood, neighbors);

CompensatedSummation<RealType> denominator;
for (unsigned int j = 0; j < this->m_CovarianceKNeighborhood; ++j)
Expand Down Expand Up @@ -166,7 +166,7 @@ ManifoldParzenWindowsPointSetFunction<TPointSet, TOutput, TCoordRep>::Evaluate(c
else
{
typename PointsLocatorType::NeighborsIdentifierType neighbors;
this->m_PointsLocator->Search(point, numberOfNeighbors, neighbors);
this->m_PointsLocator->FindClosestNPoints(point, numberOfNeighbors, neighbors);

for (unsigned int j = 0; j < numberOfNeighbors; ++j)
{
Expand Down

0 comments on commit 7782feb

Please sign in to comment.