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

PointCloud2 for laser_geometry

asked 2011-12-28 20:59:08 -0500

alfa_80 gravatar image

I am using a code snippet from laser_geometry tutorial. I've tried to use this code using PointCloud type (instead of PointCloud2), but it doesn't work.

laser_geometry::LaserProjection projector_;
tf::TransformListener listener_;

void scanCallback (const sensor_msgs::LaserScan::ConstPtr& scan_in)
  sensor_msgs::PointCloud cloud;

  // Do something with cloud.

How does the signature of the line,


look like if I would use it with PointCloud2 data type?

Another question, what is the benefit of using PointCloud2 as opposed to PointCloud?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-12-29 01:08:49 -0500

DimitriProsser gravatar image

updated 2011-12-29 01:40:06 -0500

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.

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:


sensor_msgs::PointCloud cloud;


sensor_msgs::PointCloud2 cloud;

And viola! It works.

edit flag offensive delete link more


I got your fix that i just need to change the data type from sensor_msgs::PointCloud to sensor_msgs::PointCloud2, however, when should I use pcl::fromROSMsg and pcl::toROSMsg function calls? Is it implicitly done for us?
alfa_80 gravatar image alfa_80  ( 2011-12-29 01:32:48 -0500 )edit
Thanks a lot for the clear explanation.
alfa_80 gravatar image alfa_80  ( 2011-12-29 02:18:05 -0500 )edit

Question Tools


Asked: 2011-12-28 20:59:08 -0500

Seen: 1,327 times

Last updated: Dec 29 '11