pcl::PointCloud<pcl::PointXYZ>和pcl::PointCloud<pcl::PointXYZ>::Ptr传参的时候的转换

文章讲述了作者在使用PCL库处理点云数据时,遇到关于智能指针类型转换和函数参数传递的错误。通过修正函数声明中参数类型,解决了将智能指针类型的点云对象传递给函数的问题。
摘要由CSDN通过智能技术生成

自己定义了一个函数:

void gridCalculation( pcl::PointCloud<PointT> pointcloud, vector<grid>& vgrid){
........
}

然后传入参数:

    pcl::PointCloud<PointT>::Ptr cloud_max_cluster(new pcl::PointCloud<PointT>);
    vector<grid> vgrid;
    gridCalculation(*cloud_max_cluster, vgrid);

然后出现下述报错

error: could not convert ‘cloud_max_cluster.boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >::operator*()’ 
from ‘pcl::PointCloud<pcl::PointXYZ>’ to ‘pcl::PointCloud<pcl::PointXYZ>::Ptr {aka boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >}’
     gridCalculation(*cloud_max_cluster, vgrid);

cloud_max_cluster是Ptr的格式,所以传入*cloud_max_cluster,对指针进行取值,结果还是出现报错。
后来找到问题的原因了:
在函数声明的地方忘记改了,函数声明的地方,参数是智能指针。将函数声明的地方和函数定义的地方改成一样的即可。

void gridCalculation( pcl::PointCloud<PointT>::Ptr pointcloud, vector<grid>& vgrid)

下面是点云智能指针格式和非指针格式的转换:

pcl::PointCloud<PointT>::Ptr cloud_ptr(new pcl::PointCloud<PointT>);
pcl::PointCloud<PointT> cloud;
cloud = *cloud_ptr;
cloud_ptr = boost::make_shared<pcl::PointCloud<PointT>>(cloud);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值