pcl之kdtree的使用

pcl之kdtree的使用

A k-d tree, or k-dimensional tree, is a data structure used in computer science for organizing some number of points in a space with k dimensions. It is a binary search tree with other constraints imposed on it. K-d trees are very useful for range and nearest neighbor searches.

#include <pcl/point_cloud.h>
#include <pcl/kdtree/kdtree_flann.h>

#include <iostream>
#include <vector>

int main(int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
  ....
  pcl::KdTreeFLANN<pcl::PointXYZI> kdtree;
  kdtree.setIputCloud(cloud);
  pcl::PointXYZI search_point;
  ....
  // k nearest neighbor search
  int k = 10;
  std::vector<int> k_indices(k);
  std::vector<float> k_sqr_distances(k;)
  if (kdtree.nearestKSearch(search_point, k, k_indices, k_sqr_distances) > 0)
  {
    //do something
  }
  
  // neighbors within radius search
  float radius = 1.0;
  std::vector<int> 
  std::vector<float>
  if (kdtree.radiusSearch(search_point, radius, radius_indices, radius_sqr_distance) > 0)
  {
    //do something
  }

}

值得注意的是: 返回的是square_distance

参考

http://pointclouds.org/documentation/tutorials/kdtree_search.php

转载于:https://www.cnblogs.com/ChrisCoder/p/9937597.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值