最近开始动手做实验,之前写了一个小实验利用到了PCL库中的索引;

现在在写利用PCL中的RegionGrowing类来分割生成面片,无论是迭代生成还是进行提取都需要用到pcl库中定义的索引,

虽然搞的不是太明白,还是想写下来来记录自己的思路。

先看一下PCL是如何定义PointIndices的结构:

 struct PointIndices
{
PointIndices () : header (), indices ()
{} ::pcl::PCLHeader header; std::vector<int> indices; public:
typedef boost::shared_ptr< ::pcl::PointIndices> Ptr;
typedef boost::shared_ptr< ::pcl::PointIndices const> ConstPtr;
}; // struct PointIndices
   typedef boost::shared_ptr< ::pcl::PointIndices> PointIndicesPtr;
typedef boost::shared_ptr< ::pcl::PointIndices const> PointIndicesConstPtr;

可以看出在 数据结构 PointIndices 中 定义了点云的header和indices;这里我们不关心header的结构,而indices的结构就是简单的int类型的vector;

所以我们经常见到一些代码直接定义索引的时候直接使用了一下的定义:

 std::vector<int > points_indices;//int类型的vector类

或者:

 pcl::IndicesPtr indices(new std::vector <int>);//指向int类型的vector类的空智能指针

若要将智能指针指向定义的 points_indices,需要:

  pcl::IndicesPtr  index_ptr = boost::make_shared<std::vector<int>>(points_indices);

或者:

  pcl::IndicesPtr  index_ptr(new std::vector<int>(points_indices));

因为在pcl_base.h中有如下定义:

   typedef boost::shared_ptr <std::vector<int> > IndicesPtr;
typedef boost::shared_ptr <const std::vector<int> > IndicesConstPtr;

PS:

pcl中大量用到了智能指针 share_ptr,shared_ptr允许多个指针指向同一个对象

 智能指针的使用方式与普通指针类似:

  1.解引用一个智能指针返回它指向的对象;

  2.如果在一个条件判断中使用智能指针,效果就是检测它是否为空.

使用智能指针的初始化:

     //一般的初始化方式
shared_ptr<string> pint(new string("normal usage!"));
cout<<*pint<<endl; //推荐的安全的初始化方式
shared_ptr<string> pint1 = make_shared<string>("safe uage!");
cout<<*pint1<<endl;

先把之前利用到的写一些:

 1     int j = ;
std::vector<int > indexs;
for (auto i : *normals)
{
if (i.normal_z < 0.05 && i.normal_z > -0.05)
{
normals1->points.push_back(i);
indexs.push_back(j);
}
j++;
}
//打印滤波后将法向量存储在normal1的信息,以及相应的索引
std::cout << *normals1 << std::endl;
std::cout << indexs.size() << std::endl; //索引
boost::shared_ptr<std::vector<int>> index_ptr = boost::make_shared<std::vector<int>>(indexs);
// Create the filtering object
pcl::ExtractIndices<pcl::PointXYZ> extract;
// Extract the inliers
extract.setInputCloud(cloud_0);
extract.setIndices(index_ptr);
extract.setNegative(false);//如果设为true,可以提取指定index之外的点云
extract.filter(*cloud_1);
//法向量滤波后得到的点云信息
std::cout << *cloud_1 << std::endl;

上面第17行代码也可以写为:

  pcl::IndicesPtr  index_ptr = boost::make_shared<std::vector<int>>(indexs);

那么现在有pcl_base.h下的IndicesPtr,为指向int类型的vector的智能指针的索引;

PointIndices.h下的定义的数据结构 PointIndices ;那么将点云进行索引的指针可用以下:

 pcl::PointIndices index_1;
pcl::IndicesPtr index_ptr = boost::make_shared<std::vector<int>>(index_1.indices);

综上所述,索引的使用可以如下所示:

 std::vector<int > indexs;
