Skip to content

Commit

Permalink
Use contains() in most add* functions
Browse files Browse the repository at this point in the history
In most add* functions it's straight forward to replace the old pattern for
checking the ids with the new contains function. This commit contains all the
easy cases.

The warning were also adjusted to look like this:

  PCL_WARN ("[functionName] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());

Note that previously some warning were wrong, e.g., they complained about
PointClouds, even though Gradients were added. This was fixed by using the
generic warning from above.

In some spots pcl::console::print_warn was used instead of PCL_WARN.
Now PCL_WARN is used in all add* functions.
  • Loading branch information
sotte committed May 10, 2015
1 parent 4cc6b3d commit e0aec91
Showing 1 changed file with 31 additions and 65 deletions.
96 changes: 31 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,13 @@ 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 +653,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 +721,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 +846,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 +961,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 +1540,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

0 comments on commit e0aec91

Please sign in to comment.