PCL: visualize a point cloud

I am trying to visualize a point cloud using PCL CloudViewer. The problem is that I'm pretty new to C ++, and I found two tutorials demonstrating the creation of PointCloud and the second demonstrates the visualization of PointCloud. However, I cannot combine these two textbooks.

Here is what I come with:

#include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/visualization/cloud_viewer.h> int main (int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ> cloud; // Fill in the cloud data cloud.width = 5; cloud.height = 1; cloud.is_dense = false; cloud.points.resize (cloud.width * cloud.height); for (size_t i = 0; i < cloud.points.size (); ++i) { cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f); cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f); cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); } pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer"); viewer.showCloud (cloud); while (!viewer.wasStopped ()) { } return (0); } 

but they don’t even compile:

 error: no matching function for call to 'pcl::visualization::CloudViewer::showCloud(pcl::PointCloud<pcl::PointXYZ>&)' 
+8
point-cloud-library point-clouds
source share
4 answers

Your error message tells you what you need to do:

 error: no matching function for call to 'pcl::visualization::CloudViewer::showCloud(pcl::PointCloud<pcl::PointXYZ>&)' 

So, go to the documentation for CloudViewer and see what arguments this member function takes: http://docs.pointclouds.org/1.5.1/classpcl_1_1visualization_1_1_cloud_viewer.html

We see that the required const MonochromeCloud::ConstPtr &cloud not the source link you are passing. This is the typedef of a smart pointer from boost:

 typedef boost::shared_ptr<const PointCloud<PointT> > pcl::PointCloud< PointT >::ConstPtr 

So, when you create your cloud, you need to wrap it in one of these smart pointers instead of making it a local variable. Something like (unverified):

 pcl::MonochromeCloud::ConstPtr cloud(new pcl::PointCloud<pcl::PointXYZ>()); 

Then, when you go into the variable cloud, it will be of the correct type and you will not receive an error message. You will also have to change cloud.foo to cloud->foo s.

Looking at the second example, he also does this:

 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>); 
+7
source share

To give an answer right away:

 pcl::PointCloud<pcl::PointXYZRGB>::Ptr ptrCloud(&cloud); 

Then add ptrCloud to the viewer, this is what it expects:

 viewer.showCloud (ptrCloud); 
+4
source share

Tutorial for CloudViewer pcl cloudviewer tutorial http://pointclouds.org/documentation/tutorials/cloud_viewer.php#cloud-viewer defines a point cloud as follows:

 pcl::PointCloud<pcl::PointXYZRGB>**::Ptr** cloud; 

But you wrote:

 pcl::PointCloud<pcl::PointXYZ> cloud; 

So, try passing the cloud as a cloud instead of a cloud, or declare it as a pointer.

0
source share

If someone else is just looking for how to do this in ROS, you can simply do it using:

 #include <ros/ros.h> #include <pcl_ros/point_cloud.h> #include <pcl/point_types.h> #include <pcl/visualization/cloud_viewer.h> #include <sensor_msgs/PointCloud2.h> #include <pcl_conversions/pcl_conversions.h> #include <iostream> #include <pcl/common/common_headers.h> #include <pcl/features/normal_3d.h> #include <pcl/io/pcd_io.h> #include <pcl/visualization/pcl_visualizer.h> #include <pcl/console/parse.h> typedef pcl::PointCloud<pcl::PointXYZ> PointCloud; class cloudHandler { public: cloudHandler():viewer("Cloud Viewer") { pcl_sub = nh.subscribe("/camera/depth_registered/points", 10, &cloudHandler::cloudCB, this); viewer_timer = nh.createTimer(ros::Duration(0.1), &cloudHandler::timerCB,this); } void cloudCB(const sensor_msgs::PointCloud2 &input) { pcl::PointCloud<pcl::PointXYZRGB> cloud; pcl::fromROSMsg (input, cloud); viewer.showCloud(cloud.makeShared()); } void timerCB(const ros::TimerEvent&) { if(viewer.wasStopped()) { ros::shutdown(); } } protected: ros::NodeHandle nh; ros::Subscriber pcl_sub; pcl::visualization::CloudViewer viewer; ros::Timer viewer_timer; }; int main(int argc, char** argv) { ros::init(argc, argv, "pcl_visualize"); cloudHandler handler; ros::spin(); return 0; } 

The inclusion can probably be cleared more :)

0
source share

All Articles