9#include "MantidKernel/ANN/ANN.h"
10#include "MantidKernel/DllConfig.h"
96 const auto numPoints =
static_cast<int>(points.size());
98 std::runtime_error(
"Need at least one point to initialise NearestNeighbours.");
100 m_dataPoints = std::make_unique<NNDataPoints>(numPoints,
static_cast<int>(N));
102 for (
size_t i = 0; i < points.size(); ++i) {
103 Eigen::Map<VectorType>(m_dataPoints->mutablePoint(
static_cast<int>(i)), N, 1) = points[i];
105 m_kdTree = std::make_unique<ANNkd_tree>(m_dataPoints->rawData(), numPoints,
static_cast<int>(N));
123 const auto numNeighbours =
static_cast<int>(k);
125 auto nnIndexList = std::unique_ptr<ANNidx[]>(
new ANNidx[numNeighbours]);
126 auto nnDistList = std::unique_ptr<ANNdist[]>(
new ANNdist[numNeighbours]);
129 auto point = std::unique_ptr<ANNcoord[]>(annAllocPt(N));
130 Eigen::Map<VectorType>(point.get(), N, 1) = pos;
133 m_kdTree->annkSearch(point.get(), numNeighbours, nnIndexList.get(), nnDistList.get(),
error);
135 return makeResults(k, std::move(nnIndexList), std::move(nnDistList));
149 const std::unique_ptr<ANNdist[]> nnDistList) {
153 for (
size_t i = 0; i < k; ++i) {
155 auto pos = m_dataPoints->mutablePoint(nnIndexList[i]);
156 VectorType point = Eigen::Map<VectorType>(pos, N, 1);
157 results.emplace_back(point, nnIndexList[i], nnDistList[i]);
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
NNDataPoints is a thin RAII wrapper class around the ANNpointArray type.
ANNcoord * mutablePoint(const int i)
Access a raw point in the collection of points.
const int m_nPts
Number of points stored.
NNDataPoints(const int nPts, const int nElems)
Construct a new set of data points.
ANNpointArray m_data
Array of points for use with NN search.
ANNpointArray rawData()
Return a handle to the raw ANNpointArray wrapped by this class.
Eigen::Matrix< double, N, 1 > VectorType
std::unique_ptr< NNDataPoints > m_dataPoints
handle to the list of data points to search through
std::vector< std::tuple< VectorType, size_t, double > > NearestNeighbourResults
NearestNeighbours(const NearestNeighbours &)=delete
NearestNeighbours(const std::vector< VectorType > &points)
Create a nearest neighbour search object.
std::unique_ptr< ANNkd_tree > m_kdTree
handle to the ANN KD-tree used for searching
NearestNeighbourResults findNearest(const VectorType &pos, const size_t k=1, const double error=0.0)
Find the k nearest neighbours to a given point.
NearestNeighbourResults makeResults(const size_t k, const std::unique_ptr< ANNidx[]> nnIndexList, const std::unique_ptr< ANNdist[]> nnDistList)
Helper function to create a instance of NearestNeighbourResults.
Helper class which provides the Collimation Length for SANS instruments.