-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathANNWrapper.cpp
51 lines (41 loc) · 1 KB
/
ANNWrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "ANNWrapper.h"
namespace mvg
{
ANNWrapper::ANNWrapper()
{
m_k = 1;
}
ANNWrapper::~ANNWrapper()
{
if (m_dists != nullptr) delete[] m_dists;
}
void ANNWrapper::SetPoints(const std::vector <openMVG::Vec3f> &P)
{
dataset = openMVG::Matf(P.size(), dim);
m_nnidx = Eigen::VectorXi(m_k); // allocate near neigh indices
m_dists = new KFLANN::DistanceType[m_k]; // allocate near neighbor m_dists
for (unsigned int i = 0; i < P.size(); i++)
{
dataset(i, 0) = P.at(i).x();
dataset(i, 1) = P.at(i).y();
dataset(i, 2) = P.at(i).z();
}
matcher.Build(dataset.data(), P.size(), dim);
}
void ANNWrapper::FindClosest(const openMVG::Vec3f &P, double *sq_distance, int *index)
{
m_query_pt[0] = P.x();
m_query_pt[1] = P.y();
m_query_pt[2] = P.z();
matcher.SearchNeighbour(m_query_pt.data(), m_nnidx.data(), m_dists);
for (int i = 0; i < m_k; i++)
{
sq_distance[i] = m_dists[i];
index[i] = m_nnidx[i];
}
}
void ANNWrapper::SetResults(int a)
{
m_k = a;
}
}