Skip to content

Commit

Permalink
Add checks in point cloud handler for correct types
Browse files Browse the repository at this point in the history
See #6186
  • Loading branch information
mvieth committed Dec 9, 2024
1 parent 59fda2d commit 77a03dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,16 @@ PointCloudColorHandlerGenericField<PointT>::setInputCloud (
{
PointCloudColorHandler<PointT>::setInputCloud (cloud);
field_idx_ = pcl::getFieldIndex<PointT> (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;
}


Expand Down
8 changes: 8 additions & 0 deletions visualization/src/point_cloud_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ pcl::visualization::PointCloudColorHandlerGenericField<pcl::PCLPointCloud2>::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());
}
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -575,6 +579,10 @@ pcl::visualization::PointCloudColorHandlerLabelField<pcl::PCLPointCloud2>::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");
}
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 77a03dc

Please sign in to comment.