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

Add removeAllCoordinateSystems and templated addPointCloudPrincipalCurvatures #965

Merged
merged 2 commits into from
Oct 22, 2014
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
136 changes: 133 additions & 3 deletions visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include <vtkAppendPolyData.h>
#include <vtkTextProperty.h>
#include <vtkLODActor.h>
#include <vtkLineSource.h>

#include <pcl/visualization/common/shapes.h>

Expand Down Expand Up @@ -539,9 +540,9 @@ pcl::visualization::PCLVisualizer::addArrow (const P1 &pt1, const P2 &pt2, doubl
////////////////////////////////////////////////////////////////////////////////////////////
template <typename P1, typename P2> bool
pcl::visualization::PCLVisualizer::addArrow (const P1 &pt1, const P2 &pt2,
double r_line, double g_line, double b_line,
double r_text, double g_text, double b_text,
const std::string &id, int viewport)
double r_line, double g_line, double b_line,
double r_text, double g_text, double b_text,
const std::string &id, int viewport)
{
// 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);
Expand Down Expand Up @@ -845,6 +846,135 @@ pcl::visualization::PCLVisualizer::addPointCloudNormals (
return (true);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointNT> bool
pcl::visualization::PCLVisualizer::addPointCloudPrincipalCurvatures (
const typename pcl::PointCloud<PointNT>::ConstPtr &cloud,
const pcl::PointCloud<pcl::PrincipalCurvatures>::ConstPtr &pcs,
int level, float scale,
const std::string &id, int viewport)
{
return (addPointCloudPrincipalCurvatures<PointNT, PointNT> (cloud, cloud, pcs, level, scale, id, viewport));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename PointNT> bool
pcl::visualization::PCLVisualizer::addPointCloudPrincipalCurvatures (
const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
const typename pcl::PointCloud<PointNT>::ConstPtr &normals,
const pcl::PointCloud<pcl::PrincipalCurvatures>::ConstPtr &pcs,
int level, float scale,
const std::string &id, int viewport)
{
if (pcs->points.size () != cloud->points.size () || normals->points.size () != cloud->points.size ())
{
pcl::console::print_error ("[addPointCloudPrincipalCurvatures] The number of points differs from the number of principal curvatures/normals!\n");
return (false);
}
// 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_warn (stderr, "[addPointCloudPrincipalCurvatures] A PointCloud with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

vtkSmartPointer<vtkAppendPolyData> polydata_1 = vtkSmartPointer<vtkAppendPolyData>::New ();
vtkSmartPointer<vtkAppendPolyData> polydata_2 = vtkSmartPointer<vtkAppendPolyData>::New ();

// Setup two colors - one for each line
unsigned char green[3] = {0, 255, 0};
unsigned char blue[3] = {0, 0, 255};

// Setup the colors array
vtkSmartPointer<vtkUnsignedCharArray> line_1_colors =vtkSmartPointer<vtkUnsignedCharArray>::New ();
line_1_colors->SetNumberOfComponents (3);
line_1_colors->SetName ("Colors");
vtkSmartPointer<vtkUnsignedCharArray> line_2_colors =vtkSmartPointer<vtkUnsignedCharArray>::New ();
line_2_colors->SetNumberOfComponents (3);
line_2_colors->SetName ("Colors");

// Create the first sets of lines
for (size_t i = 0; i < cloud->points.size (); i+=level)
{
PointT p = cloud->points[i];
p.x += (pcs->points[i].pc1 * pcs->points[i].principal_curvature[0]) * scale;
p.y += (pcs->points[i].pc1 * pcs->points[i].principal_curvature[1]) * scale;
p.z += (pcs->points[i].pc1 * pcs->points[i].principal_curvature[2]) * scale;

vtkSmartPointer<vtkLineSource> line_1 = vtkSmartPointer<vtkLineSource>::New ();
line_1->SetPoint1 (cloud->points[i].x, cloud->points[i].y, cloud->points[i].z);
line_1->SetPoint2 (p.x, p.y, p.z);
line_1->Update ();
#if VTK_MAJOR_VERSION < 6
polydata_1->AddInput (line_1->GetOutput ());
#else
polydata_1->AddInputData (line_1->GetOutput ());
#endif
line_1_colors->InsertNextTupleValue (green);
}
polydata_1->Update ();
vtkSmartPointer<vtkPolyData> line_1_data = polydata_1->GetOutput ();
line_1_data->GetCellData ()->SetScalars (line_1_colors);

// Create the second sets of lines
for (size_t i = 0; i < cloud->points.size (); i += level)
{
Eigen::Vector3f pc (pcs->points[i].principal_curvature[0],
pcs->points[i].principal_curvature[1],
pcs->points[i].principal_curvature[2]);
Eigen::Vector3f normal (normals->points[i].normal[0],
normals->points[i].normal[1],
normals->points[i].normal[2]);
Eigen::Vector3f pc_c = pc.cross (normal);

PointT p = cloud->points[i];
p.x += (pcs->points[i].pc2 * pc_c[0]) * scale;
p.y += (pcs->points[i].pc2 * pc_c[1]) * scale;
p.z += (pcs->points[i].pc2 * pc_c[2]) * scale;

vtkSmartPointer<vtkLineSource> line_2 = vtkSmartPointer<vtkLineSource>::New ();
line_2->SetPoint1 (cloud->points[i].x, cloud->points[i].y, cloud->points[i].z);
line_2->SetPoint2 (p.x, p.y, p.z);
line_2->Update ();
#if VTK_MAJOR_VERSION < 6
polydata_2->AddInput (line_2->GetOutput ());
#else
polydata_2->AddInputData (line_2->GetOutput ());
#endif

line_2_colors->InsertNextTupleValue (blue);
}
polydata_2->Update ();
vtkSmartPointer<vtkPolyData> line_2_data = polydata_2->GetOutput ();
line_2_data->GetCellData ()->SetScalars (line_2_colors);

// Assemble the two sets of lines
vtkSmartPointer<vtkAppendPolyData> alldata = vtkSmartPointer<vtkAppendPolyData>::New ();
#if VTK_MAJOR_VERSION < 6
alldata->AddInput (line_1_data);
alldata->AddInput (line_2_data);
#else
alldata->AddInputData (line_1_data);
alldata->AddInputData (line_2_data);
#endif

// Create an Actor
vtkSmartPointer<vtkLODActor> actor;
createActorFromVTKDataSet (alldata->GetOutput (), actor);
actor->GetMapper ()->SetScalarModeToUseCellData ();

// Add it to all renderers
addActorToRenderer (actor, viewport);

// Save the pointer/ID pair to the global actor map
CloudActor act;
act.actor = actor;
(*cloud_actor_map_)[id] = act;
return (true);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename GradientT> bool
pcl::visualization::PCLVisualizer::addPointCloudIntensityGradients (
Expand Down
37 changes: 29 additions & 8 deletions visualization/include/pcl/visualization/pcl_visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ namespace pcl
bool
removeAllShapes (int viewport = 0);

/** \brief Removes all existing 3D axes (coordinate systems)
* \param[in] viewport view port where the 3D axes should be removed from (default: all)
*/
bool
removeAllCoordinateSystems (int viewport = 0);

/** \brief Set the viewport's background color.
* \param[in] r the red component of the RGB color
* \param[in] g the green component of the RGB color
Expand Down Expand Up @@ -599,6 +605,21 @@ namespace pcl
int level = 100, float scale = 0.02f,
const std::string &id = "cloud", int viewport = 0);

/** \brief Add the estimated principal curvatures of a Point Cloud to screen.
* \param[in] cloud the input point cloud dataset containing the XYZ data and normals
* \param[in] pcs the input point cloud dataset containing the principal curvatures data
* \param[in] level display only every level'th point. Default: 100
* \param[in] scale the normal arrow scale. Default: 1.0
* \param[in] id the point cloud object id. Default: "cloud"
* \param[in] viewport the view port where the Point Cloud should be added (default: all)
*/
template <typename PointNT> bool
addPointCloudPrincipalCurvatures (
const typename pcl::PointCloud<PointNT>::ConstPtr &cloud,
const typename pcl::PointCloud<pcl::PrincipalCurvatures>::ConstPtr &pcs,
int level = 100, float scale = 1.0f,
const std::string &id = "cloud", int viewport = 0);

/** \brief Add the estimated principal curvatures of a Point Cloud to screen.
* \param[in] cloud the input point cloud dataset containing the XYZ data
* \param[in] normals the input point cloud dataset containing the normal data
Expand All @@ -608,10 +629,10 @@ namespace pcl
* \param[in] id the point cloud object id. Default: "cloud"
* \param[in] viewport the view port where the Point Cloud should be added (default: all)
*/
bool
template <typename PointT, typename PointNT> bool
addPointCloudPrincipalCurvatures (
const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud,
const pcl::PointCloud<pcl::Normal>::ConstPtr &normals,
const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
const typename pcl::PointCloud<PointNT>::ConstPtr &normals,
const pcl::PointCloud<pcl::PrincipalCurvatures>::ConstPtr &pcs,
int level = 100, float scale = 1.0f,
const std::string &id = "cloud", int viewport = 0);
Expand Down Expand Up @@ -1280,11 +1301,11 @@ namespace pcl
* \param[in] id the line id/name (default: "arrow")
* \param[in] viewport (optional) the id of the new viewport (default: 0)
*/
template <typename P1, typename P2> bool
addArrow (const P1 &pt1, const P2 &pt2,
double r_line, double g_line, double b_line,
double r_text, double g_text, double b_text,
const std::string &id = "arrow", int viewport = 0);
template <typename P1, typename P2> bool
addArrow (const P1 &pt1, const P2 &pt2,
double r_line, double g_line, double b_line,
double r_text, double g_text, double b_text,
const std::string &id = "arrow", int viewport = 0);


/** \brief Add a sphere shape from a point and a radius
Expand Down
118 changes: 8 additions & 110 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
#include <vtkPLYReader.h>
#include <vtkAxes.h>
#include <vtkTubeFilter.h>
#include <vtkLineSource.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkAxesActor.h>
#include <vtkRenderWindowInteractor.h>
Expand Down Expand Up @@ -900,118 +899,17 @@ pcl::visualization::PCLVisualizer::removeAllShapes (int viewport)

/////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::PCLVisualizer::addPointCloudPrincipalCurvatures (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud,
const pcl::PointCloud<pcl::Normal>::ConstPtr &normals,
const pcl::PointCloud<pcl::PrincipalCurvatures>::ConstPtr &pcs,
int level, float scale,
const std::string &id, int viewport)
pcl::visualization::PCLVisualizer::removeAllCoordinateSystems (int viewport)
{
if (pcs->points.size () != cloud->points.size () || normals->points.size () != cloud->points.size ())
{
pcl::console::print_error ("[addPointCloudPrincipalCurvatures] The number of points differs from the number of principal curvatures/normals!\n");
return (false);
}
// 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_warn (stderr, "[addPointCloudPrincipalCurvatures] A PointCloud with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

vtkSmartPointer<vtkAppendPolyData> polydata_1 = vtkSmartPointer<vtkAppendPolyData>::New ();
vtkSmartPointer<vtkAppendPolyData> polydata_2 = vtkSmartPointer<vtkAppendPolyData>::New ();

// Setup two colors - one for each line
unsigned char green[3] = {0, 255, 0};
unsigned char blue[3] = {0, 0, 255};

// Setup the colors array
vtkSmartPointer<vtkUnsignedCharArray> line_1_colors =vtkSmartPointer<vtkUnsignedCharArray>::New ();
line_1_colors->SetNumberOfComponents (3);
line_1_colors->SetName ("Colors");
vtkSmartPointer<vtkUnsignedCharArray> line_2_colors =vtkSmartPointer<vtkUnsignedCharArray>::New ();
line_2_colors->SetNumberOfComponents (3);
line_2_colors->SetName ("Colors");

// Create the first sets of lines
for (size_t i = 0; i < cloud->points.size (); i+=level)
{
pcl::PointXYZ p = cloud->points[i];
p.x += (pcs->points[i].pc1 * pcs->points[i].principal_curvature[0]) * scale;
p.y += (pcs->points[i].pc1 * pcs->points[i].principal_curvature[1]) * scale;
p.z += (pcs->points[i].pc1 * pcs->points[i].principal_curvature[2]) * scale;

vtkSmartPointer<vtkLineSource> line_1 = vtkSmartPointer<vtkLineSource>::New ();
line_1->SetPoint1 (cloud->points[i].x, cloud->points[i].y, cloud->points[i].z);
line_1->SetPoint2 (p.x, p.y, p.z);
line_1->Update ();
#if VTK_MAJOR_VERSION < 6
polydata_1->AddInput (line_1->GetOutput ());
#else
polydata_1->AddInputData (line_1->GetOutput ());
#endif
line_1_colors->InsertNextTupleValue (green);
}
polydata_1->Update ();
vtkSmartPointer<vtkPolyData> line_1_data = polydata_1->GetOutput ();
line_1_data->GetCellData ()->SetScalars (line_1_colors);

// Create the second sets of lines
for (size_t i = 0; i < cloud->points.size (); i += level)
// Check to see if the given ID entry exists
CoordinateActorMap::iterator am_it = coordinate_actor_map_->begin ();
while (am_it != coordinate_actor_map_->end () )
{
Eigen::Vector3f pc (pcs->points[i].principal_curvature[0],
pcs->points[i].principal_curvature[1],
pcs->points[i].principal_curvature[2]);
Eigen::Vector3f normal (normals->points[i].normal[0],
normals->points[i].normal[1],
normals->points[i].normal[2]);
Eigen::Vector3f pc_c = pc.cross (normal);

pcl::PointXYZ p = cloud->points[i];
p.x += (pcs->points[i].pc2 * pc_c[0]) * scale;
p.y += (pcs->points[i].pc2 * pc_c[1]) * scale;
p.z += (pcs->points[i].pc2 * pc_c[2]) * scale;

vtkSmartPointer<vtkLineSource> line_2 = vtkSmartPointer<vtkLineSource>::New ();
line_2->SetPoint1 (cloud->points[i].x, cloud->points[i].y, cloud->points[i].z);
line_2->SetPoint2 (p.x, p.y, p.z);
line_2->Update ();
#if VTK_MAJOR_VERSION < 6
polydata_2->AddInput (line_2->GetOutput ());
#else
polydata_2->AddInputData (line_2->GetOutput ());
#endif

line_2_colors->InsertNextTupleValue (blue);
if (removeCoordinateSystem (am_it->first, viewport))
am_it = coordinate_actor_map_->begin ();
else
++am_it;
}
polydata_2->Update ();
vtkSmartPointer<vtkPolyData> line_2_data = polydata_2->GetOutput ();
line_2_data->GetCellData ()->SetScalars (line_2_colors);

// Assemble the two sets of lines
vtkSmartPointer<vtkAppendPolyData> alldata = vtkSmartPointer<vtkAppendPolyData>::New ();
#if VTK_MAJOR_VERSION < 6
alldata->AddInput (line_1_data);
alldata->AddInput (line_2_data);
#else
alldata->AddInputData (line_1_data);
alldata->AddInputData (line_2_data);
#endif

// Create an Actor
vtkSmartPointer<vtkLODActor> actor;
createActorFromVTKDataSet (alldata->GetOutput (), actor);
actor->GetMapper ()->SetScalarModeToUseCellData ();

// Add it to all renderers
addActorToRenderer (actor, viewport);

// Save the pointer/ID pair to the global actor map
CloudActor act;
act.actor = actor;
(*cloud_actor_map_)[id] = act;
return (true);
}

Expand Down
2 changes: 1 addition & 1 deletion visualization/tools/pcd_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ main (int argc, char** argv)
p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_COLOR, 1.0, 0.0, 0.0, cloud_name_normals_pc.str ());
p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 3, cloud_name_normals_pc.str ());
cloud_name_normals_pc << "-pc";
p->addPointCloudPrincipalCurvatures (cloud_xyz, cloud_normals, cloud_pc, factor, pc_scale, cloud_name_normals_pc.str (), viewport);
p->addPointCloudPrincipalCurvatures<pcl::PointXYZ, pcl::Normal> (cloud_xyz, cloud_normals, cloud_pc, factor, pc_scale, cloud_name_normals_pc.str (), viewport);
p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 3, cloud_name_normals_pc.str ());
}

Expand Down