diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index 7b8d3d3b38e..97be7bc14aa 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -1200,7 +1200,19 @@ namespace pcl setShapeRenderingProperties (int property, double value, const std::string &id, int viewport = 0); - /** \brief Set the rendering properties of a shape (3x values - e.g., RGB) + /** \brief Set the rendering properties of a shape (2x values - e.g., LUT minmax values) + * \param[in] property the property type + * \param[in] val1 the first value to be set + * \param[in] val2 the second value to be set + * \param[in] id the shape object id + * \param[in] viewport the view port where the shape's properties should be modified (default: all) + * \note When using \ref addPolygonMesh you you should use \ref setPointCloudRenderingProperties + */ + bool + setShapeRenderingProperties (int property, double val1, double val2, + const std::string &id, int viewport = 0); + + /** \brief Set the rendering properties of a shape (3x values - e.g., RGB) * \param[in] property the property type * \param[in] val1 the first value to be set * \param[in] val2 the second value to be set diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 7c84b7543ee..d4296ea5a67 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -1609,6 +1609,58 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties ( return (true); } +///////////////////////////////////////////////////////////////////////////////////////////// +bool +pcl::visualization::PCLVisualizer::setShapeRenderingProperties ( + int property, double val1, double val2, const std::string &id, int) +{ + // Check to see if this ID entry already exists (has it been already added to the visualizer?) + ShapeActorMap::iterator am_it = shape_actor_map_->find (id); + + if (am_it == shape_actor_map_->end ()) + { + pcl::console::print_error ("[setShapeRenderingProperties] Could not find any shape with id <%s>!\n", id.c_str ()); + return (false); + } + // Get the actor pointer + vtkActor* actor = vtkActor::SafeDownCast (am_it->second); + if (!actor) + return (false); + + switch (property) + { + case PCL_VISUALIZER_LUT_RANGE: + { + // Check if the mapper has scalars + if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()) + break; + + // Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default) + if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray")) + break; + + // Check that range values are correct + if (val1 >= val2) + { + PCL_WARN ("[setShapeRenderingProperties] Range max must be greater than range min!\n"); + return (false); + } + + // Update LUT + actor->GetMapper ()->GetLookupTable ()->SetRange (val1, val2); + actor->GetMapper()->UseLookupTableScalarRangeOn (); + style_->updateLookUpTableDisplay (false); + break; + } + default: + { + pcl::console::print_error ("[setShapeRenderingProperties] Unknown property (%d) specified!\n", property); + return (false); + } + } + return (true); +} + ///////////////////////////////////////////////////////////////////////////////////////////// bool pcl::visualization::PCLVisualizer::setShapeRenderingProperties ( @@ -1733,17 +1785,45 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties ( if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()) break; - double range[2]; - actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->GetRange (range); + // Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default) + if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray")) + break; + + // Get range limits from existing LUT + double *range; + range = actor->GetMapper ()->GetLookupTable ()->GetRange (); + actor->GetMapper ()->ScalarVisibilityOn (); actor->GetMapper ()->SetScalarRange (range[0], range[1]); - vtkSmartPointer table = vtkSmartPointer::New (); - getColormapLUT (static_cast(static_cast(value)), table); + vtkSmartPointer table; + if (!pcl::visualization::getColormapLUT (static_cast(static_cast(value)), table)) + break; table->SetRange (range[0], range[1]); actor->GetMapper ()->SetLookupTable (table); style_->updateLookUpTableDisplay (false); - break; } + case PCL_VISUALIZER_LUT_RANGE: + { + // Check if the mapper has scalars + if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()) + break; + + // Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default) + if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray")) + break; + + switch (int(value)) + { + case PCL_VISUALIZER_LUT_RANGE_AUTO: + double range[2]; + actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->GetRange (range); + actor->GetMapper ()->GetLookupTable ()->SetRange (range[0], range[1]); + actor->GetMapper ()->UseLookupTableScalarRangeOn (); + style_->updateLookUpTableDisplay (false); + break; + } + break; + } default: { pcl::console::print_error ("[setShapeRenderingProperties] Unknown property (%d) specified!\n", property);