Skip to content

Commit 8ba0882

Browse files
committed
feat: bind fcl convex type
1 parent 780f4b0 commit 8ba0882

File tree

4 files changed

+95
-29
lines changed

4 files changed

+95
-29
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This package also supports most of FCL's object shapes, including:
1717
* Ellipsoid
1818
* Capsule
1919
* Cone
20+
* Convex
2021
* Cylinder
2122
* Half-Space
2223
* Plane
@@ -25,10 +26,11 @@ This package also supports most of FCL's object shapes, including:
2526

2627
## Installation
2728

28-
First, install [octomap](https://github.com/OctoMap/octomap), which is necessary using OcTree. For Ubuntu, using `sudo apt-get install liboctomap-dev`
29+
First, install [octomap](https://github.com/OctoMap/octomap), which is necessary to use OcTree. For Ubuntu, use `sudo apt-get install liboctomap-dev`.
2930
Second, install FCL using the instructions provided [here](https://github.com/flexible-collision-library/fcl).
3031
If you're on Ubuntu 17.04 or newer, you can install FCL using `sudo apt-get install libfcl-dev`.
3132
Otherwise, just compile FCL from source -- it's quick and easy, and its dependencies are all easily installed via `apt` or `brew`.
33+
Note: the provided install scripts (under `build_dependencies`) can automate this process as well.
3234

3335
In order to install the Python wrappers for FCL, simply run
3436
```shell
@@ -39,8 +41,7 @@ pip install python-fcl
3941

4042
### Collision Objects
4143
The primary construct in FCL is the `CollisionObject`, which forms the backbone of all collision and distance computations.
42-
A `CollisionObject` consists of two components -- its geometry, defined by a `CollisionGeometry` object,
43-
and its pose, defined by a `Transform` object.
44+
A `CollisionObject` consists of two components -- its geometry, defined by a `CollisionGeometry` object, and its pose, defined by a `Transform` object.
4445

4546
#### Collision Geometries
4647
There are two main types of `CollisionGeometry` objects -- geometric primitives, such as boxes and spheres,
@@ -88,6 +89,20 @@ m.addSubModel(verts, tris)
8889
m.endModel()
8990
```
9091

92+
If the mesh is convex, such as the example above, you can also wrap it in the `Convex` class. Note that the instantiation is a bit different because the `Convex` class supports arbitrary polygons for each face of the convex object.
93+
```python
94+
verts = np.array([[1.0, 1.0, 1.0],
95+
[2.0, 1.0, 1.0],
96+
[1.0, 2.0, 1.0],
97+
[1.0, 1.0, 2.0]])
98+
tris = np.array([[0,2,1],
99+
[0,3,2],
100+
[0,1,3],
101+
[1,2,3]])
102+
faces = np.concatenate((3 * np.ones((len(tris), 1), dtype=np.int64), tris), axis=1).flatten()
103+
c = fcl.Convex(verts, len(tris), faces)
104+
```
105+
91106
#### Transforms
92107
In addition to a `CollisionGeometry`, a `CollisionObject` requires a `Transform`, which tells FCL where the `CollisionGeometry` is actually located in the world.
93108
All `Transform` objects specify a rigid transformation (i.e. a rotation and a translation).

src/fcl/__init__.py

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
try:
22
from .fcl import (
3-
CollisionObject,
4-
CollisionGeometry,
5-
Transform,
6-
TriangleP,
73
Box,
8-
Sphere,
9-
Ellipsoid,
4+
BVHModel,
105
Capsule,
6+
CollisionGeometry,
7+
CollisionObject,
118
Cone,
9+
Convex,
1210
Cylinder,
11+
DynamicAABBTreeCollisionManager,
12+
Ellipsoid,
1313
Halfspace,
14-
Plane,
15-
BVHModel,
1614
OcTree,
17-
DynamicAABBTreeCollisionManager,
15+
Plane,
16+
Sphere,
17+
Transform,
18+
TriangleP,
1819
collide,
1920
continuousCollide,
20-
distance,
2121
defaultCollisionCallback,
2222
defaultDistanceCallback,
23+
distance,
2324
)
2425
except ModuleNotFoundError:
2526
import traceback
@@ -28,21 +29,60 @@
2829
print("Failed to import fcl.fcl. It is probably not correctly compiled.")
2930

3031
from .collision_data import (
31-
OBJECT_TYPE,
3232
NODE_TYPE,
33+
OBJECT_TYPE,
3334
CCDMotionType,
3435
CCDSolverType,
35-
GJKSolverType,
36-
Contact,
37-
CostSource,
36+
CollisionData,
3837
CollisionRequest,
3938
CollisionResult,
39+
Contact,
4040
ContinuousCollisionRequest,
4141
ContinuousCollisionResult,
42+
CostSource,
43+
DistanceData,
4244
DistanceRequest,
4345
DistanceResult,
44-
CollisionData,
45-
DistanceData,
46+
GJKSolverType,
4647
)
47-
4848
from .version import __version__
49+
50+
__all__ = [
51+
"CollisionObject",
52+
"CollisionGeometry",
53+
"Transform",
54+
"TriangleP",
55+
"Box",
56+
"Sphere",
57+
"Ellipsoid",
58+
"Capsule",
59+
"Cone",
60+
"Convex",
61+
"Cylinder",
62+
"Halfspace",
63+
"Plane",
64+
"BVHModel",
65+
"OcTree",
66+
"DynamicAABBTreeCollisionManager",
67+
"collide",
68+
"continuousCollide",
69+
"distance",
70+
"defaultCollisionCallback",
71+
"defaultDistanceCallback",
72+
"OBJECT_TYPE",
73+
"NODE_TYPE",
74+
"CCDMotionType",
75+
"CCDSolverType",
76+
"GJKSolverType",
77+
"Contact",
78+
"CostSource",
79+
"CollisionRequest",
80+
"CollisionResult",
81+
"ContinuousCollisionRequest",
82+
"ContinuousCollisionResult",
83+
"DistanceRequest",
84+
"DistanceResult",
85+
"CollisionData",
86+
"DistanceData",
87+
"__version__",
88+
]

src/fcl/fcl.pyx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,20 @@ cdef class Cone(CollisionGeometry):
332332
def __set__(self, value):
333333
(<defs.Coned*> self.thisptr).lz = <double?> value
334334

335+
cdef class Convex(CollisionGeometry):
336+
def __cinit__(self, vertices, num_faces, faces):
337+
cdef vector[defs.Vector3d] vs
338+
cdef vector[int] fs
339+
for vert in vertices:
340+
vs.push_back(numpy_to_vec3d(vert))
341+
for face in faces:
342+
fs.push_back(face)
343+
self.thisptr = new defs.Convexd(defs.make_shared[vector[defs.Vector3d]](vs), num_faces, defs.make_shared[vector[int]](fs))
344+
345+
property num_faces:
346+
def __get__(self):
347+
return (<defs.Convexd*> self.thisptr).getFaceCount()
348+
335349
cdef class Cylinder(CollisionGeometry):
336350
def __cinit__(self, radius, lz):
337351
self.thisptr = new defs.Cylinderd(radius, lz)

src/fcl/fcl_defs.pxd

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
cimport octomap_defs as octomap
12
from libcpp cimport bool
3+
from libcpp.memory cimport make_shared, shared_ptr
4+
from libcpp.set cimport set
25
from libcpp.string cimport string
36
from libcpp.vector cimport vector
4-
from libcpp.set cimport set
5-
from libcpp.memory cimport shared_ptr
6-
cimport octomap_defs as octomap
7+
78

89
cdef extern from "Python.h":
910
ctypedef struct PyObject
@@ -231,12 +232,8 @@ cdef extern from "fcl/geometry/shape/cylinder.h" namespace "fcl":
231232

232233
cdef extern from "fcl/geometry/shape/convex.h" namespace "fcl":
233234
cdef cppclass Convexd(ShapeBased):
234-
Convexd(Vector3d* plane_nomals_,
235-
double* plane_dis_,
236-
int num_planes,
237-
Vector3d* points_,
238-
int num_points_,
239-
int* polygons_) except +
235+
Convexd(const shared_ptr[const vector[Vector3d]]& vertices, int num_faces, const shared_ptr[const vector[int]]& faces) except +
236+
int getFaceCount()
240237

241238
cdef extern from "fcl/geometry/shape/halfspace.h" namespace "fcl":
242239
cdef cppclass Halfspaced(ShapeBased):

0 commit comments

Comments
 (0)