-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add PCLVisualizer::containsCloud. #1181
Conversation
@@ -579,6 +579,17 @@ 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 clound with the given id was already added to this vizualizer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cloud not clound 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this is why reviews are a good idea, thanks! :)
a66b656
to
66115a6
Compare
👍 There is one subtlety that's worth documenting. For some reason when you add a polygon mesh (with I would add a note/warning to the docstring to avoid confusion. |
I searched a bit more and pretty much everything you add to the viewer ends up in the
I guess the underlying problem is that the concept of the Anyway, should we mention previously named functions as well? Or should we rename the function? |
Maybe this function should also check |
Oh man, I didn't even know that I don't know what is the best way to proceed. How about this:
|
Or we can enforce uniqueness of the name independently of the particular actor map where it ends up. Then only a single |
This would mean that every time we want to add "stuff" we have to check if the id aleady exists in one of the three actor maps, right? This would require quite a bit of refactoring (nothing hard but quite a few lines of code). My two-liner is turning into something bigger but I guess I could implement it. Would this somehow influence the backward compatibility? |
The refactoring will amount to changing lines like: ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
if (am_it != shape_actor_map_->end ())
{
// ... with which every
Well may give problems to those who used objects of different types with the same name. (But I have hard times imagining why someone would add a point cloud called "cloud" and then a sphere also called "cloud"). Anyway, a warning message will be printed, so it will be relatively easy to solve the problem for those who are affected. |
OK, I'll implement it... |
I just found https://github.com/PointCloudLibrary/pcl/blob/master/visualization/src/pcl_visualizer.cpp#L780. |
I don't think so. Check this commit message. It seems that there was/is quite a jumble with what goes where (to which actor map). For example, polygon meshes end up in cloud map, whereas polygons go to the shape map... |
Some addPointCloud function do multiple things. Here is an example: pcl::visualization::PCLVisualizer::addPointCloud (
const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
const GeometryHandlerConstPtr &geometry_handler,
const std::string &id, int viewport)
{
CloudActorMap::iterator am_it = cloud_actor_map_->find (id);
if (am_it != cloud_actor_map_->end ())
{
am_it->second.geometry_handlers.push_back (geometry_handler);
return (true);
}
PointCloudColorHandlerCustom<PointT> color_handler (cloud, 255, 255, 255);
return (fromHandlersToScreen (geometry_handler, color_handler, id, viewport, cloud->sensor_origin_, cloud->sensor_orientation_));
} If id was not added yet, the data is added. Should the later case not be handled in the update function? |
Hm... maybe. But that's a different issue, isn't it? Could you please squash the first two commits? Also please correct a few whitespace/line break issues in the last commit (lines 85, 124, 614). 👍 for the elaborate commit message! |
`contains` allows to check if the viewer (or more precisely the *_actor_map) already contains input data with the given id. Why `contains()`: Currently `updatePointCloud` checks if the viewer contains something with the given id AND updates the point cloud. However, in many scenarios only the check is important. The new `contains` is much clearer and only requires the id of the data. `contains` also removes the need for manual bookkeeping (ala `graph_added` flags), because now it is easy to query any *_actor_map, not just the cloud_actor_map.
e0aec91
to
10f088e
Compare
I just wanted to mention the issue though. I squashed the two commits. But I'm not sure about the whitespaces. Looks ok to me. What exactly do you mean? |
CloudActorMap::iterator am_it = cloud_actor_map_->find (id); | ||
|
||
if (am_it != cloud_actor_map_->end ()) | ||
if ( contains(id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space before and missing space after contains
Thanks! I left inline comments. |
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.
10f088e
to
4a4eb21
Compare
Thanks! Updated. |
Add PCLVisualizer::containsCloud.
Hey,
I "needed" the following function and it's just two lines of code. It basically allows you to check the PCLVisualizer contains the cloud with the given id independent of the type of the cloud.
Let me know what you think.
containsCloud
allows to check if the viewer already contains a cloud with thegiven id.
updatePointCloud
also checks this AND updates the point cloud, however,in many scenarios only the check is important.
containsCloud
is much clearer and only requires the id of the cloud.Why
containsCloud
:In many tutorials the user keeps track of the added pointclouds by hand, i.e.,
flags like
graph_added
are used.This is necessary because the
updatePointCloud
cannot be used.containsCloud
solves this issue.