From b7e9fdd62e12c8c00cc0f28b04a2d8a6863315b3 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 26 Aug 2016 14:10:50 -0400 Subject: [PATCH 1/8] Find bullet using cmake find_package and support for bullet built with double precision (see #636, #660) --- CMakeLists.txt | 46 ++++++++++++++++++++++++++++++++++------------ dart/config.h.in | 4 ++++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e638282cafb64..10719e6f8a001 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -355,21 +355,43 @@ else() set(HAVE_SHARK FALSE) endif() -# BulletCollision -if(UNIX) - pkg_check_modules(BULLET bullet>=2.82 QUIET) - if(NOT BULLET_FOUND) - pkg_check_modules(BULLET bullet2.82>=2.82 QUIET) - endif() -else() - find_package(Bullet COMPONENTS BulletMath BulletCollision QUIET) -endif() +# Bullet. Force MODULE mode to use the FindBullet.cmake file distributed with +# CMake. Otherwise, we may end up using the BulletConfig.cmake file distributed +# with Bullet, which uses relative paths and may break transitive dependencies. +find_package(Bullet COMPONENTS BulletMath BulletCollision MODULE QUIET) + if(BULLET_FOUND) - message(STATUS "Looking for BulletCollision - ${BULLET_VERSION} found") + # Test whether Bullet was built with double precision. If so, we need to + # define the BT_USE_DOUBLE_PRECISION pre-processor directive before including + # any Bullet headers. This is a workaround for the fact that Bullet does not + # add the definition to BULLET_DEFINITIONS or generate a #cmakedefine header. + include(CheckCXXSourceCompiles) + set(CMAKE_REQUIRED_FLAGS "") + set(CMAKE_REQUIRED_DEFINITIONS "-DBT_USE_DOUBLE_PRECISION") + set(CMAKE_REQUIRED_INCLUDES "${BULLET_INCLUDE_DIRS}") + set(CMAKE_REQUIRED_LIBRARIES "${BULLET_LIBRARIES}") + check_cxx_source_compiles( + " + #include + int main() + { + btVector3 v(0., 0., 1.); + btStaticPlaneShape planeShape(v, 0.); + return 0; + } + " + BT_USE_DOUBLE_PRECISION + ) + + if(BT_USE_DOUBLE_PRECISION) + message(STATUS "Looking for Bullet - found (double precision)") + else() + message(STATUS "Looking for Bullet - found (single precision)") + endif() + set(HAVE_BULLET_COLLISION TRUE) - add_definitions(-DHAVE_BULLET_COLLISION) else() - message(STATUS "Looking for BulletCollision - NOT found, please install libbullet-dev") + message(STATUS "Looking for Bullet - NOT found, to use BulletCollisionDetector, please install libbullet-dev") set(HAVE_BULLET_COLLISION FALSE) endif() diff --git a/dart/config.h.in b/dart/config.h.in index 588c24f91bfc9..36b0e120c5715 100644 --- a/dart/config.h.in +++ b/dart/config.h.in @@ -54,4 +54,8 @@ #cmakedefine ASSIMP_AISCENE_CTOR_DTOR_DEFINED 1 #cmakedefine ASSIMP_AIMATERIAL_CTOR_DTOR_DEFINED 1 +// Workaround for the fact that Bullet does not add the definition to +// BULLET_DEFINITIONS or generate a #cmakedefine header. +#cmakedefine BT_USE_DOUBLE_PRECISION + #endif // #ifndef DART_CONFIG_H_ From b3c21005ef18876db8c7a198b9ec60ad4140135a Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 26 Aug 2016 14:45:03 -0400 Subject: [PATCH 2/8] Use btGImpactMeshShape instead of btConvexTriangleMeshShape --- dart/collision/bullet/BulletCollisionNode.cpp | 10 +++++----- dart/collision/bullet/BulletCollisionNode.h | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dart/collision/bullet/BulletCollisionNode.cpp b/dart/collision/bullet/BulletCollisionNode.cpp index 23872260b1e1f..365d4581998b6 100644 --- a/dart/collision/bullet/BulletCollisionNode.cpp +++ b/dart/collision/bullet/BulletCollisionNode.cpp @@ -148,8 +148,8 @@ BulletCollisionNode::BulletCollisionNode(dynamics::BodyNode* _bodyNode) { const dynamics::MeshShape* shapeMesh = static_cast(shape.get()); - btConvexTriangleMeshShape* btMesh = _createMesh(shapeMesh->getScale(), - shapeMesh->getMesh()); + btGImpactMeshShape* btMesh = _createMesh(shapeMesh->getScale(), + shapeMesh->getMesh()); btCollisionObject* btCollObj = new btCollisionObject(); // Add user data @@ -208,7 +208,7 @@ btCollisionObject*BulletCollisionNode::getBulletCollisionObject(int _i) } //============================================================================== -btConvexTriangleMeshShape* _createMesh(const Eigen::Vector3d& _scale, +btGImpactMeshShape* _createMesh(const Eigen::Vector3d& _scale, const aiScene* _mesh) { btTriangleMesh* btMesh = new btTriangleMesh(); @@ -230,8 +230,8 @@ btConvexTriangleMeshShape* _createMesh(const Eigen::Vector3d& _scale, } } - btConvexTriangleMeshShape* btMeshShape = - new btConvexTriangleMeshShape(btMesh); + btGImpactMeshShape* btMeshShape = new btGImpactMeshShape(btMesh); + btMeshShape->updateBound(); return btMeshShape; } diff --git a/dart/collision/bullet/BulletCollisionNode.h b/dart/collision/bullet/BulletCollisionNode.h index 45102756fbe7f..2fbf5394377d1 100644 --- a/dart/collision/bullet/BulletCollisionNode.h +++ b/dart/collision/bullet/BulletCollisionNode.h @@ -41,6 +41,7 @@ #include #include +#include #include #include "dart/dynamics/SmartPointer.h" @@ -91,8 +92,8 @@ class BulletCollisionNode : public CollisionNode }; /// @brief Create Bullet mesh from assimp3 mesh -btConvexTriangleMeshShape* _createMesh(const Eigen::Vector3d& _scale, - const aiScene* _mesh); +btGImpactMeshShape* _createMesh( + const Eigen::Vector3d& _scale, const aiScene* _mesh); } // namespace collision } // namespace dart From 20457320836132d1555f398e216a5d484b31590d Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 26 Aug 2016 15:48:58 -0400 Subject: [PATCH 3/8] Sync poses of viz shape and coll shape of ground in shapes.skel --- data/skel/shapes.skel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/skel/shapes.skel b/data/skel/shapes.skel index f4b981f14cedb..42e420d00aa94 100644 --- a/data/skel/shapes.skel +++ b/data/skel/shapes.skel @@ -20,7 +20,7 @@ 0.95 0.95 0.95 - 0 0 0 0 0 0 + 0 -0.005 0 0 0 0 10 0.01 10 From 6fedd1057d7bf1a525bd5258ab59b5441c38a90d Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 26 Aug 2016 15:49:11 -0400 Subject: [PATCH 4/8] Bump version to 5.1.3 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10719e6f8a001..5f04ac870e2e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ project(dart) set(DART_MAJOR_VERSION "5") set(DART_MINOR_VERSION "1") -set(DART_PATCH_VERSION "2") +set(DART_PATCH_VERSION "3") set(DART_VERSION "${DART_MAJOR_VERSION}.${DART_MINOR_VERSION}.${DART_PATCH_VERSION}") set(DART_PKG_DESC "Dynamic Animation and Robotics Toolkit.") set(DART_PKG_EXTERNAL_DEPS "flann, ccd, fcl") From 1a5d9593fa0044f984e2799011a8b0ece6eb48c7 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 26 Aug 2016 15:59:14 -0400 Subject: [PATCH 5/8] Update changelog --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 466a4fb87343a..aa53049316cbe 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ ### Version 5.1.3 (201X-XX-XX) +1. Switched to use btGImpactMeshShape instead of btConvexTriangleMeshShape for mesh + * [Pull request #764](https://github.com/dartsim/dart/pull/764) + 1. Backported [#749](https://github.com/dartsim/dart/pull/749) to DART 5.1 * [Pull request #759](https://github.com/dartsim/dart/pull/759) From 7c2c3a352eff6d7bb76bcc2744aca0e4c0cb8811 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 26 Aug 2016 19:22:25 -0400 Subject: [PATCH 6/8] Backport #761 to DART 5.1 as a single commit --- CMakeLists.txt | 3 +++ cmake/FindFLANN.cmake | 7 ++++++- dart/config.h.in | 1 + unittests/CMakeLists.txt | 4 ++-- unittests/testNearestNeighbor.cpp | 7 ++++++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f04ac870e2e6..d1d1632f538ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,12 +251,14 @@ if(NOT BUILD_CORE_ONLY) find_package(FLANN 1.8.4 QUIET) if(FLANN_FOUND) message(STATUS "Looking for FLANN - ${FLANN_VERSION} found") + set(HAVE_FLANN TRUE) else() if(FLANN_VERSION) message(SEND_ERROR "Looking for FLANN - ${FLANN_VERSION} found, ${PROJECT_NAME} requires 1.8.4 or greater.") else() message(SEND_ERROR "Looking for FLANN - NOT found, please install libflann-dev") endif() + set(HAVE_FLANN FALSE) endif() # TINYXML @@ -428,6 +430,7 @@ endif() if(NOT BUILD_CORE_ONLY) set(DART_DEPENDENCIES ${urdfdom_LIBRARIES} + ${FLANN_LIBRARIES} ${TINYXML_LIBRARIES} ${TINYXML2_LIBRARIES} ) diff --git a/cmake/FindFLANN.cmake b/cmake/FindFLANN.cmake index 382213e9108d6..ef0b2daca7e2a 100644 --- a/cmake/FindFLANN.cmake +++ b/cmake/FindFLANN.cmake @@ -6,6 +6,7 @@ # This sets the following variables: # FLANN_FOUND # FLANN_INCLUDE_DIRS +# FLANN_LIBRARIES # FLANN_VERSION find_package(PkgConfig QUIET) @@ -19,6 +20,10 @@ find_path(FLANN_INCLUDE_DIRS HINTS ${PC_FLANN_INCLUDEDIR} PATHS "${CMAKE_INSTALL_PREFIX}/include") +# Libraries +find_library(FLANN_LIBRARIES flann_cpp + HINTS ${PC_FLANN_LIBDIR}) + # Version set(FLANN_VERSION ${PC_FLANN_VERSION}) @@ -26,6 +31,6 @@ set(FLANN_VERSION ${PC_FLANN_VERSION}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(FLANN FAIL_MESSAGE DEFAULT_MSG - REQUIRED_VARS FLANN_INCLUDE_DIRS + REQUIRED_VARS FLANN_INCLUDE_DIRS FLANN_LIBRARIES VERSION_VAR FLANN_VERSION) diff --git a/dart/config.h.in b/dart/config.h.in index 36b0e120c5715..92e491252fde2 100644 --- a/dart/config.h.in +++ b/dart/config.h.in @@ -46,6 +46,7 @@ #cmakedefine HAVE_IPOPT 1 #cmakedefine HAVE_SNOPT 1 #cmakedefine HAVE_BULLET_COLLISION 1 +#cmakedefine HAVE_FLANN 1 #define DART_ROOT_PATH "@CMAKE_SOURCE_DIR@/" #define DART_DATA_PATH "@CMAKE_SOURCE_DIR@/data/" diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 66ea55823e91c..9180d9f67f0ec 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -84,11 +84,11 @@ foreach(test ${tests}) endforeach(test) if(HAVE_IPOPT) - target_link_libraries(testOptimizer dart-optimizer-ipopt ${IPOPT_LIBRARIES}) + target_link_libraries(testOptimizer dart-optimizer-ipopt) endif(HAVE_IPOPT) if(HAVE_NLOPT) - target_link_libraries(testOptimizer dart-optimizer-nlopt ${NLOPT_LIBRARIES}) + target_link_libraries(testOptimizer dart-optimizer-nlopt) endif(HAVE_NLOPT) if(HAVE_SNOPT) diff --git a/unittests/testNearestNeighbor.cpp b/unittests/testNearestNeighbor.cpp index 898ccc1fff707..f3710d39b082b 100644 --- a/unittests/testNearestNeighbor.cpp +++ b/unittests/testNearestNeighbor.cpp @@ -7,11 +7,15 @@ #include #include -#include #include +#include +#if HAVE_FLANN +#include +#endif // HAVE_FLANN #include "TestHelpers.h" /* ********************************************************************************************* */ +#if HAVE_FLANN TEST(NEAREST_NEIGHBOR, 2D) { // Build the index with the first node @@ -44,6 +48,7 @@ TEST(NEAREST_NEIGHBOR, 2D) { bool equality = equals(Vector2d(point[0], point[1]), p3, 1e-3); EXPECT_TRUE(equality); } +#endif // HAVE_FLANN /* ********************************************************************************************* */ int main(int argc, char* argv[]) { From eb6c050df22c5627bd66d703eadd612ba43cac6a Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Sat, 27 Aug 2016 03:13:01 -0400 Subject: [PATCH 7/8] Install flann from source for Appveyor tests We do this because the dart prerequisites doesn't install the lib files of flann. --- appveyor.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e33e34b9a07af..9fbf4480d8755 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -52,10 +52,24 @@ before_build: - cmd: cd C:\projects\dart - cmd: md build - cmd: cd build - # We generate project files for Visual Studio 12 because the boost binaries installed on the test server are for Visual Studio 12. - cmd: if "%platform%"=="Win32" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015 - cmd: if "%platform%"=="x64" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015 Win64 - - cmd: cmake -G "%CMAKE_GENERATOR_NAME%" -DCMAKE_BUILD_TYPE=%configuration% -DBUILD_CORE_ONLY="%BUILD_CORE_ONLY%" -DDART_BUILD_EXAMPLES="%BUILD_EXAMPLES%" -DDART_BUILD_TUTORIALS="%BUILD_TUTORIALS%" -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" -DBoost_USE_STATIC_LIBS="ON" -Durdfdom_DIR="%urdfdom_DIR%" -Durdfdom_headers_DIR="%urdfdom_headers_DIR%" -DDART_MSVC_DEFAULT_OPTIONS="%MSVC_DEFAULT_OPTIONS%" .. + - cmd: if "%platform%"=="Win32" set PROGRAM_FILES_PATH=Program Files (x86) + - cmd: if "%platform%"=="x64" set PROGRAM_FILES_PATH=Program Files + - cmd: if not exist "C:\%PROGRAM_FILES_PATH%\flann\include\flann\flann.hpp" ( + curl -L -o flann-1.9.1.tar.gz https://github.com/mariusmuja/flann/archive/1.9.1.tar.gz && + cmake -E tar zxf flann-1.9.1.tar.gz && + cd flann-1.9.1 && + md build && + cd build && + cmake -G "%CMAKE_GENERATOR_NAME%" -DCMAKE_BUILD_TYPE=%Configuration% .. && + cmake --build . --target install --config %Configuration% && + cd ..\.. + ) else (echo Using cached flann) + - cmd: cd C:\projects\dart + - cmd: md build + - cmd: cd build + - cmd: cmake -G "%CMAKE_GENERATOR_NAME%" -DCMAKE_BUILD_TYPE=%configuration% -DBUILD_CORE_ONLY="%BUILD_CORE_ONLY%" -DDART_BUILD_EXAMPLES="%BUILD_EXAMPLES%" -DDART_BUILD_TUTORIALS="%BUILD_TUTORIALS%" -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" -DBoost_USE_STATIC_LIBS="ON" -Durdfdom_DIR="%urdfdom_DIR%" -Durdfdom_headers_DIR="%urdfdom_headers_DIR%" -DDART_MSVC_DEFAULT_OPTIONS="%MSVC_DEFAULT_OPTIONS%" -DFLANN_INCLUDE_DIRS="C:\%PROGRAM_FILES_PATH%\flann\include" -DFLANN_LIBRARIES="C:\%PROGRAM_FILES_PATH%\flann\lib\flann_cpp_s.lib" .. build: project: C:\projects\dart\build\dart.sln # path to Visual Studio solution or project From f3910c88c2067c94c0431f338a7d0173303d74a7 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Sat, 27 Aug 2016 03:27:59 -0400 Subject: [PATCH 8/8] Remove unnecessary lines in appveyor.yml --- appveyor.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 9fbf4480d8755..409fae0662fcb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -49,9 +49,6 @@ install: # scripts to run before build before_build: - - cmd: cd C:\projects\dart - - cmd: md build - - cmd: cd build - cmd: if "%platform%"=="Win32" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015 - cmd: if "%platform%"=="x64" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015 Win64 - cmd: if "%platform%"=="Win32" set PROGRAM_FILES_PATH=Program Files (x86)