Wildmeshing Toolkit
Loading...
Searching...
No Matches
KNN.hpp
1#pragma once
2
3#include <nanoflann.hpp>
4#include <wmtk/Types.hpp>
5
6namespace wmtk {
7
9{
10 using coord_t = double;
11
12 // Must return the number of data points
13 inline size_t kdtree_get_point_count() const { return pts.size(); }
14
15 // Returns the dim'th component of the idx'th point in the class
16 inline double kdtree_get_pt(const size_t idx, const size_t dim) const { return pts[idx][dim]; }
17
18 std::vector<Vector3d> pts;
19
20 template <class BBOX>
21 bool kdtree_get_bbox(BBOX& /* bb */) const
22 {
23 return false;
24 }
25};
26
27class KNN
28{
29 // construct a kd-tree index:
30 using my_kd_tree_t = nanoflann::
31 KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<double, PointCloud>, PointCloud, 3>;
32
33public:
34 KNN(const std::vector<Vector3d>& pts);
35
36 void nearest_neighbor(
37 const Vector3d& query_point,
38 uint32_t& nearest_point_index,
39 double& sq_dist) const;
40
41 void nearest_neighbors(
42 const Vector3d& query_point,
43 std::vector<uint32_t>& nearest_point_indices,
44 std::vector<double>& sq_dist) const;
45
46 const Vector3d& point(const uint32_t& index) const { return point_cloud.pts[index]; }
47
48private:
49 PointCloud point_cloud;
50 std::unique_ptr<my_kd_tree_t> m_kd_tree;
51};
52
53} // namespace wmtk
Definition KNN.hpp:28
Definition KNN.hpp:9
double coord_t
The type of each coordinate.
Definition KNN.hpp:10