I'm trying to partitioning & perform some actions to a point cloud using pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree
.
In the method, it provides a public function called
setInputCloud(const PointCloudConstPtr &cloud_arg, IndicesConstPtr &indices_arg = IndicesConstPtr ())
In the doc, the explanation is used as below.
*\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
Further,
// public typedefs
typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr;
typedef pcl::PointCloud<PointT> PointCloud;
typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
What I have already done is,
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();
This works fine. But I need, without creating a new point cloud with selectedIndices
, to use the existing inputCloud
and use selectedIndices
to the function.
I know octree.setInputCloud(inputCloud, selectedIndices);
function is not working. It 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>}
Do I need to convert std::shared_ptr<pcl::PointIndices>const to std::shared_ptr<const std::vector<int> >&
? How can I do this?
Found the solution to the above question.
PCL Function
setInputCloud(const PointCloudConstPtr &cloud_arg, IndicesConstPtr &indices_arg = IndicesConstPtr ())
accepts indices but you have to convert it to the pcl::IndicesPtr
type.
So, My solution was to,
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();
and results were as expected.