DART 6.7.3
Loading...
Searching...
No Matches
CollisionGroup.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2019, 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_COLLISION_DETAIL_COLLISIONGROUP_HPP_
34#define DART_COLLISION_DETAIL_COLLISIONGROUP_HPP_
35
37
40
41namespace dart {
42namespace collision {
43
44//==============================================================================
45template <typename... Others>
47 const dynamics::ShapeFrame* shapeFrame, const Others*... others)
48{
49 addShapeFrame(shapeFrame);
50
51 addShapeFramesOf(others...);
52}
53
54//==============================================================================
55template <typename... Others>
57 const std::vector<const dynamics::ShapeFrame*>& shapeFrames,
58 const Others*... others)
59{
60 addShapeFrames(shapeFrames);
61
62 addShapeFramesOf(others...);
63}
64
65//==============================================================================
66template <typename... Others>
68 const CollisionGroup* otherGroup, const Others*... others)
69{
70 assert(otherGroup);
71
72 if (otherGroup && this != otherGroup)
73 {
74 for (const auto& info : otherGroup->mObjectInfoList)
75 addShapeFrame(info->mFrame);
76 }
77
78 addShapeFramesOf(others...);
79}
80
81//==============================================================================
82template <typename... Others>
84 const dynamics::BodyNode* bodyNode, const Others*... others)
85{
86 assert(bodyNode);
87
88 auto collisionShapeNodes
90
91 for (auto& shapeNode : collisionShapeNodes)
92 addShapeFrame(shapeNode);
93
94 addShapeFramesOf(others...);
95}
96
97//==============================================================================
98template <typename... Others>
100 const dynamics::MetaSkeleton* skel, const Others*... others)
101{
102 assert(skel);
103
104 auto numBodyNodes = skel->getNumBodyNodes();
105 for (auto i = 0u; i < numBodyNodes; ++i)
107
108 addShapeFramesOf(others...);
109}
110
111//==============================================================================
112template <typename... Others>
114 const dynamics::ConstBodyNodePtr& bodyNode,
115 const Others&... others)
116{
117 const auto inserted = mBodyNodeSources.insert(
118 BodyNodeSources::value_type(
119 bodyNode.get(),
120 BodyNodeSource(bodyNode.get(), bodyNode->getVersion()))
121 );
122
123 if(inserted.second)
124 {
125 const BodyNodeSources::iterator& entry = inserted.first;
126
127 const auto collisionShapeNodes =
128 bodyNode->getShapeNodesWith<dynamics::CollisionAspect>();
129
130 for (const auto& shapeNode : collisionShapeNodes)
131 {
132 entry->second.mObjects.insert(
133 {shapeNode, addShapeFrameImpl(shapeNode, bodyNode.get())});
134 }
135 }
136
137 subscribeTo(others...);
138}
139
140//==============================================================================
141template <typename... Others>
143 const dynamics::ConstSkeletonPtr& skeleton,
144 const Others&... others)
145{
146 const auto inserted = mSkeletonSources.insert(
147 SkeletonSources::value_type(
148 skeleton.get(),
149 SkeletonSource(skeleton, skeleton->getVersion()))
150 );
151
152 if(inserted.second)
153 {
154 SkeletonSource& entry = inserted.first->second;
155
156 const std::size_t numBodies = skeleton->getNumBodyNodes();
157 for (std::size_t i = 0u ; i < numBodies; ++i)
158 {
159 const dynamics::BodyNode* bn = skeleton->getBodyNode(i);
160
161 const auto& collisionShapeNodes =
163
164 auto& childInfo = entry.mChildren.insert(
165 std::make_pair(bn, SkeletonSource::ChildInfo(bn->getVersion())))
166 .first->second;
167
168 for (const auto& shapeNode : collisionShapeNodes)
169 {
170 entry.mObjects.insert(
171 {shapeNode, addShapeFrameImpl(shapeNode, skeleton.get())});
172 childInfo.mFrames.insert(shapeNode);
173 }
174 }
175 }
176
177 subscribeTo(others...);
178}
179
180//==============================================================================
181template <typename... Others>
183 const dynamics::ShapeFrame* shapeFrame, const Others*... others)
184{
185 removeShapeFrame(shapeFrame);
186
187 removeShapeFramesOf(others...);
188}
189
190//==============================================================================
191template <typename... Others>
193 const std::vector<const dynamics::ShapeFrame*>& shapeFrames,
194 const Others*... others)
195{
196 removeShapeFrames(shapeFrames);
197
198 removeShapeFramesOf(others...);
199}
200
201//==============================================================================
202template <typename... Others>
204 const CollisionGroup* otherGroup, const Others*... others)
205{
206 assert(otherGroup);
207
208 if (otherGroup)
209 {
210 if (this == otherGroup)
211 {
213 return;
214 }
215
216 for (const auto& info : otherGroup->mObjectInfoList)
217 removeShapeFrame(info->mFrame);
218 }
219
220 removeShapeFramesOf(others...);
221}
222
223//==============================================================================
224template <typename... Others>
226 const dynamics::BodyNode* bodyNode, const Others*... others)
227{
228 assert(bodyNode);
229
230 auto collisionShapeNodes
232
233 for (auto& shapeNode : collisionShapeNodes)
234 removeShapeFrame(shapeNode);
235
236 removeShapeFramesOf(others...);
237}
238
239//==============================================================================
240template <typename... Others>
242 const dynamics::MetaSkeleton* skel, const Others*... others)
243{
244 assert(skel);
245
246 auto numBodyNodes = skel->getNumBodyNodes();
247 for (auto i = 0u; i < numBodyNodes; ++i)
249
250 removeShapeFramesOf(others...);
251}
252
253//==============================================================================
254template <typename... Others>
256 const dynamics::BodyNode* bodyNode,
257 const Others*... others)
258{
259 auto it = mBodyNodeSources.find(bodyNode);
260 if(it != mBodyNodeSources.end())
261 {
262 for(const auto& entry : it->second.mObjects)
263 removeShapeFrameInternal(entry.first, bodyNode);
264
265 mBodyNodeSources.erase(it);
266 }
267
268 unsubscribeFrom(others...);
269}
270
271//==============================================================================
272template <typename... Others>
274 const dynamics::Skeleton* skeleton,
275 const Others*... others)
276{
277 auto it = mSkeletonSources.find(skeleton);
278 if(it != mSkeletonSources.end())
279 {
280 for(const auto& entry : it->second.mObjects)
281 {
283 entry.first, static_cast<const dynamics::MetaSkeleton*>(skeleton));
284 }
285
286 mSkeletonSources.erase(it);
287 }
288
289 unsubscribeFrom(others...);
290}
291
292} // namespace collision
293} // namespace dart
294
295#endif // DART_COLLISION_DETAIL_COLLISIONGROUP_HPP_
Definition CollisionGroup.hpp:51
void addShapeFramesOf()
Do nothing.
Definition CollisionGroup.cpp:80
void subscribeTo()
Do nothing.
Definition CollisionGroup.cpp:86
void removeShapeFrames(const std::vector< const dynamics::ShapeFrame * > &shapeFrames)
Remove ShapeFrames from this CollisionGroup.
Definition CollisionGroup.cpp:130
void addShapeFrames(const std::vector< const dynamics::ShapeFrame * > &shapeFrames)
Add ShapeFrames to this CollisionGroup.
Definition CollisionGroup.cpp:72
SkeletonSources mSkeletonSources
Skeleton sources that this group is subscribed to.
Definition CollisionGroup.hpp:512
void unsubscribeFrom(const dynamics::BodyNode *bodyNode, const Others *... others)
Unsubscribe from bodyNode.
Definition CollisionGroup.hpp:255
ObjectInfo * addShapeFrameImpl(const dynamics::ShapeFrame *shapeFrame, const void *source)
Implementation of addShapeFrame.
Definition CollisionGroup.cpp:329
void removeAllShapeFrames()
Remove all the ShapeFrames in this CollisionGroup.
Definition CollisionGroup.cpp:144
void addShapeFrame(const dynamics::ShapeFrame *shapeFrame)
Add a ShapeFrame to this CollisionGroup.
Definition CollisionGroup.cpp:66
void removeShapeFrame(const dynamics::ShapeFrame *shapeFrame)
Remove a ShapeFrame from this CollisionGroup.
Definition CollisionGroup.cpp:92
void removeShapeFramesOf()
Do nothing.
Definition CollisionGroup.cpp:138
void addShapeFramesOf(const dynamics::MetaSkeleton *skeleton, const Others *... others)
Add ShapeFrames of MetaSkeleton, and also add another ShapeFrames of other various objects.
Definition CollisionGroup.hpp:99
void removeShapeFrameInternal(const dynamics::ShapeFrame *shapeFrame, const void *source)
Internal version of removeShapeFrame.
Definition CollisionGroup.cpp:368
ObjectInfoList mObjectInfoList
Information about ShapeFrames and CollisionObjects that have been added to this CollisionGroup.
Definition CollisionGroup.hpp:364
BodyNodeSources mBodyNodeSources
BodyNode sources that this group is susbscribed to.
Definition CollisionGroup.hpp:515
virtual std::size_t getVersion() const
Get the version number of this object.
Definition VersionCounter.cpp:61
BodyNode class represents a single node of the skeleton.
Definition BodyNode.hpp:78
const std::vector< ShapeNode * > getShapeNodesWith()
Return the list of ShapeNodes containing given Aspect.
Definition BodyNode.hpp:217
Definition ShapeFrame.hpp:119
MetaSkeleton is a pure abstract base class that provides a common interface for obtaining data (such ...
Definition MetaSkeleton.hpp:62
virtual BodyNode * getBodyNode(std::size_t _idx)=0
Get BodyNode whose index is _idx.
virtual std::size_t getNumBodyNodes() const =0
Get number of body nodes.
Definition ShapeFrame.hpp:164
class Skeleton
Definition Skeleton.hpp:59
TemplateBodyNodePtr is a templated class that enables users to create a reference-counting BodyNodePt...
Definition BodyNodePtr.hpp:111
BodyNodeT * get() const
Get the raw BodyNode pointer.
Definition BodyNodePtr.hpp:164
std::shared_ptr< const Skeleton > ConstSkeletonPtr
Definition SmartPointer.hpp:60
Definition BulletCollisionDetector.cpp:63
This is information pertaining to a child of the source.
Definition CollisionGroup.hpp:459
This struct is used to store sources of ShapeFrames that the CollisionGroup is subscribed to,...
Definition CollisionGroup.hpp:446
std::unordered_map< const Child *, ChildInfo > mChildren
The last known versions of the children related to this source.
Definition CollisionGroup.hpp:477
std::unordered_map< const dynamics::ShapeFrame *, ObjectInfo * > mObjects
The set of objects that pertain to this source.
Definition CollisionGroup.hpp:454