Skip to content

Commit

Permalink
pcd_viewer: fix color handling when there are invalid fields
Browse files Browse the repository at this point in the history
* invalid fields needs to be skipped otherwise ColorHandler indexes will overflow
  • Loading branch information
hrnr committed Nov 30, 2017
1 parent d398555 commit 30f29c1
Showing 1 changed file with 8 additions and 4 deletions.
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

0 comments on commit 30f29c1

Please sign in to comment.