pcl icon indicating copy to clipboard operation
pcl copied to clipboard

Correct usage of `radiusSearch` results when unsorted search trees are provided as input

Open kunaltyagi opened this issue 4 years ago • 9 comments

Provides a more robust fix to issues described in #4999

TL;DR: current algorithm assumes the output of radiusSearch is sorted. This is not always the case. A solution is to skip the point when it matches the query index (implemented here)

It is also possible to only perform this when the search is un-sorted, and the current patch can be updated to reflect that. I'm not sure how much of a difference that is going to make, specially since a lot of logic would need to be duplicated to provide the minimal benefit. That could also be done simply by using [[unlikely]] (but that's added in C++20 in the standard, with compiler specific versions available). A separate PR can add that to pcl_macros.h + update here and other places

Thoughts?

kunaltyagi avatar Dec 05 '21 00:12 kunaltyagi

Seems like seed_queue should be of type pcl::Indices in our_cvfh. Also: maybe range-for loops are an option?

mvieth avatar Dec 05 '21 16:12 mvieth

In the extract_clusters, they query the tree if it returns sorted or not, like this:

  // Check if the tree is sorted -- if it is we don't need to check the first element
  int nn_start_idx = tree->getSortedResults () ? 1 : 0;

I guess that would be faster, than to (sometimes several times) compare and do array indexing?

larshg avatar Dec 06 '21 21:12 larshg

@larshg Like I mentioned, it's possible, but I didn't know if the effort would be worth it. I've pushed a change in our_cvfh, so you can take a look and decide if this is the way to go for the other files.

kunaltyagi avatar Dec 07 '21 06:12 kunaltyagi

@larshg Like I mentioned, it's possible, but I didn't know if the effort would be worth it. I've pushed a change in our_cvfh, so you can take a look and decide if this is the way to go for the other files.

Ah. sorry didn't get that from the initial post.

I think it's fine to just have your original implementation since the tree will always return unordered points, it doesn't make much sense to check if it does / doesn't.

larshg avatar Dec 07 '21 06:12 larshg

Since the tree is exposed, we can't be sure if it'd return ordered or unordered outputs, specially if kdtree_flann is used (which returns sorted results by default)

kunaltyagi avatar Dec 07 '21 07:12 kunaltyagi

It's not in all cases the tree is fully exposed to the user - sometimes they are private in PCL, ie. in our_cvfh. But I guess the most save approach is to assume its exposed and the increased runtime is probably neglectable.

larshg avatar Dec 07 '21 07:12 larshg

ie. in our_cvfh.

Not really. See https://github.com/PointCloudLibrary/pcl/blob/master/features/include/pcl/features/impl/our_cvfh.hpp#L612 (the false argument implies that the output results are unsorted)

kunaltyagi avatar Dec 07 '21 09:12 kunaltyagi

ie. in our_cvfh.

Not really. See https://github.com/PointCloudLibrary/pcl/blob/master/features/include/pcl/features/impl/our_cvfh.hpp#L612 (the false argument implies that the output results are unsorted)

Yes, and in this case the user can't change that. It at least requires a code change, if the tree in the our_cvfh, should output sorted results?

larshg avatar Dec 07 '21 10:12 larshg

Will not update this. My preferred approach is via #5092

kunaltyagi avatar Feb 23 '22 05:02 kunaltyagi