Giter Club home page Giter Club logo

Comments (4)

qianyizh avatar qianyizh commented on May 3, 2024

See this for detailed document:
http://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html

TL;DR version:

By default, pybind11 automatically converts std::vector to python list. However, the downside is that the access is copy semantic.
If you want reference semantic (as should be done for nodes_ and edges_, you should declare it OPAQUE. This is done by adding PYBIND11_MAKE_OPAQUE macro in py3d.h. See current examples:

PYBIND11_MAKE_OPAQUE(std::vector<Eigen::Vector3d>);
PYBIND11_MAKE_OPAQUE(std::vector<Eigen::Vector3i>);
PYBIND11_MAKE_OPAQUE(std::vector<Eigen::Vector2i>);
PYBIND11_MAKE_OPAQUE(std::vector<Eigen::Matrix4d>);

from open3d.

syncle avatar syncle commented on May 3, 2024

Thanks. I added

PYBIND11_MAKE_OPAQUE(std::vector<three::PoseGraphEdge>);
PYBIND11_MAKE_OPAQUE(std::vector<three::PoseGraphNode>);

but I got following error

# python
pose_graph.nodes.append(PoseGraphNode(trans))
pose_graph.edges.append(PoseGraphEdge(t, s, trans, info, False))

TypeError: Unable to convert function return value to a Python type! The signature was
	(self: py3d.PoseGraph) -> std::__1::vector<three::PoseGraphNode, std::__1::allocator<three::PoseGraphNode> >

Do I need to also define pybind_eigen_vector_of_* functions in Open3D/src/Python/py3d_eigen.cpp? I concern that would be tricky and redundant as PoseGraphEdge has many member variables.

from open3d.

syncle avatar syncle commented on May 3, 2024

I reviewed pybind11 STL containers manual carefully and found answer.

This definition should come earlier than PoseGraphEdge

PYBIND11_MAKE_OPAQUE(std::vector<three::PoseGraphEdge>);

and I need to add following line after definition of PoseGraphEdge

py::bind_vector<std::vector<PoseGraphEdge>>(m, "PoseGraphEdgeVector");

From following python script, now I can get

	pose_graph = PoseGraph()
	print(pose_graph)
	pose_graph.edges.append(PoseGraphEdge(t, s, trans, info, False))
	print(pose_graph)

        [python output]
        PoseGraph with 0 nodes and 0 edges.
        PoseGraph with 0 nodes and 1 edges.

from open3d.

syncle avatar syncle commented on May 3, 2024

Addressed in #73

from open3d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.