From 5098f907f1de08a53227fd269aa55650b9215cca Mon Sep 17 00:00:00 2001 From: Dmitry Neverov Date: Mon, 27 Apr 2020 16:16:34 +0900 Subject: [PATCH 01/20] Buildable version with reduced functionality: Updated header file locations Disabled functions not present in Eigen objects Disabled distance function Set Eigen scalar template parameter to `double` everywhere --- fcl/__init__.py | 4 +- fcl/fcl.pyx | 370 ++++++++++++++++++------------------- fcl/fcl_defs.pxd | 463 ++++++++++++++++++++++++----------------------- setup.py | 2 +- 4 files changed, 426 insertions(+), 413 deletions(-) diff --git a/fcl/__init__.py b/fcl/__init__.py index e852be0..fae3eb8 100644 --- a/fcl/__init__.py +++ b/fcl/__init__.py @@ -1,5 +1,5 @@ -from .fcl import CollisionObject, CollisionGeometry, Transform, TriangleP, Box, Sphere, Ellipsoid, Capsule, Cone, Cylinder, Halfspace, Plane, BVHModel, OcTree, DynamicAABBTreeCollisionManager, collide, continuousCollide, distance, defaultCollisionCallback, defaultDistanceCallback - +from .fcl import CollisionObject, CollisionGeometry, Transform, TriangleP, Box, Sphere, Ellipsoid, Capsule, Cone, Cylinder, Halfspace, Plane, BVHModel, OcTree, DynamicAABBTreeCollisionManager, collide, continuousCollide, defaultCollisionCallback, defaultDistanceCallback +#distance from .collision_data import OBJECT_TYPE, NODE_TYPE, CCDMotionType, CCDSolverType, GJKSolverType, Contact, CostSource, CollisionRequest, CollisionResult, ContinuousCollisionRequest, ContinuousCollisionResult, DistanceRequest, DistanceResult, CollisionData, DistanceData from .version import __version__ diff --git a/fcl/fcl.pyx b/fcl/fcl.pyx index ab28ca8..c867aa7 100644 --- a/fcl/fcl.pyx +++ b/fcl/fcl.pyx @@ -20,36 +20,36 @@ from collision_data import Contact, CostSource, CollisionRequest, ContinuousColl # Transforms ############################################################################### cdef class Transform: - cdef defs.Transform3f *thisptr + cdef defs.Transform3d *thisptr def __cinit__(self, *args): if len(args) == 0: - self.thisptr = new defs.Transform3f() + self.thisptr = new defs.Transform3d() elif len(args) == 1: if isinstance(args[0], Transform): - self.thisptr = new defs.Transform3f(deref(( args[0]).thisptr)) - else: - data = numpy.array(args[0]) - if data.shape == (3,3): - self.thisptr = new defs.Transform3f(numpy_to_mat3f(data)) - elif data.shape == (4,): - self.thisptr = new defs.Transform3f(numpy_to_quaternion3f(data)) - elif data.shape == (3,): - self.thisptr = new defs.Transform3f(numpy_to_vec3f(data)) - else: - raise ValueError('Invalid input to Transform().') + self.thisptr = new defs.Transform3d(deref(( args[0]).thisptr)) +# else: +# data = numpy.array(args[0]) +# if data.shape == (3,3): +# self.thisptr = new defs.Transform3d(numpy_to_mat3d(data)) +# elif data.shape == (4,): +# self.thisptr = new defs.Transform3d(numpy_to_quaternion3d(data)) +# elif data.shape == (3,): +# self.thisptr = new defs.Transform3d(numpy_to_vec3d(data)) +# else: +# raise ValueError('Invalid input to Transform().') elif len(args) == 2: rot = numpy.array(args[0]) trans = numpy.array(args[1]).squeeze() if not trans.shape == (3,): raise ValueError('Translation must be (3,).') - if rot.shape == (3,3): - self.thisptr = new defs.Transform3f(numpy_to_mat3f(rot), numpy_to_vec3f(trans)) - elif rot.shape == (4,): - self.thisptr = new defs.Transform3f(numpy_to_quaternion3f(rot), numpy_to_vec3f(trans)) - else: - raise ValueError('Invalid input to Transform().') +# if rot.shape == (3,3): +# self.thisptr = new defs.Transform3d(numpy_to_mat3d(rot), numpy_to_vec3d(trans)) +# elif rot.shape == (4,): +# self.thisptr = new defs.Transform3d(numpy_to_quaternion3d(rot), numpy_to_vec3d(trans)) +# else: +# raise ValueError('Invalid input to Transform().') else: raise ValueError('Too many arguments to Transform().') @@ -57,30 +57,30 @@ cdef class Transform: if self.thisptr: free(self.thisptr) - def getRotation(self): - return mat3f_to_numpy(self.thisptr.getRotation()) +# def getRotation(self): +# return mat3d_to_numpy(self.thisptr.getRotation()) - def getTranslation(self): - return vec3f_to_numpy(self.thisptr.getTranslation()) +# def getTranslation(self): +# return vec3d_to_numpy(self.thisptr.getTranslation()) - def getQuatRotation(self): - return quaternion3f_to_numpy(self.thisptr.getQuatRotation()) +# def getQuatRotation(self): +# return quaternion3d_to_numpy(self.thisptr.getQuatRotation()) - def setRotation(self, R): - self.thisptr.setRotation(numpy_to_mat3f(R)) +# def setRotation(self, R): +# self.thisptr.setRotation(numpy_to_mat3d(R)) - def setTranslation(self, T): - self.thisptr.setTranslation(numpy_to_vec3f(T)) +# def setTranslation(self, T): +# self.thisptr.setTranslation(numpy_to_vec3d(T)) - def setQuatRotation(self, q): - self.thisptr.setQuatRotation(numpy_to_quaternion3f(q)) +# def setQuatRotation(self, q): +# self.thisptr.setQuatRotation(numpy_to_quaternion3d(q)) ############################################################################### # Collision objects and geometries ############################################################################### cdef class CollisionObject: - cdef defs.CollisionObject *thisptr + cdef defs.CollisionObjectd *thisptr cdef defs.PyObject *geom cdef bool _no_instance @@ -92,9 +92,9 @@ cdef class CollisionObject: self._no_instance = _no_instance if geom.getNodeType() is not None and not self._no_instance: if tf is not None: - self.thisptr = new defs.CollisionObject(defs.shared_ptr[defs.CollisionGeometry](geom.thisptr), deref(tf.thisptr)) + self.thisptr = new defs.CollisionObjectd(defs.shared_ptr[defs.CollisionGeometryd](geom.thisptr), deref(tf.thisptr)) else: - self.thisptr = new defs.CollisionObject(defs.shared_ptr[defs.CollisionGeometry](geom.thisptr)) + self.thisptr = new defs.CollisionObjectd(defs.shared_ptr[defs.CollisionGeometryd](geom.thisptr)) self.thisptr.setUserData( self.geom) # Save the python geometry object for later retrieval else: if not self._no_instance: @@ -112,24 +112,24 @@ cdef class CollisionObject: return self.thisptr.getNodeType() def getTranslation(self): - return vec3f_to_numpy(self.thisptr.getTranslation()) + return vec3d_to_numpy(self.thisptr.getTranslation()) def setTranslation(self, vec): - self.thisptr.setTranslation(numpy_to_vec3f(vec)) + self.thisptr.setTranslation(numpy_to_vec3d(vec)) self.thisptr.computeAABB() def getRotation(self): - return mat3f_to_numpy(self.thisptr.getRotation()) + return mat3d_to_numpy(self.thisptr.getRotation()) - def setRotation(self, mat): - self.thisptr.setRotation(numpy_to_mat3f(mat)) - self.thisptr.computeAABB() +# def setRotation(self, mat): +# self.thisptr.setRotation(numpy_to_mat3d(mat)) +# self.thisptr.computeAABB() - def getQuatRotation(self): - return quaternion3f_to_numpy(self.thisptr.getQuatRotation()) +# def getQuatRotation(self): +# return quaternion3d_to_numpy(self.thisptr.getQuatRotation()) def setQuatRotation(self, q): - self.thisptr.setQuatRotation(numpy_to_quaternion3f(q)) + self.thisptr.setQuatRotation(numpy_to_quaternion3d(q)) self.thisptr.computeAABB() def getTransform(self): @@ -151,7 +151,7 @@ cdef class CollisionObject: return self.thisptr.isUncertain() cdef class CollisionGeometry: - cdef defs.CollisionGeometry *thisptr + cdef defs.CollisionGeometryd *thisptr def __cinit__(self): pass @@ -175,7 +175,7 @@ cdef class CollisionGeometry: property aabb_center: def __get__(self): if self.thisptr: - return vec3f_to_numpy(self.thisptr.aabb_center) + return vec3d_to_numpy(self.thisptr.aabb_center) else: return None def __set__(self, value): @@ -188,153 +188,153 @@ cdef class CollisionGeometry: cdef class TriangleP(CollisionGeometry): def __cinit__(self, a, b, c): - self.thisptr = new defs.TriangleP(numpy_to_vec3f(a), numpy_to_vec3f(b), numpy_to_vec3f(c)) + self.thisptr = new defs.TrianglePd(numpy_to_vec3d(a), numpy_to_vec3d(b), numpy_to_vec3d(c)) property a: def __get__(self): - return vec3f_to_numpy(( self.thisptr).a) + return vec3d_to_numpy(( self.thisptr).a) def __set__(self, value): - ( self.thisptr).a[0] = value[0] - ( self.thisptr).a[1] = value[1] - ( self.thisptr).a[2] = value[2] + ( self.thisptr).a[0] = value[0] + ( self.thisptr).a[1] = value[1] + ( self.thisptr).a[2] = value[2] property b: def __get__(self): - return vec3f_to_numpy(( self.thisptr).b) + return vec3d_to_numpy(( self.thisptr).b) def __set__(self, value): - ( self.thisptr).b[0] = value[0] - ( self.thisptr).b[1] = value[1] - ( self.thisptr).b[2] = value[2] + ( self.thisptr).b[0] = value[0] + ( self.thisptr).b[1] = value[1] + ( self.thisptr).b[2] = value[2] property c: def __get__(self): - return vec3f_to_numpy(( self.thisptr).c) + return vec3d_to_numpy(( self.thisptr).c) def __set__(self, value): - ( self.thisptr).c[0] = value[0] - ( self.thisptr).c[1] = value[1] - ( self.thisptr).c[2] = value[2] + ( self.thisptr).c[0] = value[0] + ( self.thisptr).c[1] = value[1] + ( self.thisptr).c[2] = value[2] cdef class Box(CollisionGeometry): def __cinit__(self, x, y, z): - self.thisptr = new defs.Box(x, y, z) + self.thisptr = new defs.Boxd(x, y, z) property side: def __get__(self): - return vec3f_to_numpy(( self.thisptr).side) + return vec3d_to_numpy(( self.thisptr).side) def __set__(self, value): - ( self.thisptr).side[0] = value[0] - ( self.thisptr).side[1] = value[1] - ( self.thisptr).side[2] = value[2] + ( self.thisptr).side[0] = value[0] + ( self.thisptr).side[1] = value[1] + ( self.thisptr).side[2] = value[2] cdef class Sphere(CollisionGeometry): def __cinit__(self, radius): - self.thisptr = new defs.Sphere(radius) + self.thisptr = new defs.Sphered(radius) property radius: def __get__(self): - return ( self.thisptr).radius + return ( self.thisptr).radius def __set__(self, value): - ( self.thisptr).radius = value + ( self.thisptr).radius = value cdef class Ellipsoid(CollisionGeometry): def __cinit__(self, a, b, c): - self.thisptr = new defs.Ellipsoid( a, b, c) + self.thisptr = new defs.Ellipsoidd( a, b, c) property radii: def __get__(self): - return vec3f_to_numpy(( self.thisptr).radii) + return vec3d_to_numpy(( self.thisptr).radii) def __set__(self, values): - ( self.thisptr).radii = numpy_to_vec3f(values) + ( self.thisptr).radii = numpy_to_vec3d(values) cdef class Capsule(CollisionGeometry): def __cinit__(self, radius, lz): - self.thisptr = new defs.Capsule(radius, lz) + self.thisptr = new defs.Capsuled(radius, lz) property radius: def __get__(self): - return ( self.thisptr).radius + return ( self.thisptr).radius def __set__(self, value): - ( self.thisptr).radius = value + ( self.thisptr).radius = value property lz: def __get__(self): - return ( self.thisptr).lz + return ( self.thisptr).lz def __set__(self, value): - ( self.thisptr).lz = value + ( self.thisptr).lz = value cdef class Cone(CollisionGeometry): def __cinit__(self, radius, lz): - self.thisptr = new defs.Cone(radius, lz) + self.thisptr = new defs.Coned(radius, lz) property radius: def __get__(self): - return ( self.thisptr).radius + return ( self.thisptr).radius def __set__(self, value): - ( self.thisptr).radius = value + ( self.thisptr).radius = value property lz: def __get__(self): - return ( self.thisptr).lz + return ( self.thisptr).lz def __set__(self, value): - ( self.thisptr).lz = value + ( self.thisptr).lz = value cdef class Cylinder(CollisionGeometry): def __cinit__(self, radius, lz): - self.thisptr = new defs.Cylinder(radius, lz) + self.thisptr = new defs.Cylinderd(radius, lz) property radius: def __get__(self): - return ( self.thisptr).radius + return ( self.thisptr).radius def __set__(self, value): - ( self.thisptr).radius = value + ( self.thisptr).radius = value property lz: def __get__(self): - return ( self.thisptr).lz + return ( self.thisptr).lz def __set__(self, value): - ( self.thisptr).lz = value + ( self.thisptr).lz = value cdef class Halfspace(CollisionGeometry): def __cinit__(self, n, d): - self.thisptr = new defs.Halfspace(defs.Vec3f( n[0], + self.thisptr = new defs.Halfspaced(defs.Vector3d( n[0], n[1], n[2]), d) property n: def __get__(self): - return vec3f_to_numpy(( self.thisptr).n) + return vec3d_to_numpy(( self.thisptr).n) def __set__(self, value): - ( self.thisptr).n[0] = value[0] - ( self.thisptr).n[1] = value[1] - ( self.thisptr).n[2] = value[2] + ( self.thisptr).n[0] = value[0] + ( self.thisptr).n[1] = value[1] + ( self.thisptr).n[2] = value[2] property d: def __get__(self): - return ( self.thisptr).d + return ( self.thisptr).d def __set__(self, value): - ( self.thisptr).d = value + ( self.thisptr).d = value cdef class Plane(CollisionGeometry): def __cinit__(self, n, d): - self.thisptr = new defs.Plane(defs.Vec3f( n[0], + self.thisptr = new defs.Planed(defs.Vector3d( n[0], n[1], n[2]), d) property n: def __get__(self): - return vec3f_to_numpy(( self.thisptr).n) + return vec3d_to_numpy(( self.thisptr).n) def __set__(self, value): - ( self.thisptr).n[0] = value[0] - ( self.thisptr).n[1] = value[1] - ( self.thisptr).n[2] = value[2] + ( self.thisptr).n[0] = value[0] + ( self.thisptr).n[1] = value[1] + ( self.thisptr).n[2] = value[2] property d: def __get__(self): - return ( self.thisptr).d + return ( self.thisptr).d def __set__(self, value): - ( self.thisptr).d = value + ( self.thisptr).d = value cdef class BVHModel(CollisionGeometry): def __cinit__(self): @@ -355,20 +355,20 @@ cdef class BVHModel(CollisionGeometry): return n def addVertex(self, x, y, z): - n = ( self.thisptr).addVertex(defs.Vec3f( x, y, z)) + n = ( self.thisptr).addVertex(defs.Vector3d( x, y, z)) return self._check_ret_value(n) def addTriangle(self, v1, v2, v3): - n = ( self.thisptr).addTriangle(numpy_to_vec3f(v1), - numpy_to_vec3f(v2), - numpy_to_vec3f(v3)) + n = ( self.thisptr).addTriangle(numpy_to_vec3d(v1), + numpy_to_vec3d(v2), + numpy_to_vec3d(v3)) return self._check_ret_value(n) def addSubModel(self, verts, triangles): - cdef vector[defs.Vec3f] ps + cdef vector[defs.Vector3d] ps cdef vector[defs.Triangle] tris for vert in verts: - ps.push_back(numpy_to_vec3f(vert)) + ps.push_back(numpy_to_vec3d(vert)) for tri in triangles: tris.push_back(defs.Triangle( tri[0], tri[1], tri[2])) n = ( self.thisptr).addSubModel(ps, tris) @@ -406,7 +406,7 @@ cdef class OcTree(CollisionGeometry): self.tree = new octomap.OcTree(r) self.tree.readBinaryData(ss) - self.thisptr = new defs.OcTree(defs.shared_ptr[octomap.OcTree](self.tree)) + self.thisptr = new defs.OcTreed(defs.shared_ptr[octomap.OcTree](self.tree)) ############################################################################### @@ -414,11 +414,11 @@ cdef class OcTree(CollisionGeometry): ############################################################################### cdef class DynamicAABBTreeCollisionManager: - cdef defs.DynamicAABBTreeCollisionManager *thisptr + cdef defs.DynamicAABBTreeCollisionManagerd *thisptr cdef list objs def __cinit__(self): - self.thisptr = new defs.DynamicAABBTreeCollisionManager() + self.thisptr = new defs.DynamicAABBTreeCollisionManagerd() self.objs = [] def __dealloc__(self): @@ -426,7 +426,7 @@ cdef class DynamicAABBTreeCollisionManager: del self.thisptr def registerObjects(self, other_objs): - cdef vector[defs.CollisionObject*] pobjs + cdef vector[defs.CollisionObjectd*] pobjs for obj in other_objs: self.objs.append(obj) pobjs.push_back(( obj).thisptr) @@ -445,7 +445,7 @@ cdef class DynamicAABBTreeCollisionManager: self.thisptr.setup() def update(self, arg=None): - cdef vector[defs.CollisionObject*] objs + cdef vector[defs.CollisionObjectd*] objs if hasattr(arg, "__len__"): for a in arg: objs.push_back(( a).thisptr) @@ -471,18 +471,18 @@ cdef class DynamicAABBTreeCollisionManager: else: raise ValueError - def distance(self, *args): - if len(args) == 2 and inspect.isroutine(args[1]): - fn = DistanceFunction(args[1], args[0]) - self.thisptr.distance( fn, DistanceCallBack) - elif len(args) == 3 and isinstance(args[0], DynamicAABBTreeCollisionManager): - fn = DistanceFunction(args[2], args[1]) - self.thisptr.distance(( args[0]).thisptr, fn, DistanceCallBack) - elif len(args) == 3 and inspect.isroutine(args[2]): - fn = DistanceFunction(args[2], args[1]) - self.thisptr.distance(( args[0]).thisptr, fn, DistanceCallBack) - else: - raise ValueError +# def distance(self, *args): +# if len(args) == 2 and inspect.isroutine(args[1]): +# fn = DistanceFunction(args[1], args[0]) +# self.thisptr.distance( fn, DistanceCallBack) +# elif len(args) == 3 and isinstance(args[0], DynamicAABBTreeCollisionManager): +# fn = DistanceFunction(args[2], args[1]) +# self.thisptr.distance(( args[0]).thisptr, fn, DistanceCallBack) +# elif len(args) == 3 and inspect.isroutine(args[2]): +# fn = DistanceFunction(args[2], args[1]) +# self.thisptr.distance(( args[0]).thisptr, fn, DistanceCallBack) +# else: +# raise ValueError def clear(self): self.thisptr.clear() @@ -547,10 +547,10 @@ def collide(CollisionObject o1, CollisionObject o2, if result is None: result = CollisionResult() - cdef defs.CollisionResult cresult + cdef defs.CollisionResultd cresult cdef size_t ret = defs.collide(o1.thisptr, o2.thisptr, - defs.CollisionRequest( + defs.CollisionRequestd( request.num_max_contacts, request.enable_contact, request.num_max_cost_sources, @@ -562,12 +562,12 @@ def collide(CollisionObject o1, CollisionObject o2, result.is_collision = result.is_collision or cresult.isCollision() - cdef vector[defs.Contact] contacts + cdef vector[defs.Contactd] contacts cresult.getContacts(contacts) for idx in range(contacts.size()): result.contacts.append(c_to_python_contact(contacts[idx], o1, o2)) - cdef vector[defs.CostSource] costs + cdef vector[defs.CostSourced] costs cresult.getCostSources(costs) for idx in range(costs.size()): result.cost_sources.append(c_to_python_costsource(costs[idx])) @@ -583,13 +583,13 @@ def continuousCollide(CollisionObject o1, Transform tf1_end, if result is None: result = ContinuousCollisionResult() - cdef defs.ContinuousCollisionResult cresult + cdef defs.ContinuousCollisionResultd cresult - cdef defs.FCL_REAL ret = defs.continuousCollide(o1.thisptr, deref(tf1_end.thisptr), + cdef double ret = defs.continuousCollide(o1.thisptr, deref(tf1_end.thisptr), o2.thisptr, deref(tf2_end.thisptr), - defs.ContinuousCollisionRequest( + defs.ContinuousCollisionRequestd( request.num_max_iterations, - request.toc_err, + request.toc_err, request.ccd_motion_type, request.gjk_solver_type, request.ccd_solver_type, @@ -601,31 +601,31 @@ def continuousCollide(CollisionObject o1, Transform tf1_end, result.time_of_contact = min(cresult.time_of_contact, result.time_of_contact) return ret -def distance(CollisionObject o1, CollisionObject o2, - request = None, result=None): - - if request is None: - request = DistanceRequest() - if result is None: - result = DistanceResult() - - cdef defs.DistanceResult cresult - - cdef double dis = defs.distance(o1.thisptr, o2.thisptr, - defs.DistanceRequest( - request.enable_nearest_points, - request.gjk_solver_type - ), - cresult) - - result.min_distance = min(cresult.min_distance, result.min_distance) - result.nearest_points = [vec3f_to_numpy(cresult.nearest_points[0]), - vec3f_to_numpy(cresult.nearest_points[1])] - result.o1 = c_to_python_collision_geometry(cresult.o1, o1, o2) - result.o2 = c_to_python_collision_geometry(cresult.o2, o1, o2) - result.b1 = cresult.b1 - result.b2 = cresult.b2 - return dis +#def distance(CollisionObject o1, CollisionObject o2, +# request = None, result=None): +# +# if request is None: +# request = DistanceRequest() +# if result is None: +# result = DistanceResult() +# +# cdef defs.DistanceResultd cresult +# +# cdef double dis = defs.distance(o1.thisptr, o2.thisptr, +# defs.DistanceRequestd( +# request.enable_nearest_points, +# request.gjk_solver_type +# ), +# cresult) +# +# result.min_distance = min(cresult.min_distance, result.min_distance) +# result.nearest_points = [vec3d_to_numpy(cresult.nearest_points[0]), +# vec3d_to_numpy(cresult.nearest_points[1])] +# result.o1 = c_to_python_collision_geometry(cresult.o1, o1, o2) +# result.o2 = c_to_python_collision_geometry(cresult.o2, o1, o2) +# result.b1 = cresult.b1 +# result.b2 = cresult.b2 +# return dis ############################################################################### # Collision and Distance Callback Functions @@ -651,9 +651,9 @@ def defaultDistanceCallback(CollisionObject o1, CollisionObject o2, cdata): if cdata.done: return True, result.min_distance - - distance(o1, o2, request, result) - +# +# distance(o1, o2, request, result) +# dist = result.min_distance if dist <= 0: @@ -670,7 +670,7 @@ cdef class CollisionFunction: self.py_func = py_func self.py_args = py_args - cdef bool eval_func(self, defs.CollisionObject*o1, defs.CollisionObject*o2): + cdef bool eval_func(self, defs.CollisionObjectd*o1, defs.CollisionObjectd*o2): cdef object py_r = defs.PyObject_CallObject(self.py_func, (copy_ptr_collision_object(o1), copy_ptr_collision_object(o2), @@ -686,18 +686,18 @@ cdef class DistanceFunction: self.py_func = py_func self.py_args = py_args - cdef bool eval_func(self, defs.CollisionObject*o1, defs.CollisionObject*o2, defs.FCL_REAL& dist): + cdef bool eval_func(self, defs.CollisionObjectd*o1, defs.CollisionObjectd*o2, double& dist): cdef object py_r = defs.PyObject_CallObject(self.py_func, (copy_ptr_collision_object(o1), copy_ptr_collision_object(o2), self.py_args)) - (&dist)[0] = py_r[1] + (&dist)[0] = py_r[1] return py_r[0] -cdef inline bool CollisionCallBack(defs.CollisionObject*o1, defs.CollisionObject*o2, void*cdata): +cdef inline bool CollisionCallBack(defs.CollisionObjectd*o1, defs.CollisionObjectd*o2, void*cdata): return ( cdata).eval_func(o1, o2) -cdef inline bool DistanceCallBack(defs.CollisionObject*o1, defs.CollisionObject*o2, void*cdata, defs.FCL_REAL& dist): +cdef inline bool DistanceCallBack(defs.CollisionObjectd*o1, defs.CollisionObjectd*o2, void*cdata, double& dist): return ( cdata).eval_func(o1, o2, dist) @@ -705,56 +705,56 @@ cdef inline bool DistanceCallBack(defs.CollisionObject*o1, defs.CollisionObject* # Helper Functions ############################################################################### -cdef quaternion3f_to_numpy(defs.Quaternion3f q): - return numpy.array([q.getW(), q.getX(), q.getY(), q.getZ()]) +#cdef quaternion3d_to_numpy(defs.Quaterniond q): +# return numpy.array([q.getW(), q.getX(), q.getY(), q.getZ()]) -cdef defs.Quaternion3f numpy_to_quaternion3f(a): - return defs.Quaternion3f( a[0], a[1], a[2], a[3]) +cdef defs.Quaterniond numpy_to_quaternion3d(a): + return defs.Quaterniond( a[0], a[1], a[2], a[3]) -cdef vec3f_to_numpy(defs.Vec3f vec): +cdef vec3d_to_numpy(defs.Vector3d vec): return numpy.array([vec[0], vec[1], vec[2]]) -cdef defs.Vec3f numpy_to_vec3f(a): - return defs.Vec3f( a[0], a[1], a[2]) +cdef defs.Vector3d numpy_to_vec3d(a): + return defs.Vector3d( a[0], a[1], a[2]) -cdef mat3f_to_numpy(defs.Matrix3f m): +cdef mat3d_to_numpy(defs.Matrix3d m): return numpy.array([[m(0,0), m(0,1), m(0,2)], [m(1,0), m(1,1), m(1,2)], [m(2,0), m(2,1), m(2,2)]]) -cdef defs.Matrix3f numpy_to_mat3f(a): - return defs.Matrix3f( a[0][0], a[0][1], a[0][2], - a[1][0], a[1][1], a[1][2], - a[2][0], a[2][1], a[2][2]) +#cdef defs.Matrix3d numpy_to_mat3d(a): +# return defs.Matrix3d( a[0][0], a[0][1], a[0][2], +# a[1][0], a[1][1], a[1][2], +# a[2][0], a[2][1], a[2][2]) -cdef c_to_python_collision_geometry(defs.const_CollisionGeometry*geom, CollisionObject o1, CollisionObject o2): - cdef CollisionGeometry o1_py_geom = (( o1.thisptr).getUserData()) - cdef CollisionGeometry o2_py_geom = (( o2.thisptr).getUserData()) - if geom == o1_py_geom.thisptr: +cdef c_to_python_collision_geometry(defs.const_CollisionGeometryd*geom, CollisionObject o1, CollisionObject o2): + cdef CollisionGeometry o1_py_geom = (( o1.thisptr).getUserData()) + cdef CollisionGeometry o2_py_geom = (( o2.thisptr).getUserData()) + if geom == o1_py_geom.thisptr: return o1_py_geom else: return o2_py_geom -cdef c_to_python_contact(defs.Contact contact, CollisionObject o1, CollisionObject o2): +cdef c_to_python_contact(defs.Contactd contact, CollisionObject o1, CollisionObject o2): c = Contact() c.o1 = c_to_python_collision_geometry(contact.o1, o1, o2) c.o2 = c_to_python_collision_geometry(contact.o2, o1, o2) c.b1 = contact.b1 c.b2 = contact.b2 - c.normal = vec3f_to_numpy(contact.normal) - c.pos = vec3f_to_numpy(contact.pos) + c.normal = vec3d_to_numpy(contact.normal) + c.pos = vec3d_to_numpy(contact.pos) c.penetration_depth = contact.penetration_depth return c -cdef c_to_python_costsource(defs.CostSource cost_source): +cdef c_to_python_costsource(defs.CostSourced cost_source): c = CostSource() - c.aabb_min = vec3f_to_numpy(cost_source.aabb_min) - c.aabb_max = vec3f_to_numpy(cost_source.aabb_max) + c.aabb_min = vec3d_to_numpy(cost_source.aabb_min) + c.aabb_max = vec3d_to_numpy(cost_source.aabb_max) c.cost_density = cost_source.cost_density c.total_cost = cost_source.total_cost return c -cdef copy_ptr_collision_object(defs.CollisionObject*cobj): +cdef copy_ptr_collision_object(defs.CollisionObjectd*cobj): geom = cobj.getUserData() co = CollisionObject(geom, _no_instance=True) ( co).thisptr = cobj diff --git a/fcl/fcl_defs.pxd b/fcl/fcl_defs.pxd index d5461fd..50dd926 100644 --- a/fcl/fcl_defs.pxd +++ b/fcl/fcl_defs.pxd @@ -18,136 +18,138 @@ cdef extern from "Python.h": # shared_ptr(T*) except + # T* get() -cdef extern from "fcl/data_types.h" namespace "fcl": - ctypedef double FCL_REAL - -cdef extern from "fcl/math/vec_3f.h" namespace "fcl": - cdef cppclass Vec3f: - Vec3f() except + - Vec3f(FCL_REAL x, FCL_REAL y, FCL_REAL z) except + - FCL_REAL& operator[](size_t i) - -cdef extern from "fcl/math/matrix_3f.h" namespace "fcl": - cdef cppclass Matrix3f: - Matrix3f() except + - Matrix3f(FCL_REAL xx, FCL_REAL xy, FCL_REAL xz, - FCL_REAL yx, FCL_REAL yy, FCL_REAL yz, - FCL_REAL zx, FCL_REAL zy, FCL_REAL zz) except + - FCL_REAL operator()(size_t i, size_t j) - -cdef extern from "fcl/math/transform.h" namespace "fcl": - cdef cppclass Quaternion3f: - Quaternion3f() except + - Quaternion3f(FCL_REAL a, FCL_REAL b, - FCL_REAL c, FCL_REAL d) except + - void fromRotation(Matrix3f& R) - void fromAxisAngle(Vec3f& axis, FCL_REAL angle) - FCL_REAL& getW() - FCL_REAL& getX() - FCL_REAL& getY() - FCL_REAL& getZ() - - cdef cppclass Transform3f: - Transform3f() except + - Transform3f(Matrix3f& R_, Vec3f& T_) - Transform3f(Quaternion3f& q_, Vec3f& T_) - Transform3f(Matrix3f& R_) - Transform3f(Quaternion3f& q_) - Transform3f(Vec3f& T_) - Transform3f(Transform3f& tf_) - Matrix3f& getRotation() - Vec3f& getTranslation() - Quaternion3f& getQuatRotation() - void setRotation(Matrix3f& R_) - void setTranslation(Vec3f& T_) - void setQuatRotation(Quaternion3f & q_) - -cdef extern from "fcl/collision_data.h" namespace "fcl": - +cdef extern from "fcl/common/types.h" namespace "fcl": + cdef cppclass Vector3d: + Vector3d() except + + Vector3d(double x, double y, double z) except + + double& operator[](size_t i) + + cdef cppclass Matrix3d: + Matrix3d() except + +# Matrix3d(double xx, double xy, double xz, +# double yx, double yy, double yz, +# double zx, double zy, double zz) except + + double operator()(size_t i, size_t j) + + cdef cppclass Quaterniond: + Quaterniond() except + + Quaterniond(double a, double b, + double c, double d) except + + void fromRotation(Matrix3d& R) + void fromAxisAngle(Vector3d& axis, double angle) +# double& getW() +# double& getX() +# double& getY() +# double& getZ() + + cdef cppclass Transform3d: + Transform3d() except + +# Transform3d(Matrix3d& R_, Vector3d& T_) +# Transform3d(Quaterniond& q_, Vector3d& T_) +# Transform3d(Matrix3d& R_) +# Transform3d(Quaterniond& q_) +# Transform3d(Vector3d& T_) + Transform3d(Transform3d& tf_) +# Matrix3d& getRotation() +# Vector3d& getTranslation() +# Quaterniond& getQuatRotation() +# void setRotation(Matrix3d& R_) +# void setTranslation(Vector3d& T_) +# void setQuatRotation(Quaterniond & q_) + +cdef extern from "fcl/narrowphase/continuous_collision_request.h" namespace "fcl": cdef enum CCDMotionType: CCDM_TRANS, CCDM_LINEAR, CCDM_SCREW, CCDM_SPLINE cdef enum CCDSolverType: CCDC_NAIVE, CCDC_CONSERVATIVE_ADVANCEMENT, CCDC_RAY_SHOOTING, CCDC_POLYNOMIAL_SOLVER + cdef cppclass ContinuousCollisionRequestd: + size_t num_max_iterations_, + double toc_err_, + CCDMotionType ccd_motion_type_, + GJKSolverType gjk_solver_type_, + GJKSolverType ccd_solver_type_ + + ContinuousCollisionRequestd( + size_t num_max_iterations_, + double toc_err_, + CCDMotionType ccd_motion_type_, + GJKSolverType gjk_solver_type_, + CCDSolverType ccd_solver_type_ ) + +cdef extern from "fcl/narrowphase/gjk_solver_type.h" namespace "fcl": cdef enum GJKSolverType: GST_LIBCCD, GST_INDEP - cdef cppclass Contact: - CollisionGeometry *o1 - CollisionGeometry *o2 +cdef extern from "fcl/narrowphase/contact.h" namespace "fcl": + cdef cppclass Contactd: + CollisionGeometryd *o1 + CollisionGeometryd *o2 int b1 int b2 - Vec3f normal - Vec3f pos - FCL_REAL penetration_depth - Contact() except + - Contact(CollisionGeometry* o1_, - CollisionGeometry* o2_, + Vector3d normal + Vector3d pos + double penetration_depth + Contactd() except + + Contactd(CollisionGeometryd* o1_, + CollisionGeometryd* o2_, int b1_, int b2_) except + - cdef cppclass CostSource: - Vec3f aabb_min - Vec3f aabb_max - FCL_REAL cost_density - FCL_REAL total_cost +cdef extern from "fcl/narrowphase/cost_source.h" namespace "fcl": + cdef cppclass CostSourced: + Vector3d aabb_min + Vector3d aabb_max + double cost_density + double total_cost - cdef cppclass CollisionResult: - CollisionResult() except + +cdef extern from "fcl/narrowphase/collision_result.h" namespace "fcl": + cdef cppclass CollisionResultd: + CollisionResultd() except + bool isCollision() - void getContacts(vector[Contact]& contacts_) - void getCostSources(vector[CostSource]& cost_sources_) + void getContacts(vector[Contactd]& contacts_) + void getCostSources(vector[CostSourced]& cost_sources_) - cdef cppclass ContinuousCollisionResult: - ContinuousCollisionResult() except + +cdef extern from "fcl/narrowphase/continuous_collision_result.h" namespace "fcl": + cdef cppclass ContinuousCollisionResultd: + ContinuousCollisionResultd() except + bool is_collide - FCL_REAL time_of_contact - Transform3f contact_tf1, contact_tf2 + double time_of_contact + Transform3d contact_tf1, contact_tf2 - cdef cppclass CollisionRequest: +cdef extern from "fcl/narrowphase/collision_request.h" namespace "fcl": + cdef cppclass CollisionRequestd: size_t num_max_contacts bool enable_contact size_t num_max_cost_sources bool enable_cost bool use_approximate_cost GJKSolverType gjk_solver_type - CollisionRequest(size_t num_max_contacts_, + CollisionRequestd(size_t num_max_contacts_, bool enable_contact_, size_t num_max_cost_sources_, bool enable_cost_, bool use_approximate_cost_, GJKSolverType gjk_solver_type_) - cdef cppclass ContinuousCollisionRequest: - size_t num_max_iterations_, - FCL_REAL toc_err_, - CCDMotionType ccd_motion_type_, - GJKSolverType gjk_solver_type_, - GJKSolverType ccd_solver_type_ - - ContinuousCollisionRequest( - size_t num_max_iterations_, - FCL_REAL toc_err_, - CCDMotionType ccd_motion_type_, - GJKSolverType gjk_solver_type_, - CCDSolverType ccd_solver_type_ ) - - cdef cppclass DistanceResult: - FCL_REAL min_distance - Vec3f* nearest_points - CollisionGeometry* o1 - CollisionGeometry* o2 +cdef extern from "fcl/narrowphase/distance_result.h" namespace "fcl": + cdef cppclass DistanceResultd: + double min_distance + Vector3d* nearest_points + CollisionGeometryd* o1 + CollisionGeometryd* o2 int b1 int b2 - DistanceResult(FCL_REAL min_distance_) except + - DistanceResult() except + + DistanceResultd(double min_distance_) except + + DistanceResultd() except + - cdef cppclass DistanceRequest: +cdef extern from "fcl/narrowphase/distance_request.h" namespace "fcl": + cdef cppclass DistanceRequestd: bool enable_nearest_points GJKSolverType gjk_solver_type - DistanceRequest(bool enable_nearest_points_, GJKSolverType gjk_solver_type_) except + + DistanceRequestd(bool enable_nearest_points_, GJKSolverType gjk_solver_type_) except + -cdef extern from "fcl/collision_object.h" namespace "fcl": +cdef extern from "fcl/geometry/collision_geometry.h" namespace "fcl": cdef enum OBJECT_TYPE: OT_UNKNOWN, OT_BVH, OT_GEOM, OT_OCTREE, OT_COUNT cdef enum NODE_TYPE: @@ -155,34 +157,37 @@ cdef extern from "fcl/collision_object.h" namespace "fcl": GEOM_BOX, GEOM_SPHERE, GEOM_ELLIPSOID, GEOM_CAPSULE, GEOM_CONE, GEOM_CYLINDER, GEOM_CONVEX, GEOM_PLANE, GEOM_HALFSPACE, GEOM_TRIANGLE, GEOM_OCTREE, NODE_COUNT - cdef cppclass CollisionGeometry: - CollisionGeometry() except + + cdef cppclass CollisionGeometryd: + CollisionGeometryd() except + OBJECT_TYPE getObjectType() NODE_TYPE getNodeType() void computeLocalAABB() - Vec3f aabb_center - FCL_REAL aabb_radius - FCL_REAL cost_density - FCL_REAL threshold_occupied - FCL_REAL threshold_free - - cdef cppclass CollisionObject: - CollisionObject() except + - CollisionObject(shared_ptr[CollisionGeometry]& cgeom_) except + - CollisionObject(shared_ptr[CollisionGeometry]& cgeom_, Transform3f& tf) except + + Vector3d aabb_center + double aabb_radius + double cost_density + double threshold_occupied + double threshold_free + + ctypedef CollisionGeometryd const_CollisionGeometryd "const fcl::CollisionGeometryd" + +cdef extern from "fcl/narrowphase/collision_object.h" namespace "fcl": + cdef cppclass CollisionObjectd: + CollisionObjectd() except + + CollisionObjectd(shared_ptr[CollisionGeometryd]& cgeom_) except + + CollisionObjectd(shared_ptr[CollisionGeometryd]& cgeom_, Transform3d& tf) except + OBJECT_TYPE getObjectType() NODE_TYPE getNodeType() - Vec3f& getTranslation() - Matrix3f& getRotation() - Quaternion3f& getQuatRotation() - Transform3f& getTransform() - CollisionGeometry* getCollisionGeometry() - void setTranslation(Vec3f& T) - void setRotation(Matrix3f& M) - void setQuatRotation(Quaternion3f& q) - void setTransform(Quaternion3f& q, Vec3f& T) - void setTransform(Matrix3f& q, Vec3f& T) - void setTransform(Transform3f& tf) + Vector3d& getTranslation() + Matrix3d& getRotation() + Quaterniond& getQuatRotation() + Transform3d& getTransform() + CollisionGeometryd* getCollisionGeometry() + void setTranslation(Vector3d& T) + void setRotation(Matrix3d& M) + void setQuatRotation(Quaterniond& q) + void setTransform(Quaterniond& q, Vector3d& T) + void setTransform(Matrix3d& q, Vector3d& T) + void setTransform(Transform3d& tf) void setUserData(void *data) void computeAABB() void *getUserData() @@ -190,82 +195,91 @@ cdef extern from "fcl/collision_object.h" namespace "fcl": bool isFree() bool isUncertain() - ctypedef CollisionGeometry const_CollisionGeometry "const fcl::CollisionGeometry" - ctypedef CollisionObject const_CollisionObject "const fcl::CollisionObject" - -cdef extern from "fcl/shape/geometric_shapes.h" namespace "fcl": - cdef cppclass ShapeBase(CollisionGeometry): - ShapeBase() except + - - cdef cppclass TriangleP(ShapeBase): - TriangleP(Vec3f& a_, Vec3f& b_, Vec3f& c_) except + - Vec3f a, b, c - - cdef cppclass Box(ShapeBase): - Box(FCL_REAL x, FCL_REAL y, FCL_REAL z) except + - Vec3f side - - cdef cppclass Sphere(ShapeBase): - Sphere(FCL_REAL radius_) except + - FCL_REAL radius - - cdef cppclass Ellipsoid(ShapeBase): - Ellipsoid(FCL_REAL a_, FCL_REAL b_, FCL_REAL c_) except + - Vec3f radii - - cdef cppclass Capsule(ShapeBase): - Capsule(FCL_REAL radius_, FCL_REAL lz_) except + - FCL_REAL radius - FCL_REAL lz - - cdef cppclass Cone(ShapeBase): - Cone(FCL_REAL radius_, FCL_REAL lz_) except + - FCL_REAL radius - FCL_REAL lz - - cdef cppclass Cylinder(ShapeBase): - Cylinder(FCL_REAL radius_, FCL_REAL lz_) except + - FCL_REAL radius - FCL_REAL lz - - cdef cppclass Convex(ShapeBase): - Convex(Vec3f* plane_nomals_, - FCL_REAL* plane_dis_, + ctypedef CollisionObjectd const_CollisionObjectd "const fcl::CollisionObjectd" + +cdef extern from "fcl/geometry/shape/shape_base.h" namespace "fcl": + cdef cppclass ShapeBased(CollisionGeometryd): + ShapeBased() except + + +cdef extern from "fcl/geometry/shape/triangle_p.h" namespace "fcl": + cdef cppclass TrianglePd(ShapeBased): + TrianglePd(Vector3d& a_, Vector3d& b_, Vector3d& c_) except + + Vector3d a, b, c + +cdef extern from "fcl/geometry/shape/box.h" namespace "fcl": + cdef cppclass Boxd(ShapeBased): + Boxd(double x, double y, double z) except + + Vector3d side + +cdef extern from "fcl/geometry/shape/sphere.h" namespace "fcl": + cdef cppclass Sphered(ShapeBased): + Sphered(double radius_) except + + double radius + +cdef extern from "fcl/geometry/shape/ellipsoid.h" namespace "fcl": + cdef cppclass Ellipsoidd(ShapeBased): + Ellipsoidd(double a_, double b_, double c_) except + + Vector3d radii + +cdef extern from "fcl/geometry/shape/capsule.h" namespace "fcl": + cdef cppclass Capsuled(ShapeBased): + Capsuled(double radius_, double lz_) except + + double radius + double lz + +cdef extern from "fcl/geometry/shape/cone.h" namespace "fcl": + cdef cppclass Coned(ShapeBased): + Coned(double radius_, double lz_) except + + double radius + double lz + +cdef extern from "fcl/geometry/shape/cylinder.h" namespace "fcl": + cdef cppclass Cylinderd(ShapeBased): + Cylinderd(double radius_, double lz_) except + + double radius + double lz + +cdef extern from "fcl/geometry/shape/convex.h" namespace "fcl": + cdef cppclass Convexd(ShapeBased): + Convexd(Vector3d* plane_nomals_, + double* plane_dis_, int num_planes, - Vec3f* points_, + Vector3d* points_, int num_points_, int* polygons_) except + - cdef cppclass Halfspace(ShapeBase): - Halfspace(Vec3f& n_, FCL_REAL d_) except + - Vec3f n - FCL_REAL d +cdef extern from "fcl/geometry/shape/halfspace.h" namespace "fcl": + cdef cppclass Halfspaced(ShapeBased): + Halfspaced(Vector3d& n_, double d_) except + + Vector3d n + double d - cdef cppclass Plane(ShapeBase): - Plane(Vec3f& n_, FCL_REAL d_) except + - Vec3f n - FCL_REAL d +cdef extern from "fcl/geometry/shape/plane.h" namespace "fcl": + cdef cppclass Planed(ShapeBased): + Planed(Vector3d& n_, double d_) except + + Vector3d n + double d -cdef extern from "fcl/broadphase/broadphase.h" namespace "fcl": - ctypedef bool (*CollisionCallBack)(CollisionObject* o1, CollisionObject* o2, void* cdata) - ctypedef bool (*DistanceCallBack)(CollisionObject* o1, CollisionObject* o2, void* cdata, FCL_REAL& dist) +cdef extern from "fcl/broadphase/broadphase_collision_manager.h" namespace "fcl": + ctypedef bool (*CollisionCallBack)(CollisionObjectd* o1, CollisionObjectd* o2, void* cdata) + ctypedef bool (*DistanceCallBack)(CollisionObjectd* o1, CollisionObjectd* o2, void* cdata, double& dist) cdef extern from "fcl/broadphase/broadphase_dynamic_AABB_tree.h" namespace "fcl": - cdef cppclass DynamicAABBTreeCollisionManager: - DynamicAABBTreeCollisionManager() except + - void registerObjects(vector[CollisionObject*]& other_objs) - void registerObject(CollisionObject* obj) - void unregisterObject(CollisionObject* obj) - void collide(DynamicAABBTreeCollisionManager* mgr, void* cdata, CollisionCallBack callback) - void distance(DynamicAABBTreeCollisionManager* mgr, void* cdata, DistanceCallBack callback) - void collide(CollisionObject* obj, void* cdata, CollisionCallBack callback) - void distance(CollisionObject* obj, void* cdata, DistanceCallBack callback) + cdef cppclass DynamicAABBTreeCollisionManagerd: + DynamicAABBTreeCollisionManagerd() except + + void registerObjects(vector[CollisionObjectd*]& other_objs) + void registerObject(CollisionObjectd* obj) + void unregisterObject(CollisionObjectd* obj) + void collide(DynamicAABBTreeCollisionManagerd* mgr, void* cdata, CollisionCallBack callback) +# void distance(DynamicAABBTreeCollisionManagerd* mgr, void* cdata, DistanceCallBack callback) + void collide(CollisionObjectd* obj, void* cdata, CollisionCallBack callback) +# void distance(CollisionObjectd* obj, void* cdata, DistanceCallBack callback) void collide(void* cdata, CollisionCallBack callback) - void distance(void* cdata, DistanceCallBack callback) +# void distance(void* cdata, DistanceCallBack callback) void setup() void update() - void update(CollisionObject* updated_obj) - void update(vector[CollisionObject*] updated_objs) + void update(CollisionObjectd* updated_obj) + void update(vector[CollisionObjectd*] updated_objs) void clear() bool empty() size_t size() @@ -277,42 +291,41 @@ cdef extern from "fcl/broadphase/broadphase_dynamic_AABB_tree.h" namespace "fcl" bool octree_as_geometry_collide bool octree_as_geometry_distance -cdef extern from "fcl/collision.h" namespace "fcl": - size_t collide(CollisionObject* o1, CollisionObject* o2, - CollisionRequest& request, - CollisionResult& result) +cdef extern from "fcl/narrowphase/collision.h" namespace "fcl": + size_t collide(CollisionObjectd* o1, CollisionObjectd* o2, + CollisionRequestd& request, + CollisionResultd& result) - size_t collide(CollisionGeometry* o1, Transform3f& tf1, - CollisionGeometry* o2, Transform3f& tf2, - CollisionRequest& request, - CollisionResult& result) + size_t collide(CollisionGeometryd* o1, Transform3d& tf1, + CollisionGeometryd* o2, Transform3d& tf2, + CollisionRequestd& request, + CollisionResultd& result) -cdef extern from "fcl/continuous_collision.h" namespace "fcl": - FCL_REAL continuousCollide(CollisionGeometry* o1, Transform3f& tf1_beg, Transform3f& tf1_end, - CollisionGeometry* o2, Transform3f& tf2_beg, Transform3f& tf2_end, - ContinuousCollisionRequest& request, - ContinuousCollisionResult& result) +cdef extern from "fcl/narrowphase/continuous_collision.h" namespace "fcl": + double continuousCollide(CollisionGeometryd* o1, Transform3d& tf1_beg, Transform3d& tf1_end, + CollisionGeometryd* o2, Transform3d& tf2_beg, Transform3d& tf2_end, + ContinuousCollisionRequestd& request, + ContinuousCollisionResultd& result) - FCL_REAL continuousCollide(CollisionObject* o1, Transform3f& tf1_end, - CollisionObject* o2, Transform3f& tf2_end, - ContinuousCollisionRequest& request, - ContinuousCollisionResult& result) + double continuousCollide(CollisionObjectd* o1, Transform3d& tf1_end, + CollisionObjectd* o2, Transform3d& tf2_end, + ContinuousCollisionRequestd& request, + ContinuousCollisionResultd& result) -cdef extern from "fcl/distance.h" namespace "fcl": - FCL_REAL distance(CollisionObject* o1, CollisionObject* o2, - DistanceRequest& request, DistanceResult& result) - FCL_REAL distance(CollisionGeometry* o1, Transform3f& tf1, - CollisionGeometry* o2, Transform3f& tf2, - DistanceRequest& request, DistanceResult& result) +cdef extern from "fcl/narrowphase/distance.h" namespace "fcl": + double distance(CollisionObjectd* o1, CollisionObjectd* o2, + DistanceRequestd& request, DistanceResultd& result) + double distance(CollisionGeometryd* o1, Transform3d& tf1, + CollisionGeometryd* o2, Transform3d& tf2, + DistanceRequestd& request, DistanceResultd& result) -cdef extern from "fcl/BVH/BVH_internal.h" namespace "fcl": +cdef extern from "fcl/geometry/BVH/BVH_internal.h" namespace "fcl": cdef enum BVHModelType: BVH_MODEL_UNKNOWN, # unknown model type BVH_MODEL_TRIANGLES, # triangle model BVH_MODEL_POINTCLOUD # point cloud model -cdef extern from "fcl/BVH/BVH_internal.h" namespace "fcl": cdef enum BVHReturnCode: BVH_OK = 0, # BVH is valid BVH_ERR_MODEL_OUT_OF_MEMORY = -1, # Cannot allocate memory for vertices and triangles @@ -325,7 +338,6 @@ cdef extern from "fcl/BVH/BVH_internal.h" namespace "fcl": BVH_ERR_UNKNOWN = -8 # Unknown failure -cdef extern from "fcl/BVH/BVH_internal.h" namespace "fcl": cdef enum BVHBuildState: BVH_BUILD_STATE_EMPTY, # empty state, immediately after constructor BVH_BUILD_STATE_BEGUN, # after beginModel(), state for adding geometry primitives @@ -334,36 +346,37 @@ cdef extern from "fcl/BVH/BVH_internal.h" namespace "fcl": BVH_BUILD_STATE_UPDATED, # after tree has been build for updated geometry, ready for ccd use BVH_BUILD_STATE_REPLACE_BEGUN, # after beginReplaceModel(), state for replacing geometry primitives -cdef extern from "fcl/data_types.h" namespace "fcl": +cdef extern from "fcl/math/triangle.h" namespace "fcl": cdef cppclass Triangle: Triangle() except + Triangle(size_t p1, size_t p2, size_t p3) except + size_t vids[3] -cdef extern from "fcl/BVH/BV_splitter.h" namespace "fcl": +# TODO what about these guys? +cdef extern from "fcl/geometry/BVH/detail/BV_splitter_base.h" namespace "fcl": cdef cppclass BVSplitterBase: pass -cdef extern from "fcl/BVH/BV_fitter.h" namespace "fcl": +cdef extern from "fcl/geometry/BVH/detail/BV_fitter_base.h" namespace "fcl": cdef cppclass BVFitterBase: pass -cdef extern from "fcl/BVH/BVH_model.h" namespace "fcl": +cdef extern from "fcl/geometry/BVH/BVH_model.h" namespace "fcl": # Cython only accepts type template parameters. # see https://groups.google.com/forum/#!topic/cython-users/xAZxdCFw6Xs - cdef cppclass BVHModel "fcl::BVHModel" ( CollisionGeometry ): + cdef cppclass BVHModel "fcl::BVHModel" ( CollisionGeometryd ): # Constructing an empty BVH BVHModel() except + BVHModel(BVHModel& other) except + # #Geometry point data - Vec3f* vertices + Vector3d* vertices # #Geometry triangle index data, will be NULL for point clouds Triangle* tri_indices # #Geometry point data in previous frame - Vec3f* prev_vertices + Vector3d* prev_vertices # #Number of triangles int num_tris @@ -383,16 +396,16 @@ cdef extern from "fcl/BVH/BVH_model.h" namespace "fcl": int beginModel(int num_tris_, int num_vertices_) - int addVertex(const Vec3f& p) + int addVertex(const Vector3d& p) - int addTriangle(const Vec3f& p1, const Vec3f& p2, const Vec3f& p3) + int addTriangle(const Vector3d& p1, const Vector3d& p2, const Vector3d& p3) - #int addSubModel(const std::vector& ps) - # void getCostSources(vector[CostSource]& cost_sources_) + #int addSubModel(const std::vector& ps) + # void getCostSources(vector[CostSourced]& cost_sources_) - #int addSubModel(const vector[Vec3f]& ps) + #int addSubModel(const vector[Vector3d]& ps) # - int addSubModel(const vector[Vec3f]& ps, const vector[Triangle]& ts) + int addSubModel(const vector[Vector3d]& ps, const vector[Triangle]& ts) int endModel() @@ -401,9 +414,9 @@ cdef extern from "fcl/BVH/BVH_model.h" namespace "fcl": # void computeLocalAABB() -cdef extern from "fcl/octree.h" namespace "fcl": - cdef cppclass OcTree(CollisionGeometry): +cdef extern from "fcl/geometry/octree/octree.h" namespace "fcl": + cdef cppclass OcTreed(CollisionGeometryd): # Constructing - OcTree(FCL_REAL resolution) except + - OcTree(shared_ptr[octomap.OcTree]& tree_) except + + OcTreed(double resolution) except + + OcTreed(shared_ptr[octomap.OcTree]& tree_) except + diff --git a/setup.py b/setup.py index 4dedd51..c00ce0b 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ platform_supported = True include_dirs = ['/usr/include', '/usr/local/include', - '/usr/include/eigen3'] + '/usr/local/include/eigen3'] lib_dirs = ['/usr/lib', '/usr/local/lib'] From bc62e9ceac81d36daa9116d601ffd43c18faf9dc Mon Sep 17 00:00:00 2001 From: Dmitry Neverov Date: Mon, 27 Apr 2020 19:22:40 +0900 Subject: [PATCH 02/20] Fixed Transform extension type: Vector3, Matrix3, Quaternion and Transform are now native Eigen objects in FCL, so helper functions were changed accordingly. --- fcl/fcl.pyx | 134 +++++++++++++++++++++++++++++------------------ fcl/fcl_defs.pxd | 35 +++++-------- 2 files changed, 96 insertions(+), 73 deletions(-) diff --git a/fcl/fcl.pyx b/fcl/fcl.pyx index c867aa7..a2d0a3f 100644 --- a/fcl/fcl.pyx +++ b/fcl/fcl.pyx @@ -16,6 +16,21 @@ cimport octomap_defs as octomap cimport std_defs as std from collision_data import Contact, CostSource, CollisionRequest, ContinuousCollisionRequest, CollisionResult, ContinuousCollisionResult, DistanceRequest, DistanceResult +""" +Eigen::Transform linear and translation parts are returned as Eigen::Block +It can be an rvalue and an lvalue, so in C++ you could assign something to translation() like: + `tf.translation() = (Vector3d (0., 0., 50));` +In python and cython however, a function call is never an lvalue, so we workaround with the following macro +""" +cdef extern from *: + """ + /* Verbatim C as a workaround for assingment to lvalue-returning functions*/ + #define ASSIGN(a, b) a = b + """ + void ASSIGN(defs.Vector3d&, defs.Vector3d) + void ASSIGN(defs.Matrix3d&, defs.Matrix3d) + #void ASSIGN[T](T&, T) # This doesn't work somehow + ############################################################################### # Transforms ############################################################################### @@ -25,31 +40,51 @@ cdef class Transform: def __cinit__(self, *args): if len(args) == 0: self.thisptr = new defs.Transform3d() + self.thisptr.setIdentity() elif len(args) == 1: if isinstance(args[0], Transform): self.thisptr = new defs.Transform3d(deref(( args[0]).thisptr)) -# else: -# data = numpy.array(args[0]) -# if data.shape == (3,3): -# self.thisptr = new defs.Transform3d(numpy_to_mat3d(data)) -# elif data.shape == (4,): -# self.thisptr = new defs.Transform3d(numpy_to_quaternion3d(data)) -# elif data.shape == (3,): -# self.thisptr = new defs.Transform3d(numpy_to_vec3d(data)) -# else: -# raise ValueError('Invalid input to Transform().') + else: + data = numpy.array(args[0]) + if data.shape == (3,3): + self.thisptr = new defs.Transform3d() + self.thisptr.setIdentity() + ASSIGN(self.thisptr.linear(), + numpy_to_mat3d(data)) + elif data.shape == (4,): + self.thisptr = new defs.Transform3d() + self.thisptr.setIdentity() + ASSIGN(self.thisptr.linear(), + numpy_to_quaternion3d(data).toRotationMatrix()) + elif data.shape == (3,): + self.thisptr = new defs.Transform3d() + self.thisptr.setIdentity() + ASSIGN(self.thisptr.translation(), + numpy_to_vec3d(data)) + else: + raise ValueError('Invalid input to Transform().') elif len(args) == 2: rot = numpy.array(args[0]) trans = numpy.array(args[1]).squeeze() if not trans.shape == (3,): raise ValueError('Translation must be (3,).') -# if rot.shape == (3,3): -# self.thisptr = new defs.Transform3d(numpy_to_mat3d(rot), numpy_to_vec3d(trans)) -# elif rot.shape == (4,): -# self.thisptr = new defs.Transform3d(numpy_to_quaternion3d(rot), numpy_to_vec3d(trans)) -# else: -# raise ValueError('Invalid input to Transform().') + if rot.shape == (3,3): + self.thisptr = new defs.Transform3d() + self.thisptr.setIdentity() + ASSIGN(self.thisptr.linear(), + numpy_to_mat3d(rot)) + ASSIGN(self.thisptr.translation(), + numpy_to_vec3d(trans)) + elif rot.shape == (4,): + self.thisptr = new defs.Transform3d() + self.thisptr.setIdentity() + ASSIGN(self.thisptr.linear(), + numpy_to_quaternion3d(rot).toRotationMatrix()) + ASSIGN(self.thisptr.translation(), + numpy_to_vec3d(trans)) + else: + raise ValueError('Invalid input to Transform().') else: raise ValueError('Too many arguments to Transform().') @@ -57,23 +92,27 @@ cdef class Transform: if self.thisptr: free(self.thisptr) -# def getRotation(self): -# return mat3d_to_numpy(self.thisptr.getRotation()) + def getRotation(self): + return mat3d_to_numpy(self.thisptr.linear()) -# def getTranslation(self): -# return vec3d_to_numpy(self.thisptr.getTranslation()) + def getTranslation(self): + return vec3d_to_numpy(self.thisptr.translation()) -# def getQuatRotation(self): -# return quaternion3d_to_numpy(self.thisptr.getQuatRotation()) + def getQuatRotation(self): + cdef defs.Quaterniond quaternion = defs.Quaterniond(self.thisptr.linear()) + return quaternion3d_to_numpy(quaternion) -# def setRotation(self, R): -# self.thisptr.setRotation(numpy_to_mat3d(R)) + def setRotation(self, R): + ASSIGN(self.thisptr.linear(), + numpy_to_mat3d(R)) -# def setTranslation(self, T): -# self.thisptr.setTranslation(numpy_to_vec3d(T)) + def setTranslation(self, T): + ASSIGN(self.thisptr.translation(), + numpy_to_vec3d(T)) -# def setQuatRotation(self, q): -# self.thisptr.setQuatRotation(numpy_to_quaternion3d(q)) + def setQuatRotation(self, q): + ASSIGN(self.thisptr.linear(), + numpy_to_quaternion3d(q).toRotationMatrix()) ############################################################################### # Collision objects and geometries @@ -121,12 +160,12 @@ cdef class CollisionObject: def getRotation(self): return mat3d_to_numpy(self.thisptr.getRotation()) -# def setRotation(self, mat): -# self.thisptr.setRotation(numpy_to_mat3d(mat)) -# self.thisptr.computeAABB() + def setRotation(self, mat): + self.thisptr.setRotation(numpy_to_mat3d(mat)) + self.thisptr.computeAABB() -# def getQuatRotation(self): -# return quaternion3d_to_numpy(self.thisptr.getQuatRotation()) + def getQuatRotation(self): + return quaternion3d_to_numpy(self.thisptr.getQuatRotation()) def setQuatRotation(self, q): self.thisptr.setQuatRotation(numpy_to_quaternion3d(q)) @@ -295,10 +334,8 @@ cdef class Cylinder(CollisionGeometry): ( self.thisptr).lz = value cdef class Halfspace(CollisionGeometry): - def __cinit__(self, n, d): - self.thisptr = new defs.Halfspaced(defs.Vector3d( n[0], - n[1], - n[2]), + def __cinit__(self, np.ndarray[double, ndim=1, mode="c"] n, d): + self.thisptr = new defs.Halfspaced(defs.Vector3d(&n[0]), d) property n: @@ -316,10 +353,8 @@ cdef class Halfspace(CollisionGeometry): ( self.thisptr).d = value cdef class Plane(CollisionGeometry): - def __cinit__(self, n, d): - self.thisptr = new defs.Planed(defs.Vector3d( n[0], - n[1], - n[2]), + def __cinit__(self, np.ndarray[double, ndim=1, mode="c"] n, d): + self.thisptr = new defs.Planed(defs.Vector3d(&n[0]), d) property n: @@ -355,7 +390,8 @@ cdef class BVHModel(CollisionGeometry): return n def addVertex(self, x, y, z): - n = ( self.thisptr).addVertex(defs.Vector3d( x, y, z)) + cdef np.ndarray[double, ndim=1, mode="c"] n = numpy.array([x, y, z]) + n = ( self.thisptr).addVertex(defs.Vector3d(&n[0])) return self._check_ret_value(n) def addTriangle(self, v1, v2, v3): @@ -705,8 +741,8 @@ cdef inline bool DistanceCallBack(defs.CollisionObjectd*o1, defs.CollisionObject # Helper Functions ############################################################################### -#cdef quaternion3d_to_numpy(defs.Quaterniond q): -# return numpy.array([q.getW(), q.getX(), q.getY(), q.getZ()]) +cdef quaternion3d_to_numpy(defs.Quaterniond q): + return numpy.array([q.w(), q.x(), q.y(), q.z()]) cdef defs.Quaterniond numpy_to_quaternion3d(a): return defs.Quaterniond( a[0], a[1], a[2], a[3]) @@ -714,18 +750,16 @@ cdef defs.Quaterniond numpy_to_quaternion3d(a): cdef vec3d_to_numpy(defs.Vector3d vec): return numpy.array([vec[0], vec[1], vec[2]]) -cdef defs.Vector3d numpy_to_vec3d(a): - return defs.Vector3d( a[0], a[1], a[2]) +cdef defs.Vector3d numpy_to_vec3d(np.ndarray[double, ndim=1, mode="c"] a): + return defs.Vector3d(&a[0]) cdef mat3d_to_numpy(defs.Matrix3d m): return numpy.array([[m(0,0), m(0,1), m(0,2)], [m(1,0), m(1,1), m(1,2)], [m(2,0), m(2,1), m(2,2)]]) -#cdef defs.Matrix3d numpy_to_mat3d(a): -# return defs.Matrix3d( a[0][0], a[0][1], a[0][2], -# a[1][0], a[1][1], a[1][2], -# a[2][0], a[2][1], a[2][2]) +cdef defs.Matrix3d numpy_to_mat3d(np.ndarray[double, ndim=2, mode="c"] a): + return defs.Matrix3d(&a[0, 0]) cdef c_to_python_collision_geometry(defs.const_CollisionGeometryd*geom, CollisionObject o1, CollisionObject o2): cdef CollisionGeometry o1_py_geom = (( o1.thisptr).getUserData()) diff --git a/fcl/fcl_defs.pxd b/fcl/fcl_defs.pxd index 50dd926..f392565 100644 --- a/fcl/fcl_defs.pxd +++ b/fcl/fcl_defs.pxd @@ -21,41 +21,30 @@ cdef extern from "Python.h": cdef extern from "fcl/common/types.h" namespace "fcl": cdef cppclass Vector3d: Vector3d() except + - Vector3d(double x, double y, double z) except + + Vector3d(double *data) except + double& operator[](size_t i) cdef cppclass Matrix3d: Matrix3d() except + -# Matrix3d(double xx, double xy, double xz, -# double yx, double yy, double yz, -# double zx, double zy, double zz) except + + Matrix3d(double *data) double operator()(size_t i, size_t j) cdef cppclass Quaterniond: Quaterniond() except + - Quaterniond(double a, double b, - double c, double d) except + - void fromRotation(Matrix3d& R) - void fromAxisAngle(Vector3d& axis, double angle) -# double& getW() -# double& getX() -# double& getY() -# double& getZ() + Quaterniond(double a, double b, double c, double d) except + + Quaterniond(Matrix3d& R) except + + double& w() + double& x() + double& y() + double& z() + Matrix3d& toRotationMatrix() cdef cppclass Transform3d: Transform3d() except + -# Transform3d(Matrix3d& R_, Vector3d& T_) -# Transform3d(Quaterniond& q_, Vector3d& T_) -# Transform3d(Matrix3d& R_) -# Transform3d(Quaterniond& q_) -# Transform3d(Vector3d& T_) Transform3d(Transform3d& tf_) -# Matrix3d& getRotation() -# Vector3d& getTranslation() -# Quaterniond& getQuatRotation() -# void setRotation(Matrix3d& R_) -# void setTranslation(Vector3d& T_) -# void setQuatRotation(Quaterniond & q_) + void setIdentity() + Matrix3d& linear() + Vector3d& translation() cdef extern from "fcl/narrowphase/continuous_collision_request.h" namespace "fcl": cdef enum CCDMotionType: From 23672d91c4debe33d79926b96a1364da3cfe4357 Mon Sep 17 00:00:00 2001 From: Dmitry Neverov Date: Mon, 27 Apr 2020 19:38:01 +0900 Subject: [PATCH 03/20] Returned all previous functionallity: distance function and its dependants. Now the old test/* is passing. --- fcl/__init__.py | 4 +-- fcl/fcl.pyx | 80 ++++++++++++++++++++++++------------------------ fcl/fcl_defs.pxd | 6 ++-- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/fcl/__init__.py b/fcl/__init__.py index fae3eb8..e852be0 100644 --- a/fcl/__init__.py +++ b/fcl/__init__.py @@ -1,5 +1,5 @@ -from .fcl import CollisionObject, CollisionGeometry, Transform, TriangleP, Box, Sphere, Ellipsoid, Capsule, Cone, Cylinder, Halfspace, Plane, BVHModel, OcTree, DynamicAABBTreeCollisionManager, collide, continuousCollide, defaultCollisionCallback, defaultDistanceCallback -#distance +from .fcl import CollisionObject, CollisionGeometry, Transform, TriangleP, Box, Sphere, Ellipsoid, Capsule, Cone, Cylinder, Halfspace, Plane, BVHModel, OcTree, DynamicAABBTreeCollisionManager, collide, continuousCollide, distance, defaultCollisionCallback, defaultDistanceCallback + from .collision_data import OBJECT_TYPE, NODE_TYPE, CCDMotionType, CCDSolverType, GJKSolverType, Contact, CostSource, CollisionRequest, CollisionResult, ContinuousCollisionRequest, ContinuousCollisionResult, DistanceRequest, DistanceResult, CollisionData, DistanceData from .version import __version__ diff --git a/fcl/fcl.pyx b/fcl/fcl.pyx index a2d0a3f..b2fb29c 100644 --- a/fcl/fcl.pyx +++ b/fcl/fcl.pyx @@ -507,18 +507,18 @@ cdef class DynamicAABBTreeCollisionManager: else: raise ValueError -# def distance(self, *args): -# if len(args) == 2 and inspect.isroutine(args[1]): -# fn = DistanceFunction(args[1], args[0]) -# self.thisptr.distance( fn, DistanceCallBack) -# elif len(args) == 3 and isinstance(args[0], DynamicAABBTreeCollisionManager): -# fn = DistanceFunction(args[2], args[1]) -# self.thisptr.distance(( args[0]).thisptr, fn, DistanceCallBack) -# elif len(args) == 3 and inspect.isroutine(args[2]): -# fn = DistanceFunction(args[2], args[1]) -# self.thisptr.distance(( args[0]).thisptr, fn, DistanceCallBack) -# else: -# raise ValueError + def distance(self, *args): + if len(args) == 2 and inspect.isroutine(args[1]): + fn = DistanceFunction(args[1], args[0]) + self.thisptr.distance( fn, DistanceCallBack) + elif len(args) == 3 and isinstance(args[0], DynamicAABBTreeCollisionManager): + fn = DistanceFunction(args[2], args[1]) + self.thisptr.distance(( args[0]).thisptr, fn, DistanceCallBack) + elif len(args) == 3 and inspect.isroutine(args[2]): + fn = DistanceFunction(args[2], args[1]) + self.thisptr.distance(( args[0]).thisptr, fn, DistanceCallBack) + else: + raise ValueError def clear(self): self.thisptr.clear() @@ -637,31 +637,31 @@ def continuousCollide(CollisionObject o1, Transform tf1_end, result.time_of_contact = min(cresult.time_of_contact, result.time_of_contact) return ret -#def distance(CollisionObject o1, CollisionObject o2, -# request = None, result=None): -# -# if request is None: -# request = DistanceRequest() -# if result is None: -# result = DistanceResult() -# -# cdef defs.DistanceResultd cresult -# -# cdef double dis = defs.distance(o1.thisptr, o2.thisptr, -# defs.DistanceRequestd( -# request.enable_nearest_points, -# request.gjk_solver_type -# ), -# cresult) -# -# result.min_distance = min(cresult.min_distance, result.min_distance) -# result.nearest_points = [vec3d_to_numpy(cresult.nearest_points[0]), -# vec3d_to_numpy(cresult.nearest_points[1])] -# result.o1 = c_to_python_collision_geometry(cresult.o1, o1, o2) -# result.o2 = c_to_python_collision_geometry(cresult.o2, o1, o2) -# result.b1 = cresult.b1 -# result.b2 = cresult.b2 -# return dis +def distance(CollisionObject o1, CollisionObject o2, + request = None, result=None): + + if request is None: + request = DistanceRequest() + if result is None: + result = DistanceResult() + + cdef defs.DistanceResultd cresult + + cdef double dis = defs.distance(o1.thisptr, o2.thisptr, + defs.DistanceRequestd( + request.enable_nearest_points, + request.gjk_solver_type + ), + cresult) + + result.min_distance = min(cresult.min_distance, result.min_distance) + result.nearest_points = [vec3d_to_numpy(cresult.nearest_points[0]), + vec3d_to_numpy(cresult.nearest_points[1])] + result.o1 = c_to_python_collision_geometry(cresult.o1, o1, o2) + result.o2 = c_to_python_collision_geometry(cresult.o2, o1, o2) + result.b1 = cresult.b1 + result.b2 = cresult.b2 + return dis ############################################################################### # Collision and Distance Callback Functions @@ -687,9 +687,9 @@ def defaultDistanceCallback(CollisionObject o1, CollisionObject o2, cdata): if cdata.done: return True, result.min_distance -# -# distance(o1, o2, request, result) -# + + distance(o1, o2, request, result) + dist = result.min_distance if dist <= 0: diff --git a/fcl/fcl_defs.pxd b/fcl/fcl_defs.pxd index f392565..649f2f0 100644 --- a/fcl/fcl_defs.pxd +++ b/fcl/fcl_defs.pxd @@ -260,11 +260,11 @@ cdef extern from "fcl/broadphase/broadphase_dynamic_AABB_tree.h" namespace "fcl" void registerObject(CollisionObjectd* obj) void unregisterObject(CollisionObjectd* obj) void collide(DynamicAABBTreeCollisionManagerd* mgr, void* cdata, CollisionCallBack callback) -# void distance(DynamicAABBTreeCollisionManagerd* mgr, void* cdata, DistanceCallBack callback) + void distance(DynamicAABBTreeCollisionManagerd* mgr, void* cdata, DistanceCallBack callback) void collide(CollisionObjectd* obj, void* cdata, CollisionCallBack callback) -# void distance(CollisionObjectd* obj, void* cdata, DistanceCallBack callback) + void distance(CollisionObjectd* obj, void* cdata, DistanceCallBack callback) void collide(void* cdata, CollisionCallBack callback) -# void distance(void* cdata, DistanceCallBack callback) + void distance(void* cdata, DistanceCallBack callback) void setup() void update() void update(CollisionObjectd* updated_obj) From 2dee00364c65eb5021efc4a0695a0371ff431dec Mon Sep 17 00:00:00 2001 From: Dmitry Neverov Date: Mon, 27 Apr 2020 20:51:19 +0900 Subject: [PATCH 04/20] Fixed ordering mismatch bug --- fcl/fcl.pyx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fcl/fcl.pyx b/fcl/fcl.pyx index b2fb29c..f15e777 100644 --- a/fcl/fcl.pyx +++ b/fcl/fcl.pyx @@ -334,7 +334,7 @@ cdef class Cylinder(CollisionGeometry): ( self.thisptr).lz = value cdef class Halfspace(CollisionGeometry): - def __cinit__(self, np.ndarray[double, ndim=1, mode="c"] n, d): + def __cinit__(self, np.ndarray[double, ndim=1] n, d): self.thisptr = new defs.Halfspaced(defs.Vector3d(&n[0]), d) @@ -353,7 +353,7 @@ cdef class Halfspace(CollisionGeometry): ( self.thisptr).d = value cdef class Plane(CollisionGeometry): - def __cinit__(self, np.ndarray[double, ndim=1, mode="c"] n, d): + def __cinit__(self, np.ndarray[double, ndim=1] n, d): self.thisptr = new defs.Planed(defs.Vector3d(&n[0]), d) @@ -390,7 +390,7 @@ cdef class BVHModel(CollisionGeometry): return n def addVertex(self, x, y, z): - cdef np.ndarray[double, ndim=1, mode="c"] n = numpy.array([x, y, z]) + cdef np.ndarray[double, ndim=1] n = numpy.array([x, y, z]) n = ( self.thisptr).addVertex(defs.Vector3d(&n[0])) return self._check_ret_value(n) @@ -750,7 +750,7 @@ cdef defs.Quaterniond numpy_to_quaternion3d(a): cdef vec3d_to_numpy(defs.Vector3d vec): return numpy.array([vec[0], vec[1], vec[2]]) -cdef defs.Vector3d numpy_to_vec3d(np.ndarray[double, ndim=1, mode="c"] a): +cdef defs.Vector3d numpy_to_vec3d(np.ndarray[double, ndim=1] a): return defs.Vector3d(&a[0]) cdef mat3d_to_numpy(defs.Matrix3d m): @@ -758,8 +758,11 @@ cdef mat3d_to_numpy(defs.Matrix3d m): [m(1,0), m(1,1), m(1,2)], [m(2,0), m(2,1), m(2,2)]]) -cdef defs.Matrix3d numpy_to_mat3d(np.ndarray[double, ndim=2, mode="c"] a): - return defs.Matrix3d(&a[0, 0]) +cdef defs.Matrix3d numpy_to_mat3d(np.ndarray[double, ndim=2] a): + # NOTE Eigen defaults to column-major storage, + # which corresponds to non-default Fortran mode of ordering in numpy + cdef np.ndarray[double, ndim=2, mode='fortran'] f = np.ndarray.copy(a, order='F') + return defs.Matrix3d(&f[0, 0]) cdef c_to_python_collision_geometry(defs.const_CollisionGeometryd*geom, CollisionObject o1, CollisionObject o2): cdef CollisionGeometry o1_py_geom = (( o1.thisptr).getUserData()) From af54f5908fdc531b8ede2f293a92c50af8b0873c Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Thu, 23 Jul 2020 21:33:18 +0200 Subject: [PATCH 05/20] Fix bvh path --- fcl/fcl_defs.pxd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fcl/fcl_defs.pxd b/fcl/fcl_defs.pxd index 649f2f0..2bbe78a 100644 --- a/fcl/fcl_defs.pxd +++ b/fcl/fcl_defs.pxd @@ -309,7 +309,7 @@ cdef extern from "fcl/narrowphase/distance.h" namespace "fcl": CollisionGeometryd* o2, Transform3d& tf2, DistanceRequestd& request, DistanceResultd& result) -cdef extern from "fcl/geometry/BVH/BVH_internal.h" namespace "fcl": +cdef extern from "fcl/geometry/bvh/BVH_internal.h" namespace "fcl": cdef enum BVHModelType: BVH_MODEL_UNKNOWN, # unknown model type BVH_MODEL_TRIANGLES, # triangle model @@ -342,15 +342,15 @@ cdef extern from "fcl/math/triangle.h" namespace "fcl": size_t vids[3] # TODO what about these guys? -cdef extern from "fcl/geometry/BVH/detail/BV_splitter_base.h" namespace "fcl": +cdef extern from "fcl/geometry/bvh/detail/BV_splitter_base.h" namespace "fcl": cdef cppclass BVSplitterBase: pass -cdef extern from "fcl/geometry/BVH/detail/BV_fitter_base.h" namespace "fcl": +cdef extern from "fcl/geometry/bvh/detail/BV_fitter_base.h" namespace "fcl": cdef cppclass BVFitterBase: pass -cdef extern from "fcl/geometry/BVH/BVH_model.h" namespace "fcl": +cdef extern from "fcl/geometry/bvh/BVH_model.h" namespace "fcl": # Cython only accepts type template parameters. # see https://groups.google.com/forum/#!topic/cython-users/xAZxdCFw6Xs cdef cppclass BVHModel "fcl::BVHModel" ( CollisionGeometryd ): From 6ecd4d221f1a0f1bd993d26f8fa9e87c5e12e7bc Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Wed, 21 Jul 2021 11:36:01 +0200 Subject: [PATCH 06/20] update metadata to fcl 0.6.1 Use fcl version as version to make targeted version more obvious. --- README.md | 7 ++++--- fcl/version.py | 2 +- setup.py | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9297ebe..6fc558f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ +# Disclaimer +This is fork of https://github.com/BerkeleyAutomation/python-fcl intented to be used in [ifcopenshell](https://github.com/IfcOpenShell/IfcOpenShell) / [BlenderBIM Add-on](https://blenderbim.org/) as orgininal repo is currently unactive and is not merging any PR. + # python-fcl ### Python Interface for the Flexible Collision Library -[![Build Status](https://travis-ci.org/BerkeleyAutomation/python-fcl.svg?branch=master)](https://travis-ci.org/BerkeleyAutomation/python-fcl) - Python-FCL is an (unofficial) Python interface for the [Flexible Collision Library (FCL)](https://github.com/flexible-collision-library/fcl), an excellent C++ library for performing proximity and collision queries on pairs of geometric models. -Currently, this package is targeted for FCL 0.5.0. +Currently, this package is targeted for FCL 0.6.1. This package supports three types of proximity queries for pairs of geometric models: * __Collision Detection__: Detecting whether two models overlap (and optionally where). diff --git a/fcl/version.py b/fcl/version.py index b459ff2..8411e55 100644 --- a/fcl/version.py +++ b/fcl/version.py @@ -1 +1 @@ -__version__ = '0.0.12' +__version__ = '0.6.1' diff --git a/setup.py b/setup.py index c00ce0b..019c6c3 100644 --- a/setup.py +++ b/setup.py @@ -19,8 +19,8 @@ if prefix in sys.platform: platform_supported = True include_dirs = ['/usr/include', - '/usr/local/include', - '/usr/local/include/eigen3'] + '/usr/include', + '/usr/include/eigen3'] lib_dirs = ['/usr/lib', '/usr/local/lib'] @@ -49,9 +49,9 @@ version=__version__, description='Python bindings for the Flexible Collision Library', long_description='Python bindings for the Flexible Collision Library', - url='https://github.com/BerkeleyAutomation/python-fcl', - author='Matthew Matl', - author_email='mmatl@eecs.berkeley.edu', + url='https://github.com/CyrilWaechter/python-fcl', + author='Cyril Waechter', + author_email='cyrwae@hotmail.com', license = "BSD", classifiers=[ 'Development Status :: 3 - Alpha', From 92502dcfcd2a127e2c71596d5a6f6990c918d140 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Fri, 23 Jul 2021 07:02:30 +0200 Subject: [PATCH 07/20] update docker file for manylinux build --- requirements/Dockerfile | 16 ++++++---------- requirements/build.bash | 7 +++++++ requirements/clone.bash | 22 +++++----------------- requirements/install_cmake.bash | 5 ----- setup.py | 5 +++-- 5 files changed, 21 insertions(+), 34 deletions(-) delete mode 100644 requirements/install_cmake.bash diff --git a/requirements/Dockerfile b/requirements/Dockerfile index eaccf63..52965aa 100644 --- a/requirements/Dockerfile +++ b/requirements/Dockerfile @@ -6,14 +6,7 @@ # ln -sf requirements/Dockerfile . # docker build . -t pythonfcl -FROM quay.io/pypa/manylinux1_x86_64:latest - - -RUN yum install -y gcc - -# install cmake 2.8.12 -COPY requirements/install_cmake.bash . -RUN bash install_cmake.bash +FROM quay.io/pypa/manylinux_2_24_x86_64:latest # clone FCL and libccd # the exact checkouts are in clone.bash @@ -27,7 +20,7 @@ RUN bash build.bash # manylinux includes a bunch of pythons # to test with others change this env variable #ENV PATH=/opt/python/cp27-cp27m/bin:$PATH -ENV PATH=/opt/python/cp36-cp36m/bin:$PATH +ENV PATH=/opt/python/cp39-cp39/bin:$PATH # we need numpy to build python-fcl # since we set our path we'll be using the right pip @@ -35,4 +28,7 @@ RUN pip install numpy cython # build the python-fcl module COPY . /python_fcl -RUN cd /python_fcl && python setup.py build_ext +RUN pip wheel /python_fcl --no-deps -w wheelhouse/ +RUN pip install /python_fcl --no-index -f /wheelhouse +RUN ls /wheelhouse +RUN auditwheel repair wheelhouse/python_fcl-0.6.1-cp39-cp39-linux_x86_64.whl --plat manylinux_2_24_x86_64 -w /wheelhouse diff --git a/requirements/build.bash b/requirements/build.bash index 16b7091..0d1653b 100644 --- a/requirements/build.bash +++ b/requirements/build.bash @@ -1,15 +1,22 @@ +echo "Install eigen" +cmake -B build -S eigen-3.3.9 +cmake --install build + +echo "Build and install libccd" cd libccd cmake . make -j4 make install cd .. +echo "Build and install octomap" cd octomap cmake . make -j4 make install cd .. +echo "Build and install fcl" cd fcl cmake . make -j4 diff --git a/requirements/clone.bash b/requirements/clone.bash index fc7d56a..e200678 100644 --- a/requirements/clone.bash +++ b/requirements/clone.bash @@ -1,24 +1,12 @@ rm -rf libccd -git clone https://github.com/danfis/libccd.git -cd libccd -git pull -git checkout 64f02f741ac94fccd0fb660a5bffcbe6d01d9939 -cd .. +git clone --depth 1 --branch v2.1 https://github.com/danfis/libccd.git rm -rf octomap -git clone https://github.com/OctoMap/octomap.git -cd octomap -git pull -git checkout b8c1d62a7a64ce0a5df278503f31d73acafa97e4 -cd .. +git clone --depth 1 --branch v1.8.0 https://github.com/OctoMap/octomap.git rm -rf fcl -git clone https://github.com/flexible-collision-library/fcl.git -cd fcl -git pull -git checkout 22f375f333beccc10c527974cef96784f0841649 -cd .. +git clone --depth 1 --branch v0.6.1 https://github.com/flexible-collision-library/fcl.git # get eigen -#curl -OL https://github.com/RLovelett/eigen/archive/3.3.4.tar.gz -#tar -zxvf 3.3.4.tar.gz +curl -OL https://gitlab.com/libeigen/eigen/-/archive/3.3.9/eigen-3.3.9.tar.gz +tar -zxf eigen-3.3.9.tar.gz \ No newline at end of file diff --git a/requirements/install_cmake.bash b/requirements/install_cmake.bash deleted file mode 100644 index 06072cd..0000000 --- a/requirements/install_cmake.bash +++ /dev/null @@ -1,5 +0,0 @@ -# install cmake using their shell script -# we do this because fcl needs cmake >= 2.8.12, but centos 5 -# from the manylinux image has only cmake 2.8.11 -curl -OL https://cmake.org/files/v2.8/cmake-2.8.12.2-Linux-i386.sh -bash cmake-2.8.12.2-Linux-i386.sh --skip-license --prefix=/usr diff --git a/setup.py b/setup.py index 019c6c3..1f9b490 100644 --- a/setup.py +++ b/setup.py @@ -19,8 +19,9 @@ if prefix in sys.platform: platform_supported = True include_dirs = ['/usr/include', - '/usr/include', - '/usr/include/eigen3'] + '/usr/local/include', + '/usr/include/eigen3', + '/usr/local/include/eigen3'] lib_dirs = ['/usr/lib', '/usr/local/lib'] From 158e3c9e79e22e3a096db7f28753e8e6acf3431a Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Fri, 23 Jul 2021 11:38:35 +0200 Subject: [PATCH 08/20] Add github actions to build python wheels --- .github/workflows/wheels.yml | 19 +++++++ .gitignore | 3 + pyproject.toml | 10 ++++ setup.cfg | 33 +++++++++++ setup.py | 103 ++++++++++++----------------------- 5 files changed, 101 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/wheels.yml create mode 100644 pyproject.toml create mode 100644 setup.cfg diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml new file mode 100644 index 0000000..5c396b6 --- /dev/null +++ b/.github/workflows/wheels.yml @@ -0,0 +1,19 @@ +name: Build + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build wheel py${{matrix.python}} on ${{matrix.platform}} + runs-on: ${{matrix.platform}} + strategy: + matrix: + platform: [ubuntu-latest] # [ubuntu-latest, macos-latest, windows-latest] + python: [39] + steps: + - uses: actions/checkout@v2 + - name: Build wheels + uses: pypa/cibuildwheel@v2.0.0 + - uses: actions/upload-artifact@v2 + with: + path: ./wheelhouse/*.whl \ No newline at end of file diff --git a/.gitignore b/.gitignore index db59b2b..8f238da 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,6 @@ venv.bak/ # mypy .mypy_cache/ + +# vscode settings +.vscode/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..249cd8b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[build-system] +requires = ["setuptools", "wheel", "numpy", "Cython"] +build-backend = "setuptools.build_meta" + +[tool.cibuildwheel] +before-all = "bash requirements/clone.bash && bash requirements/build.bash" +before-build = "pip install numpy cython" +manylinux-x86_64-image = "manylinux_2_24" +test-requires = "pytest" +test-command = "pytest {package}/test" \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..3b133e3 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,33 @@ +[metadata] +name = python-fcl +version = attr: fcl.__version__ +description = Python bindings for the Flexible Collision Library +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/CyrilWaechter/python-fcl +maintainer = Cyril Waechter +maintainer_email = cyrwae@hotmail.com +license = BSD +license_files = LICENSE +classifiers = + Development Status :: 3 - Alpha + License :: OSI Approved :: BSD License + Operating System :: POSIX :: Linux + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.0 + Programming Language :: Python :: 3.1 + Programming Language :: Python :: 3.2 + Programming Language :: Python :: 3.3 + Programming Language :: Python :: 3.4 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 +keywords = fcl collision distance +packages = fcl +setup_requires = + numpy + Cython +install_requires = + numpy + Cython diff --git a/setup.py b/setup.py index 1f9b490..4df633f 100644 --- a/setup.py +++ b/setup.py @@ -1,83 +1,52 @@ import os import sys -import inspect from setuptools import Extension, setup -# get current directory of file in case someone -# called setup.py from elsewhere -cwd = os.path.dirname(os.path.abspath( - inspect.getfile(inspect.currentframe()))) - -# load __version__ -exec(open(os.path.join(cwd, - 'fcl/version.py'), 'r').read()) - -platform_supported = False -for prefix in ['darwin', 'linux', 'bsd']: - if prefix in sys.platform: - platform_supported = True - include_dirs = ['/usr/include', - '/usr/local/include', - '/usr/include/eigen3', - '/usr/local/include/eigen3'] - lib_dirs = ['/usr/lib', - '/usr/local/lib'] - - if 'CPATH' in os.environ: - include_dirs += os.environ['CPATH'].split(':') - if 'LD_LIBRARY_PATH' in os.environ: - lib_dirs += os.environ['LD_LIBRARY_PATH'].split(':') - - try: - # get the numpy include path from numpy - import numpy - include_dirs.append(numpy.get_include()) - except: - pass - - break - -if sys.platform == "win32": +def get_include_dirs(): platform_supported = False - -if not platform_supported: + for prefix in ['darwin', 'linux', 'bsd']: + if prefix in sys.platform: + platform_supported = True + include_dirs = ['/usr/include', + '/usr/local/include', + '/usr/include/eigen3', + '/usr/local/include/eigen3'] + + if 'CPATH' in os.environ: + include_dirs += os.environ['CPATH'].split(':') + + break + if sys.platform == "win32": + platform_supported = False + if not platform_supported: + raise NotImplementedError(sys.platform) + + # get the numpy include path from numpy + import numpy + include_dirs.append(numpy.get_include()) + return include_dirs + +def get_libraries_dir(): + for prefix in ['darwin', 'linux', 'bsd']: + if prefix in sys.platform: + platform_supported = True + lib_dirs = ['/usr/lib', + '/usr/local/lib'] + + if 'LD_LIBRARY_PATH' in os.environ: + lib_dirs += os.environ['LD_LIBRARY_PATH'].split(':') + return lib_dirs raise NotImplementedError(sys.platform) + setup( - name='python-fcl', - version=__version__, - description='Python bindings for the Flexible Collision Library', - long_description='Python bindings for the Flexible Collision Library', - url='https://github.com/CyrilWaechter/python-fcl', - author='Cyril Waechter', - author_email='cyrwae@hotmail.com', - license = "BSD", - classifiers=[ - 'Development Status :: 3 - Alpha', - 'License :: OSI Approved :: BSD License', - 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.0', - 'Programming Language :: Python :: 3.1', - 'Programming Language :: Python :: 3.2', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - ], - keywords='fcl collision distance', - packages=['fcl'], - setup_requires=['cython'], - install_requires=['numpy', 'cython'], ext_modules=[Extension( "fcl.fcl", ["fcl/fcl.pyx"], - include_dirs = include_dirs, - library_dirs = lib_dirs, + include_dirs = get_include_dirs(), + library_dirs = get_libraries_dir(), libraries=[ "fcl","octomap" ], From 8f606d5cb9a971811dc63e8df297fd103d5bcb90 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Sun, 25 Jul 2021 04:46:57 +0200 Subject: [PATCH 09/20] Fix many issues in deployment process * Fix conflicting folder name between python package and fcl dependency * Move to `src/module` tree schema * Fix `setup.cfg` options * Merge clone and build bash scripts for clarity (future mac/win builds) --- .gitignore | 1 + MANIFEST.in | 5 -- .../Dockerfile | 0 build_dependencies/install_linux.sh | 41 ++++++++++++++ fcl/__init__.py | 5 -- pyproject.toml | 2 +- requirements/build.bash | 24 -------- requirements/clone.bash | 12 ---- setup.cfg | 13 ++++- setup.py | 56 ++++++++++--------- src/fcl/__init__.py | 48 ++++++++++++++++ {fcl => src/fcl}/collision_data.py | 0 {fcl => src/fcl}/fcl.pyx | 0 {fcl => src/fcl}/fcl_defs.pxd | 0 {fcl => src/fcl}/octomap_defs.pxd | 0 {fcl => src/fcl}/std_defs.pxd | 0 {fcl => src/fcl}/version.py | 0 17 files changed, 134 insertions(+), 73 deletions(-) delete mode 100644 MANIFEST.in rename {requirements => build_dependencies}/Dockerfile (100%) create mode 100644 build_dependencies/install_linux.sh delete mode 100644 fcl/__init__.py delete mode 100644 requirements/build.bash delete mode 100644 requirements/clone.bash create mode 100644 src/fcl/__init__.py rename {fcl => src/fcl}/collision_data.py (100%) rename {fcl => src/fcl}/fcl.pyx (100%) rename {fcl => src/fcl}/fcl_defs.pxd (100%) rename {fcl => src/fcl}/octomap_defs.pxd (100%) rename {fcl => src/fcl}/std_defs.pxd (100%) rename {fcl => src/fcl}/version.py (100%) diff --git a/.gitignore b/.gitignore index 8f238da..2cd1861 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ wheels/ .installed.cfg *.egg MANIFEST +deps/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index d616172..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -# Include the license -include LICENSE -include fcl/fcl_defs.pxd -include fcl/octomap_defs.pxd -include fcl/std_defs.pxd diff --git a/requirements/Dockerfile b/build_dependencies/Dockerfile similarity index 100% rename from requirements/Dockerfile rename to build_dependencies/Dockerfile diff --git a/build_dependencies/install_linux.sh b/build_dependencies/install_linux.sh new file mode 100644 index 0000000..022f08c --- /dev/null +++ b/build_dependencies/install_linux.sh @@ -0,0 +1,41 @@ +mkdir -p deps +cd deps +get eigen +curl -OL https://gitlab.com/libeigen/eigen/-/archive/3.3.9/eigen-3.3.9.tar.gz +tar -zxf eigen-3.3.9.tar.gz + +rm -rf libccd +git clone --depth 1 --branch v2.1 https://github.com/danfis/libccd.git + +rm -rf octomap +git clone --depth 1 --branch v1.8.0 https://github.com/OctoMap/octomap.git + +rm -rf fcl +git clone --depth 1 --branch v0.6.1 https://github.com/flexible-collision-library/fcl.git + +echo "Install eigen" +cmake -B build -S eigen-3.3.9 +cmake --install build + +echo "Build and install libccd" +cd libccd +cmake . +make -j4 +make install +cd .. + +echo "Build and install octomap" +cd octomap +cmake . +make -j4 +make install +cd .. + +echo "Build and install fcl" +cd fcl +cmake . +make -j4 +make install +cd .. + +cd .. \ No newline at end of file diff --git a/fcl/__init__.py b/fcl/__init__.py deleted file mode 100644 index e852be0..0000000 --- a/fcl/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .fcl import CollisionObject, CollisionGeometry, Transform, TriangleP, Box, Sphere, Ellipsoid, Capsule, Cone, Cylinder, Halfspace, Plane, BVHModel, OcTree, DynamicAABBTreeCollisionManager, collide, continuousCollide, distance, defaultCollisionCallback, defaultDistanceCallback - -from .collision_data import OBJECT_TYPE, NODE_TYPE, CCDMotionType, CCDSolverType, GJKSolverType, Contact, CostSource, CollisionRequest, CollisionResult, ContinuousCollisionRequest, ContinuousCollisionResult, DistanceRequest, DistanceResult, CollisionData, DistanceData - -from .version import __version__ diff --git a/pyproject.toml b/pyproject.toml index 249cd8b..bb25658 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel", "numpy", "Cython"] build-backend = "setuptools.build_meta" [tool.cibuildwheel] -before-all = "bash requirements/clone.bash && bash requirements/build.bash" +before-all = "bash build_dependencies/install_linux.sh" before-build = "pip install numpy cython" manylinux-x86_64-image = "manylinux_2_24" test-requires = "pytest" diff --git a/requirements/build.bash b/requirements/build.bash deleted file mode 100644 index 0d1653b..0000000 --- a/requirements/build.bash +++ /dev/null @@ -1,24 +0,0 @@ -echo "Install eigen" -cmake -B build -S eigen-3.3.9 -cmake --install build - -echo "Build and install libccd" -cd libccd -cmake . -make -j4 -make install -cd .. - -echo "Build and install octomap" -cd octomap -cmake . -make -j4 -make install -cd .. - -echo "Build and install fcl" -cd fcl -cmake . -make -j4 -make install -cd .. diff --git a/requirements/clone.bash b/requirements/clone.bash deleted file mode 100644 index e200678..0000000 --- a/requirements/clone.bash +++ /dev/null @@ -1,12 +0,0 @@ -rm -rf libccd -git clone --depth 1 --branch v2.1 https://github.com/danfis/libccd.git - -rm -rf octomap -git clone --depth 1 --branch v1.8.0 https://github.com/OctoMap/octomap.git - -rm -rf fcl -git clone --depth 1 --branch v0.6.1 https://github.com/flexible-collision-library/fcl.git - -# get eigen -curl -OL https://gitlab.com/libeigen/eigen/-/archive/3.3.9/eigen-3.3.9.tar.gz -tar -zxf eigen-3.3.9.tar.gz \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 3b133e3..d0af2c8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,10 +24,21 @@ classifiers = Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 keywords = fcl collision distance -packages = fcl + +[options] +include_package_data = True +package_dir = + = src +packages = find: setup_requires = numpy Cython install_requires = numpy Cython + +[options.package_data] +* = *.pyx, *.pxd + +[options.packages.find] +where = src \ No newline at end of file diff --git a/setup.py b/setup.py index 4df633f..ab96748 100644 --- a/setup.py +++ b/setup.py @@ -2,20 +2,23 @@ import sys from setuptools import Extension, setup +from Cython.Build import cythonize def get_include_dirs(): platform_supported = False - for prefix in ['darwin', 'linux', 'bsd']: + for prefix in ["darwin", "linux", "bsd"]: if prefix in sys.platform: platform_supported = True - include_dirs = ['/usr/include', - '/usr/local/include', - '/usr/include/eigen3', - '/usr/local/include/eigen3'] - - if 'CPATH' in os.environ: - include_dirs += os.environ['CPATH'].split(':') + include_dirs = [ + "/usr/include", + "/usr/local/include", + "/usr/include/eigen3", + "/usr/local/include/eigen3", + ] + + if "CPATH" in os.environ: + include_dirs += os.environ["CPATH"].split(":") break if sys.platform == "win32": @@ -25,32 +28,35 @@ def get_include_dirs(): # get the numpy include path from numpy import numpy + include_dirs.append(numpy.get_include()) return include_dirs + def get_libraries_dir(): - for prefix in ['darwin', 'linux', 'bsd']: + for prefix in ["darwin", "linux", "bsd"]: if prefix in sys.platform: platform_supported = True - lib_dirs = ['/usr/lib', - '/usr/local/lib'] - - if 'LD_LIBRARY_PATH' in os.environ: - lib_dirs += os.environ['LD_LIBRARY_PATH'].split(':') + lib_dirs = ["/usr/lib", "/usr/local/lib"] + + if "LD_LIBRARY_PATH" in os.environ: + lib_dirs += os.environ["LD_LIBRARY_PATH"].split(":") return lib_dirs raise NotImplementedError(sys.platform) setup( - ext_modules=[Extension( - "fcl.fcl", - ["fcl/fcl.pyx"], - include_dirs = get_include_dirs(), - library_dirs = get_libraries_dir(), - libraries=[ - "fcl","octomap" - ], - language="c++", - extra_compile_args = ["-std=c++11"] - )] + ext_modules=cythonize( + [ + Extension( + "fcl.fcl", + ["src/fcl/fcl.pyx"], + include_dirs=get_include_dirs(), + library_dirs=get_libraries_dir(), + libraries=["fcl", "octomap"], + language="c++", + extra_compile_args=["-std=c++11"], + ) + ], + ) ) diff --git a/src/fcl/__init__.py b/src/fcl/__init__.py new file mode 100644 index 0000000..5a6e4af --- /dev/null +++ b/src/fcl/__init__.py @@ -0,0 +1,48 @@ +try: + from .fcl import ( + CollisionObject, + CollisionGeometry, + Transform, + TriangleP, + Box, + Sphere, + Ellipsoid, + Capsule, + Cone, + Cylinder, + Halfspace, + Plane, + BVHModel, + OcTree, + DynamicAABBTreeCollisionManager, + collide, + continuousCollide, + distance, + defaultCollisionCallback, + defaultDistanceCallback, + ) +except ModuleNotFoundError: + import traceback + + traceback.print_exc() + print("Failed to import fcl.fcl. It is probably not correctly compiled.") + +from .collision_data import ( + OBJECT_TYPE, + NODE_TYPE, + CCDMotionType, + CCDSolverType, + GJKSolverType, + Contact, + CostSource, + CollisionRequest, + CollisionResult, + ContinuousCollisionRequest, + ContinuousCollisionResult, + DistanceRequest, + DistanceResult, + CollisionData, + DistanceData, +) + +from .version import __version__ diff --git a/fcl/collision_data.py b/src/fcl/collision_data.py similarity index 100% rename from fcl/collision_data.py rename to src/fcl/collision_data.py diff --git a/fcl/fcl.pyx b/src/fcl/fcl.pyx similarity index 100% rename from fcl/fcl.pyx rename to src/fcl/fcl.pyx diff --git a/fcl/fcl_defs.pxd b/src/fcl/fcl_defs.pxd similarity index 100% rename from fcl/fcl_defs.pxd rename to src/fcl/fcl_defs.pxd diff --git a/fcl/octomap_defs.pxd b/src/fcl/octomap_defs.pxd similarity index 100% rename from fcl/octomap_defs.pxd rename to src/fcl/octomap_defs.pxd diff --git a/fcl/std_defs.pxd b/src/fcl/std_defs.pxd similarity index 100% rename from fcl/std_defs.pxd rename to src/fcl/std_defs.pxd diff --git a/fcl/version.py b/src/fcl/version.py similarity index 100% rename from fcl/version.py rename to src/fcl/version.py From bf53e5509e71e3d8bfd0d6ac71c617cb8df7dee4 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Mon, 26 Jul 2021 12:08:43 +0200 Subject: [PATCH 10/20] Add macos build --- .github/workflows/wheels.yml | 4 ++-- build_dependencies/install_macos.sh | 23 +++++++++++++++++++++++ pyproject.toml | 18 ++++++++++++++---- setup.cfg | 2 ++ 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 build_dependencies/install_macos.sh diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 5c396b6..fa427d6 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -4,11 +4,11 @@ on: [push, pull_request] jobs: build_wheels: - name: Build wheel py${{matrix.python}} on ${{matrix.platform}} + name: Build wheel on ${{matrix.platform}} runs-on: ${{matrix.platform}} strategy: matrix: - platform: [ubuntu-latest] # [ubuntu-latest, macos-latest, windows-latest] + platform: [ubuntu-latest, macos-latest] # [ubuntu-latest, macos-latest, windows-latest] python: [39] steps: - uses: actions/checkout@v2 diff --git a/build_dependencies/install_macos.sh b/build_dependencies/install_macos.sh new file mode 100644 index 0000000..9d89609 --- /dev/null +++ b/build_dependencies/install_macos.sh @@ -0,0 +1,23 @@ +brew update > /dev/null + +# brew install git +# brew install cmake +# brew install eigen +# brew install libccd +brew install fcl + +# mkdir -p deps +# cd deps +# # Octomap +# git clone https://github.com/OctoMap/octomap +# cd octomap +# git checkout tags/v1.8.0 +# mkdir build +# cd build +# cmake .. +# make +# sudo make install + +# cd .. +# cd .. +# cd .. \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index bb25658..ac99b93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,8 +3,18 @@ requires = ["setuptools", "wheel", "numpy", "Cython"] build-backend = "setuptools.build_meta" [tool.cibuildwheel] -before-all = "bash build_dependencies/install_linux.sh" -before-build = "pip install numpy cython" +skip = "pp*" +before-build = "pip install numpy Cython" manylinux-x86_64-image = "manylinux_2_24" -test-requires = "pytest" -test-command = "pytest {package}/test" \ No newline at end of file +# test-requires = "pytest" +# test-command = "pytest {package}/test" + +[tool.cibuildwheel.linux] +before-all = "bash build_dependencies/install_linux.sh" +archs = ["x86_64"] + +[tool.cibuildwheel.macos] +before-all = "bash build_dependencies/install_macos.sh" + +[tool.cibuildwheel.windows] +archs = ["AMD64"] \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index d0af2c8..58e63b5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,6 +5,8 @@ description = Python bindings for the Flexible Collision Library long_description = file: README.md long_description_content_type = text/markdown url = https://github.com/CyrilWaechter/python-fcl +author = Jelle Feringa, Matthew Matl, Shirokuma, Michael Dawson-Haggerty, See contributor list +author_email = jelleferinga@gmail.com, mmatl@eecs.berkeley.edu, rootstock_acg@yahoo.co.jp maintainer = Cyril Waechter maintainer_email = cyrwae@hotmail.com license = BSD From 0a046fb20b8cef10f74a81a9b5f0edff510c1623 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Tue, 27 Jul 2021 17:35:25 +0200 Subject: [PATCH 11/20] Add windows build --- .github/workflows/wheels.yml | 3 +- build_dependencies/install_windows.ps1 | 101 +++++++++++++++++++++++++ pyproject.toml | 9 ++- setup.cfg | 2 +- setup.py | 66 ++++++++++------ 5 files changed, 150 insertions(+), 31 deletions(-) create mode 100644 build_dependencies/install_windows.ps1 diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index fa427d6..7858377 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -8,8 +8,7 @@ jobs: runs-on: ${{matrix.platform}} strategy: matrix: - platform: [ubuntu-latest, macos-latest] # [ubuntu-latest, macos-latest, windows-latest] - python: [39] + platform: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v2 - name: Build wheels diff --git a/build_dependencies/install_windows.ps1 b/build_dependencies/install_windows.ps1 new file mode 100644 index 0000000..c0dbdc0 --- /dev/null +++ b/build_dependencies/install_windows.ps1 @@ -0,0 +1,101 @@ +<# +Originally based on script written by Pebaz (https://github.com/Pebaz/python-fcl/blob/master/requirements/build_win32.ps1) +but with many modification in order to use fcl 0.6.1 and install dependencies without admin rights. + +This script builds fcl and it's dependencies for python-fcl on Windows. + +It downloads, builds, installs, and then deletes: + * fcl + * libccd + * eigen + * octomap +#> + +$base_dir = Get-Location + +# Create a directory that encapsulates all dependencies +mkdir -p deps; Set-Location deps + +# All compiled depencies will be install in following folder +$install_dir = "$base_dir\deps\install" + + +#------------------------------------------------------------------------------ +# Eigen +Write-Host "Building Eigen" +$eigen_ver = "3.3.9" +Invoke-WebRequest -Uri https://gitlab.com/libeigen/eigen/-/archive/$eigen_ver/eigen-$eigen_ver.tar.gz -Outfile eigen-$eigen_ver.tar.gz +tar -zxf "eigen-$eigen_ver.tar.gz" +Set-Location "eigen-$eigen_ver" + +cmake -B build ` + -D CMAKE_BUILD_TYPE=Release ` + -G "Visual Studio 16 2019" ` + -D BUILD_SHARED_LIBS=ON ` + -D CMAKE_INSTALL_PREFIX=$install_dir +cmake --install build + +Set-Location .. + + +# ------------------------------------------------------------------------------ +# LibCCD +Write-Host "Building LibCCD" +git clone --depth 1 --branch v2.1 https://github.com/danfis/libccd +Set-Location libccd + +cmake -B build ` + -D CMAKE_BUILD_TYPE=Release ` + -G "Visual Studio 16 2019" ` + -D BUILD_SHARED_LIBS=ON ` + -D CMAKE_INSTALL_PREFIX=$install_dir +cmake --build build --config Release --target install + +Set-Location .. + + +# ------------------------------------------------------------------------------ +# Octomap +Write-Host "Building Octomap" +git clone --depth 1 --branch v1.8.0 https://github.com/OctoMap/octomap +Set-Location octomap + +cmake -B build ` + -D CMAKE_PREFIX_PATH=$install_dir ` + -D CMAKE_BUILD_TYPE=Release ` + -G "Visual Studio 16 2019" ` + -D BUILD_SHARED_LIBS=ON ` + -D CMAKE_INSTALL_PREFIX=$install_dir ` + -D BUILD_OCTOVIS_SUBPROJECT=OFF ` + -D BUILD_DYNAMICETD3D_SUBPROJECT=OFF +cmake --build build --config Release +cmake --build build --config Release --target install + +Set-Location .. + +# ------------------------------------------------------------------------------ +# FCL +Write-Host "Building FCL" +git clone --depth 1 --branch v0.6.1 https://github.com/flexible-collision-library/fcl +Set-Location fcl + +cmake -B build ` + -D CMAKE_PREFIX_PATH=$install_dir ` + -D CMAKE_BUILD_TYPE=Release ` + -G "Visual Studio 16 2019" ` + -D CMAKE_INSTALL_PREFIX=$install_dir + +cmake --build build --config Release --target install +Write-Host "Done" +Set-Location .. + +# ------------------------------------------------------------------------------ +# Python-FCL + +Write-Host "Copying dependent DLLs" +Copy-Item $install_dir\bin\octomap.dll $base_dir\src\fcl +Copy-Item $install_dir\bin\octomath.dll $base_dir\src\fcl +Copy-Item $install_dir\bin\ccd.dll $base_dir\src\fcl + +Set-Location $base_dir +Write-Host "All done!" diff --git a/pyproject.toml b/pyproject.toml index ac99b93..aba56a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,8 +6,6 @@ build-backend = "setuptools.build_meta" skip = "pp*" before-build = "pip install numpy Cython" manylinux-x86_64-image = "manylinux_2_24" -# test-requires = "pytest" -# test-command = "pytest {package}/test" [tool.cibuildwheel.linux] before-all = "bash build_dependencies/install_linux.sh" @@ -15,6 +13,11 @@ archs = ["x86_64"] [tool.cibuildwheel.macos] before-all = "bash build_dependencies/install_macos.sh" +test-requires = "pytest" +test-command = "pytest {package}/test" [tool.cibuildwheel.windows] -archs = ["AMD64"] \ No newline at end of file +before-all = "powershell build_dependencies\\install_windows.ps1" +archs = ["AMD64"] +test-requires = "pytest" +test-command = "pytest {package}\\test" \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 58e63b5..aad6d41 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ install_requires = Cython [options.package_data] -* = *.pyx, *.pxd +* = *.pyx, *.pxd, *.dll [options.packages.find] where = src \ No newline at end of file diff --git a/setup.py b/setup.py index ab96748..a7fb666 100644 --- a/setup.py +++ b/setup.py @@ -4,26 +4,34 @@ from setuptools import Extension, setup from Cython.Build import cythonize +INSTALL_PREFIX_WIN = "deps\\install" -def get_include_dirs(): - platform_supported = False + +def is_nix_platform(platform): for prefix in ["darwin", "linux", "bsd"]: if prefix in sys.platform: - platform_supported = True - include_dirs = [ - "/usr/include", - "/usr/local/include", - "/usr/include/eigen3", - "/usr/local/include/eigen3", - ] - - if "CPATH" in os.environ: - include_dirs += os.environ["CPATH"].split(":") - - break - if sys.platform == "win32": - platform_supported = False - if not platform_supported: + return True + return False + + +def get_include_dirs(): + if is_nix_platform(sys.platform): + include_dirs = [ + "/usr/include", + "/usr/local/include", + "/usr/include/eigen3", + "/usr/local/include/eigen3", + ] + + if "CPATH" in os.environ: + include_dirs += os.environ["CPATH"].split(":") + + elif sys.platform == "win32": + include_dirs = [ + f"{INSTALL_PREFIX_WIN}\\include", + f"{INSTALL_PREFIX_WIN}\\include\\eigen3", + ] + else: raise NotImplementedError(sys.platform) # get the numpy include path from numpy @@ -34,17 +42,25 @@ def get_include_dirs(): def get_libraries_dir(): - for prefix in ["darwin", "linux", "bsd"]: - if prefix in sys.platform: - platform_supported = True - lib_dirs = ["/usr/lib", "/usr/local/lib"] + if is_nix_platform(sys.platform): + lib_dirs = ["/usr/lib", "/usr/local/lib"] + + if "LD_LIBRARY_PATH" in os.environ: + lib_dirs += os.environ["LD_LIBRARY_PATH"].split(":") + return lib_dirs + if sys.platform == "win32": + return [f"{INSTALL_PREFIX_WIN}\\lib"] - if "LD_LIBRARY_PATH" in os.environ: - lib_dirs += os.environ["LD_LIBRARY_PATH"].split(":") - return lib_dirs raise NotImplementedError(sys.platform) +def get_libraries(): + libraries = ["fcl", "octomap"] + if sys.platform == "win32": + libraries.extend(["octomath", "ccd", "vcruntime"]) + return libraries + + setup( ext_modules=cythonize( [ @@ -53,7 +69,7 @@ def get_libraries_dir(): ["src/fcl/fcl.pyx"], include_dirs=get_include_dirs(), library_dirs=get_libraries_dir(), - libraries=["fcl", "octomap"], + libraries=get_libraries(), language="c++", extra_compile_args=["-std=c++11"], ) From 369e48c8d1848de3ccec7772e7b02e35803c24d1 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Tue, 27 Jul 2021 21:02:50 +0200 Subject: [PATCH 12/20] Update setup.cfg + refactor ps script --- build_dependencies/install_windows.ps1 | 13 ++++++++----- setup.cfg | 14 ++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/build_dependencies/install_windows.ps1 b/build_dependencies/install_windows.ps1 index c0dbdc0..aeae411 100644 --- a/build_dependencies/install_windows.ps1 +++ b/build_dependencies/install_windows.ps1 @@ -11,11 +11,15 @@ It downloads, builds, installs, and then deletes: * octomap #> +# Remember starting location for future usage $base_dir = Get-Location # Create a directory that encapsulates all dependencies mkdir -p deps; Set-Location deps +# Build options +$generator = "Visual Studio 16 2019" + # All compiled depencies will be install in following folder $install_dir = "$base_dir\deps\install" @@ -30,7 +34,7 @@ Set-Location "eigen-$eigen_ver" cmake -B build ` -D CMAKE_BUILD_TYPE=Release ` - -G "Visual Studio 16 2019" ` + -G $generator ` -D BUILD_SHARED_LIBS=ON ` -D CMAKE_INSTALL_PREFIX=$install_dir cmake --install build @@ -46,7 +50,7 @@ Set-Location libccd cmake -B build ` -D CMAKE_BUILD_TYPE=Release ` - -G "Visual Studio 16 2019" ` + -G $generator ` -D BUILD_SHARED_LIBS=ON ` -D CMAKE_INSTALL_PREFIX=$install_dir cmake --build build --config Release --target install @@ -63,7 +67,7 @@ Set-Location octomap cmake -B build ` -D CMAKE_PREFIX_PATH=$install_dir ` -D CMAKE_BUILD_TYPE=Release ` - -G "Visual Studio 16 2019" ` + -G $generator ` -D BUILD_SHARED_LIBS=ON ` -D CMAKE_INSTALL_PREFIX=$install_dir ` -D BUILD_OCTOVIS_SUBPROJECT=OFF ` @@ -82,11 +86,10 @@ Set-Location fcl cmake -B build ` -D CMAKE_PREFIX_PATH=$install_dir ` -D CMAKE_BUILD_TYPE=Release ` - -G "Visual Studio 16 2019" ` + -G $generator ` -D CMAKE_INSTALL_PREFIX=$install_dir cmake --build build --config Release --target install -Write-Host "Done" Set-Location .. # ------------------------------------------------------------------------------ diff --git a/setup.cfg b/setup.cfg index aad6d41..8b75367 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,16 +15,14 @@ classifiers = Development Status :: 3 - Alpha License :: OSI Approved :: BSD License Operating System :: POSIX :: Linux - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 + Operating System :: MacOS + Operating System :: Microsoft :: Windows Programming Language :: Python :: 3 - Programming Language :: Python :: 3.0 - Programming Language :: Python :: 3.1 - Programming Language :: Python :: 3.2 - Programming Language :: Python :: 3.3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: Implementation :: CPython keywords = fcl collision distance [options] From f64a153457368db0822b793e24b73ef599b03008 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Thu, 29 Jul 2021 12:41:55 +0200 Subject: [PATCH 13/20] Fix build for blender and win ci * Blender use a specific version of numpy. * ci failed to compiled fcl while it was correctyl compiled locally with the same build script. Use precompiled binaries until we found out why. * upload wheels to release --- .github/workflows/wheels.yml | 9 ++++++- blender_requirements.txt | 2 ++ build_dependencies/install_windows.ps1 | 2 +- build_dependencies/install_windows_ci.ps1 | 29 +++++++++++++++++++++++ pyproject.toml | 4 ++-- 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 blender_requirements.txt create mode 100644 build_dependencies/install_windows_ci.ps1 diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 7858377..b0108c9 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -15,4 +15,11 @@ jobs: uses: pypa/cibuildwheel@v2.0.0 - uses: actions/upload-artifact@v2 with: - path: ./wheelhouse/*.whl \ No newline at end of file + path: ./wheelhouse/*.whl + - uses: xresloader/upload-to-github-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + file: ./wheelhouse/*.whl + overwrite: true + update_latest_release: true \ No newline at end of file diff --git a/blender_requirements.txt b/blender_requirements.txt new file mode 100644 index 0000000..f6319cd --- /dev/null +++ b/blender_requirements.txt @@ -0,0 +1,2 @@ +numpy==1.19.5 +Cython \ No newline at end of file diff --git a/build_dependencies/install_windows.ps1 b/build_dependencies/install_windows.ps1 index aeae411..d2822cd 100644 --- a/build_dependencies/install_windows.ps1 +++ b/build_dependencies/install_windows.ps1 @@ -4,7 +4,7 @@ but with many modification in order to use fcl 0.6.1 and install dependencies wi This script builds fcl and it's dependencies for python-fcl on Windows. -It downloads, builds, installs, and then deletes: +It downloads, builds, installs: * fcl * libccd * eigen diff --git a/build_dependencies/install_windows_ci.ps1 b/build_dependencies/install_windows_ci.ps1 new file mode 100644 index 0000000..bec5ebb --- /dev/null +++ b/build_dependencies/install_windows_ci.ps1 @@ -0,0 +1,29 @@ +<# +This script install precompiled dependencies to build python-fcl on Windows: + * fcl + * libccd + * eigen + * octomap +#> + +# Remember starting location for future usage +$base_dir = Get-Location +# Binaries folder +$install_dir = "$base_dir\deps\install" + + +$file_name = "PrecompiledDependenciesWindows.zip" +Invoke-WebRequest -Uri "https://github.com/CyrilWaechter/python-fcl/releases/download/v0.6.1/$file_name" -Outfile $file_name +Expand-Archive $file_name -DestinationPath deps + + +# ------------------------------------------------------------------------------ +# Python-FCL + +Write-Host "Copying dependent DLLs" +Copy-Item $install_dir\bin\octomap.dll $base_dir\src\fcl +Copy-Item $install_dir\bin\octomath.dll $base_dir\src\fcl +Copy-Item $install_dir\bin\ccd.dll $base_dir\src\fcl + +Set-Location $base_dir +Write-Host "All done!" diff --git a/pyproject.toml b/pyproject.toml index aba56a1..e7f48d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] skip = "pp*" -before-build = "pip install numpy Cython" +before-build = "pip install -r blender_requirements.txt" manylinux-x86_64-image = "manylinux_2_24" [tool.cibuildwheel.linux] @@ -17,7 +17,7 @@ test-requires = "pytest" test-command = "pytest {package}/test" [tool.cibuildwheel.windows] -before-all = "powershell build_dependencies\\install_windows.ps1" +before-all = "powershell build_dependencies\\install_windows_ci.ps1" archs = ["AMD64"] test-requires = "pytest" test-command = "pytest {package}\\test" \ No newline at end of file From 4d13c917ba3f5208d6257d8c7e4633da4f941ae0 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Tue, 3 Aug 2021 10:42:53 +0200 Subject: [PATCH 14/20] Fix release tag and remove useless before build cibuildwheel already install dependencies during the process. --- .github/workflows/wheels.yml | 4 +++- pyproject.toml | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index b0108c9..e0f1e3f 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -22,4 +22,6 @@ jobs: with: file: ./wheelhouse/*.whl overwrite: true - update_latest_release: true \ No newline at end of file + draft: false + update_latest_release: true + tag_name: v0.6.1 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index e7f48d4..cd9a2d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,12 @@ [build-system] -requires = ["setuptools", "wheel", "numpy", "Cython"] +requires = ["setuptools", "wheel", "oldest-supported-numpy", "Cython"] build-backend = "setuptools.build_meta" [tool.cibuildwheel] skip = "pp*" -before-build = "pip install -r blender_requirements.txt" manylinux-x86_64-image = "manylinux_2_24" +test-requires = "pytest" +test-command = "pytest {package}/test" [tool.cibuildwheel.linux] before-all = "bash build_dependencies/install_linux.sh" @@ -13,11 +14,7 @@ archs = ["x86_64"] [tool.cibuildwheel.macos] before-all = "bash build_dependencies/install_macos.sh" -test-requires = "pytest" -test-command = "pytest {package}/test" [tool.cibuildwheel.windows] before-all = "powershell build_dependencies\\install_windows_ci.ps1" -archs = ["AMD64"] -test-requires = "pytest" -test-command = "pytest {package}\\test" \ No newline at end of file +archs = ["AMD64"] \ No newline at end of file From 840fd6491e59e6f32f02428121dd997ec53f6cf8 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Tue, 3 Aug 2021 11:20:49 +0200 Subject: [PATCH 15/20] Fix Linux build : build on manylinux_2010 instead --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index cd9a2d3..ef88f68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,6 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] skip = "pp*" -manylinux-x86_64-image = "manylinux_2_24" test-requires = "pytest" test-command = "pytest {package}/test" From 9c1811619122dd5887d8ce2cb6827eab5cf90f84 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Wed, 4 Aug 2021 11:31:25 +0200 Subject: [PATCH 16/20] Modify metadata/dockerfile/travis to prepare merge --- .travis.yml | 6 ------ README.md | 3 --- build_dependencies/Dockerfile | 13 ++++--------- setup.cfg | 4 ++-- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 76785fe..5172712 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,5 @@ env: global: - - CIBW_BEFORE_BUILD="yum install -y gcc && yum install -y glibc.i686 && pip install - numpy cython && cd requirements && bash install_cmake.bash && bash clone.bash - && bash build.bash" - - CIBW_TEST_REQUIRES="nose2" - - CIBW_TEST_COMMAND="cd {project}/test && nose2" - - CIBW_SKIP="cp33-* cp34-*" - TWINE_USERNAME=mmatl matrix: include: diff --git a/README.md b/README.md index 6fc558f..bfe9822 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -# Disclaimer -This is fork of https://github.com/BerkeleyAutomation/python-fcl intented to be used in [ifcopenshell](https://github.com/IfcOpenShell/IfcOpenShell) / [BlenderBIM Add-on](https://blenderbim.org/) as orgininal repo is currently unactive and is not merging any PR. - # python-fcl ### Python Interface for the Flexible Collision Library diff --git a/build_dependencies/Dockerfile b/build_dependencies/Dockerfile index 52965aa..da9d08f 100644 --- a/build_dependencies/Dockerfile +++ b/build_dependencies/Dockerfile @@ -6,16 +6,11 @@ # ln -sf requirements/Dockerfile . # docker build . -t pythonfcl -FROM quay.io/pypa/manylinux_2_24_x86_64:latest - -# clone FCL and libccd -# the exact checkouts are in clone.bash -COPY requirements/clone.bash . -RUN bash clone.bash +FROM quay.io/pypa/manylinux2010_x86_64:latest # build and install libccd and fcl using cmake -COPY requirements/build.bash . -RUN bash build.bash +COPY build_dependencies/install_linux.sh . +RUN bash install_linux.sh # manylinux includes a bunch of pythons # to test with others change this env variable @@ -31,4 +26,4 @@ COPY . /python_fcl RUN pip wheel /python_fcl --no-deps -w wheelhouse/ RUN pip install /python_fcl --no-index -f /wheelhouse RUN ls /wheelhouse -RUN auditwheel repair wheelhouse/python_fcl-0.6.1-cp39-cp39-linux_x86_64.whl --plat manylinux_2_24_x86_64 -w /wheelhouse +RUN auditwheel repair wheelhouse/python_fcl-0.6.1-cp39-cp39-linux_x86_64.whl --plat manylinux2010_x86_64 -w /wheelhouse diff --git a/setup.cfg b/setup.cfg index 8b75367..4b431f7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,8 +7,8 @@ long_description_content_type = text/markdown url = https://github.com/CyrilWaechter/python-fcl author = Jelle Feringa, Matthew Matl, Shirokuma, Michael Dawson-Haggerty, See contributor list author_email = jelleferinga@gmail.com, mmatl@eecs.berkeley.edu, rootstock_acg@yahoo.co.jp -maintainer = Cyril Waechter -maintainer_email = cyrwae@hotmail.com +maintainer = Matthew Matl +maintainer_email = mmatl@eecs.berkeley.edu license = BSD license_files = LICENSE classifiers = From 12edfe2deef752171b59f33dc6e7541bc50c8779 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Wed, 4 Aug 2021 12:30:11 +0200 Subject: [PATCH 17/20] Split push/release github actions workflows --- .github/workflows/push.yml | 18 ++++++++++++++++++ .github/workflows/{wheels.yml => release.yml} | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/push.yml rename .github/workflows/{wheels.yml => release.yml} (94%) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..7858377 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,18 @@ +name: Build + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build wheel on ${{matrix.platform}} + runs-on: ${{matrix.platform}} + strategy: + matrix: + platform: [ubuntu-latest, macos-latest, windows-latest] + steps: + - uses: actions/checkout@v2 + - name: Build wheels + uses: pypa/cibuildwheel@v2.0.0 + - uses: actions/upload-artifact@v2 + with: + path: ./wheelhouse/*.whl \ No newline at end of file diff --git a/.github/workflows/wheels.yml b/.github/workflows/release.yml similarity index 94% rename from .github/workflows/wheels.yml rename to .github/workflows/release.yml index e0f1e3f..c2a68c1 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,6 @@ -name: Build +name: Release -on: [push, pull_request] +on: release jobs: build_wheels: From 2173ff923aba94fb6f64370d8844064413df0758 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Thu, 5 Aug 2021 09:01:28 +0200 Subject: [PATCH 18/20] Remove useless blender_requirement.txt --- blender_requirements.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 blender_requirements.txt diff --git a/blender_requirements.txt b/blender_requirements.txt deleted file mode 100644 index f6319cd..0000000 --- a/blender_requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -numpy==1.19.5 -Cython \ No newline at end of file From c5d4f1ff73b634cf6ca093122eb91c77d0feefd1 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Fri, 6 Aug 2021 13:00:17 -0400 Subject: [PATCH 19/20] Update src/fcl/fcl.pyx Co-authored-by: Dmitry Neverov --- src/fcl/fcl.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fcl/fcl.pyx b/src/fcl/fcl.pyx index f15e777..fc4c52c 100644 --- a/src/fcl/fcl.pyx +++ b/src/fcl/fcl.pyx @@ -750,8 +750,9 @@ cdef defs.Quaterniond numpy_to_quaternion3d(a): cdef vec3d_to_numpy(defs.Vector3d vec): return numpy.array([vec[0], vec[1], vec[2]]) -cdef defs.Vector3d numpy_to_vec3d(np.ndarray[double, ndim=1] a): - return defs.Vector3d(&a[0]) +cdef defs.Vector3d numpy_to_vec3d(arr): + cdef double[:] memview = arr.astype(numpy.float64) + return defs.Vector3d(&memview[0]) cdef mat3d_to_numpy(defs.Matrix3d m): return numpy.array([[m(0,0), m(0,1), m(0,2)], @@ -796,4 +797,3 @@ cdef copy_ptr_collision_object(defs.CollisionObjectd*cobj): co = CollisionObject(geom, _no_instance=True) ( co).thisptr = cobj return co - From 9c19f8a371c3fd912493ef3776e8beb8ac89f255 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Fri, 6 Aug 2021 13:00:24 -0400 Subject: [PATCH 20/20] Update src/fcl/fcl.pyx Co-authored-by: Dmitry Neverov --- src/fcl/fcl.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fcl/fcl.pyx b/src/fcl/fcl.pyx index fc4c52c..ff8209e 100644 --- a/src/fcl/fcl.pyx +++ b/src/fcl/fcl.pyx @@ -759,11 +759,11 @@ cdef mat3d_to_numpy(defs.Matrix3d m): [m(1,0), m(1,1), m(1,2)], [m(2,0), m(2,1), m(2,2)]]) -cdef defs.Matrix3d numpy_to_mat3d(np.ndarray[double, ndim=2] a): +cdef defs.Matrix3d numpy_to_mat3d(arr): # NOTE Eigen defaults to column-major storage, # which corresponds to non-default Fortran mode of ordering in numpy - cdef np.ndarray[double, ndim=2, mode='fortran'] f = np.ndarray.copy(a, order='F') - return defs.Matrix3d(&f[0, 0]) + cdef double[:, :] memview = arr.astype(numpy.float64, order='F') + return defs.Matrix3d(&memview[0, 0]) cdef c_to_python_collision_geometry(defs.const_CollisionGeometryd*geom, CollisionObject o1, CollisionObject o2): cdef CollisionGeometry o1_py_geom = (( o1.thisptr).getUserData())