From bf7da0f6dd390db0718b664eb1d66920f8088c92 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Thu, 5 Apr 2018 15:29:06 -0700 Subject: [PATCH 1/3] Add World::hasSkeleton() --- dart/simulation/World.cpp | 7 +++++++ dart/simulation/World.hpp | 3 +++ unittests/comprehensive/test_World.cpp | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/dart/simulation/World.cpp b/dart/simulation/World.cpp index db31e47066f30..57918b4d71be9 100644 --- a/dart/simulation/World.cpp +++ b/dart/simulation/World.cpp @@ -391,6 +391,13 @@ std::set World::removeAllSkeletons() return ptrs; } +//============================================================================== +bool World::hasSkeleton(const dynamics::SkeletonPtr& skeleton) +{ + return std::find(mSkeletons.begin(), mSkeletons.end(), skeleton) + != mSkeletons.end(); +} + //============================================================================== int World::getIndex(int _index) const { diff --git a/dart/simulation/World.hpp b/dart/simulation/World.hpp index 90e840bede515..d484217e9b94b 100644 --- a/dart/simulation/World.hpp +++ b/dart/simulation/World.hpp @@ -149,6 +149,9 @@ class World : public virtual common::Subject /// pointers to them, in case you want to recycle them std::set removeAllSkeletons(); + /// Returns wether this World contains a Skeleton. + bool hasSkeleton(const dynamics::SkeletonPtr& skeleton); + /// Get the dof index for the indexed skeleton int getIndex(int _index) const; diff --git a/unittests/comprehensive/test_World.cpp b/unittests/comprehensive/test_World.cpp index 63e4c37357380..c45855de92310 100644 --- a/unittests/comprehensive/test_World.cpp +++ b/unittests/comprehensive/test_World.cpp @@ -95,9 +95,16 @@ TEST(World, AddingAndRemovingSkeletons) for (int i = 0; i < nSteps; ++i) world->step(); + EXPECT_FALSE(world->hasSkeleton(skeleton1)); + EXPECT_FALSE(world->hasSkeleton(skeleton2)); + EXPECT_FALSE(world->hasSkeleton(skeleton3)); + EXPECT_FALSE(world->hasSkeleton(skeleton4)); + // Add skeleton1, skeleton2 world->addSkeleton(skeleton1); + EXPECT_TRUE(world->hasSkeleton(skeleton1)); world->addSkeleton(skeleton2); + EXPECT_TRUE(world->hasSkeleton(skeleton2)); EXPECT_TRUE(world->getNumSkeletons() == 2); for (int i = 0; i < nSteps; ++i) world->step(); @@ -119,7 +126,9 @@ TEST(World, AddingAndRemovingSkeletons) // Add skeleton3, skeleton4 world->addSkeleton(skeleton3); + EXPECT_TRUE(world->hasSkeleton(skeleton3)); world->addSkeleton(skeleton4); + EXPECT_TRUE(world->hasSkeleton(skeleton4)); EXPECT_TRUE(world->getNumSkeletons() == 3); for (int i = 0; i < nSteps; ++i) world->step(); From 69e1fa38256e4095bf2320d3ead858c91c7ed668 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Thu, 5 Apr 2018 15:37:46 -0700 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53773ee61f86b..0938061aa2c1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * Added FOV API to OSG viewer: [#1048](https://github.com/dartsim/dart/pull/1048) +* Simulation + + * Added World::hasSkeleton(): [#1050](https://github.com/dartsim/dart/pull/1050) + ### [DART 6.4.0 (2018-03-26)](https://github.com/dartsim/dart/milestone/39?closed=1) * Common From 894121eb359a7987d7686fc89e26ed4dcee9edda Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Thu, 5 Apr 2018 16:33:47 -0700 Subject: [PATCH 3/3] Use ConstSkeletonPtr for hasSkeleton() --- dart/simulation/World.cpp | 2 +- dart/simulation/World.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dart/simulation/World.cpp b/dart/simulation/World.cpp index 57918b4d71be9..51ff870a224ce 100644 --- a/dart/simulation/World.cpp +++ b/dart/simulation/World.cpp @@ -392,7 +392,7 @@ std::set World::removeAllSkeletons() } //============================================================================== -bool World::hasSkeleton(const dynamics::SkeletonPtr& skeleton) +bool World::hasSkeleton(const dynamics::ConstSkeletonPtr& skeleton) const { return std::find(mSkeletons.begin(), mSkeletons.end(), skeleton) != mSkeletons.end(); diff --git a/dart/simulation/World.hpp b/dart/simulation/World.hpp index d484217e9b94b..026743f3949fe 100644 --- a/dart/simulation/World.hpp +++ b/dart/simulation/World.hpp @@ -150,7 +150,7 @@ class World : public virtual common::Subject std::set removeAllSkeletons(); /// Returns wether this World contains a Skeleton. - bool hasSkeleton(const dynamics::SkeletonPtr& skeleton); + bool hasSkeleton(const dynamics::ConstSkeletonPtr& skeleton) const; /// Get the dof index for the indexed skeleton int getIndex(int _index) const;