Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pointcloud visualization with colormaps #1581

Merged
merged 4 commits into from
Jun 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions visualization/include/pcl/visualization/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include <pcl/pcl_macros.h>
#include <pcl/visualization/eigen.h>
#include <vtkMatrix4x4.h>
#include <vtkSmartPointer.h>
#include <vtkLookupTable.h>

namespace pcl
{
Expand Down Expand Up @@ -91,23 +93,19 @@ namespace pcl
PCL_EXPORTS float
viewScreenArea (const Eigen::Vector3d &eye, const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const Eigen::Matrix4d &view_projection_matrix, int width, int height);

/** \brief Set of rendering properties
* \c PCL_VISUALIZER_POINT_SIZE: integer starting from 1
* \c PCL_VISUALIZER_OPACITY: Float going from 0.0 (transparent) to 1.0 (opaque)
* \c PCL_VISUALIZER_LINE_WIDTH: Integer starting from 1
* \c PCL_VISUALIZER_COLOR: 3 floats (R, G, B) going from 0.0 (dark) to 1.0 (light)
*/
/** \brief Set of rendering properties. */
enum RenderingProperties
{
PCL_VISUALIZER_POINT_SIZE,
PCL_VISUALIZER_OPACITY,
PCL_VISUALIZER_LINE_WIDTH,
PCL_VISUALIZER_POINT_SIZE, /**< integer starting from 1 */
PCL_VISUALIZER_OPACITY, /**< Float going from 0.0 (transparent) to 1.0 (opaque) */
PCL_VISUALIZER_LINE_WIDTH, /**< Integer starting from 1 */
PCL_VISUALIZER_FONT_SIZE,
PCL_VISUALIZER_COLOR,
PCL_VISUALIZER_COLOR, /**< 3 floats (R, G, B) going from 0.0 (dark) to 1.0 (light) */
PCL_VISUALIZER_REPRESENTATION,
PCL_VISUALIZER_IMMEDIATE_RENDERING,
PCL_VISUALIZER_SHADING,
PCL_VISUALIZER_LUT
PCL_VISUALIZER_LUT, /**< colormap type \ref pcl::visualization::LookUpTableRepresentationProperties */
PCL_VISUALIZER_LUT_RANGE /**< two doubles (min and max) or \ref pcl::visualization::LookUpTableRepresentationProperties::PCL_VISUALIZER_LUT_RANGE_AUTO */
};

enum RenderingRepresentationProperties
Expand All @@ -124,17 +122,26 @@ 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 */
/*! Colormap properties. See [mathworks colormap page](http://www.mathworks.com/help/matlab/ref/colormap.html#input_argument_name) for image representations of the colormaps. */
enum LookUpTableRepresentationProperties
{ //
PCL_VISUALIZER_LUT_JET,
PCL_VISUALIZER_LUT_JET_INVERSE,
PCL_VISUALIZER_LUT_HSV,
PCL_VISUALIZER_LUT_HSV_INVERSE,
PCL_VISUALIZER_LUT_GREY
{
PCL_VISUALIZER_LUT_JET, /**< Jet colormap */
PCL_VISUALIZER_LUT_JET_INVERSE, /**< Inverse jet colormap */
PCL_VISUALIZER_LUT_HSV, /**< HSV colormap */
PCL_VISUALIZER_LUT_HSV_INVERSE, /**< Inverse HSV colormap */
PCL_VISUALIZER_LUT_GREY, /**< Grey colormap (black to white) */
PCL_VISUALIZER_LUT_BLUE2RED, /**< Blue to red colormap (blue to white to red) */
PCL_VISUALIZER_LUT_RANGE_AUTO /**< Set LUT range to min and max values of the data */
};

/** \brief Generate a lookup table for a colormap.
* \param[in] colormap_type
* \param[out] table a vtk lookup table
* \note The list of available colormaps can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
*/
PCL_EXPORTS bool
getColormapLUT (LookUpTableRepresentationProperties colormap_type, vtkSmartPointer<vtkLookupTable> &table);

//////////////////////////////////////////////////////////////////////////////////////////////
/** \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 @@ -1148,6 +1148,18 @@ namespace pcl
setPointCloudRenderingProperties (int property, double val1, double val2, double val3,
const std::string &id = "cloud", int viewport = 0);

/** \brief Set the rendering properties of a PointCloud (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 point cloud object id (default: cloud)
* \param[in] viewport the view port where the Point Cloud's rendering properties should be modified (default: all)
* \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
*/
bool
setPointCloudRenderingProperties (int property, double val1, double val2,
const std::string &id = "cloud", int viewport = 0);

/** \brief Set the rendering properties of a PointCloud
* \param[in] property the property type
* \param[in] value the value to be set
Expand Down
86 changes: 86 additions & 0 deletions visualization/src/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <pcl/point_types.h>
#include <pcl/visualization/common/common.h>
#include <pcl/console/print.h>
#include <stdlib.h>

//////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -357,6 +358,91 @@ pcl::visualization::viewScreenArea (
return (fabsf (float (sum * 0.5f)));
}

/////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::getColormapLUT (LookUpTableRepresentationProperties colormap_type, vtkSmartPointer<vtkLookupTable> &table)
{
table = vtkSmartPointer<vtkLookupTable>::New ();
switch (colormap_type)
{
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;
}

case PCL_VISUALIZER_LUT_BLUE2RED:
{
table->SetSaturationRange (1, 1);
table->SetAlphaRange (1, 1);
table->SetNumberOfTableValues (256);

double red[3] = {1.0, 0.0, 0.0};
double white[3] = {1.0, 1.0, 1.0};
double blue[3] = {0.0, 0.0, 1.0};

for (size_t i = 0; i < 128; i++)
{
double weight = static_cast<double>(i) / 128.0;
table->SetTableValue ( i,
white[0] * weight + blue[0] * (1 - weight),
white[1] * weight + blue[1] * (1 - weight),
white[2] * weight + blue[2] * (1 - weight) );
}

for (size_t i = 128; i < 256; i++)
{
double weight = (static_cast<double>(i) -128.0) / 128.0;
table->SetTableValue ( i,
red[0] * weight + white[0] * (1 - weight),
red[1] * weight + white[1] * (1 - weight),
red[2] * weight + white[2] * (1 - weight) );
}
break;
}
default:
PCL_WARN ("[pcl::visualization::getColormapLUT] Requested colormap type does not exist!\n");
return false;
}
table->Build ();
return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////
void
pcl::visualization::Camera::computeViewMatrix (Eigen::Matrix4d &view_mat) const
Expand Down
131 changes: 100 additions & 31 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@

#include <pcl/visualization/common/shapes.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/common/common.h>
#include <pcl/common/time.h>
#include <boost/uuid/sha1.hpp>
#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -1330,6 +1331,58 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties (
return (true);
}

/////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties (
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?)
CloudActorMap::iterator am_it = cloud_actor_map_->find (id);

if (am_it == cloud_actor_map_->end ())
{
pcl::console::print_error ("[setPointCloudRenderingProperties] Could not find any PointCloud datasets with id <%s>!\n", id.c_str ());
return (false);
}
// Get the actor pointer
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor);
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 ("[setPointCloudRenderingProperties] 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 ("[setPointCloudRenderingProperties] Unknown property (%d) specified!\n", property);
return (false);
}
}
return (true);
}

/////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (int property, double &value, const std::string &id)
Expand Down Expand Up @@ -1422,6 +1475,52 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties (
actor->Modified ();
break;
}
case PCL_VISUALIZER_LUT:
{
// 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;

// Get range limits from existing LUT
double *range;
range = actor->GetMapper ()->GetLookupTable ()->GetRange ();

actor->GetMapper ()->ScalarVisibilityOn ();
actor->GetMapper ()->SetScalarRange (range[0], range[1]);
vtkSmartPointer<vtkLookupTable> table;
if (!pcl::visualization::getColormapLUT (static_cast<LookUpTableRepresentationProperties>(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 ("[setPointCloudRenderingProperties] Unknown property (%d) specified!\n", property);
Expand Down Expand Up @@ -1639,38 +1738,8 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties (
actor->GetMapper ()->ScalarVisibilityOn ();
actor->GetMapper ()->SetScalarRange (range[0], range[1]);
vtkSmartPointer<vtkLookupTable> table = vtkSmartPointer<vtkLookupTable>::New ();
getColormapLUT (static_cast<LookUpTableRepresentationProperties>(value), table);
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);
style_->updateLookUpTableDisplay (false);
break;
Expand Down