Skip to content

Commit

Permalink
Merge pull request #1143 from VictorLamoine/vtk_PolyDataMapper
Browse files Browse the repository at this point in the history
New variant of addModelFromPolyData
  • Loading branch information
jspricke committed May 17, 2015
2 parents 0ffe5df + 1c6f92c commit 085e13a
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
14 changes: 13 additions & 1 deletion visualization/include/pcl/visualization/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions visualization/include/pcl/visualization/pcl_visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<vtkPolyDataMapper> 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")
Expand Down
78 changes: 78 additions & 0 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#include <vtkPNMReader.h>
#include <vtkPNGReader.h>
#include <vtkTIFFReader.h>
#include <vtkLookupTable.h>

#include <pcl/visualization/common/shapes.h>
#include <pcl/visualization/pcl_visualizer.h>
Expand Down Expand Up @@ -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<vtkLookupTable> table = vtkSmartPointer<vtkLookupTable>::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);
Expand Down Expand Up @@ -2194,6 +2241,37 @@ pcl::visualization::PCLVisualizer::addModelFromPolyData (
return (true);
}

////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::PCLVisualizer::addModelFromPolyData (vtkSmartPointer<vtkPolyDataMapper> 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<vtkActor> actor = vtkSmartPointer<vtkActor>::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
Expand Down

0 comments on commit 085e13a

Please sign in to comment.