将索引插入 PCL 库中的 pcl::octree::OctreePointCloudSearch<pcl::PointXYZ>
Insert indices to pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> in PCL Library
我正在尝试使用 pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree
对点云进行分区和执行一些操作。
在方法中,它提供了一个public函数调用
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);
功能不起作用。它returns
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> >&
吗?我该怎么做?
找到上述问题的答案。
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();
结果如预期。
我正在尝试使用 pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree
对点云进行分区和执行一些操作。
在方法中,它提供了一个public函数调用
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);
功能不起作用。它returns
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> >&
吗?我该怎么做?
找到上述问题的答案。
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();
结果如预期。