ros / common_msgs

Commonly used messages in ROS. Includes messages for actions (actionlib_msgs), diagnostics (diagnostic_msgs), geometric primitives (geometry_msgs), robot navigation (nav_msgs), and common sensors (sensor_msgs), such as laser range finders, cameras, point clouds.
http://wiki.ros.org/common_msgs
179 stars 191 forks source link

sensor_msgs: Generate optimal msg lentgth when both "xyz" and "rgb(a)… #77

Open tmoinel opened 9 years ago

tmoinel commented 9 years ago

…" are given to PointCloud2Modifier.

With this patch PointCloud2Modifier::setPointCloud2FieldsByString make PointCloud2 message with an optimal length by removing unnecessary trailling offset without messing with the padding. It cut in half the msg length.

When we used something like in https://github.com/ros-perception/image_pipeline/blob/indigo/depth_image_proc/src/nodelets/point_cloud_xyzrgb.cpp#L251

     sensor_msgs::PointCloud2Modifier pcd_modifier(*cloud_msg);
     pcd_modifier.setPointCloud2FieldsByString(2, "xyz", "rgb"); 

By exemple, with kinect images the cloud msg length was 9.83MB. Now it's 4.92MB, like with just the xyz part.

Since it's a core library every project that depends on it should be recompiled.

tfoote commented 9 years ago

@vrabaud can you review?

vrabaud commented 9 years ago

ok, totally agreed in principle (and that was the next step for this PointCloud2 iterator) BUT, by doing your optimization, that would break the PCL converters. Those paddings were added by PCL for having the data-structure memory-aligned, but by consequence, it got the messages to be memory aligned and therefore too big.

There are 3 ways to read PointCloud2:

The idea is to have everybody use the iterator so that we can optimize the size. So the next step, is to have the PCL converters use the iterator but it would require some heavy macro work to get get it to work with any point type.

tmoinel commented 9 years ago

Sorry for the waiting I was in holidays.

ok, I made some test and dig into PCL conversions:

If everybody follow the field description there will not be any problems to read. This is, I guess, why PointCloud2 was created for otherwise we would use the old PointCloud.

I also find a little inconsistency in https://github.com/ros/common_msgs/blob/jade-devel/sensor_msgs/include/sensor_msgs/impl/point_cloud2_iterator.h#L216 rgba must be type of uint32 (datatype=6) and not float32 (datatype=7) according to https://github.com/PointCloudLibrary/pcl/blob/master/common/include/pcl/point_types.h#L683 fix by https://github.com/ThomasMoinel/common_msgs/commit/d4778fb06814e550fb51ba5243446d4dc063177f I can push a fix on a separate pull request if you prefer.

vrabaud commented 9 years ago

For RGBA, please make a pull request quoting: https://github.com/PointCloudLibrary/pcl/blob/master/common/include/pcl/point_types.h#L108 Thx

vrabaud commented 9 years ago

Forget about my previous comment but please add the commit you mention as a comment so that we keep track of it.

So two things:

vrabaud commented 8 years ago

@ThomasMoinel , any input on my questions ? Thx

peci1 commented 2 years ago

There is also a relevant effort going on in PCL: https://github.com/PointCloudLibrary/pcl/issues/4939.