Random Access for Points in sensor_msgs::PointCloud2 ?

asked 2019-11-11 03:44:08 -0600

moooeeeep gravatar image

It seems the only way to access points in a sensor_msgs::PointCloud2 is sequential iteration via sensor_msgs::PointCloud2ConstIterator. I couldn't find an API to access the point data fields at a random index.

As we know the dimensions and the row_step and point_step from the message content, it should be possible to calculate the actual offset for each point via pointer arithmetic. Is there a ready to use API that can be used to do this?

Or is this really impractical, e.g., because the added pointer arithmetics outweigh copying (parts of) the pointcloud into a more convenient data structure?

edit retag flag offensive close merge delete

Comments

1

I believe the reason for why you cannot find a way to access individual elements in a sensor_msgs/PointCloud2message is that you're not supposed to do that.

Accepted workflow would be to convert the message into a regular pcl::PointCloud using pcl::fromROSMsg (note, this is a method from pcl_conversions, not PCL itself directly) and then use regular PCL API to work with that data structure (instead of the message itself).

See also wiki/pcl/Overview, specifically the section about Point Cloud conversion.

Having written that, there is some support for working with sensor_msgs/PointCloud2 directly. See #q11556 for some info on that ( @peci1's answer).

gvdhoorn gravatar imagegvdhoorn ( 2019-11-11 03:59:13 -0600 )edit

+1 for @gvdhoorn's answer. I think that should be an answer to mark as correct.

stevemacenski gravatar imagestevemacenski ( 2019-11-11 11:04:27 -0600 )edit