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

How to convert between different point cloud types using PCL?

asked 2011-03-21 22:51:16 -0600

Julius gravatar image

updated 2011-03-21 22:51:49 -0600

I wonder whether there is an elegant way to convert instances of pcl::PointCloud<pcl::PointXYZ> to pcl::PointCloud<pcl::PointXYZRGB>and vice-versa?

I am trying to load point cloud data from a .pcd-file that only includes XYZ data. Finally, I want to feed this point cloud into a module that requires PointXYZRGB data (but actually does not use the RGB data).

My current solution is to call pcd::io::loadPCDFile in order to populate pcl::PointCloud<pcl::PointXYZ> and then just copy points over one-by-one to a XYZRGB point cloud. Note that I am relatively new to C++ programming and might have overseen an obvious solution.

(I am using diamondback)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-06-05 07:40:54 -0600

Julius gravatar image

In the meantime, I found the effective (and simple) solution

PointCloud<PointXYZ> cloud_xyz;
// [...]
PointCloud<PointXYZRGB> cloud_xyzrgb;
copyPointCloud(cloud_xyz, cloud_xyzrgb);

a quick diff on serialized files showed this to be equivalent to

for (size_t i = 0; i < cloud_xyz.points.size(); i++) {
    cloud_xyzrgb.points[i].x = cloud_xyz.points[i].x;
    cloud_xyzrgb.points[i].y = cloud_xyz.points[i].y;
    cloud_xyzrgb.points[i].z = cloud_xyz.points[i].z;

See API documentation.

edit flag offensive delete link more

answered 2011-05-03 09:49:17 -0600

Julius gravatar image

Just saw this showing up on the PCL mailing list by chance. Radu B. Rusu "You need to copy the data manually for now between the two types. [...] Improving this is on the top of our list for PCL 2.x."

edit flag offensive delete link more

Question Tools



Asked: 2011-03-21 22:51:16 -0600

Seen: 43,720 times

Last updated: Jun 05 '11