DART 6.10.1
Loading...
Searching...
No Matches
BodyNode.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2021, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_DYNAMICS_DETAIL_BODYNODE_HPP_
34#define DART_DYNAMICS_DETAIL_BODYNODE_HPP_
35
36#include <utility>
37
39
40namespace dart {
41namespace dynamics {
42
43//==============================================================================
44template <class JointType>
46 BodyNode* _newParent, const typename JointType::Properties& _joint)
47{
48 if (nullptr == _newParent)
49 return getSkeleton()->moveBodyNodeTree<JointType>(
50 this, getSkeleton(), nullptr, _joint);
51 else
52 return getSkeleton()->moveBodyNodeTree<JointType>(
53 this, _newParent->getSkeleton(), _newParent, _joint);
54}
55
56//==============================================================================
57template <class JointType>
59 const SkeletonPtr& _newSkeleton,
60 BodyNode* _newParent,
61 const typename JointType::Properties& _joint)
62{
63 return getSkeleton()->moveBodyNodeTree<JointType>(
64 this, _newSkeleton, _newParent, _joint);
65}
66
67//==============================================================================
68template <class JointType>
70 const std::string& _skeletonName,
71 const typename JointType::Properties& _joint)
72{
74 skel->setName(_skeletonName);
75 moveTo<JointType>(skel, nullptr, _joint);
76 return skel;
77}
78
79//==============================================================================
80template <class JointType>
82 const typename JointType::Properties& _joint)
83{
84 return moveTo<JointType>(getParentBodyNode(), _joint);
85}
86
87//==============================================================================
88template <class JointType>
89std::pair<JointType*, BodyNode*> BodyNode::copyTo(
90 BodyNode* _newParent,
91 const typename JointType::Properties& _joint,
92 bool _recursive)
93{
94 if (nullptr == _newParent)
95 return getSkeleton()->cloneBodyNodeTree<JointType>(
96 this, getSkeleton(), nullptr, _joint, _recursive);
97 else
98 return getSkeleton()->cloneBodyNodeTree<JointType>(
99 this, _newParent->getSkeleton(), _newParent, _joint, _recursive);
100}
101
102//==============================================================================
103template <class JointType>
104std::pair<JointType*, BodyNode*> BodyNode::copyTo(
105 const SkeletonPtr& _newSkeleton,
106 BodyNode* _newParent,
107 const typename JointType::Properties& _joint,
108 bool _recursive) const
109{
110 return getSkeleton()->cloneBodyNodeTree<JointType>(
111 this, _newSkeleton, _newParent, _joint, _recursive);
112}
113
114//==============================================================================
115template <class JointType>
117 const std::string& _skeletonName,
118 const typename JointType::Properties& _joint,
119 bool _recursive) const
120{
122 skel->setName(_skeletonName);
123 copyTo<JointType>(skel, nullptr, _joint, _recursive);
124 return skel;
125}
126
127//==============================================================================
128template <class JointType, class NodeType>
129std::pair<JointType*, NodeType*> BodyNode::createChildJointAndBodyNodePair(
130 const typename JointType::Properties& _jointProperties,
131 const typename NodeType::Properties& _bodyProperties)
132{
133 return getSkeleton()->createJointAndBodyNodePair<JointType, NodeType>(
134 this, _jointProperties, _bodyProperties);
135}
136
137//==============================================================================
138template <class NodeType, typename... Args>
139NodeType* BodyNode::createNode(Args&&... args)
140{
141 NodeType* node = new NodeType(this, std::forward<Args>(args)...);
142 node->attach();
143
144 return node;
145}
146
147//==============================================================================
148template <class ShapeNodeProperties>
150 ShapeNodeProperties properties, bool automaticName)
151{
152 if (automaticName)
153 {
154 properties.mName
155 = getName() + "_ShapeNode_" + std::to_string(getNumShapeNodes());
156 }
157
158 return createNode<ShapeNode>(properties);
159}
160
161//==============================================================================
162template <class ShapeType>
163ShapeNode* BodyNode::createShapeNode(const std::shared_ptr<ShapeType>& shape)
164{
166 properties.mShape = shape;
167
168 return createShapeNode(properties, true);
169}
170
171//==============================================================================
172template <class ShapeType, class StringType>
174 const std::shared_ptr<ShapeType>& shape, StringType&& name)
175{
177 properties.mShape = shape;
178 properties.mName = std::forward<StringType>(name);
179
180 return createShapeNode(properties, false);
181}
182
183//==============================================================================
184template <class... Aspects>
186{
187 return createShapeNodeWith<Aspects...>(
188 shape, getName() + "_ShapeNode_" + std::to_string(getNumShapeNodes()));
189}
190
191//==============================================================================
192template <class... Aspects>
194 const ShapePtr& shape, const std::string& name)
195{
196 auto shapeNode = createShapeNode(shape, name);
197
198 common::createAspects<ShapeNode, Aspects...>(shapeNode);
199
200 return shapeNode;
201}
202
203//==============================================================================
204template <class AspectT>
206{
207 auto count = 0u;
208 auto numShapeNode = getNumShapeNodes();
209
210 for (auto i = 0u; i < numShapeNode; ++i)
211 {
212 if (getShapeNode(i)->has<AspectT>())
213 ++count;
214 }
215
216 return count;
217}
218
219//==============================================================================
220template <class AspectT>
221const std::vector<ShapeNode*> BodyNode::getShapeNodesWith()
222{
223 std::vector<ShapeNode*> shapeNodes;
224
225 auto numShapeNode = getNumShapeNodes();
226
227 for (auto i = 0u; i < numShapeNode; ++i)
228 {
229 auto shapeNode = getShapeNode(i);
230
231 if (shapeNode->has<AspectT>())
232 shapeNodes.push_back(shapeNode);
233 }
234
235 return shapeNodes;
236}
237
238//==============================================================================
239template <class AspectT>
240const std::vector<const ShapeNode*> BodyNode::getShapeNodesWith() const
241{
242 std::vector<const ShapeNode*> shapeNodes;
243
244 auto numShapeNode = getNumShapeNodes();
245
246 for (auto i = 0u; i < numShapeNode; ++i)
247 {
248 const auto shapeNode = getShapeNode(i);
249
250 if (shapeNode->has<AspectT>())
251 shapeNodes.push_back(shapeNode);
252 }
253
254 return shapeNodes;
255}
256
257//==============================================================================
258template <class AspectT>
260{
261 auto shapeNodes = getShapeNodesWith<AspectT>();
262 for (auto shapeNode : shapeNodes)
263 shapeNode->remove();
264}
265
266} // namespace dynamics
267} // namespace dart
268
269#endif // DART_DYNAMICS_DETAIL_BODYNODE_HPP_
BodyPropPtr properties
Definition SdfParser.cpp:80
std::string * name
Definition SkelParser.cpp:1697
const AspectProperties & getAspectProperties() const
Definition EmbeddedAspect.hpp:408
Definition CompositeData.hpp:186
BodyNode class represents a single node of the skeleton.
Definition BodyNode.hpp:79
const std::string & getName() const override
Return the name of this Entity.
Definition BodyNode.cpp:456
void removeAllShapeNodesWith()
Remove all ShapeNodes containing given Aspect from this BodyNode.
Definition BodyNode.hpp:259
ShapeNode * createShapeNode(ShapeNodeProperties properties, bool automaticName=true)
Create an ShapeNode attached to this BodyNode.
Definition BodyNode.hpp:149
SkeletonPtr getSkeleton() override
Return the Skeleton that this Node is attached to.
Definition BodyNode.cpp:858
std::size_t getNumShapeNodes() const
Definition BodyNode.cpp:954
NodeType * createNode(Args &&... args)
Create some Node type and attach it to this BodyNode.
Definition BodyNode.hpp:139
const std::vector< ShapeNode * > getShapeNodesWith()
Return the list of ShapeNodes containing given Aspect.
Definition BodyNode.hpp:221
JointType * changeParentJointType(const typename JointType::Properties &_joint=typename JointType::Properties())
Change the Joint type of this BodyNode's parent Joint.
Definition BodyNode.hpp:81
std::pair< JointType *, NodeType * > createChildJointAndBodyNodePair(const typename JointType::Properties &_jointProperties=typename JointType::Properties(), const typename NodeType::Properties &_bodyProperties=typename NodeType::Properties())
Create a Joint and BodyNode pair as a child of this BodyNode.
Definition BodyNode.hpp:129
SkeletonPtr split(const std::string &_skeletonName)
Remove this BodyNode and all of its children (recursively) from their current Skeleton and move them ...
Definition BodyNode.cpp:809
SkeletonPtr copyAs(const std::string &_skeletonName, bool _recursive=true) const
Create clones of this BodyNode and all of its children (recursively) and create a new Skeleton with t...
Definition BodyNode.cpp:847
bool moveTo(BodyNode *_newParent)
Remove this BodyNode and all of its children (recursively) from their current parent BodyNode,...
Definition BodyNode.cpp:785
ShapeNode * createShapeNodeWith(const ShapePtr &shape)
Create a ShapeNode with the specified Aspects and an automatically assigned name: <BodyNodeName>Shape...
Definition BodyNode.hpp:185
ShapeNode * getShapeNode(std::size_t index)
Definition BodyNode.cpp:954
BodyNode * getParentBodyNode()
Return the parent BodyNdoe of this BodyNode.
Definition BodyNode.cpp:882
std::size_t getNumShapeNodesWith() const
Return the number of ShapeNodes containing given Aspect in this BodyNode.
Definition BodyNode.hpp:205
std::pair< Joint *, BodyNode * > copyTo(BodyNode *_newParent, bool _recursive=true)
Create clones of this BodyNode and all of its children recursively (unless _recursive is set to false...
Definition BodyNode.cpp:819
Definition ShapeNode.hpp:49
static SkeletonPtr create(const std::string &_name="Skeleton")
Create a new Skeleton inside of a shared_ptr.
Definition Skeleton.cpp:384
void createAspects(T *)
Attach an arbitrary number of Aspects to the specified Composite type.
Definition Composite.hpp:145
std::shared_ptr< Shape > ShapePtr
Definition SmartPointer.hpp:81
std::shared_ptr< Skeleton > SkeletonPtr
Definition SmartPointer.hpp:60
Definition BulletCollisionDetector.cpp:65