我正在尝试使用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> >&吗?我该怎么做?
发布于 2022-04-05 06:01:53
找到了解决上述问题的方法。
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();结果与预期相符。
https://stackoverflow.com/questions/71723586
复制相似问题