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

Projector cannot be instantiated from Python #242

Closed
KleinYuan opened this issue Mar 10, 2022 · 6 comments
Closed

Projector cannot be instantiated from Python #242

KleinYuan opened this issue Mar 10, 2022 · 6 comments

Comments

@KleinYuan
Copy link

KleinYuan commented Mar 10, 2022

It seems the Projector cannot be instantiated from Python. To reproduce it:

>>> import lanelet2
>>> lanelet2.projection.Projector(lanelet2.io.Origin(0,0,0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: This class cannot be instantiated from Python

Is it because this class is not bind? I have no issue with UTMProjector tho.
It looks like already bind-ed:

class_<projection::UtmProjector, std::shared_ptr<projection::UtmProjector>, bases<Projector>>("UtmProjector",
init<Origin>("origin"))

@m-naumann
Copy link
Member

The Projector class is just defining the interface, using the UtmProjector is most probably what you want. Or why are you intending to instantiate the base class?

@KleinYuan
Copy link
Author

The Projector class is just defining the interface, using the UtmProjector is most probably what you want. Or why are you intending to instantiate the base class?

The reason why is that we are trying to do a custom forward/reverse. Namely, we need to write a new class either inheriting the projector or wrap on top of it. Neither seems working. If I do a new class inheriting Projector, the error is as follows:

Boost.Python.ArgumentError: Python argument types in
    lanelet2.io.load(str, Projector)
did not match C++ signature:
    load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > filename, lanelet::Origin origin)
    load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > filename, lanelet::Projector projector=<lanelet2.projection.MercatorProjector object at 0x7f82a22efad0>)

@m-naumann
Copy link
Member

Okay, makes sense.

Supporting classes inherited in python is some more effort: https://www.boost.org/doc/libs/1_78_0/libs/python/doc/html/reference/high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.introduction

So either you'd have to add that, or implement your custom projection in cpp.

@KleinYuan
Copy link
Author

Okay, makes sense.

Supporting classes inherited in python is some more effort: https://www.boost.org/doc/libs/1_78_0/libs/python/doc/html/reference/high_level_components/boost_python_wrapper_hpp.html#high_level_components.boost_python_wrapper_hpp.introduction

So either you'd have to add that, or implement your custom projection in cpp.

Right. I think maybe we can add a default projector under the projector for the purpose (, and bind it to python).

@m-naumann
Copy link
Member

Makes sense, see also #244 for an example, maybe you can even contribute your projector

@KleinYuan
Copy link
Author

KleinYuan commented Mar 29, 2022

I ended up with following the PR your recommended to write my own projector and bind to python to have my problem solved! Thanks for the great suggestions @m-naumann

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

No branches or pull requests

2 participants