Random Access for Points in sensor_msgs::PointCloud2 ?
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?
Asked by moooeeeep on 2019-11-11 04:44:08 UTC
Comments
I believe the reason for why you cannot find a way to access individual elements in a
sensor_msgs/PointCloud2
message 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 frompcl_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).Asked by gvdhoorn on 2019-11-11 04:59:13 UTC
+1 for @gvdhoorn's answer. I think that should be an answer to mark as correct.
Asked by stevemacenski on 2019-11-11 12:04:27 UTC