small_gicp
traits.hpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright 2024 Kenji Koide
2 // SPDX-License-Identifier: MIT
3 #pragma once
4 
5 #include <type_traits>
6 #include <Eigen/Core>
7 
8 namespace small_gicp {
9 
10 namespace traits {
11 
12 template <typename T>
13 struct Traits;
14 
22 template <typename T>
23 size_t knn_search(const T& tree, const Eigen::Vector4d& point, size_t k, size_t* k_indices, double* k_sq_dists) {
24  return Traits<T>::knn_search(tree, point, k, k_indices, k_sq_dists);
25 }
26 
28 template <typename T>
30  template <typename U, int = (&Traits<U>::nearest_neighbor_search, 0)>
31  static std::true_type test(U*);
32  static std::false_type test(...);
33 
34  static constexpr bool value = decltype(test((T*)nullptr))::value;
35 };
36 
43 template <typename T, std::enable_if_t<has_nearest_neighbor_search<T>::value, bool> = true>
44 size_t nearest_neighbor_search(const T& tree, const Eigen::Vector4d& point, size_t* k_index, double* k_sq_dist) {
45  return Traits<T>::nearest_neighbor_search(tree, point, k_index, k_sq_dist);
46 }
47 
54 template <typename T, std::enable_if_t<!has_nearest_neighbor_search<T>::value, bool> = true>
55 size_t nearest_neighbor_search(const T& tree, const Eigen::Vector4d& point, size_t* k_index, double* k_sq_dist) {
56  return Traits<T>::knn_search(tree, point, 1, k_index, k_sq_dist);
57 }
58 
59 } // namespace traits
60 
61 } // namespace small_gicp
size_t nearest_neighbor_search(const T &tree, const Eigen::Vector4d &point, size_t *k_index, double *k_sq_dist)
Find the nearest neighbor. If Traits<T>::nearest_neighbor_search is not defined, fallback to knn_sear...
Definition: traits.hpp:44
auto point(const T &points, size_t i)
Get i-th point. 4D vector is used to take advantage of SIMD intrinsics. The last element must be fill...
Definition: traits.hpp:40
size_t knn_search(const T &tree, const Eigen::Vector4d &point, size_t k, size_t *k_indices, double *k_sq_dists)
Find k-nearest neighbors.
Definition: traits.hpp:23
Definition: flat_container.hpp:12
Definition: traits.hpp:13
Check if T has nearest_neighbor_search method.
Definition: traits.hpp:29
static constexpr bool value
Definition: traits.hpp:34