PCL点云库:Kd树
Kd树按空间划分生成叶子节点,各个叶子节点里存放点数据,其可以按半径搜索或邻区搜索。PCL中的Kd tree的基础数据结构使用了FLANN以便可以快速的进行邻区搜索。FLANN is a library for performing fast approximate nearest neighbor searches in high dimensional spaces。下面是一个最基本的例子,只寻找一个最近点:
#include <pcl/point_cloud.h>
#include <pcl/kdtree/kdtree_flann.h> #include <iostream>
#include <vector>
#include <ctime> int main (int argc, char** argv)
{
srand (time (NULL)); //seeds rand() with the system time time_t begin,end;
begin = clock(); //开始计时
//-------------------------------------------------------------------------------
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); // Generate pointcloud data
cloud->width = ;
cloud->height = ;
cloud->points.resize (cloud->width * cloud->height); // fills a PointCloud with random data
for (size_t i = ; i < cloud->points.size (); ++i)
{
cloud->points[i].x = 1024.0f * rand () / (RAND_MAX + 1.0f);
cloud->points[i].y = 1024.0f * rand () / (RAND_MAX + 1.0f);
cloud->points[i].z = 1024.0f * rand () / (RAND_MAX + 1.0f);
} // creates kdtree object
pcl::KdTreeFLANN<pcl::PointXYZ> kdtree; // sets our randomly created cloud as the input
kdtree.setInputCloud (cloud); //create a “searchPoint” which is assigned random coordinates
pcl::PointXYZ searchPoint; searchPoint.x = 1024.0f * rand () / (RAND_MAX + 1.0f);
searchPoint.y = 1024.0f * rand () / (RAND_MAX + 1.0f);
searchPoint.z = 1024.0f * rand () / (RAND_MAX + 1.0f); // K nearest neighbor search
int K = ;
std::vector<int> pointIdxNKNSearch(K);
std::vector<float> pointNKNSquaredDistance(K); std::cout << "K nearest neighbor search at (" << searchPoint.x
<< " " << searchPoint.y
<< " " << searchPoint.z
<< ") with K=" << K << std::endl; /***********************************************************************************************
template<typename PointT>
virtual int pcl::KdTree< PointT >::nearestKSearch ( const PointT & p_q,
int k,
std::vector< int > & k_indices,
std::vector< float > & k_sqr_distances
) const [pure virtual] Search for k-nearest neighbors for the given query point.
Parameters:
[in] the given query point
[in] k the number of neighbors to search for
[out] the resultant indices of the neighboring points
[out] the resultant squared distances to the neighboring points
Returns:
number of neighbors found
********************************************************************************************/
if ( kdtree.nearestKSearch (searchPoint, K, pointIdxNKNSearch, pointNKNSquaredDistance) > )
{
for (size_t i = ; i < pointIdxNKNSearch.size (); ++i)
std::cout << " " << cloud->points[ pointIdxNKNSearch[i] ].x
<< " " << cloud->points[ pointIdxNKNSearch[i] ].y
<< " " << cloud->points[ pointIdxNKNSearch[i] ].z
<< " (squared distance: " << pointNKNSquaredDistance[i] << ")" << std::endl;
}
//--------------------------------------------------------------------------------------------
end = clock(); //结束计时
double Times = double(end - begin) / CLOCKS_PER_SEC; //将clock()函数的结果转化为以秒为单位的量 std::cout<<"time: "<<Times<<"s"<<std::endl; return ;
}
生成四十万个随机点,release版本下测试0.3s左右找到最近点,这比之前自己写的Kd树不知快到哪里去了。当然自己写只是为了更好的理解其中的原理,真要用的时候还得靠别人的轮子...
参考:
PCL点云库:Kd树的更多相关文章
- PCL点云库:ICP算法
ICP(Iterative Closest Point迭代最近点)算法是一种点集对点集配准方法.在VTK.PCL.MRPT.MeshLab等C++库或软件中都有实现,可以参见维基百科中的ICP Alg ...
- PCL点云库中的坐标系(CoordinateSystem)
博客转载自:https://blog.csdn.net/qq_33624918/article/details/80488590 引言 世上本没有坐标系,用的人多了,便定义了坐标系统用来定位.地理坐标 ...
- Windows下安装PCL点云库
原文链接:http://blog.csdn.net/u012337034/article/details/38270109 简介: 在Windows下安装PCL点云库的方法大概有两种: ...
- Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境
Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境 下载PCL For windows 软件包 到这个网站下载PCL-All-In-One Installer: ...
- python利用pybind11调用PCL点云库
2019年7月9日14:31:13 完成了一个简单的小例子,python生成点云数据,利用pybind11传给PCL显示. ubuntu 16.04 + Anaconda3 python3.6 + ...
- PCL点云库(Point Cloud Library)简介
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=29 什么是PCL PCL(Point Cloud Library)是在吸收了 ...
- PCL点云库:对点云进行变换(Using a matrix to transform a point cloud)
点云数据可以用ASCII码的形式存储在PCD文件中(关于该格式的描述可以参考链接:The PCD (Point Cloud Data) file format).为了生成三维点云数据,在excel中用 ...
- [PCL]1 PCL点云库安装
1.安装文件下载:官网,我还是比较喜欢别人编译好的安装包啊,哈哈. http://www.pointclouds.org/downloads/windows.html 2.傻瓜式安装(下面的依赖项都集 ...
- PCL点云库增加自定义数据类型
#include <pcl/filters/passthrough.h> #include <pcl/filters/impl/passthrough.hpp> // the ...
随机推荐
- 纯CSS实现tooltip提示框,CSS箭头及形状
本片介绍仅用CSS做出tooltip那样的提示框及箭头等形状! 首先介绍一下CSS:after选择器 定义和用法:(参考w3school:after选择器) :after选择器在被选元素的内容后面插入 ...
- [转]Android View.onMeasure方法的理解
转自:http://blog.sina.com.cn/s/blog_61fbf8d10100zzoy.html Android View.onMeasure方法的理解 View在屏幕上显示出来要先经过 ...
- awk 反过滤不想要的列 和循环列
[root@elk_m ~]# awk '{print $0}' install.log.syslog |head -1 <86>Feb 29 02:58:28 groupadd[1598 ...
- html5 canvas围绕中心点旋转
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- .NET调用外部接口将得到的List数据,并使用XmlSerializer序列化List对象成XML格式
BidOpeningData.BidSupervisionSoapClient client = new BidOpeningData.BidSupervisionSoapClient(); Dict ...
- linux pptpd账号同时登录的问题
最近搞了个云主机搭建个VPN服务器给自己用, 特别是在公共场所的wifi上网时, 很多APP, 或者网站是没有https的, 所以为了保证信息(主要是账号密码)的安全, 搭个私有vpn还是很有必要的. ...
- (转)MVC设计模式学习总结
原文 : chenchun的博客 http://www.cnblogs.com/jobscn/archive/2011/11/08/2240725.html -------------------- ...
- IOS 谓词
// 谓词 Person *person = [[Person alloc]init]; person.name = @"zhang san"; person.age = 20; ...
- wkhtmltopdf 中文参数详解
linux:wkhtmltopdf [OPTIONS]… [More input files] windows:wkhtmltopdf.exe [OPTIONS]… [More input files ...
- [翻译] java NIO Buffer
原文地址:http://tutorials.jenkov.com/java-nio/buffers.html JAVA NIO 是在和channel交互的时候使用的.正如你所知道的,数据是从chann ...