From 71fe377d8272c812c359284827755424b91ccc4d Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Tue, 7 May 2024 10:54:20 +0200 Subject: [PATCH] subt_ign: Correctly migrate to FCL 0.6 Signed-off-by: Martin Pecka --- subt_ign/include/subt_ign/VisibilityTable.hh | 15 +++++++++++ subt_ign/package.xml | 5 ++-- subt_ign/src/VisibilityPlugin.cc | 4 +++ subt_ign/src/VisibilityTable.cc | 22 +++++++++++++++- subt_ign/src/ign_to_fcl.cc | 27 +++++++++++++++++++- subt_ign/src/ign_to_fcl.hh | 15 +++++++++++ 6 files changed, 84 insertions(+), 4 deletions(-) diff --git a/subt_ign/include/subt_ign/VisibilityTable.hh b/subt_ign/include/subt_ign/VisibilityTable.hh index da918440..7ba030a3 100644 --- a/subt_ign/include/subt_ign/VisibilityTable.hh +++ b/subt_ign/include/subt_ign/VisibilityTable.hh @@ -28,9 +28,16 @@ #include #include +#include + namespace fcl { +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 class CollisionObject; +#else + template class CollisionObject; + using CollisionObjectd = CollisionObject; +#endif } namespace subt @@ -95,7 +102,11 @@ namespace subt /// \param[in] _collObjs Collision Objects of models. /// \sa Generate public: void SetModelCollisionObjects( +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 const std::map> &_collObjs); +#else + const std::map> &_collObjs); +#endif /// \brief Get the collection of sampled 3D points and their associated /// vertex id. @@ -218,7 +229,11 @@ namespace subt /// \brief A map of model name to its bounding box. Used for generating LUT private: std::map> collisionObjs; +#else + std::shared_ptr> collisionObjs; +#endif /// \brief A map that stores 3D points an the vertex id in which are located private: std::map, uint64_t> vertices; diff --git a/subt_ign/package.xml b/subt_ign/package.xml index 306bf2dc..9cfdff73 100644 --- a/subt_ign/package.xml +++ b/subt_ign/package.xml @@ -1,4 +1,4 @@ - + subt_ign 0.1.0 The ROS package for the DARPA SubT challenge. @@ -20,7 +20,8 @@ subt_ros libccd-dev - libfcl-dev + libfcl-dev + fcl rosbag roslib diff --git a/subt_ign/src/VisibilityPlugin.cc b/subt_ign/src/VisibilityPlugin.cc index d2dba2f5..ba24061a 100644 --- a/subt_ign/src/VisibilityPlugin.cc +++ b/subt_ign/src/VisibilityPlugin.cc @@ -61,7 +61,11 @@ class subt::VisibilityPluginPrivate /// \brief A map of model name ot its bounding box public: std::map bboxes; +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 public: std::map> fclObjs; +#else + public: std::map> fclObjs; +#endif /// \brief Name of the world public: std::string worldName; diff --git a/subt_ign/src/VisibilityTable.cc b/subt_ign/src/VisibilityTable.cc index c52cf9cd..60d9ad7d 100644 --- a/subt_ign/src/VisibilityTable.cc +++ b/subt_ign/src/VisibilityTable.cc @@ -33,10 +33,14 @@ #include #include +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 #include #include - #include +#else +#include +#include +#endif using namespace ignition; using namespace subt; @@ -167,7 +171,11 @@ void VisibilityTable::SetModelBoundingBoxes( ////////////////////////////////////////////////// void VisibilityTable::SetModelCollisionObjects( +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 const std::map> &_collObjs) +#else + const std::map> &_collObjs) +#endif { this->collisionObjs= _collObjs; } @@ -209,10 +217,17 @@ uint64_t VisibilityTable::Index(const ignition::math::Vector3d &_position) const else { // Fall back to using FCL to find the closest mesh. +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 auto box = std::make_shared(0.01, 0.01, 0.01); auto boxObj = std::make_shared(box, fcl::Matrix3f::getIdentity(), fcl::Vec3f(_position.X(), _position.Y(), _position.Z())); +#else + auto box = std::make_shared(0.01, 0.01, 0.01); + auto boxObj = std::make_shared(box, + fcl::Matrix3d::Identity(), + fcl::Vector3d(_position.X(), _position.Y(), _position.Z())); +#endif uint64_t closestIdx = 0; float closestDist = 1e9; @@ -230,8 +245,13 @@ uint64_t VisibilityTable::Index(const ignition::math::Vector3d &_position) const if (meshIt == this->collisionObjs.end()) continue; +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 fcl::DistanceRequest request(true, true); fcl::DistanceResult fclResult; +#else + fcl::DistanceRequestd request(true, true); + fcl::DistanceResultd fclResult; +#endif fcl::distance(meshIt->second.get(), boxObj.get(), request, fclResult); if (fclResult.min_distance < closestDist) diff --git a/subt_ign/src/ign_to_fcl.cc b/subt_ign/src/ign_to_fcl.cc index 0628e9cf..7283c679 100644 --- a/subt_ign/src/ign_to_fcl.cc +++ b/subt_ign/src/ign_to_fcl.cc @@ -1,9 +1,13 @@ #include "ign_to_fcl.hh" #include +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 #include #include #include +#else +#include +#endif #include #include @@ -25,7 +29,11 @@ convert_to_fcl(const ignition::common::Mesh &_mesh) for (auto ii = 0u; ii < _mesh.SubMeshCount(); ++ii) { auto submesh = _mesh.SubMeshByIndex(ii).lock(); +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 std::vector vertices; +#else + std::vector vertices; +#endif std::vector triangles; vertices.reserve(submesh->VertexCount()); @@ -33,7 +41,11 @@ convert_to_fcl(const ignition::common::Mesh &_mesh) for(size_t jj = 0; jj < submesh->VertexCount(); ++jj) { +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 vertices.push_back(fcl::Vec3f( +#else + vertices.push_back(fcl::Vector3d( +#endif submesh->Vertex(jj).X(), submesh->Vertex(jj).Y(), submesh->Vertex(jj).Z())); @@ -55,13 +67,21 @@ convert_to_fcl(const ignition::common::Mesh &_mesh) return ret; } +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 std::shared_ptr +#else +std::shared_ptr +#endif convert_to_fcl(const ignition::common::Mesh &_mesh, const ignition::math::Pose3d &_pose) { auto model = convert_to_fcl(_mesh); +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 fcl::Matrix3f rot; +#else + fcl::Matrix3d rot; +#endif for(size_t ii = 0; ii < 3; ++ii) { for(size_t jj = 0; jj < 3; ++jj) @@ -70,8 +90,13 @@ convert_to_fcl(const ignition::common::Mesh &_mesh, } } - auto obj = std::make_shared(model, rot, +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 + auto obj = std::make_shared(model, rot, fcl::Vec3f(_pose.Pos().X(), _pose.Pos().Y(), _pose.Pos().Z())); +#else + auto obj = std::make_shared(model, rot, + fcl::Vector3d(_pose.Pos().X(), _pose.Pos().Y(), _pose.Pos().Z())); +#endif return obj; } diff --git a/subt_ign/src/ign_to_fcl.hh b/subt_ign/src/ign_to_fcl.hh index 4b001a8f..87b2e1b2 100644 --- a/subt_ign/src/ign_to_fcl.hh +++ b/subt_ign/src/ign_to_fcl.hh @@ -1,9 +1,16 @@ #ifndef IGN_TO_FCL_HH_ #define IGN_TO_FCL_HH_ +#include +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 #include #include #include +#else +#include +#include +#include +#endif #include #include @@ -18,7 +25,11 @@ namespace subt /// BVH = Bounding Volume Heirarchy /// OBB = Oriented Bounding Box /// RSS = Rectange Swept Sphere +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 using Model = fcl::BVHModel; +#else +using Model = fcl::BVHModel; +#endif /// \brief Create an fcl model from an ignition mesh. /// @@ -36,7 +47,11 @@ convert_to_fcl(const ignition::common::Mesh &_mesh); /// \param[in] _mesh mesh to convert to fcl model. /// \param[in] _pose world pose of the model. /// \return collision object when successfully converted otherwise nullptr +#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5 std::shared_ptr +#else +std::shared_ptr +#endif convert_to_fcl(const ignition::common::Mesh &_mesh, const ignition::math::Pose3d &_pose);