将索引插入到 PCL 库中的 pcl::octree::OctreePointCloudSearch<pcl::PointXYZ>

问题描述 投票:0回答:1

我正在尝试使用

pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree
对点云进行分区和执行一些操作。

在方法中,它提供了一个公共函数,名为

setInputCloud(const PointCloudConstPtr &cloud_arg, IndicesConstPtr &indices_arg = IndicesConstPtr ())

在文档中,使用的解释如下。

*\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

此外,

// public typedefs
typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr;
typedef pcl::PointCloud<PointT> PointCloud;
typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;

我已经做了的是,

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);
功能不起作用。它回来了

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> >&
吗?我怎样才能做到这一点?

c++ 3d geometry point-cloud-library point-clouds
1个回答
0
投票

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

PCL功能

 setInputCloud(const PointCloudConstPtr &cloud_arg, IndicesConstPtr &indices_arg = IndicesConstPtr ())

接受索引,但您必须将其转换为

pcl::IndicesPtr
类型。

所以,我的解决方案是,

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();

结果符合预期。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.