Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jcarpent opened this issue May 15, 2023 Discussed in #422 · 3 comments
Open

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

jcarpent opened this issue May 15, 2023 Discussed in #422 · 3 comments

Comments

@jcarpent
Copy link
Contributor

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.

@jcarpent
Copy link
Contributor Author

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

@manuel-koch
Copy link

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))

@jcarpent
Copy link
Contributor Author

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]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants