From 77a03dc32702427fb3547668c55f9b8533f59b32 Mon Sep 17 00:00:00 2001 From: Markus Vieth Date: Sat, 7 Dec 2024 14:11:43 +0100 Subject: [PATCH] Add checks in point cloud handler for correct types See https://github.com/PointCloudLibrary/pcl/issues/6186 --- .../impl/point_cloud_color_handlers.hpp | 12 +++++++++--- visualization/src/point_cloud_handlers.cpp | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/visualization/include/pcl/visualization/impl/point_cloud_color_handlers.hpp b/visualization/include/pcl/visualization/impl/point_cloud_color_handlers.hpp index 7441dd8a4a9..4e5aa57b5c4 100644 --- a/visualization/include/pcl/visualization/impl/point_cloud_color_handlers.hpp +++ b/visualization/include/pcl/visualization/impl/point_cloud_color_handlers.hpp @@ -368,10 +368,16 @@ PointCloudColorHandlerGenericField::setInputCloud ( { PointCloudColorHandler::setInputCloud (cloud); field_idx_ = pcl::getFieldIndex (field_name_, fields_); - if (field_idx_ != -1) - capable_ = true; - else + if (field_idx_ == -1) { capable_ = false; + return; + } + if (fields_[field_idx_].datatype != pcl::PCLPointField::PointFieldTypes::FLOAT32) { + capable_ = false; + PCL_ERROR("[pcl::PointCloudColorHandlerGenericField::setInputCloud] This currently only works with float32 fields, but field %s has a different type.\n", field_name_.c_str()); + return; + } + capable_ = true; } diff --git a/visualization/src/point_cloud_handlers.cpp b/visualization/src/point_cloud_handlers.cpp index 4b70dd9ec17..00dedb9b5ae 100644 --- a/visualization/src/point_cloud_handlers.cpp +++ b/visualization/src/point_cloud_handlers.cpp @@ -420,6 +420,10 @@ pcl::visualization::PointCloudColorHandlerGenericField::Poi { field_idx_ = pcl::getFieldIndex (*cloud, field_name); capable_ = field_idx_ != -1; + if (field_idx_ != -1 && cloud_->fields[field_idx_].datatype != pcl::PCLPointField::PointFieldTypes::FLOAT32) { + capable_ = false; + PCL_ERROR("[pcl::PointCloudColorHandlerGenericField] This currently only works with float32 fields, but field %s has a different type.\n", field_name.c_str()); + } } /////////////////////////////////////////////////////////////////////////////////////////// @@ -575,6 +579,10 @@ pcl::visualization::PointCloudColorHandlerLabelField::Point field_idx_ = pcl::getFieldIndex (*cloud, "label"); capable_ = field_idx_ != -1; static_mapping_ = static_mapping; + if (field_idx_ != -1 && cloud_->fields[field_idx_].datatype != pcl::PCLPointField::PointFieldTypes::UINT32) { + capable_ = false; + PCL_ERROR("[pcl::PointCloudColorHandlerLabelField] This currently only works with uint32 fields, but label field has a different type.\n"); + } } ///////////////////////////////////////////////////////////////////////////////////////////