pcl::PointIndices index_1;
pcl::IndicesPtr indices_plane(new std::vector <int>(indexs));
pcl::IndicesPtr index_ptr(new std::vector<int>(index_1.indices));
pcl::IndicesPtr index_ptr = boost::make_shared<std::vector<int>>(index_1.indices);
pcl::IndicesPtr index_ptr = boost::make_shared<std::vector<int>>(indexs);
//pcl::IndicesPtr index_ptr = boost::make_shared<std::vector<int>>(index_1);//这个index_1的索引不可用,因为index_1为PointIndices类,只能用上述第5行那样调用

利用ExtractIndices进行索引点云的提取:

   pcl::ExtractIndices<pcl::PointXYZ> extract;
extract.setInputCloud(cloud_0);
extract.setIndices(index_ptr);
extract.setNegative(false);//如果设为true,可以提取指定index之外的点云
extract.filter(*cloud_1);

总结一下,这篇文章主要是解决在PCL使用过程中,用于自定义条件的点云提取,将点云的索引进行相应的存储在 vector<int> 数组中,利用

  pcl::IndicesPtr  index_ptr = boost::make_shared<std::vector<int>>(points_indices);

或者:

  pcl::IndicesPtr  index_ptr(new std::vector<int>(points_indices));

进行智能指针的转化,以利用ExtractIndices类中的 setIndices()函数进行点云的提取。

举例如下:

     //根据想要的点添加到自定义的indices_0的数组中,
//std::vector<int> indices_0;
pcl::PointIndices indices_0; indices_0.indices.push_back();
indices_0.indices.push_back();
indices_0.indices.push_back();
//将自定义的indices_0数组进行智能指针的转化
//pcl::IndicesPtr index_ptr_0 = boost::make_shared<std::vector<int>>(indices_0.indices);
pcl::IndicesPtr index_ptr_0(new std::vector<int>(indices_0.indices)); //利用ExtractIndices根据索引进行点云的提取
pcl::ExtractIndices<pcl::PointXYZ> extract;
extract.setInputCloud(cloud_0);
extract.setIndices(index_ptr_0);
extract.setNegative(false);//如果设为true,可以提取指定index之外的点云
extract.filter(*cloud_1); //cloud_1索引0,1,2分别对应与cloud_0索引的0,10,100
std::cout << *cloud_1 << std::endl;
std::cout << cloud_1->at() << std::endl;
std::cout << cloud_1->at() << std::endl;
std::cout << cloud_1->at() << std::endl; std::cout << *cloud_0 << std::endl;
std::cout << cloud_0->at() << std::endl;
std::cout << cloud_0->at() << std::endl;
std::cout << cloud_0->at() << std::endl;

关于pcl索引的使用的更多相关文章

  1. PCL中的类

    1. PCLBase pcl_base.h中定义了PCL中的基类PCLBase,PCL中的大部分算法都使用了其中的方法. PCLBase实现了点云数据及其索引的定义和访问. 两个主要的变量input_ ...

  2. PCL近邻搜索相关的类

    首先PCL定义了搜索的基类pcl::search::Search<PointInT> template<typename PointT> class Search 其子类包括: ...

  3. PCL中使用FLANN库(2)

    接着上一篇的介绍继续 关于在使用readHeader函数读取点云数据头的类型的代码(Read a point cloud data header from a PCD file.) pcl::PCLP ...

  4. PCL中使用FLANN库(1)

    FLANN库全称是Fast Library for Approximate Nearest Neighbors,它是目前最完整的(近似)最近邻开源库.不但实现了一系列查找算法,还包含了一种自动选取最快 ...

  5. PCL中分割方法的介绍(3)

    (3)上两篇介绍了关于欧几里德分割,条件分割,最小分割法等等还有之前就有用RANSAC法的分割方法,这一篇是关于区域生成的分割法, 区 域生长的基本 思想是: 将具有相似性的像素集合起来构成区域.首先 ...

  6. PCL中分割_欧式分割(1)

    基于欧式距离的分割和基于区域生长的分割本质上都是用区分邻里关系远近来完成的.由于点云数据提供了更高维度的数据,故有很多信息可以提取获得.欧几里得算法使用邻居之间距离作为判定标准,而区域生长算法则利用了 ...

  7. 如何在ROS中使用PCL(2)

    记录关于我们运行roslaunch openni_launch openni.launch  命令时生成的话题以及这些话题的数据类型便于后期的处理,只有知道它们的数据结构,才能很好的对数据进行处理,我 ...

  8. PCL特征点与配准(1)

    关于输入一个具体的物体的点云,从场景中找出与该物体点云相匹配的,这种方法可以用来抓取指定的物体等等,具体的代码的解释如下,需要用到的一些基础的知识,在之前的博客中都有提及,其中用到的一些方法可以翻阅前 ...

  9. 如何在ROS中使用PCL—数据格式(1)

    在ROS中点云的数据类型 在ROS中表示点云的数据结构有: sensor_msgs::PointCloud      sensor_msgs::PointCloud2     pcl::PointCl ...

