From 2841967fc6628c9aea58c93227b28abdf5dfbcc2 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Thu, 21 Jul 2016 17:34:40 -0400 Subject: [PATCH] Update API to support fcl 0.5 and tinyxml 4.0 -- for DART 6.1 (#750) * Update API to support fcl 0.5.0 * Update changelog * Use type aliasing rather than boilerplate preprocessors * Switch to use XML_SUCCESS rather than XML_NO_ERROR --- CHANGELOG.md | 1 + dart/collision/fcl/FCLCollisionDetector.cpp | 10 +++------- dart/collision/fcl/FCLCollisionDetector.hpp | 7 ++++--- dart/collision/fcl/FCLCollisionObject.cpp | 2 +- dart/collision/fcl/FCLCollisionObject.hpp | 3 ++- dart/collision/fcl/FCLTypes.hpp | 8 ++++++++ dart/utils/XmlHelpers.cpp | 10 +++++----- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac756d7cb5a30..945e1b8606cc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Collision detection + * Added support of FCL 0.5.0: [#749](https://github.com/dartsim/dart/pull/749) * Added warnings for unsupported shape pairs of DARTCollisionDetector: [#722](https://github.com/dartsim/dart/pull/722) * Misc improvements and bug fixes diff --git a/dart/collision/fcl/FCLCollisionDetector.cpp b/dart/collision/fcl/FCLCollisionDetector.cpp index 6d5173c060b05..c746cd4944428 100644 --- a/dart/collision/fcl/FCLCollisionDetector.cpp +++ b/dart/collision/fcl/FCLCollisionDetector.cpp @@ -431,8 +431,6 @@ fcl::BVHModel* createEllipsoid(float _sizeX, float _sizeY, float _sizeZ) return model; } -#if FCL_MAJOR_MINOR_VERSION_AT_MOST(0,4) - //============================================================================== template fcl::BVHModel* createCylinder(double _baseRadius, double _topRadius, @@ -536,8 +534,6 @@ fcl::BVHModel* createCylinder(double _baseRadius, double _topRadius, return model; } -#endif - //============================================================================== template fcl::BVHModel* createMesh(float _scaleX, float _scaleY, float _scaleZ, @@ -782,7 +778,7 @@ std::unique_ptr FCLCollisionDetector::createCollisionObject( } //============================================================================== -boost::shared_ptr +fcl_shared_ptr FCLCollisionDetector::claimFCLCollisionGeometry( const dynamics::ConstShapePtr& shape) { @@ -805,7 +801,7 @@ FCLCollisionDetector::claimFCLCollisionGeometry( } //============================================================================== -boost::shared_ptr +fcl_shared_ptr FCLCollisionDetector::createFCLCollisionGeometry( const dynamics::ConstShapePtr& shape, FCLCollisionDetector::PrimitiveShape type, @@ -930,7 +926,7 @@ FCLCollisionDetector::createFCLCollisionGeometry( geom = createEllipsoid(0.1, 0.1, 0.1); } - return boost::shared_ptr(geom, deleter); + return fcl_shared_ptr(geom, deleter); } //============================================================================== diff --git a/dart/collision/fcl/FCLCollisionDetector.hpp b/dart/collision/fcl/FCLCollisionDetector.hpp index b808619022801..d37c0e58ccb8f 100644 --- a/dart/collision/fcl/FCLCollisionDetector.hpp +++ b/dart/collision/fcl/FCLCollisionDetector.hpp @@ -36,6 +36,7 @@ #include #include // This should be removed once we migrate to fcl 0.5 #include "dart/collision/CollisionDetector.hpp" +#include "dart/collision/fcl/FCLTypes.hpp" namespace dart { namespace collision { @@ -130,7 +131,7 @@ class FCLCollisionDetector : public CollisionDetector /// Return fcl::CollisionGeometry associated with give Shape. New /// fcl::CollisionGeome will be created if it hasn't created yet. - boost::shared_ptr claimFCLCollisionGeometry( + fcl_shared_ptr claimFCLCollisionGeometry( const dynamics::ConstShapePtr& shape); protected: @@ -162,7 +163,7 @@ class FCLCollisionDetector : public CollisionDetector /// Create fcl::CollisionGeometry with the custom deleter /// FCLCollisionGeometryDeleter - boost::shared_ptr createFCLCollisionGeometry( + fcl_shared_ptr createFCLCollisionGeometry( const dynamics::ConstShapePtr& shape, FCLCollisionDetector::PrimitiveShape type, const FCLCollisionGeometryDeleter& deleter); @@ -170,7 +171,7 @@ class FCLCollisionDetector : public CollisionDetector private: using ShapeMap = std::map>; + fcl_weak_ptr>; // TODO(JS): FCL replaced all the use of boost in version 0.5. Once we migrate // to 0.5 or greater, this also should be changed to // std::weak_ptr diff --git a/dart/collision/fcl/FCLCollisionObject.cpp b/dart/collision/fcl/FCLCollisionObject.cpp index db77466280d0a..bf4a682550cf0 100644 --- a/dart/collision/fcl/FCLCollisionObject.cpp +++ b/dart/collision/fcl/FCLCollisionObject.cpp @@ -63,7 +63,7 @@ const fcl::CollisionObject* FCLCollisionObject::getFCLCollisionObject() const FCLCollisionObject::FCLCollisionObject( CollisionDetector* collisionDetector, const dynamics::ShapeFrame* shapeFrame, - const boost::shared_ptr& fclCollGeom) + const fcl_shared_ptr& fclCollGeom) : CollisionObject(collisionDetector, shapeFrame), mFCLCollisionObjectUserData(new UserData(this)), mFCLCollisionObject(new fcl::CollisionObject(fclCollGeom)) diff --git a/dart/collision/fcl/FCLCollisionObject.hpp b/dart/collision/fcl/FCLCollisionObject.hpp index ff011cf75e074..544c36eea1fbb 100644 --- a/dart/collision/fcl/FCLCollisionObject.hpp +++ b/dart/collision/fcl/FCLCollisionObject.hpp @@ -34,6 +34,7 @@ #include #include "dart/collision/CollisionObject.hpp" +#include "dart/collision/fcl/FCLTypes.hpp" namespace dart { namespace collision { @@ -64,7 +65,7 @@ class FCLCollisionObject : public CollisionObject /// Constructor FCLCollisionObject(CollisionDetector* collisionDetector, const dynamics::ShapeFrame* shapeFrame, - const boost::shared_ptr& fclCollGeom); + const fcl_shared_ptr& fclCollGeom); // Documentation inherited void updateEngineData() override; diff --git a/dart/collision/fcl/FCLTypes.hpp b/dart/collision/fcl/FCLTypes.hpp index 8fa6e88108a81..8fbf15c2c130f 100644 --- a/dart/collision/fcl/FCLTypes.hpp +++ b/dart/collision/fcl/FCLTypes.hpp @@ -46,6 +46,14 @@ (FCL_MAJOR_VERSION < x || (FCL_MAJOR_VERSION <= x && \ (FCL_MINOR_VERSION < y || (FCL_MINOR_VERSION <= y)))) +#if FCL_VERSION_AT_LEAST(0,5,0) +template using fcl_shared_ptr = std::shared_ptr; +template using fcl_weak_ptr = std::weak_ptr; +#else +template using fcl_shared_ptr = boost::shared_ptr; +template using fcl_weak_ptr = boost::weak_ptr; +#endif + namespace dart { namespace collision { diff --git a/dart/utils/XmlHelpers.cpp b/dart/utils/XmlHelpers.cpp index adaf7de17647f..bb0fcc7ca329e 100644 --- a/dart/utils/XmlHelpers.cpp +++ b/dart/utils/XmlHelpers.cpp @@ -726,7 +726,7 @@ bool getAttributeBool(const tinyxml2::XMLElement* element, const int result = element->QueryBoolAttribute(attributeName.c_str(), &val); - if (result != tinyxml2::XML_NO_ERROR) + if (result != tinyxml2::XML_SUCCESS) { dtwarn << "[getAttribute] Error in parsing bool type attribute [" << attributeName << "] of an element [" << element->Name() @@ -744,7 +744,7 @@ int getAttributeInt(const tinyxml2::XMLElement* element, int val = 0; const int result = element->QueryIntAttribute(attributeName.c_str(), &val); - if (result != tinyxml2::XML_NO_ERROR) + if (result != tinyxml2::XML_SUCCESS) { dtwarn << "[getAttribute] Error in parsing int type attribute [" << attributeName << "] of an element [" << element->Name() @@ -763,7 +763,7 @@ unsigned int getAttributeUInt(const tinyxml2::XMLElement* element, const int result = element->QueryUnsignedAttribute(attributeName.c_str(), &val); - if (result != tinyxml2::XML_NO_ERROR) + if (result != tinyxml2::XML_SUCCESS) { dtwarn << "[getAttribute] Error in parsing unsiged int type attribute [" << attributeName << "] of an element [" << element->Name() @@ -782,7 +782,7 @@ float getAttributeFloat(const tinyxml2::XMLElement* element, const int result = element->QueryFloatAttribute(attributeName.c_str(), &val); - if (result != tinyxml2::XML_NO_ERROR) + if (result != tinyxml2::XML_SUCCESS) { dtwarn << "[getAttribute] Error in parsing float type attribute [" << attributeName << "] of an element [" << element->Name() @@ -801,7 +801,7 @@ double getAttributeDouble(const tinyxml2::XMLElement* element, const int result = element->QueryDoubleAttribute(attributeName.c_str(), &val); - if (result != tinyxml2::XML_NO_ERROR) + if (result != tinyxml2::XML_SUCCESS) { dtwarn << "[getAttribute] Error in parsing double type attribute [" << attributeName << "] of an element [" << element->Name()