From 417aca2349696e09215d429da4c5b7aceab01984 Mon Sep 17 00:00:00 2001 From: xmc <1802974410@qq.com> Date: Mon, 17 Aug 2026 10:17:00 +0800 Subject: [PATCH] [sensor_msgs] Fix row_step when resizing organized PointCloud2 Signed-off-by: xmc <1802974410@qq.com> --- .../include/sensor_msgs/impl/point_cloud2_iterator.hpp | 1 + sensor_msgs/test/test_pointcloud_iterator.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sensor_msgs/include/sensor_msgs/impl/point_cloud2_iterator.hpp b/sensor_msgs/include/sensor_msgs/impl/point_cloud2_iterator.hpp index 418aa842..84f97453 100644 --- a/sensor_msgs/include/sensor_msgs/impl/point_cloud2_iterator.hpp +++ b/sensor_msgs/include/sensor_msgs/impl/point_cloud2_iterator.hpp @@ -153,6 +153,7 @@ inline void PointCloud2Modifier::resize(uint32_t width, uint32_t height) cloud_msg_.width = width; cloud_msg_.height = height; + cloud_msg_.row_step = cloud_msg_.width * cloud_msg_.point_step; } inline void PointCloud2Modifier::clear() diff --git a/sensor_msgs/test/test_pointcloud_iterator.cpp b/sensor_msgs/test/test_pointcloud_iterator.cpp index 91ea92dc..5fe64ce9 100644 --- a/sensor_msgs/test/test_pointcloud_iterator.cpp +++ b/sensor_msgs/test/test_pointcloud_iterator.cpp @@ -167,8 +167,9 @@ TEST(sensor_msgs, PointCloud2Resize) EXPECT_EQ(static_cast(10), cloud_msg_3.width); EXPECT_EQ(static_cast(1), cloud_msg_3.height); EXPECT_EQ(static_cast(320), cloud_msg_3.row_step); - modifier3.resize(static_cast(11), static_cast(11)); + modifier3.resize(static_cast(11), static_cast(7)); EXPECT_EQ(static_cast(11), cloud_msg_3.width); - EXPECT_EQ(static_cast(11), cloud_msg_3.height); - EXPECT_EQ(static_cast(3872), cloud_msg_3.row_step); + EXPECT_EQ(static_cast(7), cloud_msg_3.height); + EXPECT_EQ(static_cast(11 * cloud_msg_3.point_step), cloud_msg_3.row_step); + EXPECT_EQ(static_cast(11 * 7 * cloud_msg_3.point_step), cloud_msg_3.data.size()); }