diff --git a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp index 1ff4c064707..3e162bc7e7a 100644 --- a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp +++ b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp @@ -82,12 +82,9 @@ pcl::visualization::PCLVisualizer::addPointCloud ( const PointCloudGeometryHandler &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); } @@ -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); } @@ -126,12 +121,9 @@ pcl::visualization::PCLVisualizer::addPointCloud ( const PointCloudColorHandler &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. @@ -194,12 +186,9 @@ pcl::visualization::PCLVisualizer::addPointCloud ( const PointCloudGeometryHandler &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); @@ -454,11 +443,9 @@ pcl::visualization::PCLVisualizer::addPolygon ( template 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); } @@ -481,11 +468,9 @@ pcl::visualization::PCLVisualizer::addLine (const P1 &pt1, const P2 &pt2, double template 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); } @@ -510,11 +495,9 @@ pcl::visualization::PCLVisualizer::addArrow (const P1 &pt1, const P2 &pt2, doubl template 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); } @@ -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); } @@ -583,11 +564,9 @@ pcl::visualization::PCLVisualizer::addLine (const P1 &pt1, const P2 &pt2, const template bool pcl::visualization::PCLVisualizer::addSphere (const PointT ¢er, 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); } @@ -632,13 +611,14 @@ pcl::visualization::PCLVisualizer::addSphere (const PointT ¢er, double radiu template bool pcl::visualization::PCLVisualizer::updateSphere (const PointT ¢er, 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 (); @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index 2899ca1f443..b60dc646c5c 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -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)