From d5164794caf824b78d413b472e3e50c8c4e69d0c Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Thu, 16 Sep 2021 15:35:13 +0200 Subject: [PATCH 1/2] python: enhance Convex exposition --- python/collision-geometries.cc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/python/collision-geometries.cc b/python/collision-geometries.cc index e0ee90a00..54cac0bfa 100644 --- a/python/collision-geometries.cc +++ b/python/collision-geometries.cc @@ -71,6 +71,7 @@ using namespace boost::python; using namespace hpp::fcl; namespace dv = doxygen::visitor; +namespace bp = boost::python; using boost::noncopyable; @@ -122,11 +123,20 @@ void exposeBVHModel (const std::string& bvname) struct ConvexBaseWrapper { - static Vec3f points (const ConvexBase& convex, int i) + typedef Eigen::Matrix RowMatrixX3; + typedef Eigen::Map MapRowMatrixX3; + typedef Eigen::Ref RefRowMatrixX3; + + static Vec3f & point (const ConvexBase& convex, int i) { if (i >= convex.num_points) throw std::out_of_range("index is out of range"); return convex.points[i]; } + + static RefRowMatrixX3 points (const ConvexBase& convex) + { + return MapRowMatrixX3(convex.points[0].data(),convex.num_points,3); + } static list neighbors (const ConvexBase& convex, int i) { @@ -232,7 +242,18 @@ void exposeShapes () ("ConvexBase", doxygen::class_doc(), no_init) .DEF_RO_CLASS_ATTRIB (ConvexBase, center) .DEF_RO_CLASS_ATTRIB (ConvexBase, num_points) - .def ("points", &ConvexBaseWrapper::points) + .def ("point", &ConvexBaseWrapper::point, + bp::args("self","index"),"Retrieve the point given by its index.", + bp::return_internal_reference<>()) + .def ("points", &ConvexBaseWrapper::point, + bp::args("self","index"),"Retrieve the point given by its index.", + ::hpp::fcl::python::deprecated_member< bp::return_internal_reference<> >()) + .def ("points", &ConvexBaseWrapper::points, + bp::args("self"),"Retrieve all the points.", + bp::with_custodian_and_ward_postcall<0,1>()) + // .add_property ("points", + // bp::make_function(&ConvexBaseWrapper::points,bp::with_custodian_and_ward_postcall<0,1>()), + // "Points of the convex.") .def ("neighbors", &ConvexBaseWrapper::neighbors) .def ("convexHull", &ConvexBaseWrapper::convexHull, doxygen::member_func_doc(&ConvexBase::convexHull), @@ -370,8 +391,6 @@ void exposeCollisionGeometries () ; } - namespace bp = boost::python; - class_("AABB", "A class describing the AABB collision structure, which is a box in 3D space determined by two diagonal points", no_init) From 1c1557ea168ed43a658d7c4fb9f0670bdfbb4152 Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Thu, 16 Sep 2021 19:52:44 +0200 Subject: [PATCH 2/2] python: fix import for pypy --- python/fcl.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/fcl.cc b/python/fcl.cc index cd43f341d..ccac1d106 100644 --- a/python/fcl.cc +++ b/python/fcl.cc @@ -89,7 +89,10 @@ void exposeMeshLoader () BOOST_PYTHON_MODULE(hppfcl) { - boost::python::import("warnings"); + namespace bp = boost::python; + + PyImport_ImportModule("warnings"); + exposeVersion(); exposeMaths(); exposeCollisionGeometries();