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