memgraph/poc/kdtree/kdtree.hpp

36 lines
631 B
C++
Raw Normal View History

#pragma once
2015-06-19 16:04:42 +08:00
#include <vector>
#include "build.hpp"
#include "nns.hpp"
namespace kd {
2015-06-19 16:04:42 +08:00
template <class T, class U>
class KdTree {
public:
KdTree() {}
2015-06-19 16:04:42 +08:00
template <class It>
KdTree(It first, It last);
2015-06-19 16:04:42 +08:00
const U& lookup(const Point<T>& pk) const;
2015-06-19 16:04:42 +08:00
protected:
std::unique_ptr<KdNode<float, U>> root;
2015-06-19 16:04:42 +08:00
};
template <class T, class U>
const U& KdTree<T, U>::lookup(const Point<T>& pk) const {
// do a nearest neighbour search on the tree
return kd::nns(pk, root.get())->data;
2015-06-19 16:04:42 +08:00
}
template <class T, class U>
template <class It>
KdTree<T, U>::KdTree(It first, It last) {
root.reset(kd::build<T, U, It>(first, last));
2015-06-19 16:04:42 +08:00
}
}