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

add Pose2.align() to wrapper #866

Merged
merged 14 commits into from
Sep 2, 2021
Merged

add Pose2.align() to wrapper #866

merged 14 commits into from
Sep 2, 2021

Conversation

johnwlambert
Copy link
Contributor

No description provided.

@dellaert
Copy link
Member

Could you add a quick python unit test before merging though?

@johnwlambert
Copy link
Contributor Author

Could you add a quick python unit test before merging though?

Hi @dellaert, sure, I added one. One thing for us to be aware of is that if we provide ab pairs to this function, we get back bTa, not aTb, as expected. I think it's the same for the Pose3.align() as well. Maybe something to address in a PR in the future (would require modifying c++ tests also)

@johnwlambert
Copy link
Contributor Author

@ProfFan do you know what's the preferred return type in .i if the c++ return type is boost::optional<gtsam::Pose2>?

@ProfFan
Copy link
Collaborator

ProfFan commented Aug 31, 2021

@johnwlambert Good question! I haven't thought of that, but the problem is with the MATLAB bindings. I think adding an OptionalXXX typedef and ignore it in Python bindings, and adding a specialization for such an optional type would be the solution.

@dellaert
Copy link
Member

dellaert commented Aug 31, 2021

@johnwlambert Good question! I haven't thought of that, but the problem is with the MATLAB bindings. I think adding an OptionalXXX typedef and ignore it in Python bindings, and adding a specialization for such an optional type would be the solution.

Hmmm. @ProfFan can we not return None in case there is no value? Python 3 types allow for an Optional[] type, so seems like maybe pybind could support it? @johnwlambert did you check that?

@varunagrawal
Copy link
Collaborator

The wrapper supports boost::optional. We use it in GTDynamics in multiple places. You could just return boost::optional<Pose2>.

@ProfFan
Copy link
Collaborator

ProfFan commented Sep 1, 2021

@varunagrawal Yea but I don't think we support it in the MATLAB-specific code?

@varunagrawal
Copy link
Collaborator

I agree but it shouldn't error out for the matlab wrapper. I tried it locally and it compiles without issues.

If someone has a problem in the future, they can raise an issue and we'll look into it then. :)

@johnwlambert
Copy link
Contributor Author

Thanks for taking a look all. It looks like including boost::optional in the .i file leads to the following errors:

======================================================================
ERROR: test_align (test_Pose2.TestPose2)
Ensure estimation of the Pose2 element to align two 2d point clouds succeeds.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/gtsam/gtsam/python/gtsam/tests/test_Pose2.py", line 61, in test_align
    bTa = gtsam.align(ab_pairs)
TypeError: Unable to convert function return value to a Python type! The signature was
	(pairs: std::vector<std::pair<Eigen::Matrix<double, 2, 1, 0, 2, 1>, Eigen::Matrix<double, 2, 1, 0, 2, 1> >, std::allocator<std::pair<Eigen::Matrix<double, 2, 1, 0, 2, 1>, Eigen::Matrix<double, 2, 1, 0, 2, 1> > > >) -> boost::optional<gtsam::Pose2>

Did you forget to `#include <pybind11/stl.h>`? Or <pybind11/complex.h>,
<pybind11/functional.h>, <pybind11/chrono.h>, etc. Some automatic
conversions are optional and require extra headers to be included
when compiling your pybind11 module.

@varunagrawal
Copy link
Collaborator

Add #include <pybind11/stl.h> to preamble/geometry.h.
You also need to add the PYBIND_MAKE_OPAQUE macro for Point2Pairs.

I'm adding a commit since there is actually some non-trivial stuff going on here.

@ProfFan
Copy link
Collaborator

ProfFan commented Sep 1, 2021

Maybe stl_bind.h is enough? You still need the type caster though.

@varunagrawal
Copy link
Collaborator

The optional_caster is defined in pybind11/stl.h, so we do need it. 🙂

@johnwlambert
Copy link
Contributor Author

Thanks @varunagrawal and @ProfFan. I guess we are good to merge this now then?

@dellaert
Copy link
Member

dellaert commented Sep 2, 2021

Looks awesome, I'll merge!

@dellaert dellaert merged commit e320bfa into develop Sep 2, 2021
@dellaert dellaert deleted the Pose2-align branch September 2, 2021 13:48
@varunagrawal
Copy link
Collaborator

Yep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants