19 #include "nav2_route/node_spatial_tree.hpp"
39 num_of_nearest_nodes_ = num_of_nearest_nodes;
55 kdtree_ =
new kd_tree_t(DIMENSION, *adaptor_, nanoflann::KDTreeSingleIndexAdaptorParams(10));
56 kdtree_->buildIndex();
61 const geometry_msgs::msg::PoseStamped & pose_in, std::vector<unsigned int> & node_ids)
63 size_t num_results =
static_cast<size_t>(num_of_nearest_nodes_);
64 std::vector<unsigned int> ret_index(num_results);
65 std::vector<double> out_dist_sqr(num_results);
66 const double query_pt[2] = {pose_in.pose.position.x, pose_in.pose.position.y};
67 num_results = kdtree_->knnSearch(&query_pt[0], num_results, &ret_index[0], &out_dist_sqr[0]);
69 if (num_results == 0) {
73 for (
int i = 0; i < static_cast<int>(ret_index.size()); ++i) {
74 node_ids.push_back(ret_index[i]);
bool findNearestGraphNodesToPose(const geometry_msgs::msg::PoseStamped &pose_in, std::vector< unsigned int > &node_ids)
Find the closest node to a given pose.
~NodeSpatialTree()
Destructor.
void setNumOfNearestNodes(int num_of_nearest_nodes)
Set the number of nodes to search in local area for.
void computeTree(Graph &graph)
Compute the kd-tree based on the graph node information.
An adaptor for Nanoflann to operate on our graph object without copying.