Verified Commit e6c39c0c authored by Justin Carpentier's avatar Justin Carpentier
Browse files

python: check registration of types

It will avoid conflicts with other libs that already implements some of these bindings
parent 5dc9a940
//
// Software License Agreement (BSD License)
//
// Copyright (c) 2019 CNRS-LAAS
// Copyright (c) 2019 CNRS-LAAS INRIA
// Author: Joseph Mirabel
// All rights reserved.
//
......@@ -34,6 +34,8 @@
#include <boost/python.hpp>
#include <eigenpy/registration.hpp>
#include "fcl.hh"
#include <hpp/fcl/fwd.hh>
......@@ -183,48 +185,59 @@ void exposeShapes ()
void exposeCollisionGeometries ()
{
enum_<OBJECT_TYPE>("OBJECT_TYPE")
.value ("OT_UNKNOWN", OT_UNKNOWN)
.value ("OT_BVH" , OT_BVH)
.value ("OT_GEOM" , OT_GEOM)
.value ("OT_OCTREE" , OT_OCTREE)
;
enum_<NODE_TYPE>("NODE_TYPE")
.value ("BV_UNKNOWN", BV_UNKNOWN)
.value ("BV_AABB" , BV_AABB)
.value ("BV_OBB" , BV_OBB)
.value ("BV_RSS" , BV_RSS)
.value ("BV_kIOS" , BV_kIOS)
.value ("BV_OBBRSS", BV_OBBRSS)
.value ("BV_KDOP16", BV_KDOP16)
.value ("BV_KDOP18", BV_KDOP18)
.value ("BV_KDOP24", BV_KDOP24)
.value ("GEOM_BOX" , GEOM_BOX)
.value ("GEOM_SPHERE" , GEOM_SPHERE)
.value ("GEOM_CAPSULE" , GEOM_CAPSULE)
.value ("GEOM_CONE" , GEOM_CONE)
.value ("GEOM_CYLINDER" , GEOM_CYLINDER)
.value ("GEOM_CONVEX" , GEOM_CONVEX)
.value ("GEOM_PLANE" , GEOM_PLANE)
.value ("GEOM_HALFSPACE", GEOM_HALFSPACE)
.value ("GEOM_TRIANGLE" , GEOM_TRIANGLE)
.value ("GEOM_OCTREE" , GEOM_OCTREE)
;
if(!eigenpy::register_symbolic_link_to_registered_type<OBJECT_TYPE>())
{
enum_<OBJECT_TYPE>("OBJECT_TYPE")
.value ("OT_UNKNOWN", OT_UNKNOWN)
.value ("OT_BVH" , OT_BVH)
.value ("OT_GEOM" , OT_GEOM)
.value ("OT_OCTREE" , OT_OCTREE)
;
}
if(!eigenpy::register_symbolic_link_to_registered_type<NODE_TYPE>())
{
enum_<NODE_TYPE>("NODE_TYPE")
.value ("BV_UNKNOWN", BV_UNKNOWN)
.value ("BV_AABB" , BV_AABB)
.value ("BV_OBB" , BV_OBB)
.value ("BV_RSS" , BV_RSS)
.value ("BV_kIOS" , BV_kIOS)
.value ("BV_OBBRSS", BV_OBBRSS)
.value ("BV_KDOP16", BV_KDOP16)
.value ("BV_KDOP18", BV_KDOP18)
.value ("BV_KDOP24", BV_KDOP24)
.value ("GEOM_BOX" , GEOM_BOX)
.value ("GEOM_SPHERE" , GEOM_SPHERE)
.value ("GEOM_CAPSULE" , GEOM_CAPSULE)
.value ("GEOM_CONE" , GEOM_CONE)
.value ("GEOM_CYLINDER" , GEOM_CYLINDER)
.value ("GEOM_CONVEX" , GEOM_CONVEX)
.value ("GEOM_PLANE" , GEOM_PLANE)
.value ("GEOM_HALFSPACE", GEOM_HALFSPACE)
.value ("GEOM_TRIANGLE" , GEOM_TRIANGLE)
.value ("GEOM_OCTREE" , GEOM_OCTREE)
;
}
class_ <CollisionGeometry, CollisionGeometryPtr_t, noncopyable>
("CollisionGeometry", no_init)
.def ("getObjectType", &CollisionGeometry::getObjectType)
.def ("getNodeType", &CollisionGeometry::getNodeType)
if(!eigenpy::register_symbolic_link_to_registered_type<CollisionGeometry>())
{
class_ <CollisionGeometry, CollisionGeometryPtr_t, noncopyable>
("CollisionGeometry", no_init)
.def ("getObjectType", &CollisionGeometry::getObjectType)
.def ("getNodeType", &CollisionGeometry::getNodeType)
.def ("computeLocalAABB", &CollisionGeometry::computeLocalAABB)
.def ("computeLocalAABB", &CollisionGeometry::computeLocalAABB)
.def ("computeCOM", &CollisionGeometry::computeCOM)
.def ("computeMomentofInertia", &CollisionGeometry::computeMomentofInertia)
.def ("computeVolume", &CollisionGeometry::computeVolume)
.def ("computeMomentofInertiaRelatedToCOM", &CollisionGeometry::computeMomentofInertiaRelatedToCOM)
.def ("computeCOM", &CollisionGeometry::computeCOM)
.def ("computeMomentofInertia", &CollisionGeometry::computeMomentofInertia)
.def ("computeVolume", &CollisionGeometry::computeVolume)
.def ("computeMomentofInertiaRelatedToCOM", &CollisionGeometry::computeMomentofInertiaRelatedToCOM)
.def_readwrite("aabb_radius",&CollisionGeometry::aabb_radius,"AABB radius")
;
.def_readwrite("aabb_radius",&CollisionGeometry::aabb_radius,"AABB radius")
;
}
exposeShapes();
......
......@@ -35,6 +35,8 @@
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <eigenpy/registration.hpp>
#include "fcl.hh"
#include <hpp/fcl/fwd.hh>
......@@ -46,53 +48,72 @@ using namespace hpp::fcl;
void exposeCollisionAPI ()
{
enum_ <CollisionRequestFlag> ("CollisionRequestFlag")
.value ("CONTACT", CONTACT)
.value ("DISTANCE_LOWER_BOUND", DISTANCE_LOWER_BOUND)
.value ("NO_REQUEST", NO_REQUEST)
;
class_ <CollisionRequest> ("CollisionRequest", init<>())
.def (init<CollisionRequestFlag, size_t>())
if(!eigenpy::register_symbolic_link_to_registered_type<CollisionRequestFlag>())
{
enum_ <CollisionRequestFlag> ("CollisionRequestFlag")
.value ("CONTACT", CONTACT)
.value ("DISTANCE_LOWER_BOUND", DISTANCE_LOWER_BOUND)
.value ("NO_REQUEST", NO_REQUEST)
;
}
.def_readwrite ("num_max_contacts" , &CollisionRequest::num_max_contacts)
.def_readwrite ("enable_contact" , &CollisionRequest::enable_contact)
.def_readwrite ("enable_distance_lower_bound", &CollisionRequest::enable_distance_lower_bound)
.def_readwrite ("enable_cached_gjk_guess" , &CollisionRequest::enable_cached_gjk_guess)
.def_readwrite ("cached_gjk_guess" , &CollisionRequest::cached_gjk_guess)
.def_readwrite ("security_margin" , &CollisionRequest::security_margin)
.def_readwrite ("break_distance" , &CollisionRequest::break_distance)
;
if(!eigenpy::register_symbolic_link_to_registered_type<CollisionRequest>())
{
class_ <CollisionRequest> ("CollisionRequest", init<>())
.def (init<CollisionRequestFlag, size_t>())
.def_readwrite ("num_max_contacts" , &CollisionRequest::num_max_contacts)
.def_readwrite ("enable_contact" , &CollisionRequest::enable_contact)
.def_readwrite ("enable_distance_lower_bound", &CollisionRequest::enable_distance_lower_bound)
.def_readwrite ("enable_cached_gjk_guess" , &CollisionRequest::enable_cached_gjk_guess)
.def_readwrite ("cached_gjk_guess" , &CollisionRequest::cached_gjk_guess)
.def_readwrite ("security_margin" , &CollisionRequest::security_margin)
.def_readwrite ("break_distance" , &CollisionRequest::break_distance)
;
}
class_ <Contact> ("Contact", init<>())
//.def(init<CollisionGeometryPtr_t, CollisionGeometryPtr_t, int, int>())
//.def(init<CollisionGeometryPtr_t, CollisionGeometryPtr_t, int, int, Vec3f, Vec3f, FCL_REAL>())
.def_readonly ("o1", &Contact::o1)
.def_readonly ("o2", &Contact::o2)
.def_readwrite ("b1", &Contact::b1)
.def_readwrite ("b2", &Contact::b2)
.def_readwrite ("normal", &Contact::normal)
.def_readwrite ("pos", &Contact::pos)
.def_readwrite ("penetration_depth", &Contact::penetration_depth)
.def (self == self)
;
if(!eigenpy::register_symbolic_link_to_registered_type<Contact>())
{
class_ <Contact> ("Contact", init<>())
//.def(init<CollisionGeometryPtr_t, CollisionGeometryPtr_t, int, int>())
//.def(init<CollisionGeometryPtr_t, CollisionGeometryPtr_t, int, int, Vec3f, Vec3f, FCL_REAL>())
.def_readonly ("o1", &Contact::o1)
.def_readonly ("o2", &Contact::o2)
.def_readwrite ("b1", &Contact::b1)
.def_readwrite ("b2", &Contact::b2)
.def_readwrite ("normal", &Contact::normal)
.def_readwrite ("pos", &Contact::pos)
.def_readwrite ("penetration_depth", &Contact::penetration_depth)
.def (self == self)
.def (self != self)
;
}
class_< std::vector<Contact> >("StdVec_Contact")
.def(vector_indexing_suite< std::vector<Contact> >())
;
if(!eigenpy::register_symbolic_link_to_registered_type< std::vector<Contact> >())
{
class_< std::vector<Contact> >("StdVec_Contact")
.def(vector_indexing_suite< std::vector<Contact> >())
;
}
class_ <CollisionResult> ("CollisionResult", init<>())
.def ("isCollision", &CollisionResult::isCollision)
.def ("numContacts", &CollisionResult::numContacts)
.def ("getContact" , &CollisionResult::getContact , return_value_policy<copy_const_reference>())
.def ("getContacts", &CollisionResult::getContacts, return_internal_reference<>())
.def ("addContact" , &CollisionResult::addContact )
.def ("clear", &CollisionResult::clear)
;
if(!eigenpy::register_symbolic_link_to_registered_type< std::vector<CollisionResult> >())
{
class_ <CollisionResult> ("CollisionResult", init<>())
.def ("isCollision", &CollisionResult::isCollision)
.def ("numContacts", &CollisionResult::numContacts)
.def ("getContact" , &CollisionResult::getContact , return_value_policy<copy_const_reference>())
.def ("getContacts", &CollisionResult::getContacts, return_internal_reference<>())
.def ("addContact" , &CollisionResult::addContact )
.def ("clear", &CollisionResult::clear)
;
}
class_< std::vector<CollisionResult> >("CollisionResult")
.def(vector_indexing_suite< std::vector<CollisionResult> >())
;
if(!eigenpy::register_symbolic_link_to_registered_type< std::vector<CollisionResult> >())
{
class_< std::vector<CollisionResult> >("CollisionResult")
.def(vector_indexing_suite< std::vector<CollisionResult> >())
;
}
def ("collide", static_cast< std::size_t (*)(const CollisionObject*, const CollisionObject*,
const CollisionRequest&, CollisionResult&) > (&collide));
......
......@@ -35,6 +35,8 @@
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <eigenpy/registration.hpp>
#include "fcl.hh"
#include <hpp/fcl/fwd.hh>
......@@ -52,29 +54,38 @@ struct DistanceRequestWrapper
void exposeDistanceAPI ()
{
class_ <DistanceRequest> ("DistanceRequest", init<optional<bool,FCL_REAL,FCL_REAL> >())
.def_readwrite ("enable_nearest_points", &DistanceRequest::enable_nearest_points)
.def_readwrite ("rel_err" , &DistanceRequest::rel_err)
.def_readwrite ("abs_err" , &DistanceRequest::abs_err)
;
if(!eigenpy::register_symbolic_link_to_registered_type<DistanceRequest>())
{
class_ <DistanceRequest> ("DistanceRequest", init<optional<bool,FCL_REAL,FCL_REAL> >())
.def_readwrite ("enable_nearest_points", &DistanceRequest::enable_nearest_points)
.def_readwrite ("rel_err" , &DistanceRequest::rel_err)
.def_readwrite ("abs_err" , &DistanceRequest::abs_err)
;
}
class_ <DistanceResult> ("DistanceResult", init<>())
.def_readwrite ("min_distance", &DistanceResult::min_distance)
.def_readwrite ("normal", &DistanceResult::normal)
//.def_readwrite ("nearest_points", &DistanceResult::nearest_points)
.def("getNearestPoint1",&DistanceRequestWrapper::getNearestPoint1)
.def("getNearestPoint2",&DistanceRequestWrapper::getNearestPoint2)
.def_readonly ("o1", &DistanceResult::o1)
.def_readonly ("o2", &DistanceResult::o2)
.def_readwrite ("b1", &DistanceResult::b1)
.def_readwrite ("b2", &DistanceResult::b2)
if(!eigenpy::register_symbolic_link_to_registered_type<DistanceResult>())
{
class_ <DistanceResult> ("DistanceResult", init<>())
.def_readwrite ("min_distance", &DistanceResult::min_distance)
.def_readwrite ("normal", &DistanceResult::normal)
//.def_readwrite ("nearest_points", &DistanceResult::nearest_points)
.def("getNearestPoint1",&DistanceRequestWrapper::getNearestPoint1)
.def("getNearestPoint2",&DistanceRequestWrapper::getNearestPoint2)
.def_readonly ("o1", &DistanceResult::o1)
.def_readonly ("o2", &DistanceResult::o2)
.def_readwrite ("b1", &DistanceResult::b1)
.def_readwrite ("b2", &DistanceResult::b2)
.def ("clear", &DistanceResult::clear)
;
.def ("clear", &DistanceResult::clear)
;
}
class_< std::vector<DistanceResult> >("StdVec_DistanceResult")
.def(vector_indexing_suite< std::vector<DistanceResult> >())
;
if(!eigenpy::register_symbolic_link_to_registered_type< std::vector<DistanceResult> >())
{
class_< std::vector<DistanceResult> >("StdVec_DistanceResult")
.def(vector_indexing_suite< std::vector<DistanceResult> >())
;
}
def ("distance", static_cast< FCL_REAL (*)(const CollisionObject*, const CollisionObject*,
const DistanceRequest&, DistanceResult&) > (&distance));
......
......@@ -34,6 +34,8 @@
#include <boost/python.hpp>
#include <eigenpy/registration.hpp>
#include "fcl.hh"
#include <hpp/fcl/fwd.hh>
......@@ -50,12 +52,18 @@ using namespace hpp::fcl;
void exposeMeshLoader ()
{
class_ <MeshLoader> ("MeshLoader", init< optional< NODE_TYPE> >())
.def ("load", static_cast <BVHModelPtr_t (MeshLoader::*) (const std::string&, const Vec3f&)> (&MeshLoader::load))
;
if(!eigenpy::register_symbolic_link_to_registered_type<MeshLoader>())
{
class_ <MeshLoader> ("MeshLoader", init< optional< NODE_TYPE> >())
.def ("load", static_cast <BVHModelPtr_t (MeshLoader::*) (const std::string&, const Vec3f&)> (&MeshLoader::load))
;
}
class_ <CachedMeshLoader, bases<MeshLoader> > ("CachedMeshLoader", init< optional< NODE_TYPE> >())
if(!eigenpy::register_symbolic_link_to_registered_type<CachedMeshLoader>())
{
class_ <CachedMeshLoader, bases<MeshLoader> > ("CachedMeshLoader", init< optional< NODE_TYPE> >())
;
}
}
BOOST_PYTHON_MODULE(hppfcl)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment