diff --git a/CHANGELOG.md b/CHANGELOG.md index 377eb8591642c..da36fe9bc29ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Added lazy evaluation for shape's volume and bounding-box computation: [#959](https://github.com/dartsim/dart/pull/959) * Added IkFast support as analytic IK solver: [#887](https://github.com/dartsim/dart/pull/887) * Fixed NaN values caused by zero-length normals in ContactConstraint: [#881](https://github.com/dartsim/dart/pull/881) + * Extended BodyNode::createShapeNode() to accept more types of arguments: [#986](https://github.com/dartsim/dart/pull/986) * Collision detection diff --git a/dart/dynamics/BodyNode.cpp b/dart/dynamics/BodyNode.cpp index 47c968ba107c7..0ab34ae43613e 100644 --- a/dart/dynamics/BodyNode.cpp +++ b/dart/dynamics/BodyNode.cpp @@ -879,32 +879,6 @@ const Joint* BodyNode::getChildJoint(std::size_t _index) const //============================================================================== DART_BAKE_SPECIALIZED_NODE_DEFINITIONS( BodyNode, ShapeNode ) -//============================================================================== -ShapeNode* BodyNode::createShapeNode(const ShapePtr& shape) -{ - ShapeNode::BasicProperties properties; - properties.mShape = shape; - - return createShapeNode(properties, true); -} - -//============================================================================== -ShapeNode* BodyNode::createShapeNode(const ShapePtr& shape, - const std::string& name) -{ - ShapeNode::BasicProperties properties; - properties.mShape = shape; - properties.mName = name; - - return createShapeNode(properties, false); -} - -//============================================================================== -ShapeNode* BodyNode::createShapeNode(const ShapePtr& shape, const char* name) -{ - return createShapeNode(shape, std::string(name)); -} - //============================================================================== const std::vector BodyNode::getShapeNodes() { diff --git a/dart/dynamics/BodyNode.hpp b/dart/dynamics/BodyNode.hpp index 9323d30988d69..de207af5e7a97 100644 --- a/dart/dynamics/BodyNode.hpp +++ b/dart/dynamics/BodyNode.hpp @@ -544,14 +544,14 @@ class BodyNode : /// Create a ShapeNode with an automatically assigned name: /// _ShapeNode_<#>. - ShapeNode* createShapeNode(const ShapePtr& shape); + template + ShapeNode* createShapeNode(const std::shared_ptr& shape); - /// Create an ShapeNode with the specified name + /// Create a ShapeNode with the specified name + template ShapeNode* createShapeNode( - const ShapePtr& shape, const std::string& name); - - /// Create an ShapeNode with the specified name - ShapeNode* createShapeNode(const ShapePtr& shape, const char* name); + const std::shared_ptr& shape, + StringType&& name); /// Return the list of ShapeNodes const std::vector getShapeNodes(); diff --git a/dart/dynamics/detail/BodyNode.hpp b/dart/dynamics/detail/BodyNode.hpp index 4f69a89966eb4..23386e0e9e9ed 100644 --- a/dart/dynamics/detail/BodyNode.hpp +++ b/dart/dynamics/detail/BodyNode.hpp @@ -153,6 +153,29 @@ ShapeNode* BodyNode::createShapeNode(ShapeNodeProperties properties, return createNode(properties); } +//============================================================================== +template +ShapeNode* BodyNode::createShapeNode(const std::shared_ptr& shape) +{ + ShapeNode::BasicProperties properties; + properties.mShape = shape; + + return createShapeNode(properties, true); +} + +//============================================================================== +template +ShapeNode* BodyNode::createShapeNode( + const std::shared_ptr& shape, + StringType&& name) +{ + ShapeNode::BasicProperties properties; + properties.mShape = shape; + properties.mName = std::forward(name); + + return createShapeNode(properties, false); +} + //============================================================================== template ShapeNode* BodyNode::createShapeNodeWith(const ShapePtr& shape) diff --git a/unittests/regression/CMakeLists.txt b/unittests/regression/CMakeLists.txt index fa613e81887ee..5d6294e7ce29c 100644 --- a/unittests/regression/CMakeLists.txt +++ b/unittests/regression/CMakeLists.txt @@ -7,4 +7,6 @@ if(TARGET dart-utils-urdf) dart_add_test("regression" test_Issue895) + dart_add_test("regression" test_Issue986) + endif() diff --git a/unittests/regression/test_Issue986.cpp b/unittests/regression/test_Issue986.cpp new file mode 100644 index 0000000000000..0cfc80321c63a --- /dev/null +++ b/unittests/regression/test_Issue986.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011-2017, The DART development contributors + * All rights reserved. + * + * The list of contributors can be found at: + * https://github.com/dartsim/dart/blob/master/LICENSE + * + * This file is provided under the following "BSD-style" License: + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +//============================================================================== +TEST(Issue986, CreateShapeNodeShouldCompile) +{ + const auto skel = dart::dynamics::Skeleton::create(); + auto* bn = skel->createJointAndBodyNodePair().second; + const auto sphere = std::make_shared(1.0); + + bn->createShapeNode(sphere); + bn->createShapeNode(sphere, "custom name"); + + const dart::dynamics::ShapePtr generic = + std::make_shared(1.0); + + bn->createShapeNode(generic); + bn->createShapeNode(generic, "another name"); + + bn->createShapeNode(sphere, std::string("passing a string")); + bn->createShapeNode(generic, std::string("passing another string")); + + auto world = dart::simulation::World::create(); + world->addSkeleton(skel); +}