common_interfaces
common_interfaces copied to clipboard
PointCloud2Modifier::setPointCloud2FieldsByString does not support intensity
Bug report
Required Info:
- Operating System:
- Ubuntu 22.04
- Installation type:
- apt
- Version or commit hash:
- c0c0bc57f958eb54a142446f0c2a475754367eee
- DDS implementation:
- CycloneDDS
- Client library (if applicable):
- rclcpp
Steps to reproduce issue
sensor_msgs::msg::PointCloud2::SharedPtr pcl(new sensor_msgs::msg::PointCloud2);
sensor_msgs::PointCloud2Modifier modifier(*pcl);
modifier.setPointCloud2FieldsByString(2, "xyz", "intensity");
Expected behavior
Intensity field is created with correct datatype as expected.
Actual behavior
The code crashes with a runtime error.
[deskew_node-1] terminate called after throwing an instance of 'std::runtime_error'
[deskew_node-1] what(): Field intensity does not exist
Additional information
The intensity field is claimed to be supported here: https://github.com/ros2/common_interfaces/blob/c0c0bc57f958eb54a142446f0c2a475754367eee/sensor_msgs/msg/PointField.msg#L12
Yet it is not implemented here: https://github.com/ros2/common_interfaces/blob/c0c0bc57f958eb54a142446f0c2a475754367eee/sensor_msgs/include/sensor_msgs/impl/point_cloud2_iterator.hpp#L195
Was there a reason for not including the intensity field?
In the meantime, I think I can work around this as follows:
modifier.setPointCloud2Fields(
4, // Number of fields
"x", 1, sensor_msgs::msg::PointField::FLOAT32, // x field
"y", 1, sensor_msgs::msg::PointField::FLOAT32, // y field
"z", 1, sensor_msgs::msg::PointField::FLOAT32, // z field
"intensity", 1, sensor_msgs::msg::PointField::FLOAT32 // intensity field
);
Thank you for your time.