Skip to content
Snippets Groups Projects
Commit cf6b54e0 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #19131 Swap to use Eigen::Vector3d

This is consistent with the type being used in detectorInfo
parent 3b95847c
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@ DetectorSearcher::DetectorSearcher(Geometry::Instrument_const_sptr instrument,
}
void DetectorSearcher::createDetectorCache() {
std::vector<Eigen::Array3d> points;
std::vector<Eigen::Vector3d> points;
points.reserve(m_detInfo.size());
m_indexMap.reserve(m_detInfo.size());
......@@ -46,7 +46,7 @@ void DetectorSearcher::createDetectorCache() {
1. - std::cos(tt1)); // end of trajectory
E1 = E1 * (1. / E1.norm()); // normalize
Eigen::Array3d point(E1[0], E1[1], E1[2]);
Eigen::Vector3d point(E1[0], E1[1], E1[2]);
// Ignore nonsensical points
if (point.hasNaN())
......@@ -93,7 +93,7 @@ DetectorSearcher::searchUsingNearestNeighbours(const V3D &q) {
const auto detectorDir = convertQtoDirection(q);
// find where this Q vector should intersect with "extended" space
const auto neighbours =
m_detectorCacheSearch->findNearest(Eigen::Array3d(q[0], q[1], q[2]), 5);
m_detectorCacheSearch->findNearest(Eigen::Vector3d(q[0], q[1], q[2]), 5);
if (neighbours.size() == 0)
return std::make_tuple(false, 0);
......
......@@ -71,15 +71,15 @@ template <size_t N = 3> class MANTID_KERNEL_DLL NearestNeighbours {
public:
// typedefs for code brevity
typedef Eigen::Array<double, N, 1> ArrayType;
typedef std::vector<std::tuple<ArrayType, size_t, double>>
typedef Eigen::Matrix<double, N, 1> VectorType;
typedef std::vector<std::tuple<VectorType, size_t, double>>
NearestNeighbourResults;
/** Create a nearest neighbour search object
*
* @param points :: vector of Eigen::Arrays to search through
*/
NearestNeighbours(const std::vector<ArrayType> &points) {
NearestNeighbours(const std::vector<VectorType> &points) {
const auto numPoints = static_cast<int>(points.size());
if (numPoints == 0)
std::runtime_error(
......@@ -88,7 +88,7 @@ public:
m_dataPoints = make_unique<NNDataPoints>(numPoints, N);
for (size_t i = 0; i < points.size(); ++i) {
Eigen::Map<ArrayType>(m_dataPoints->mutablePoint(i), N, 1) = points[i];
Eigen::Map<VectorType>(m_dataPoints->mutablePoint(i), N, 1) = points[i];
}
m_kdTree = make_unique<ANNkd_tree>(m_dataPoints->rawData(), numPoints, N);
}
......@@ -107,7 +107,7 @@ public:
* zero then exact neighbours will be found. (default = 0.0).
* @return vector neighbours as tuples of (position, index, distance)
*/
NearestNeighbourResults findNearest(const ArrayType &pos, const size_t k = 1,
NearestNeighbourResults findNearest(const VectorType &pos, const size_t k = 1,
const double error = 0.0) {
const auto numNeighbours = static_cast<int>(k);
// create arrays to store the indices & distances of nearest neighbours
......@@ -116,7 +116,7 @@ public:
// create ANNpoint from Eigen array
auto point = std::unique_ptr<ANNcoord[]>(annAllocPt(N));
Eigen::Map<ArrayType>(point.get(), N, 1) = pos;
Eigen::Map<VectorType>(point.get(), N, 1) = pos;
// find the k nearest neighbours
m_kdTree->annkSearch(point.get(), numNeighbours, nnIndexList.get(),
......@@ -144,7 +144,7 @@ private:
for (size_t i = 0; i < k; ++i) {
// create Eigen array from ANNpoint
auto pos = m_dataPoints->mutablePoint(nnIndexList[i]);
ArrayType point = Eigen::Map<ArrayType>(pos, N, 1);
VectorType point = Eigen::Map<VectorType>(pos, N, 1);
auto item = std::make_tuple(point, nnIndexList[i], nnDistList[i]);
results.push_back(item);
}
......
......@@ -19,21 +19,21 @@ public:
NearestNeighboursTest() {}
void test_construct() {
std::vector<Array3d> pts1 = {Array3d(1, 1, 1), Array3d(2, 2, 2)};
std::vector<Vector3d> pts1 = {Vector3d(1, 1, 1), Vector3d(2, 2, 2)};
TS_ASSERT_THROWS_NOTHING(NearestNeighbours<3> nn(pts1));
std::vector<Array2d> pts2 = {Array2d(1, 1), Array2d(2, 2)};
std::vector<Vector2d> pts2 = {Vector2d(1, 1), Vector2d(2, 2)};
TS_ASSERT_THROWS_NOTHING(NearestNeighbours<2> nn(pts2));
}
void test_find_nearest() {
std::vector<Eigen::Array3d> pts = {Array3d(1, 1, 1), Array3d(2, 2, 2)};
std::vector<Eigen::Vector3d> pts = {Vector3d(1, 1, 1), Vector3d(2, 2, 2)};
NearestNeighbours<3> nn(pts);
auto results = nn.findNearest(Array3d(1, 1, 0.9));
auto results = nn.findNearest(Vector3d(1, 1, 0.9));
TS_ASSERT_EQUALS(results.size(), 1)
Eigen::Array3d pos = std::get<0>(results[0]);
Eigen::Vector3d pos = std::get<0>(results[0]);
auto index = std::get<1>(results[0]);
auto dist = std::get<2>(results[0]);
TS_ASSERT_EQUALS(pos[0], 1)
......@@ -44,14 +44,14 @@ public:
}
void test_find_nearest_2() {
std::vector<Eigen::Array2d> pts = {Array2d(1, 1), Array2d(2, 2),
Array2d(2, 3)};
std::vector<Eigen::Vector2d> pts = {Vector2d(1, 1), Vector2d(2, 2),
Vector2d(2, 3)};
NearestNeighbours<2> nn(pts);
auto results = nn.findNearest(Array2d(1, 0.9), 2);
auto results = nn.findNearest(Vector2d(1, 0.9), 2);
TS_ASSERT_EQUALS(results.size(), 2)
Eigen::Array2d pos = std::get<0>(results[0]);
Eigen::Vector2d pos = std::get<0>(results[0]);
auto index = std::get<1>(results[0]);
auto dist = std::get<2>(results[0]);
TS_ASSERT_EQUALS(pos[0], 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment