Skip to content
Snippets Groups Projects
Unverified Commit a02d95ec authored by Joseph Mirabel's avatar Joseph Mirabel Committed by GitHub
Browse files

Merge pull request #123 from jcarpent/devel

Expose additional quantities in Python
parents a17be7ee 830c2b46
No related branches found
Tags v0.3.2c
No related merge requests found
......@@ -230,16 +230,16 @@ static inline AABB translate(const AABB& aabb, const Vec3f& t)
return res;
}
static inline AABB rotate(const AABB& aabb, const Matrix3f& t)
static inline AABB rotate(const AABB& aabb, const Matrix3f& R)
{
AABB res (t * aabb.min_);
AABB res (R * aabb.min_);
Vec3f corner (aabb.min_);
const std::size_t bit[3] = { 1, 2, 4 };
for (std::size_t ic = 1; ic < 8; ++ic) { // ic = 0 corresponds to aabb.min_. Skip it.
for (std::size_t i = 0; i < 3; ++i) {
corner[i] = (ic && bit[i]) ? aabb.max_[i] : aabb.min_[i];
}
res += t * corner;
res += R * corner;
}
return res;
}
......
//
// Software License Agreement (BSD License)
//
// Copyright (c) 2019 CNRS-LAAS INRIA
// Copyright (c) 2019-2020 CNRS-LAAS INRIA
// Author: Joseph Mirabel
// All rights reserved.
//
......@@ -183,6 +183,13 @@ void exposeShapes ()
}
boost::python::tuple AABB_distance_proxy(const AABB & self, const AABB & other)
{
Vec3f P,Q;
FCL_REAL distance = self.distance(other,&P,&Q);
return boost::python::tuple((distance,P,Q));
}
void exposeCollisionGeometries ()
{
......@@ -220,6 +227,76 @@ void exposeCollisionGeometries ()
.value ("GEOM_OCTREE" , GEOM_OCTREE)
;
}
namespace bp = boost::python;
class_<AABB>("AABB",
"A class describing the AABB collision structure, which is a box in 3D space determined by two diagonal points",
no_init)
.def(init<>("Default constructor"))
.def(init<Vec3f>(bp::arg("v"),"Creating an AABB at position v with zero size."))
.def(init<Vec3f,Vec3f>(bp::args("a","b"),"Creating an AABB with two endpoints a and b."))
.def(init<AABB,Vec3f>(bp::args("core","delta"),"Creating an AABB centered as core and is of half-dimension delta."))
.def(init<Vec3f,Vec3f,Vec3f>(bp::args("a","b","c"),"Creating an AABB contains three points."))
.def("contain",
(bool (AABB::*)(const Vec3f &) const)&AABB::contain,
bp::args("self","p"),
"Check whether the AABB contains a point p.")
.def("contain",
(bool (AABB::*)(const AABB &) const)&AABB::contain,
bp::args("self","other"),
"Check whether the AABB contains another AABB.")
.def("overlap",
(bool (AABB::*)(const AABB &) const)&AABB::overlap,
bp::args("self","other"),
"Check whether two AABB are overlap.")
.def("overlap",
(bool (AABB::*)(const AABB&, AABB&) const)&AABB::overlap,
bp::args("self","other","overlapping_part"),
"Check whether two AABB are overlaping and return the overloaping part if true.")
.def("distance",
(FCL_REAL (AABB::*)(const AABB &) const)&AABB::distance,
bp::args("self","other"),
"Distance between two AABBs.")
// .def("distance",
// AABB_distance_proxy,
// bp::args("self","other"),
// "Distance between two AABBs.")
.def(bp::self + bp::self)
.def(bp::self += bp::self)
.def(bp::self += Vec3f())
.def("size",&AABB::volume,bp::arg("self"),"Size of the AABB.")
.def("center",&AABB::center,bp::arg("self"),"Center of the AABB.")
.def("width",&AABB::width,bp::arg("self"),"Width of the AABB.")
.def("height",&AABB::height,bp::arg("self"),"Height of the AABB.")
.def("depth",&AABB::depth,bp::arg("self"),"Depth of the AABB.")
.def("volume",&AABB::volume,bp::arg("self"),"Volume of the AABB.")
.def("expand",
(AABB& (AABB::*)(const AABB &, FCL_REAL))&AABB::expand,
bp::args("self","core","ratio"),
"Expand the AABB by increase the thickness of the plate by a ratio.",
bp::return_internal_reference<>())
.def("expand",
(AABB& (AABB::*)(const Vec3f &))&AABB::expand,
bp::args("self","delta"),
"Expand the half size of the AABB by delta, and keep the center unchanged.",
bp::return_internal_reference<>());
def("translate",
(AABB (*)(const AABB&, const Vec3f&))&translate,
bp::args("aabb","t"),
"Translate the center of AABB by t");
def("rotate",
(AABB (*)(const AABB&, const Matrix3f&))&rotate,
bp::args("aabb","R"),
"Rotate the AABB object by R");
if(!eigenpy::register_symbolic_link_to_registered_type<CollisionGeometry>())
{
......@@ -235,7 +312,17 @@ void exposeCollisionGeometries ()
.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.")
.def_readwrite("aabb_center",&CollisionGeometry::aabb_center,"AABB center in local coordinate.")
.def_readwrite("aabb_local",&CollisionGeometry::aabb_local,"AABB in local coordinate, used for tight AABB when only translation transform.")
.def("isOccupied",&CollisionGeometry::isOccupied,bp::arg("self"),"Whether the object is completely occupied.")
.def("isFree",&CollisionGeometry::isFree,bp::arg("self"),"Whether the object is completely free.")
.def("isUncertain",&CollisionGeometry::isUncertain,bp::arg("self"),"Whether the object has some uncertainty.")
.def_readwrite("cost_density",&CollisionGeometry::cost_density,"Collision cost for unit volume.")
.def_readwrite("threshold_occupied",&CollisionGeometry::threshold_occupied,"Threshold for occupied ( >= is occupied).")
.def_readwrite("threshold_free",&CollisionGeometry::threshold_free,"Threshold for free (<= is free).")
;
}
......@@ -243,8 +330,10 @@ void exposeCollisionGeometries ()
class_ <BVHModelBase, bases<CollisionGeometry>, BVHModelPtr_t, noncopyable>
("BVHModelBase", no_init)
.def ("vertices", &BVHModelBaseWrapper::vertices)
.def ("tri_indices", &BVHModelBaseWrapper::tri_indices)
.def ("vertices", &BVHModelBaseWrapper::vertices,
bp::args("self","index"),"Retrieve the vertex given by its index.")
.def ("tri_indices", &BVHModelBaseWrapper::tri_indices,
bp::args("self","index"),"Retrieve the triangle given by its index.")
.def_readonly ("num_vertices", &BVHModelBase::num_vertices)
.def_readonly ("num_tris", &BVHModelBase::num_tris)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment