Skip to content

Commit

Permalink
ENH: Add test for itkPointsLocator with distances
Browse files Browse the repository at this point in the history
Check if the size of the returned distance vector is same
as the returned points and the returned distances are accurate.
  • Loading branch information
PranjalSahu authored and dzenanz committed Aug 15, 2022
1 parent 7782feb commit b9005b8
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions Modules/Registration/Common/test/itkPointsLocatorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "itkPointsLocator.h"
#include "itkMapContainer.h"
#include "itkTestingMacros.h"

template <typename TPointsContainer>
int
Expand Down Expand Up @@ -66,7 +67,7 @@ testPointsLocatorTest()
typename PointsLocatorType::PointIdentifier pointId = pointsLocator->FindClosestPoint(coords);
if (pointId != 49)
{
std::cerr << "Error with FindClosestPoint()" << std::endl;
std::cerr << "Error with FindClosestPoint(), poindId does not match" << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -77,36 +78,52 @@ testPointsLocatorTest()
pointsLocator->FindClosestNPoints(coords, 10u, neighborhood);
if (neighborhood.size() != 10)
{
std::cerr << "Error with FindClosestNPoints()" << std::endl;
std::cerr << "Error with FindClosestNPoints(), size of returned points does not match" << std::endl;
return EXIT_FAILURE;
}

std::cout << "Test: Search() 1" << std::endl;

pointsLocator->Search(coords, 10u, neighborhood);
if (neighborhood.size() != 10)
std::cout << "Test: FindClosestNPoints() with distances (1)" << std::endl;
std::vector<double> distances;
pointsLocator->FindClosestNPoints(coords, 10u, neighborhood, distances);
if (neighborhood.size() != 10 || distances.size() != 10)
{
std::cerr << "Error with Search() 1" << std::endl;
std::cerr << "Error with FindClosestNPoints(), size of returned points or distances does not match" << std::endl;
return EXIT_FAILURE;
}

double radius = std::sqrt(3 * itk::Math::sqr(5.1));

std::cout << "Test: FindPointsWithinRadius()" << std::endl;
// Check if returned distances are correct
for (unsigned int i = 0; i < neighborhood.size(); ++i)
{
auto dist = coords.EuclideanDistanceTo(points->GetElement(neighborhood[i]));
ITK_TEST_EXPECT_EQUAL(dist, distances[i]);
std::cout << dist << " + " << distances[i] << std::endl;
}

pointsLocator->FindPointsWithinRadius(coords, radius, neighborhood);
if (neighborhood.size() != 11)
std::cout << "Test: FindClosestNPoints() with distances (2)" << std::endl;
pointsLocator->FindClosestNPoints(coords, 200u, neighborhood, distances);
if (neighborhood.size() != 100 || distances.size() != 100)
{
std::cerr << "Error with FindPointsWithinRadius()" << std::endl;
std::cerr << "Error with FindClosestNPoints(), size of returned points or distances is incorrect" << std::endl;
return EXIT_FAILURE;
}

std::cout << "Test: Search() 2" << std::endl;
// Check if returned distances are correct
for (unsigned int i = 0; i < neighborhood.size(); ++i)
{
auto dist = coords.EuclideanDistanceTo(points->GetElement(neighborhood[i]));
ITK_TEST_EXPECT_EQUAL(dist, distances[i]);
std::cout << dist << " * " << distances[i] << std::endl;
}

double radius = std::sqrt(3 * itk::Math::sqr(5.1));

std::cout << "Test: FindPointsWithinRadius()" << std::endl;

pointsLocator->Search(coords, radius, neighborhood);
pointsLocator->FindPointsWithinRadius(coords, radius, neighborhood);
if (neighborhood.size() != 11)
{
std::cerr << "Error with Search() 2" << std::endl;
std::cerr << "Error with FindPointsWithinRadius(), size of returned points within radius does not match"
<< std::endl;
return EXIT_FAILURE;
}

Expand Down

0 comments on commit b9005b8

Please sign in to comment.