-
-
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
[filters] Add a filter accepting a functor to reduce boiler plate code for simple filters #3890
[filters] Add a filter accepting a functor to reduce boiler plate code for simple filters #3890
Conversation
Shouldn't |
PTAL |
Co-authored-by: Sérgio Agostinho <sergio.r.agostinho@gmail.com>
Co-authored-by: Sérgio Agostinho <sergio.r.agostinho@gmail.com>
PTAL. More tests needed though |
Kind of doesn't work. The return type of If we drop all the 3 If we force the lambda to be copyable (lambdas might be an issue here), then we can return a copy (instead of a reference) of the stored functor and still keep the method as const |
I suggested to not store the lambda as const, |
Pushed a diff which is giving me errors |
Managed to trigger your error once I started invoking filter.getLambda()(/*arguments*/); If I did auto l = filter.getLambda();
l(/*arguments*/); No errors we're being triggered. I'm unsure why. (Double checked. It's implicitly creating a copy of the object stored inside) Multiple edits from here down const FunctorT&
getLambda() const noexcept
{
return lambda_;
}
/* The non-const version of the method */
FunctorT&
getLambda() noexcept
{
return lambda_;
} But basically it means we're allowing the contained object to be fully modified and rewritten once initialized. Is this something we want? I don't really care to be honest. The class does not rely on what object it holds. The user has full control over it. Alternatively we don't define the non-const method and always force the user to make a copy if it wants to modify the object. I don't mind both approaches. |
PTAL |
EXPECT_EQ(filter.getRemovedIndices()->size() + out_cloud.size(), cloud->size()); | ||
} | ||
else { | ||
EXPECT_EQ(filter.getRemovedIndices()->size(), removed_size); |
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.
It feels like removed_size should be 0 here. If true, why not explicitly setting 0 here?
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.
It should be unmodified, not equal to 0 (based on code in base classes)
Merge if no other issues (and CI is green) EDIT: |
Currently modification of filter needs sub-classing of
Filter
orFilterIndices
and quite some boiler plate code which can be reduced by working with a simple functor.Please check the PR for a WIP implementation of a class to reduce code needed for a custom class to a simple functor which checks point-by-point.
If all goes well, we can reduce a lot of existing classes to instantiations of this class with a functor, as well as more functionality easily (eg: frustum-culling, passthrough, crop-hull)
I'd have preferred to pass in the function to the
applyFilter
but that's not possible.TODO:
Add a check for is_derived_from on the impl classMove impl to namespace detailProper year on LicenseAdd a check on lambda foris_invocable
from the same arguments as thestd::function
based appraoch