Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pcd_viewer color handling when invalid fields are present in pcd #2105

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2980,10 +2980,10 @@ pcl::visualization::PCLVisualizer::updateColorHandlerIndex (const std::string &i
return (false);
}

int color_handler_size = int (am_it->second.color_handlers.size ());
if (index >= color_handler_size)
size_t color_handler_size = am_it->second.color_handlers.size ();
if (!(size_t (index) < color_handler_size))
{
pcl::console::print_warn (stderr, "[updateColorHandlerIndex] Invalid index <%d> given! Maximum range is: 0-%lu.\n", index, static_cast<unsigned long> (am_it->second.color_handlers.size ()));
pcl::console::print_warn (stderr, "[updateColorHandlerIndex] Invalid index <%d> given! Index must be less than %d.\n", index, int (color_handler_size));
return (false);
}
// Get the handler
Expand Down
12 changes: 8 additions & 4 deletions visualization/tools/pcd_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,22 +617,26 @@ main (int argc, char** argv)
{
int rgb_idx = 0;
int label_idx = 0;
int invalid_fields_count = 0;
for (size_t f = 0; f < cloud->fields.size (); ++f)
{
if (!isValidFieldName (cloud->fields[f].name))
{
++invalid_fields_count;
continue;
}
if (cloud->fields[f].name == "rgb" || cloud->fields[f].name == "rgba")
{
rgb_idx = f + 1;
rgb_idx = f - invalid_fields_count + 1 /* first is ColorHandlerRandom */;
color_handler.reset (new pcl::visualization::PointCloudColorHandlerRGBField<pcl::PCLPointCloud2> (cloud));
}
else if (cloud->fields[f].name == "label")
{
label_idx = f + 1;
label_idx = f - invalid_fields_count + 1;
color_handler.reset (new pcl::visualization::PointCloudColorHandlerLabelField<pcl::PCLPointCloud2> (cloud, !use_optimal_l_colors));
}
else
{
if (!isValidFieldName (cloud->fields[f].name))
continue;
color_handler.reset (new pcl::visualization::PointCloudColorHandlerGenericField<pcl::PCLPointCloud2> (cloud, cloud->fields[f].name));
}
// Add the cloud to the renderer
Expand Down