ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

PointCloud2 is the "official" point cloud used by PCL. There is a direct mapping from sensor_msgs::PointCloud2 to pcl::PointCloud<pcl::pointxyz> using the pcl::fromROSMsg and pcl::toROSMsg functions. I believe that PointCloud is scheduled to be phased out and replaced by PointCloud2.

In your above code, to use PointCloud2, all you need to change is the following line:

From:

sensor_msgs::PointCloud cloud;

To:

sensor_msgs::PointCloud2 cloud;

And viola! It works.

PointCloud2 is the "official" point cloud used by PCL. There is a direct mapping from sensor_msgs::PointCloud2 to pcl::PointCloud<pcl::pointxyz> pcl::PointCloud<pcl::PointXYZ> using the pcl::fromROSMsg and pcl::toROSMsg functions. I believe that PointCloud is scheduled to be phased out and replaced by PointCloud2.

The reason that you would want to use the toROSMsg or fromROSMsg calls would be to make use of PCL's built-in functions found here. For example, the pcl::PointCloud<pcl::PointXYZ> type allows you to add two point clouds together. When I do heavy Point Cloud work, I wait for a sensor_msgs::PointCloud2 callback, convert it to pcl::PointCloud<pcl::PointXYZ>, and then do all of my processing on that datatype, just because I like to use PCL functions.

In your above code, to use PointCloud2, all you need to change is the following line:

From:

sensor_msgs::PointCloud cloud;

To:

sensor_msgs::PointCloud2 cloud;

And viola! It works.