Skip to content
Snippets Groups Projects
Unverified Commit b308deef authored by Louis Montaut's avatar Louis Montaut
Browse files

readme: update python example to use coal

parent 09ee974a
No related branches found
No related tags found
No related merge requests found
Pipeline #41968 failed
...@@ -103,8 +103,8 @@ std::shared_ptr<coal::ConvexBase> loadConvexMesh(const std::string& file_name) { ...@@ -103,8 +103,8 @@ std::shared_ptr<coal::ConvexBase> loadConvexMesh(const std::string& file_name) {
} }
int main() { int main() {
// Create the hppfcl shapes. // Create the coal shapes.
// Hppfcl supports many primitive shapes: boxes, spheres, capsules, cylinders, ellipsoids, cones, planes, // Coal supports many primitive shapes: boxes, spheres, capsules, cylinders, ellipsoids, cones, planes,
// halfspace and convex meshes (i.e. convex hulls of clouds of points). // halfspace and convex meshes (i.e. convex hulls of clouds of points).
// It also supports BVHs (bounding volumes hierarchies), height-fields and octrees. // It also supports BVHs (bounding volumes hierarchies), height-fields and octrees.
std::shared_ptr<coal::Ellipsoid> shape1 = std::make_shared<coal::Ellipsoid>(0.7, 1.0, 0.8); std::shared_ptr<coal::Ellipsoid> shape1 = std::make_shared<coal::Ellipsoid>(0.7, 1.0, 0.8);
...@@ -161,7 +161,7 @@ int main() { ...@@ -161,7 +161,7 @@ int main() {
Here is the C++ example from above translated in python using HPP-FCL's python bindings: Here is the C++ example from above translated in python using HPP-FCL's python bindings:
```python ```python
import numpy as np import numpy as np
import hppfcl import coal
# Optional: # Optional:
# The Pinocchio library is a rigid body algorithms library and has a handy SE3 module. # The Pinocchio library is a rigid body algorithms library and has a handy SE3 module.
# It can be installed as simply as `conda -c conda-forge install pinocchio`. # It can be installed as simply as `conda -c conda-forge install pinocchio`.
...@@ -169,36 +169,36 @@ import hppfcl ...@@ -169,36 +169,36 @@ import hppfcl
import pinocchio as pin import pinocchio as pin
def loadConvexMesh(file_name: str): def loadConvexMesh(file_name: str):
loader = hppfcl.MeshLoader() loader = coal.MeshLoader()
bvh: hppfcl.BVHModelBase = loader.load(file_name) bvh: coal.BVHModelBase = loader.load(file_name)
bvh.buildConvexHull(True, "Qt") bvh.buildConvexHull(True, "Qt")
return bvh.convex return bvh.convex
if __name__ == "__main__": if __name__ == "__main__":
# Create hppfcl shapes # Create coal shapes
shape1 = hppfcl.Ellipsoid(0.7, 1.0, 0.8) shape1 = coal.Ellipsoid(0.7, 1.0, 0.8)
shape2 = loadConvexMesh("../path/to/mesh/file.obj") shape2 = loadConvexMesh("../path/to/mesh/file.obj")
# Define the shapes' placement in 3D space # Define the shapes' placement in 3D space
T1 = hppfcl.Transform3s() T1 = coal.Transform3s()
T1.setTranslation(pin.SE3.Random().translation) T1.setTranslation(pin.SE3.Random().translation)
T1.setRotation(pin.SE3.Random().rotation) T1.setRotation(pin.SE3.Random().rotation)
T2 = hppfcl.Transform3s(); T2 = coal.Transform3s();
# Using np arrays also works # Using np arrays also works
T1.setTranslation(np.random.rand(3)) T1.setTranslation(np.random.rand(3))
T2.setRotation(pin.SE3.Random().rotation) T2.setRotation(pin.SE3.Random().rotation)
# Define collision requests and results # Define collision requests and results
col_req = hppfcl.CollisionRequest() col_req = coal.CollisionRequest()
col_res = hppfcl.CollisionResult() col_res = coal.CollisionResult()
# Collision call # Collision call
hppfcl.collide(shape1, T1, shape2, T2, col_req, col_res) coal.collide(shape1, T1, shape2, T2, col_req, col_res)
# Accessing the collision result once it has been populated # Accessing the collision result once it has been populated
print("Is collision? ", {col_res.isCollision()}) print("Is collision? ", {col_res.isCollision()})
if col_res.isCollision(): if col_res.isCollision():
contact: hppfcl.Contact = col_res.getContact(0) contact: coal.Contact = col_res.getContact(0)
print("Penetration depth: ", contact.penetration_depth) print("Penetration depth: ", contact.penetration_depth)
print("Distance between the shapes including the security margin: ", contact.penetration_depth + col_req.security_margin) print("Distance between the shapes including the security margin: ", contact.penetration_depth + col_req.security_margin)
print("Witness point shape1: ", contact.getNearestPoint1()) print("Witness point shape1: ", contact.getNearestPoint1())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment