13 #ifndef OMPLAPP_GEOMETRY_DETAIL_FCL_METHOD_WRAPPER_
14 #define OMPLAPP_GEOMETRY_DETAIL_FCL_METHOD_WRAPPER_
16 #include "omplapp/config.h"
19 #include "omplapp/geometry/GeometrySpecification.h"
20 #include "omplapp/geometry/detail/assimpUtil.h"
23 #include <fcl/config.h>
24 #if FCL_MAJOR_VERSION==0 && FCL_MINOR_VERSION<6
25 #include <fcl/collision.h>
26 #include <fcl/distance.h>
27 #include <fcl/collision_node.h>
28 #include <fcl/traversal/traversal_node_setup.h>
29 #include <fcl/continuous_collision.h>
31 #include <fcl/narrowphase/collision.h>
32 #include <fcl/narrowphase/distance.h>
33 #include <fcl/narrowphase/continuous_collision.h>
49 OMPL_CLASS_FORWARD(FCLMethodWrapper);
52 class FCLMethodWrapper
56 #if FCL_MAJOR_VERSION==0 && FCL_MINOR_VERSION<6
57 using Vector3 = fcl::Vec3f;
58 using Quaternion = fcl::Quaternion3f;
59 using Transform = fcl::Transform3f;
60 using BVType = fcl::OBBRSS;
61 using Model = fcl::BVHModel<BVType>;
62 using MeshDistanceTraversalNodeOBBRSS = fcl::MeshDistanceTraversalNodeOBBRSS;
63 using CollisionRequest = fcl::CollisionRequest;
64 using CollisionResult = fcl::CollisionResult;
65 using ContinuousCollisionRequest = fcl::ContinuousCollisionRequest;
66 using ContinuousCollisionResult = fcl::ContinuousCollisionResult;
67 using DistanceRequest = fcl::DistanceRequest;
68 using DistanceResult = fcl::DistanceResult;
70 using Vector3 = fcl::Vector3d;
71 using Quaternion = fcl::Quaterniond;
72 using Transform = fcl::Transform3d;
73 using BVType = fcl::OBBRSS<double>;
74 using Model = fcl::BVHModel<BVType>;
75 using MeshDistanceTraversalNodeOBBRSS = fcl::detail::MeshDistanceTraversalNodeOBBRSS<double>;
76 using CollisionRequest = fcl::CollisionRequest<double>;
77 using CollisionResult = fcl::CollisionResult<double>;
78 using ContinuousCollisionRequest = fcl::ContinuousCollisionRequest<double>;
79 using ContinuousCollisionResult = fcl::ContinuousCollisionResult<double>;
80 using DistanceRequest = fcl::DistanceRequest<double>;
81 using DistanceResult = fcl::DistanceResult<double>;
84 using FCLPoseFromStateCallback = std::function<void(Transform &,
const base::State *)>;
87 GeometricStateExtractor se,
89 FCLPoseFromStateCallback poseCallback)
106 #if FCL_MAJOR_VERSION==0 && FCL_MINOR_VERSION<6
107 static Transform identity;
109 static Transform identity(Transform::Identity());
111 CollisionRequest collisionRequest;
112 CollisionResult collisionResult;
118 for (std::size_t i = 0; i <
robotParts_.size(); ++i)
122 identity, collisionRequest, collisionResult) > 0)
130 Transform trans_i, trans_j;
131 for (std::size_t i = 0 ; i <
robotParts_.size(); ++i)
135 for (std::size_t j = i + 1 ; j <
robotParts_.size(); ++j)
139 collisionRequest, collisionResult) > 0)
150 virtual bool isValid(
const base::State *s1,
const base::State *s2,
double &collisionTime)
const
152 Transform transi_beg, transi_end, trans;
153 ContinuousCollisionRequest collisionRequest(10, 0.0001, fcl::CCDM_SCREW,
154 fcl::GST_LIBCCD, fcl::CCDC_CONSERVATIVE_ADVANCEMENT);
155 ContinuousCollisionResult collisionResult;
167 fcl::continuousCollide(
robotParts_[i], transi_beg, transi_end,
169 collisionRequest, collisionResult);
170 if (collisionResult.is_collide)
172 collisionTime = collisionResult.time_of_contact;
181 Transform transj_beg, transj_end;
182 for (std::size_t i = 0 ; i <
robotParts_.size(); ++i)
187 for (std::size_t j = i+1; j <
robotParts_.size(); ++j)
193 fcl::continuousCollide(
robotParts_[i], transi_beg, transi_end,
195 collisionRequest, collisionResult);
196 if (collisionResult.is_collide)
198 collisionTime = collisionResult.time_of_contact;
208 virtual double clearance(
const base::State *state)
const
210 #if FCL_MAJOR_VERSION==0 && FCL_MINOR_VERSION<6
211 static Transform identity;
213 static Transform identity(Transform::Identity());
215 double minDist = std::numeric_limits<double>::infinity ();
218 DistanceRequest distanceRequest(
true);
219 DistanceResult distanceResult;
225 if (distanceResult.min_distance < minDist)
226 minDist = distanceResult.min_distance;
237 void configure(
const GeometrySpecification &geom)
241 std::pair<std::vector <Vector3>, std::vector<fcl::Triangle>> tri_model;
243 environment_.addSubModel(tri_model.first, tri_model.second);
254 for (
size_t rbt = 0; rbt < geom.robot.size(); ++rbt)
256 auto* model =
new Model();
258 aiVector3D shift(0.0, 0.0, 0.0);
259 if (geom.robotShift.size() > rbt)
260 shift = geom.robotShift[rbt];
263 model->addSubModel(tri_model.first, tri_model.second);
266 model->computeLocalAABB();
268 OMPL_INFORM(
"Robot piece with %d triangles loaded", model->num_tris);
274 std::pair<std::vector <Vector3>, std::vector<fcl::Triangle>>
getFCLModelFromScene(
const aiScene *scene,
const aiVector3D ¢er)
const
276 std::vector<const aiScene*> scenes(1, scene);
277 std::vector<aiVector3D> centers(1, center);
282 std::pair<std::vector<Vector3>, std::vector<fcl::Triangle>>
getFCLModelFromScene(
const std::vector<const aiScene*> &scenes,
const std::vector<aiVector3D> ¢er)
const
286 std::vector<fcl::Triangle> triangles;
287 std::vector<Vector3> pts;
289 for (
unsigned int i = 0; i < scenes.size(); ++i)
291 if (scenes[i] !=
nullptr)
293 std::vector<aiVector3D> t;
296 scene::extractTriangles(scenes[i], t);
298 if (center.size() > i)
302 assert(t.size() % 3 == 0);
306 pts.emplace_back(p[0], p[1], p[2]);
311 for (
unsigned int i = 0; i < pts.size(); i+=3)
312 triangles.emplace_back(i, i+1, i+2);
314 return std::make_pair(pts, triangles);