Skip to content

Commit fc24cef

Browse files
committed
Allow changing the range of the LUT used to visualize a cloud
1 parent 33a5f24 commit fc24cef

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

visualization/include/pcl/visualization/common/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace pcl
105105
PCL_VISUALIZER_IMMEDIATE_RENDERING,
106106
PCL_VISUALIZER_SHADING,
107107
PCL_VISUALIZER_LUT, /**< colormap type \ref pcl::visualization::LookUpTableRepresentationProperties */
108+
PCL_VISUALIZER_LUT_RANGE /**< two doubles (min and max) or \ref pcl::visualization::LookUpTableRepresentationProperties::PCL_VISUALIZER_LUT_RANGE_AUTO */
108109
};
109110

110111
enum RenderingRepresentationProperties
@@ -130,6 +131,7 @@ namespace pcl
130131
PCL_VISUALIZER_LUT_HSV_INVERSE, /**< Inverse HSV colormap */
131132
PCL_VISUALIZER_LUT_GREY, /**< Grey colormap (black to white) */
132133
PCL_VISUALIZER_LUT_BLUE2RED, /**< Blue to red colormap (blue to white to red) */
134+
PCL_VISUALIZER_LUT_RANGE_AUTO /**< Set LUT range to min and max values of the data */
133135
};
134136

135137
/** \brief Generate a lookup table for a colormap.

visualization/include/pcl/visualization/pcl_visualizer.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,18 @@ namespace pcl
11481148
setPointCloudRenderingProperties (int property, double val1, double val2, double val3,
11491149
const std::string &id = "cloud", int viewport = 0);
11501150

1151+
/** \brief Set the rendering properties of a PointCloud (2x values - e.g., LUT minmax values)
1152+
* \param[in] property the property type
1153+
* \param[in] val1 the first value to be set
1154+
* \param[in] val2 the second value to be set
1155+
* \param[in] id the point cloud object id (default: cloud)
1156+
* \param[in] viewport the view port where the Point Cloud's rendering properties should be modified (default: all)
1157+
* \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
1158+
*/
1159+
bool
1160+
setPointCloudRenderingProperties (int property, double val1, double val2,
1161+
const std::string &id = "cloud", int viewport = 0);
1162+
11511163
/** \brief Set the rendering properties of a PointCloud
11521164
* \param[in] property the property type
11531165
* \param[in] value the value to be set

visualization/src/pcl_visualizer.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,58 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties (
13311331
return (true);
13321332
}
13331333

1334+
/////////////////////////////////////////////////////////////////////////////////////////////
1335+
bool
1336+
pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties (
1337+
int property, double val1, double val2, const std::string &id, int)
1338+
{
1339+
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
1340+
CloudActorMap::iterator am_it = cloud_actor_map_->find (id);
1341+
1342+
if (am_it == cloud_actor_map_->end ())
1343+
{
1344+
pcl::console::print_error ("[setPointCloudRenderingProperties] Could not find any PointCloud datasets with id <%s>!\n", id.c_str ());
1345+
return (false);
1346+
}
1347+
// Get the actor pointer
1348+
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor);
1349+
if (!actor)
1350+
return (false);
1351+
1352+
switch (property)
1353+
{
1354+
case PCL_VISUALIZER_LUT_RANGE:
1355+
{
1356+
// Check if the mapper has scalars
1357+
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ())
1358+
break;
1359+
1360+
// Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default)
1361+
if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars () ->IsA("vtkUnsignedCharArray"))
1362+
break;
1363+
1364+
// Check that range values are correct
1365+
if (val1 >= val2)
1366+
{
1367+
PCL_WARN ("[setShapeRenderingProperties] Range max must be greater than range min!\n");
1368+
return (false);
1369+
}
1370+
1371+
// Update LUT
1372+
actor->GetMapper ()->GetLookupTable ()->SetRange (val1, val2);
1373+
actor->GetMapper()->UseLookupTableScalarRangeOn();
1374+
style_->updateLookUpTableDisplay (false);
1375+
break;
1376+
}
1377+
default:
1378+
{
1379+
pcl::console::print_error ("[setPointCloudRenderingProperties] Unknown property (%d) specified!\n", property);
1380+
return (false);
1381+
}
1382+
}
1383+
return (true);
1384+
}
1385+
13341386
/////////////////////////////////////////////////////////////////////////////////////////////
13351387
bool
13361388
pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (int property, double &value, const std::string &id)
@@ -1447,6 +1499,28 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties (
14471499
style_->updateLookUpTableDisplay (false);
14481500
break;
14491501
}
1502+
case PCL_VISUALIZER_LUT_RANGE:
1503+
{
1504+
// Check if the mapper has scalars
1505+
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ())
1506+
break;
1507+
1508+
// Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default)
1509+
if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars () ->IsA("vtkUnsignedCharArray"))
1510+
break;
1511+
1512+
switch (int(value))
1513+
{
1514+
case PCL_VISUALIZER_LUT_RANGE_AUTO:
1515+
double range[2];
1516+
actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->GetRange (range);
1517+
actor->GetMapper ()->GetLookupTable ()->SetRange (range[0], range[1]);
1518+
actor->GetMapper()->UseLookupTableScalarRangeOn();
1519+
style_->updateLookUpTableDisplay (false);
1520+
break;
1521+
}
1522+
break;
1523+
}
14501524
default:
14511525
{
14521526
pcl::console::print_error ("[setPointCloudRenderingProperties] Unknown property (%d) specified!\n", property);

0 commit comments

Comments
 (0)