首页 技术 正文
技术 2022年11月16日
0 收藏 687 点赞 4,052 浏览 4123 个字

最近开始动手做实验,之前写了一个小实验利用到了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;
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,137
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,301