diff --git a/visualization/include/pcl/visualization/common/common.h b/visualization/include/pcl/visualization/common/common.h index 5d1922971f0..4b6bd405ed0 100644 --- a/visualization/include/pcl/visualization/common/common.h +++ b/visualization/include/pcl/visualization/common/common.h @@ -100,7 +100,8 @@ namespace pcl PCL_VISUALIZER_COLOR, PCL_VISUALIZER_REPRESENTATION, PCL_VISUALIZER_IMMEDIATE_RENDERING, - PCL_VISUALIZER_SHADING + PCL_VISUALIZER_SHADING, + PCL_VISUALIZER_LUT }; enum RenderingRepresentationProperties @@ -117,6 +118,17 @@ namespace pcl PCL_VISUALIZER_SHADING_PHONG }; + /*! Look up table for color representation of vtkPolyDataMapper.\n + * See [mathworks colormap page](http://www.mathworks.com/help/matlab/ref/colormap.html#input_argument_name) for images representations of the LUTs */ + enum LookUpTableRepresentationProperties + { // + PCL_VISUALIZER_LUT_JET, + PCL_VISUALIZER_LUT_JET_INVERSE, + PCL_VISUALIZER_LUT_HSV, + PCL_VISUALIZER_LUT_HSV_INVERSE, + PCL_VISUALIZER_LUT_GREY + }; + ////////////////////////////////////////////////////////////////////////////////////////////// /** \brief Camera class holds a set of camera parameters together with the window pos/size. */ class PCL_EXPORTS Camera diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index b60dc646c5c..baf70a209b7 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -1403,6 +1403,18 @@ namespace pcl const std::string &id = "PolyData", int viewport = 0); + /** \brief Add a vtkPolyDataMapper as a mesh + * \param[in] polydatamapper vtkPolyDataMapper + * \param[in] id the model id/name (default: "PolyDataMapper") + * \param[in] viewport (optional) the id of the new viewport (default: 0) + * \return True if successful, false otherwise + * \note This allows to display a colored mesh, also see \ref PCL_VISUALIZER_LUT. + */ + bool + addModelFromPolyData (vtkSmartPointer polydatamapper, + const std::string & id = "PolyDataMapper", + int viewport = 0); + /** \brief Add a PLYmodel as a mesh * \param[in] filename of the ply file * \param[in] id the model id/name (default: "PLYModel") diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index d869ee19cd7..52d80e4740c 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -91,6 +91,7 @@ #include #include #include +#include #include #include @@ -1575,6 +1576,52 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties ( actor->Modified (); break; } + case PCL_VISUALIZER_LUT: + { + // Check if the mapper has scalars + if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()) + break; + + double range[2]; + actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->GetRange (range); + actor->GetMapper ()->ScalarVisibilityOn (); + actor->GetMapper ()->SetScalarRange (range[0], range[1]); + vtkSmartPointer table = vtkSmartPointer::New (); + table->SetRange (range[0], range[1]); + + switch (int (value)) + { + case PCL_VISUALIZER_LUT_JET: + table->SetHueRange (0, 0.667); + table->SetSaturationRange (1, 1); + table->SetAlphaRange (1, 1); + break; + case PCL_VISUALIZER_LUT_JET_INVERSE: + table->SetHueRange (0.667, 0); + table->SetSaturationRange (1, 1); + table->SetAlphaRange (1, 1); + break; + case PCL_VISUALIZER_LUT_HSV: + table->SetHueRange (0, 1); + table->SetSaturationRange (1, 1); + table->SetAlphaRange (1, 1); + break; + case PCL_VISUALIZER_LUT_HSV_INVERSE: + table->SetHueRange (1, 0); + table->SetSaturationRange (1, 1); + table->SetAlphaRange (1, 1); + break; + case PCL_VISUALIZER_LUT_GREY: + table->SetValueRange (0, 1); + table->SetHueRange (0, 0); + table->SetSaturationRange (0, 0); + table->SetAlphaRange (1, 1); + break; + } + table->Build (); + actor->GetMapper ()->SetLookupTable (table); + break; + } default: { pcl::console::print_error ("[setShapeRenderingProperties] Unknown property (%d) specified!\n", property); @@ -2194,6 +2241,37 @@ pcl::visualization::PCLVisualizer::addModelFromPolyData ( return (true); } +//////////////////////////////////////////////////////////////////////////////////////////// +bool +pcl::visualization::PCLVisualizer::addModelFromPolyData (vtkSmartPointer polydatamapper, + const std::string & id, + int viewport) +{ + if (contains (id)) + { + pcl::console::print_warn (stderr, + "[addModelFromPolyData] A shape with id <%s> already exists! Please choose a different id and retry.\n", + id.c_str ()); + return (false); + } + + // Check if mesh has color information + if (polydatamapper->GetInput ()->GetPointData ()->GetScalars ()) + { + double range[2]; + polydatamapper->GetInput ()->GetPointData ()->GetScalars ()->GetRange (range); + polydatamapper->ScalarVisibilityOn (); + polydatamapper->SetScalarRange (range[0], range[1]); + } + + vtkSmartPointer actor = vtkSmartPointer::New (); + actor->SetMapper (polydatamapper); + addActorToRenderer (actor, viewport); + + // Save the pointer/ID pair to the global actor map + (*shape_actor_map_)[id] = actor; + return (true); +} //////////////////////////////////////////////////////////////////////////////////////////// bool