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 PCLVisualizer::containsCloud. #1181

Merged
merged 2 commits into from
May 16, 2015
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
97 changes: 32 additions & 65 deletions visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,9 @@ pcl::visualization::PCLVisualizer::addPointCloud (
const PointCloudGeometryHandler<PointT> &geometry_handler,
const std::string &id, int viewport)
{
// 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 ())
if (contains (id))
{
PCL_WARN ("[addPointCloud] A PointCloud with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addPointCloud] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand All @@ -103,13 +100,11 @@ pcl::visualization::PCLVisualizer::addPointCloud (
const GeometryHandlerConstPtr &geometry_handler,
const std::string &id, int viewport)
{
// 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 ())
if (contains (id))
{
// Here we're just pushing the handlers onto the queue. If needed, something fancier could
// be done such as checking if a specific handler already exists, etc.
CloudActorMap::iterator am_it = cloud_actor_map_->find (id);
am_it->second.geometry_handlers.push_back (geometry_handler);
return (true);
}
Expand All @@ -126,12 +121,9 @@ pcl::visualization::PCLVisualizer::addPointCloud (
const PointCloudColorHandler<PointT> &color_handler,
const std::string &id, int viewport)
{
// 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 ())
if (contains (id))
{
PCL_WARN ("[addPointCloud] A PointCloud with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addPointCloud] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());

// Here we're just pushing the handlers onto the queue. If needed, something fancier could
// be done such as checking if a specific handler already exists, etc.
Expand Down Expand Up @@ -194,12 +186,9 @@ pcl::visualization::PCLVisualizer::addPointCloud (
const PointCloudGeometryHandler<PointT> &geometry_handler,
const std::string &id, int viewport)
{
// 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 ())
if (contains (id))
{
PCL_WARN ("[addPointCloud] A PointCloud with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addPointCloud] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
// Here we're just pushing the handlers onto the queue. If needed, something fancier could
// be done such as checking if a specific handler already exists, etc.
//cloud_actor_map_[id].geometry_handlers.push_back (geometry_handler);
Expand Down Expand Up @@ -454,11 +443,9 @@ pcl::visualization::PCLVisualizer::addPolygon (
template <typename P1, typename P2> bool
pcl::visualization::PCLVisualizer::addLine (const P1 &pt1, const P2 &pt2, double r, double g, double b, 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);
if (am_it != shape_actor_map_->end ())
if (contains (id))
{
PCL_WARN ("[addLine] A shape with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addLine] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand All @@ -481,11 +468,9 @@ pcl::visualization::PCLVisualizer::addLine (const P1 &pt1, const P2 &pt2, double
template <typename P1, typename P2> bool
pcl::visualization::PCLVisualizer::addArrow (const P1 &pt1, const P2 &pt2, double r, double g, double b, 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);
if (am_it != shape_actor_map_->end ())
if (contains (id))
{
PCL_WARN ("[addArrow] A shape with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addArrow] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand All @@ -510,11 +495,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, double g, double b, bool display_length, 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);
if (am_it != shape_actor_map_->end ())
if (contains (id))
{
PCL_WARN ("[addArrow] A shape with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addArrow] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand Down Expand Up @@ -545,11 +528,9 @@ pcl::visualization::PCLVisualizer::addArrow (const P1 &pt1, const P2 &pt2,
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);
if (am_it != shape_actor_map_->end ())
if (contains (id))
{
PCL_WARN ("[addArrow] A shape with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addArrow] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand Down Expand Up @@ -583,11 +564,9 @@ pcl::visualization::PCLVisualizer::addLine (const P1 &pt1, const P2 &pt2, const
template <typename PointT> bool
pcl::visualization::PCLVisualizer::addSphere (const PointT &center, double radius, double r, double g, double b, 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);
if (am_it != shape_actor_map_->end ())
if (contains (id))
{
PCL_WARN ("[addSphere] A shape with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addSphere] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand Down Expand Up @@ -632,13 +611,14 @@ pcl::visualization::PCLVisualizer::addSphere (const PointT &center, double radiu
template<typename PointT> bool
pcl::visualization::PCLVisualizer::updateSphere (const PointT &center, double radius, double r, double g, double b, const std::string &id)
{
// 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 ())
if (contains (id))
{
return (false);
}

//////////////////////////////////////////////////////////////////////////
// Get the actor pointer
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second);
#if VTK_MAJOR_VERSION < 6
vtkAlgorithm *algo = actor->GetMapper ()->GetInput ()->GetProducerPort ()->GetProducer ();
Expand Down Expand Up @@ -674,11 +654,9 @@ pcl::visualization::PCLVisualizer::addText3D (
else
tid = id;

// 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 (tid);
if (am_it != shape_actor_map_->end ())
if (contains (tid))
{
pcl::console::print_warn (stderr, "[addText3d] A text with id <%s> already exists! Please choose a different id and retry.\n", tid.c_str ());
PCL_WARN ("[addText3D] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand Down Expand Up @@ -744,12 +722,9 @@ pcl::visualization::PCLVisualizer::addPointCloudNormals (
PCL_ERROR ("[addPointCloudNormals] The number of points differs from the number of 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 ())
if (contains (id))
{
PCL_WARN ("[addPointCloudNormals] A PointCloud with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addPointCloudNormals] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand Down Expand Up @@ -872,12 +847,10 @@ pcl::visualization::PCLVisualizer::addPointCloudPrincipalCurvatures (
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 ())
if (contains (id))
{
pcl::console::print_warn (stderr, "[addPointCloudPrincipalCurvatures] A PointCloud with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addPointCloudPrincipalCurvatures] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand Down Expand Up @@ -989,12 +962,9 @@ pcl::visualization::PCLVisualizer::addPointCloudIntensityGradients (
PCL_ERROR ("[addPointCloudGradients] The number of points differs from the number of gradients!\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 ())
if (contains (id))
{
PCL_WARN ("[addPointCloudGradients] A PointCloud with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
PCL_WARN ("[addPointCloudGradients] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

Expand Down Expand Up @@ -1571,12 +1541,9 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (
if (vertices.empty () || cloud->points.empty ())
return (false);

CloudActorMap::iterator am_it = cloud_actor_map_->find (id);
if (am_it != cloud_actor_map_->end ())
if (contains (id))
{
pcl::console::print_warn (stderr,
"[addPolygonMesh] A shape with id <%s> already exists! Please choose a different id and retry.\n",
id.c_str ());
PCL_WARN ("[addPolygonMesh] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
}

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 @@ -579,6 +579,18 @@ namespace pcl
double r = 1.0, double g = 1.0, double b = 1.0,
const std::string &id = "", int viewport = 0);

/** \brief Check if the cloud, shape, or coordinate with the given id was already added to this vizualizer.
* \param[in] id the id of the cloud, shape, or coordinate to check
* \return true if a cloud, shape, or coordinate with the specified id was found
*/
inline bool
contains(const std::string &id) const
{
return (cloud_actor_map_->find (id) != cloud_actor_map_->end () ||
shape_actor_map_->find (id) != shape_actor_map_->end () ||
coordinate_actor_map_->find (id) != coordinate_actor_map_-> end());
}

/** \brief Add the estimated surface normals of a Point Cloud to screen.
* \param[in] cloud the input point cloud dataset containing XYZ data and normals
* \param[in] level display only every level'th point (default: 100)
Expand Down