问题
I am using PCL (Point Cloud Library) have a custom PointT that inherits from pcl::PointXYZ
struct PointXYZx : public pcl::PointXYZ
{
};
POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZx, (float, x, x) (float, y, y) (float, z, z))
And I want to plot it using CloudViewer:
pcl::PointCloud<PointXYZx>::Ptr cloud (new pcl::PointCloud<PointXYZx>());
pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
viewer.showCloud(cloud);
But it gives me error saying:
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> >&}’
I tried to cast the PointXYZx to PointXYZ using:
viewer.showCloud((pcl::PointCloud<pcl::PointXYZ>::Ptr)cloud);
But then it tells me:
/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));
How can I make it work?
回答1:
the input type of the showCloud function is "boost::shared_ptr" . you can instantiate a shared_ptr like below:
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);
and if you define the new point type correctly, there would be no problem with the input "cloud_test" and function "ShowCloud".
you can see this link to learn more about instantiating boost::shared_ptr.
来源:https://stackoverflow.com/questions/22209367/use-cloudviewer-with-custom-pointt-type