随机推荐

  1. Hutool 3.0.8 发布,Java 工具集

    Hutool 是一个Java工具包,提供了丰富的文件.日期.日志.正则.字符串.配置文件等工具方法,并封装了一套简单易用的ORM框架. 主页:http://hutool.cn/ 文档:http://h ...

  2. JQuery 判断checkbox是否选中,checkbox全选,获取checkbox选中值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. QDialog之屏蔽Esc键(简单深刻,要么重写keyPressEvent然后break忽略此事件,要么重写eventFilter然后return,都是为了忽略此事件)

    简述 Qt中Esc键会在一些控件中默认的进行一些事件的触发,比如:QDialog,按下Esc键窗口消失.大多数情况下,我们不需要这么做,那么就需要对默认事件进行屏蔽. 简述 源码分析 事件过滤器 事件 ...

  4. 笔记:Advanced Installer 打包Web应用

    原文:笔记:Advanced Installer 打包Web应用 公司要做一款增值税小产品,区别于ACME,本产品核心只有销项部分,面对的客户群是小企业,单税盒单开票机..... 我要做的主要有以下几 ...

  5. vmstat命令浅析

    vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况.这个命令是我查看Linux/Unix最 ...

  6. C#委托和事件 EventHandle和EventArgs

    一.背景由于对于C#委托和事件理解的不够透彻,并且平时工作中对于自己手写委托和事件很少,渐渐的只会增删改查了.特定整理了委托和事件的基本知识.二.案例案例引用了张逸 博客 中的案例,并做了处理. 创建 ...

  7. MYSQL的全局变量和会话变量

    系统变量又分为全局变量与会话变量. 全局变量在MYSQL启动的时候由服务器自动将它们初始化为默认值,这些默认值可以通过更改my.ini这个文件来更改. 会话变量在每次建立一个新的连接的时候,由MYSQ ...

  8. EditPlus 格式化HTML JS CSS

    首先你得安装一个EditPlus,然后下载你想格式化的xxxformatter.js文件,也就是网上说的EDTOOLS 1.在你的工具里边找到-->配置自定义工具 具体做法如下: 第5步 命令: ...

  9. Go语言之从0到1实现一个简单的Redis连接池

    Go语言之从0到1实现一个简单的Redis连接池 前言 最近学习了一些Go语言开发相关内容,但是苦于手头没有可以练手的项目,学的时候理解不清楚,学过容易忘. 结合之前组内分享时学到的Redis相关知识 ...

  10. Kafka 学习之路(三)—— Kafka生产者详解

    一.生产者发送消息的过程 首先介绍一下Kafka生产者发送消息的过程: Kafka会将发送消息包装为ProducerRecord对象, ProducerRecord对象包含了目标主题和要发送的内容,同 ...