Skip to content
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

[sample_consensus] Fix and improve MLESAC #4575

Merged
merged 2 commits into from
Feb 21, 2021

Conversation

mvieth
Copy link
Member

@mvieth mvieth commented Jan 16, 2021

Please see commit messages.

@mvieth mvieth added changelog: enhancement Meta-information for changelog generation needs: code review Specify why not closed/merged yet module: sample_consensus changelog: fix Meta-information for changelog generation labels Jan 16, 2021
@mvieth mvieth force-pushed the mlesac branch 3 times, most recently from 7d6f950 to dd2f0c4 Compare January 31, 2021 18:26
common/include/pcl/common/common.h Outdated Show resolved Hide resolved
common/include/pcl/common/common.h Outdated Show resolved Hide resolved
common/include/pcl/common/common.h Outdated Show resolved Hide resolved
test/common/test_common.cpp Outdated Show resolved Hide resolved
@mvieth mvieth force-pushed the mlesac branch 3 times, most recently from 8ebb478 to 34147e1 Compare February 1, 2021 12:27
* \ingroup common
*/
template<typename IteratorT, typename Functor> inline auto
computeMedian (IteratorT begin, IteratorT end, Functor f) noexcept -> typename std::iterator_traits<IteratorT>::value_type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noexcept(noexept(Functor)) might be better, but it doesn't matter much

@mvieth
Copy link
Member Author

mvieth commented Feb 2, 2021

@kunaltyagi Regarding the return type of computeMedian: I am wondering whether it would make sense to use double as the fixed return type. If you consider the last (commented-out) test, would the user expect the return of an int, so 5, or of the correct value, 5.5, which would require float or double?

@kunaltyagi
Copy link
Member

kunaltyagi commented Feb 2, 2021

That's why I commented about making the return type same as the return type of the lambda. The user will be able to switch it as needed.

Choosing double as default is problematic because in C++, we're very used to (5 + 6)/2 == 10 being true. I'd consider 5 to be the correct answer in the test case because the data-type is int

if (size%2==0)
{ // Even number of values
std::nth_element (begin, begin + (mid-1), end);
return (f(begin[mid-1]) + f(*(std::min_element (begin + mid, end)))) / 2.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/2 or /2.0?

Copy link
Member Author

@mvieth mvieth Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also write static_cast<typename std::result_of<Functor(decltype(*begin))>::type>(2.0), but I don't see a case where there would be a difference between the three

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • /2.0 worst case: int(4/2.0) is a double conversion followed by an int conversion
  • /2 worst case: T(T()/2) involves just one conversion (unless T is char)
  • static_cast worst case: no conversion :) but readability is severely affected

TBH, This is a minor issue and I've already approved of the PR a while ago 😄 so I'm fine with it not being modified

@mvieth mvieth requested a review from larshg February 21, 2021 14:55
Fixes bug: parentheses were wrong, was 2 * (sigma_ * sigma_) instead of (2 * sigma_ * sigma_). MLESAC works much better now
Improves speed by precomputing factors
Improves speed of median by using nth_element and min_element instead of sort
Use the new function in MLESAC and LMEDS
@mvieth mvieth removed the needs: code review Specify why not closed/merged yet label Feb 21, 2021
@mvieth mvieth merged commit c000c1f into PointCloudLibrary:master Feb 21, 2021
@mvieth mvieth deleted the mlesac branch February 21, 2021 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: enhancement Meta-information for changelog generation changelog: fix Meta-information for changelog generation module: sample_consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants