diff --git a/src/k4a_ros_device.cpp b/src/k4a_ros_device.cpp index 8a38b50d..5e886431 100644 --- a/src/k4a_ros_device.cpp +++ b/src/k4a_ros_device.cpp @@ -671,8 +671,6 @@ k4a_result_t K4AROSDevice::getPointCloud(const k4a::capture& capture, sensor_msg k4a_result_t K4AROSDevice::fillColorPointCloud(const k4a::image& pointcloud_image, const k4a::image& color_image, sensor_msgs::PointCloud2Ptr& point_cloud) { - point_cloud->height = pointcloud_image.get_height_pixels(); - point_cloud->width = pointcloud_image.get_width_pixels(); point_cloud->is_dense = false; point_cloud->is_bigendian = false; @@ -687,6 +685,11 @@ k4a_result_t K4AROSDevice::fillColorPointCloud(const k4a::image& pointcloud_imag sensor_msgs::PointCloud2Modifier pcd_modifier(*point_cloud); pcd_modifier.setPointCloud2FieldsByString(2, "xyz", "rgb"); + point_cloud->height = pointcloud_image.get_height_pixels(); + point_cloud->width = pointcloud_image.get_width_pixels(); + point_cloud->row_step = pointcloud_image.get_width_pixels() * point_cloud->point_step; + point_cloud->data.resize(point_cloud->height * point_cloud->width * point_cloud->point_step); + sensor_msgs::PointCloud2Iterator iter_x(*point_cloud, "x"); sensor_msgs::PointCloud2Iterator iter_y(*point_cloud, "y"); sensor_msgs::PointCloud2Iterator iter_z(*point_cloud, "z"); @@ -695,8 +698,6 @@ k4a_result_t K4AROSDevice::fillColorPointCloud(const k4a::image& pointcloud_imag sensor_msgs::PointCloud2Iterator iter_g(*point_cloud, "g"); sensor_msgs::PointCloud2Iterator iter_b(*point_cloud, "b"); - pcd_modifier.resize(point_count); - const int16_t* point_cloud_buffer = reinterpret_cast(pointcloud_image.get_buffer()); const uint8_t* color_buffer = color_image.get_buffer(); @@ -729,8 +730,6 @@ k4a_result_t K4AROSDevice::fillColorPointCloud(const k4a::image& pointcloud_imag k4a_result_t K4AROSDevice::fillPointCloud(const k4a::image& pointcloud_image, sensor_msgs::PointCloud2Ptr& point_cloud) { - point_cloud->height = pointcloud_image.get_height_pixels(); - point_cloud->width = pointcloud_image.get_width_pixels(); point_cloud->is_dense = false; point_cloud->is_bigendian = false; @@ -739,12 +738,15 @@ k4a_result_t K4AROSDevice::fillPointCloud(const k4a::image& pointcloud_image, se sensor_msgs::PointCloud2Modifier pcd_modifier(*point_cloud); pcd_modifier.setPointCloud2FieldsByString(1, "xyz"); + point_cloud->height = pointcloud_image.get_height_pixels(); + point_cloud->width = pointcloud_image.get_width_pixels(); + point_cloud->row_step = pointcloud_image.get_width_pixels() * point_cloud->point_step; + point_cloud->data.resize(point_cloud->height * point_cloud->width * point_cloud->point_step); + sensor_msgs::PointCloud2Iterator iter_x(*point_cloud, "x"); sensor_msgs::PointCloud2Iterator iter_y(*point_cloud, "y"); sensor_msgs::PointCloud2Iterator iter_z(*point_cloud, "z"); - pcd_modifier.resize(point_count); - const int16_t* point_cloud_buffer = reinterpret_cast(pointcloud_image.get_buffer()); for (size_t i = 0; i < point_count; i++, ++iter_x, ++iter_y, ++iter_z)