1 #ifndef MEDUSA_BITS_SPATIAL_SEARCH_KDTREEMUTABLE_HPP_
2 #define MEDUSA_BITS_SPATIAL_SEARCH_KDTREEMUTABLE_HPP_
18 return os <<
"KDTreeMutable:\n"
19 <<
" dimension: " << tree.
dim <<
'\n'
20 <<
" num of points: " << tree.
size() << std::endl;
23 template <
class vec_t>
25 assert_msg(point.array().isFinite().prod() == 1,
"Invalid point.");
26 auto n = points_.kdtree_get_point_count();
32 template <
class vec_t>
34 auto n = points_.kdtree_get_point_count();
35 for (
const auto& p : points) {
36 assert_msg(p.array().isFinite().prod() == 1,
"One of the points is invalid.");
39 size_ += points.size();
40 tree.addPoints(n, n + points.size() - 1);
43 template <
class vec_t>
46 assert_msg(point.array().isFinite().prod() == 1,
"Invalid query point.");
47 nanoflann::KNNResultSet<scalar_t, int> resultSet(k);
50 resultSet.init(&ret_index[0], &out_dist_sqr[0]);
51 tree.findNeighbors(resultSet, point.data(), nanoflann::SearchParams(k));
52 assert_msg(resultSet.full(),
"Not enough points in the tree, you requested %d points, "
53 "but the tree contains only %d points.", k, size());
54 return {ret_index, out_dist_sqr};
59 #endif // MEDUSA_BITS_SPATIAL_SEARCH_KDTREEMUTABLE_HPP_