We have a point cloud like pcl::PointCloud<pcl::PointXYZ> cloud which has N points. We want to find K points in cloud which their z value is less than other N-K points. What is the most efficient way to do it in pcl?
Closing since issue is unrelated to the library (but is instead a question regarding using the library for which Discord is a better fit)
You aim can be achieved through so many ways:
The most efficient way depends on what else you're doing with the cloud, size of cloud, etc.
The question is also a bit ambiguous. Do you know z and are trying to find the points (and the value of k) or do you know k and are looking for the prefect value of z
The cloud is updated each 100 milliseconds and obviously we don't know the z value. If it is not possible in pcl, it can be a good feature to be implemented. The proposed methods are not suitable in this case.
Please create a suitable proposal issue in that case. Please try to enter all possible requirements (eg: organized pre and post 'filter', example use cases, etc.)
This is solved by std::nth_element.
partition is faster (since it imposes weaker posterior conditions compared to nth_element) 馃槃
partition is faster (since it imposes weaker posterior conditions compared to nth_element) smile
But partition needs a true/false predicate, which (as I understood the issue) is not given, because the z value that divides the two groups in unknown. I too think that nth_element should be the solution.
The brute force approach to this problem is sorting whole points of vector and then get K first elements from vector which its complexity is O(NlogN)while std::nth_element solves this problem in O(N).
Most helpful comment
But partition needs a true/false predicate, which (as I understood the issue) is not given, because the
zvalue that divides the two groups in unknown. I too think that nth_element should be the solution.