C++ 将CloudViewer与自定义指针类型一起使用
我正在使用PCL(点云库),它有一个从PCL::PointXYZ继承的自定义PointTC++ 将CloudViewer与自定义指针类型一起使用,c++,boost,point-cloud-library,C++,Boost,Point Cloud Library,我正在使用PCL(点云库),它有一个从PCL::PointXYZ继承的自定义PointT struct PointXYZx : public pcl::PointXYZ { }; POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZx, (float, x, x) (float, y, y) (float, z, z)) 我想用CloudViewer绘制它: pcl::PointCloud<PointXYZx>::Ptr cloud (new
struct PointXYZx : public pcl::PointXYZ
{
};
POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZx, (float, x, x) (float, y, y) (float, z, z))
我想用CloudViewer绘制它:
pcl::PointCloud<PointXYZx>::Ptr cloud (new pcl::PointCloud<PointXYZx>());
pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
viewer.showCloud(cloud);
pcl::PointCloud::Ptr cloud(新的pcl::PointCloud());
pcl::visualization::CloudViewer查看器(“简单云查看器”);
查看器.showCloud(cloud);
但它给了我一个错误的说法:
main.cpp: In function ‘int main()’:
main.cpp:30:29: error: no matching function for call to ‘pcl::visualization::CloudViewer::showCloud(pcl::PointCloud<PointXYZx>::Ptr&)’
viewer.showCloud(cloud);
^
/usr/include/pcl-1.7/pcl/visualization/cloud_viewer.h:97:9: note: no known conversion for argument 1 from ‘pcl::PointCloud<PointXYZx>::Ptr {aka boost::shared_ptr<pcl::PointCloud<PointXYZx> >}’ to ‘const ConstPtr& {aka const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&}’
main.cpp:在函数“int main()”中:
main.cpp:30:29:错误:调用“pcl::visualization::CloudViewer::showCloud(pcl::PointCloud::Ptr&)”时没有匹配的函数
查看器.showCloud(cloud);
^
/usr/include/pcl-1.7/pcl/visualization/cloud_viewer.h:97:9:注意:参数1从'pcl::PointCloud::Ptr{aka boost::sharedptr}'到'const ConstPtr&{aka const boost::sharedptr&}没有已知的转换
我尝试使用以下方法将PointXYZx强制转换为PointXYZ:
viewer.showCloud((pcl::PointCloud<pcl::PointXYZ>::Ptr)cloud);
viewer.showCloud((pcl::PointCloud::Ptr)云);
但它告诉我:
/home/bruce/projects/mapomatix/mapomatix-pc/main.cpp:30:65: error: no matching function for call to ‘boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >::shared_ptr(pcl::PointCloud<PointXYZx>::Ptr&)’
viewer.showCloud((pcl::PointCloud<pcl::PointXYZ>::Ptr)(cloud));
/home/bruce/projects/mapomatix/mapomatix pc/main.cpp:30:65:错误:调用“boost::shared\u ptr::shared\u ptr(pcl::PointCloud::ptr&)”没有匹配的函数
showCloud((pcl::PointCloud::Ptr)(cloud));
如何使其工作?showCloud函数的输入类型是“boost::shared\u ptr”。您可以实例化一个共享的ptr,如下所示:
boost::shared_ptr<pcl::PointCloud<pcl::PointXYZx>> cloud_test;
cloud_test = boost::make_shared <pcl::PointCloud<pcl::PointXYZx>> (new pcl::PointCloud<pcl::PointXYZx>);
viewer.showCloud(cloud_test);
boost::共享云测试;
cloud\u test=boost::make\u shared(新的pcl::PointCloud);
viewer.showCloud(cloud_测试);
如果您正确定义了新的点类型,那么输入“cloud\u test”和函数“ShowCloud”就不会有问题
您可以看到这一点来了解有关实例化boost::shared_ptr的更多信息