10#include <gtsam_points/config.hpp>
11#include <gtsam_points/ann/small_kdtree.hpp>
12#include <gtsam_points/types/frame_traits.hpp>
13#include <gtsam_points/ann/nearest_neighbor_search.hpp>
14#include <gtsam_points/util/parallelism.hpp>
16namespace gtsam_points {
21template <
typename Frame>
24 using Index = UnsafeKdTree<Frame>;
26 KdTree2(
const std::shared_ptr<const Frame>& frame,
int build_num_threads = 1)
30 is_omp_default() || build_num_threads == 1 ?
33#ifdef GTSAM_POINTS_USE_TBB
34 new Index(*this->frame, KdTreeBuilderTBB())
39 if (frame::size(*frame) == 0) {
40 std::cerr <<
"error: empty frame is given for KdTree2" << std::endl;
41 std::cerr <<
" : frame::size() may not be implemented" << std::endl;
57 double max_sq_dist = std::numeric_limits<double>::max())
const override {
60 return index->knn_search(Eigen::Map<const Eigen::Vector3d>(pt), k, k_indices, k_sq_dists, setting);
77 std::vector<size_t>& indices,
78 std::vector<double>& sq_dists,
79 int max_num_neighbors = std::numeric_limits<int>::max())
const override {
81 setting.
max_nn = max_num_neighbors;
82 return index->radius_search(Eigen::Map<const Eigen::Vector3d>(pt), radius, indices, sq_dists, setting);
86 const std::shared_ptr<const Frame> frame;
90 std::unique_ptr<Index> index;
KdTree-based nearest neighbor search.
Definition kdtree2.hpp:22
virtual size_t radius_search(const double *pt, double radius, std::vector< size_t > &indices, std::vector< double > &sq_dists, int max_num_neighbors=std::numeric_limits< int >::max()) const override
Radius search.
Definition kdtree2.hpp:74
virtual size_t knn_search(const double *pt, size_t k, size_t *k_indices, double *k_sq_dists, double max_sq_dist=std::numeric_limits< double >::max()) const override
Find k nearest neighbors.
Definition kdtree2.hpp:52
Kd-tree builder with OpenMP.
Definition small_kdtree.hpp:189
Single thread Kd-tree builder.
Definition small_kdtree.hpp:124
K-nearest neighbor search setting.
Definition knn_result.hpp:11
int max_nn
Maximum number of neighbors to search.
Definition knn_result.hpp:20
double max_sq_dist
Maximum squared distance to search.
Definition knn_result.hpp:21
Nearest neighbor search interface.
Definition nearest_neighbor_search.hpp:16