Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend createShapeNode to accept more types of arguments #986

Merged
merged 5 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 0 additions & 26 deletions dart/dynamics/BodyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShapeNode*> BodyNode::getShapeNodes()
{
Expand Down
12 changes: 6 additions & 6 deletions dart/dynamics/BodyNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,14 @@ class BodyNode :

/// Create a ShapeNode with an automatically assigned name:
/// <BodyNodeName>_ShapeNode_<#>.
ShapeNode* createShapeNode(const ShapePtr& shape);
template <class ShapeType>
ShapeNode* createShapeNode(const std::shared_ptr<ShapeType>& shape);

/// Create an ShapeNode with the specified name
/// Create a ShapeNode with the specified name
template <class ShapeType, class StringType>
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<ShapeType>& shape,
StringType&& name);

/// Return the list of ShapeNodes
const std::vector<ShapeNode*> getShapeNodes();
Expand Down
23 changes: 23 additions & 0 deletions dart/dynamics/detail/BodyNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,29 @@ ShapeNode* BodyNode::createShapeNode(ShapeNodeProperties properties,
return createNode<ShapeNode>(properties);
}

//==============================================================================
template <class ShapeType>
ShapeNode* BodyNode::createShapeNode(const std::shared_ptr<ShapeType>& shape)
{
ShapeNode::BasicProperties properties;
properties.mShape = shape;

return createShapeNode(properties, true);
}

//==============================================================================
template <class ShapeType, class StringType>
ShapeNode* BodyNode::createShapeNode(
const std::shared_ptr<ShapeType>& shape,
StringType&& name)
{
ShapeNode::BasicProperties properties;
properties.mShape = shape;
properties.mName = std::forward<StringType>(name);

return createShapeNode(properties, false);
}

//==============================================================================
template <class... Aspects>
ShapeNode* BodyNode::createShapeNodeWith(const ShapePtr& shape)
Expand Down
2 changes: 2 additions & 0 deletions unittests/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ if(TARGET dart-utils-urdf)

dart_add_test("regression" test_Issue895)

dart_add_test("regression" test_Issue986)

endif()
59 changes: 59 additions & 0 deletions unittests/regression/test_Issue986.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>
#include <TestHelpers.hpp>
#include <dart/dart.hpp>
#include <dart/utils/urdf/DartLoader.hpp>

//==============================================================================
TEST(Issue986, CreateShapeNodeShouldCompile)
{
const auto skel = dart::dynamics::Skeleton::create();
auto* bn = skel->createJointAndBodyNodePair<FreeJoint>().second;
const auto sphere = std::make_shared<dart::dynamics::SphereShape>(1.0);

bn->createShapeNode(sphere);
bn->createShapeNode(sphere, "custom name");

const dart::dynamics::ShapePtr generic =
std::make_shared<dart::dynamics::SphereShape>(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);
}