Search code examples
pointersshared-ptrpoint-cloud-librarypoint-cloudsoutliers

pcl::PointCloud<pcl::PointXYZ> to pcl::PointCloud<pcl::PointXYZ>::Ptr (Covert poincloud to ptr)


I am using PCL 1.3. Is there any function to convert pointcloud to pointcloud::ptr. I am new at PCL libraries. I have a ROS node subscribing to sensor_msgs/PoinCloud2 topic then I am converting it into pcl::Poincloud and now I want to do pcl::StatisticalOutlierRemoval. The outlier removal function takes in the pointers, not the Poincloud itself(That's what I understood). So for that purpose I would like to know the solution of how to convert between them?

pcl::PointCloud<pcl::PointXYZ> point_cloud
pcl::fromPCLPointCloud2(cloud_filtered, point_cloud);


pcl::removeNaNFromPointCloud(point_cloud, point_cloud, nan_idx);

pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
sor.setInputCloud (point_cloud);
sor.setMeanK (50);
sor.setStddevMulThresh (1.0);
sor.filter (*point_cloud);

error: no matching function for call to ‘pcl::StatisticalOutlierRemovalpcl::PointXYZ::setInputCloud(**pcl::PointCloudpcl::PointXYZ**&)’

note: candidate: void pcl::PCLBase::setInputCloud(const PointCloudConstPtr&) [with PointT = pcl::PointXYZ; pcl::PCLBase::PointCloudConstPtr = boost::shared_ptr<const pcl::PointCloudpcl::PointXYZ >]


Solution

  • pcl::PointCloud<pcl::PointXYZ>::Ptr is a shared_ptr - so, simply speaking, it is a wrapper around a pointer that manages it's lifetime (in our case a wrapper around a pointer to pcl::PointCloud<pcl::PointXYZ>).

    You instatiate it by passing a pointer, such as the one that comes from a new: pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud(new pcl::PointCloud< pcl::PointXYZ>);

    Since pcl::fromPCLPointCloud2 expects a pcl::PointCloud<pcl::PointXYZ>, you need dereferencing: pcl::fromPCLPointCloud2(cloud_filtered, *point_cloud);