humanoid-path-planner/hpp-fcl

How to create a collision object from a (convex) mesh

jcarpent opened this issue · 3 comments

Discussed in #422

Originally posted by manuel-koch May 15, 2023
I'm new to hpp-fcl and can't find useful documentation about the python interface.
There seem to be some c++ code examples ( mostly doxygen stuff ) but I have difficulties converting them to python.

I'm trying to replicate some functionality from the original fcl library.
In their example they have something like

# FCL for a non-convex mesh
verts = np.array([[1.0, 1.0, 1.0],
                  [2.0, 1.0, 1.0],
                  [1.0, 2.0, 1.0],
                  [1.0, 1.0, 2.0]])
tris  = np.array([[0,2,1],
                  [0,3,2],
                  [0,1,3],
                  [1,2,3]])
m = fcl.BVHModel()
m.beginModel(len(verts), len(tris))
m.addSubModel(verts, tris)
m.endModel()

# FCL for a convex mesh
verts = np.array([[1.0, 1.0, 1.0],
                  [2.0, 1.0, 1.0],
                  [1.0, 2.0, 1.0],
                  [1.0, 1.0, 2.0]])
tris  = np.array([[0,2,1],
                  [0,3,2],
                  [0,1,3],
                  [1,2,3]])
faces = np.concatenate((3 * np.ones((len(tris), 1), dtype=np.int64), tris), axis=1).flatten()
c = fcl.Convex(verts, len(tris), faces)

# how would it look like for HPP-FCL ??

How would that look like for hpp-fcl ?
Thank you for helping getting starting with hpp-fcl.

I propose adding new signatures to comply with your needs fully. In the near future, we plan make the API much Eigen friendly.

I stumbled on some other strange issue with interface types, i.e. some numpy type can't be used whereas the plain python type can be used:

import hppfcl as fcl
from pyrr import Matrix44

transformation = Matrix44.identity(dtype="f4"))
(scale_x, scale_y, scale_z), _, _ = transformation.decompose()
fcl.Box(scale_x, scale_y, scale_z)

>               fcl.Box(scale_x, scale_y, scale_z)
E               Boost.Python.ArgumentError: Python argument types in
E                   Box.__init__(Box, numpy.float32, numpy.float32, numpy.float32)
E               did not match C++ signature:
E                   __init__(_object*, Eigen::Matrix<double, 3, 1, 0, 3, 1>)
E                   __init__(_object*, double, double, double)
E                   __init__(_object*, hpp::fcl::Box)
E                   __init__(_object*)

but the following works with type conversion

fcl.Box(float(scale_x), float(scale_y), float(scale_z))

This issue is expected, as float32 values are not directly cast into float64 values.
You can rather use:

fcl.Box(np.array([scale_x, scale_y, scale_z]))