首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PCL库中插入pcl::octree::OctreePointCloudSearch<pcl::PointXYZ>索引

在PCL库中插入pcl::octree::OctreePointCloudSearch<pcl::PointXYZ>索引
EN

Stack Overflow用户
提问于 2022-04-03 06:40:28
回答 1查看 166关注 0票数 0

我正在尝试使用pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree对点云进行分区&执行一些操作。

在该方法中,它提供了一个称为

代码语言:javascript
复制
setInputCloud(const PointCloudConstPtr &cloud_arg, IndicesConstPtr &indices_arg = IndicesConstPtr ())

在文档中,解释如下所示。

代码语言:javascript
复制
*\brief Provide a pointer to the input data set.
     * \param[in] cloud_arg the const boost shared pointer to a PointCloud message
     * \param[in] indices_arg the point indices subset that is to be used from \a cloud - if 0 the whole point cloud is used

此外,

代码语言:javascript
复制
// public typedefs
typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr;
typedef pcl::PointCloud<PointT> PointCloud;
typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;

我已经做的是,

代码语言:javascript
复制
pcl::PointCloud<pcl::PointXYZ>::Ptr inputCloud (new pcl::PointCloud<pcl::PointXYZ> ());
pcl::PointIndices::Ptr cloudIndices(new pcl::PointIndices());
pcl::PointIndices::Ptr selectedIndices(new pcl::PointIndices());

/* some code to fill inputCloud and cloudIndices & selectedIndices
(selectedIndices is contains only chosen indices set from all cloudIndices) */

float resolution = 0.1;
pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(resolution);
octree.setInputCloud(inputCloud);
octree.addPointsFromInputCloud();

这个很好用。但是,在不使用selectedIndices创建新的点云的情况下,我需要使用现有的inputCloud并对函数使用selectedIndices

我知道octree.setInputCloud(inputCloud, selectedIndices);函数不起作用。它回来了

代码语言:javascript
复制
error: cannot convert ‘pcl::PointIndices::Ptr’ {aka ‘std::shared_ptr<pcl::PointIndices>’} to ‘const IndicesConstPtr&’ {aka ‘const std::shared_ptr<const std::vector<int> >&’}
  169 |     octree.setInputCloud (inputCloud,selectedIndices);
      |                                             ^~~~~~~~~~~~~~~~~~~~~~
      |                                             |
      |                                             pcl::PointIndices::Ptr {aka std::shared_ptr<pcl::PointIndices>}

我需要转换std::shared_ptr<pcl::PointIndices>const to std::shared_ptr<const std::vector<int> >&吗?我该怎么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-05 06:01:53

找到了解决上述问题的方法。

PCL函数

代码语言:javascript
复制
 setInputCloud(const PointCloudConstPtr &cloud_arg, IndicesConstPtr &indices_arg = IndicesConstPtr ())

接受索引,但必须将其转换为pcl::IndicesPtr类型。

所以,我的解决办法是,

代码语言:javascript
复制
pcl::IndicesPtr indicesTemp(new std::vector<int>());
std::copy(selectedIndices->indices.begin(), selectedIndices->indices.end(), std::back_inserter(*indicesTemp));

float resolution = 0.1;
pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(resolution);
octree.setInputCloud(inputCloud,indicesTemp);
octree.addPointsFromInputCloud();

结果与预期相符。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71723586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档