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 ...
随机推荐
- BizTalk开发系列(三十四) Xpath
XPath 是在 XML 文档中查找信息的语言,在BizTalk的开发中应用非常广泛,当然你可以不必先学Xpath再去学BizTalk.但是如果对Xpath有一定了解的 话,在很多应用下会使你的开发更 ...
- Android课程---首学开发
新建一个Activity2类: package com.hanqi.test; import android.app.Activity; import android.os.Bundle; impor ...
- Android 网络通信框架Volley简介
1.1. Volley引入的背景在以前,我们可能面临如下很多麻烦的问题. 比如以前从网上下载图片的步骤可能是这样的流程: 在ListAdapter#getView()里开始图像的读取. 通过Async ...
- 并发两个Thread的怪事——已解决
截图是马士兵视频的代码.我这样试了下,的确可行. 但是一般来说,主线程就是用来启动子线程的,所以我用了下图的形式,运行了3次.结果运行结果一直在变化,并且都没有正确的显示内容.这个截图里面编号11的线 ...
- 蓝牙协议栈记录—BTStack
TSTack User Guid 翻译过来的 1.简介 2.BTStack 架构 BTStack在所实现的协议和服务之间采用很多状态机实现相互作用,特点: <1>单线程.BTStack只有 ...
- 【五子棋AI循序渐进】关于VCT,VCF的思考和核心代码
前面几篇发布了一些有关五子棋的基本算法,其中有一些BUG也有很多值得再次思考的问题,在框架和效果上基本达到了一个简单的AI的水平,当然,我也是初学并没有掌握太多的高级技术.对于这个程序现在还在优化当中 ...
- C#编程利器之三:接口(Interface)【转】
C#编程利器之三:接口(Interface) C#接口是一个让很多初学者容易迷糊的东西,用起来好象很简单,定义接口,然后在里面定义方法,通过继承与他的子类来完成具体的实现.但没有真正认识接口的作用的时 ...
- SQL Server 定时自动备份数据库
在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库,这篇文章介绍使用SQL Server 数据库代理中的作业定时自动备份数据库. 1.启动SQL Server代理服务,如下图: 绿色 ...
- centos7安装出现license information(license not accepted)解决办法
若出现license information(license not accepted),即说明需要同意许可信息,输入1-回车-2-回车-c-回车-c回车,即可解决.
- 【转】Web性能压力测试工具之ApacheBench(ab)详解
PS:网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个自带的,名为ab的程序,可以对Apache或其它类型的服务器进行网 ...