0
$\begingroup$

Rosanswers logo

I have a sensor_msg::PointCloud2 with the following fields/channels: x, y, z, intensity, ring, time. However, I need a copy of this cloud containing only the x, y, z data.

Erasing the fields from the sensor_msgs::PointField does not suffice, as far as I understood these are only the "labels" for the data and erasing them won't change the size of the point cloud. Thus, I need to erase the data points themselves.

What would be the best way to achieve this? Is there even a function like pcl::removeField() that I failed to see?


Originally posted by labude on ROS Answers with karma: 98 on 2022-08-18

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

In case someone finds this useful, here is how I solved it:

Convert the sensor msg to a PointCloud, this removes all fields except xyz, then convert back to a sensor msg.

An example:

  sensor_msgs::PointCloud2 msg; // contains x,y,z and other fields such as intensity
  pcl::PointCloud<pcl::PointXYZ> tmp;
  pcl::fromROSMsg( msg, tmp );
  // Here you could perform operations on the point cloud
  pcl::toROSMsg( tmp, msg );

Originally posted by labude with karma: 98 on 2022-08-19

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.