DART 6.12.2
Loading...
Searching...
No Matches
CollisionGroup.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_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
87 auto collisionShapeNodes
89
90 for (auto& shapeNode : collisionShapeNodes)
91 addShapeFrame(shapeNode);
92
93 addShapeFramesOf(others...);
94}
95
96//==============================================================================
97template <typename... Others>
99 const dynamics::MetaSkeleton* skel, const Others*... others)
100{
101 assert(skel);
102
103 auto numBodyNodes = skel->getNumBodyNodes();
104 for (auto i = 0u; i < numBodyNodes; ++i)
106
107 addShapeFramesOf(others...);
108}
109
110//==============================================================================
111template <typename... Others>
113 const dynamics::ConstBodyNodePtr& bodyNode, const Others&... others)
114{
115 const auto inserted = mBodyNodeSources.insert(BodyNodeSources::value_type(
116 bodyNode.get(), BodyNodeSource(bodyNode.get(), bodyNode->getVersion())));
117
118 if (inserted.second)
119 {
120 const BodyNodeSources::iterator& entry = inserted.first;
121
122 const auto collisionShapeNodes
123 = bodyNode->getShapeNodesWith<dynamics::CollisionAspect>();
124
125 for (const auto& shapeNode : collisionShapeNodes)
126 {
127 entry->second.mObjects.insert(
128 {shapeNode, addShapeFrameImpl(shapeNode, bodyNode.get())});
129 }
130 }
131
132 subscribeTo(others...);
133}
134
135//==============================================================================
136template <typename... Others>
138 const dynamics::ConstSkeletonPtr& skeleton, const Others&... others)
139{
140 const auto inserted = mSkeletonSources.insert(SkeletonSources::value_type(
141 skeleton.get(), SkeletonSource(skeleton, skeleton->getVersion())));
142
143 if (inserted.second)
144 {
145 SkeletonSource& entry = inserted.first->second;
146
147 const std::size_t numBodies = skeleton->getNumBodyNodes();
148 for (std::size_t i = 0u; i < numBodies; ++i)
149 {
150 const dynamics::BodyNode* bn = skeleton->getBodyNode(i);
151
152 const auto& collisionShapeNodes
154
155 auto& childInfo
156 = entry.mChildren
157 .insert(std::make_pair(
159 .first->second;
160
161 for (const auto& shapeNode : collisionShapeNodes)
162 {
163 entry.mObjects.insert(
164 {shapeNode, addShapeFrameImpl(shapeNode, skeleton.get())});
165 childInfo.mFrames.insert(shapeNode);
166 }
167 }
168 }
169
170 subscribeTo(others...);
171}
172
173//==============================================================================
174template <typename... Others>
176 const dynamics::ShapeFrame* shapeFrame, const Others*... others)
177{
178 removeShapeFrame(shapeFrame);
179
180 removeShapeFramesOf(others...);
181}
182
183//==============================================================================
184template <typename... Others>
186 const std::vector<const dynamics::ShapeFrame*>& shapeFrames,
187 const Others*... others)
188{
189 removeShapeFrames(shapeFrames);
190
191 removeShapeFramesOf(others...);
192}
193
194//==============================================================================
195template <typename... Others>
197 const CollisionGroup* otherGroup, const Others*... others)
198{
199 assert(otherGroup);
200
201 if (otherGroup)
202 {
203 if (this == otherGroup)
204 {
206 return;
207 }
208
209 for (const auto& info : otherGroup->mObjectInfoList)
210 removeShapeFrame(info->mFrame);
211 }
212
213 removeShapeFramesOf(others...);
214}
215
216//==============================================================================
217template <typename... Others>
219 const dynamics::BodyNode* bodyNode, const Others*... others)
220{
221 assert(bodyNode);
222
223 auto collisionShapeNodes
225
226 for (auto& shapeNode : collisionShapeNodes)
227 removeShapeFrame(shapeNode);
228
229 removeShapeFramesOf(others...);
230}
231
232//==============================================================================
233template <typename... Others>
235 const dynamics::MetaSkeleton* skel, const Others*... others)
236{
237 assert(skel);
238
239 auto numBodyNodes = skel->getNumBodyNodes();
240 for (auto i = 0u; i < numBodyNodes; ++i)
242
243 removeShapeFramesOf(others...);
244}
245
246//==============================================================================
247template <typename... Others>
249 const dynamics::BodyNode* bodyNode, const Others*... others)
250{
251 auto it = mBodyNodeSources.find(bodyNode);
252 if (it != mBodyNodeSources.end())
253 {
254 for (const auto& entry : it->second.mObjects)
255 removeShapeFrameInternal(entry.first, bodyNode);
256
257 mBodyNodeSources.erase(it);
258 }
259
260 unsubscribeFrom(others...);
261}
262
263//==============================================================================
264template <typename... Others>
266 const dynamics::Skeleton* skeleton, const Others*... others)
267{
268 auto it = mSkeletonSources.find(skeleton);
269 if (it != mSkeletonSources.end())
270 {
271 for (const auto& entry : it->second.mObjects)
272 {
274 entry.first, static_cast<const dynamics::MetaSkeleton*>(skeleton));
275 }
276
277 mSkeletonSources.erase(it);
278 }
279
280 unsubscribeFrom(others...);
281}
282
283} // namespace collision
284} // namespace dart
285
286#endif // DART_COLLISION_DETAIL_COLLISIONGROUP_HPP_
Definition CollisionGroup.hpp:54
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:512
void unsubscribeFrom(const dynamics::BodyNode *bodyNode, const Others *... others)
Unsubscribe from bodyNode.
Definition CollisionGroup.hpp:248
ObjectInfo * addShapeFrameImpl(const dynamics::ShapeFrame *shapeFrame, const void *source)
Implementation of addShapeFrame.
Definition CollisionGroup.cpp:348
void removeAllShapeFrames()
Remove all the ShapeFrames in this CollisionGroup.
Definition CollisionGroup.cpp:146
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:390
ObjectInfoList mObjectInfoList
Information about ShapeFrames and CollisionObjects that have been added to this CollisionGroup.
Definition CollisionGroup.hpp:374
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:60
BodyNode class represents a single node of the skeleton.
Definition BodyNode.hpp:79
const std::vector< ShapeNode * > getShapeNodesWith()
Return the list of ShapeNodes containing given Aspect.
Definition BodyNode.hpp:221
Definition ShapeFrame.hpp:117
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:192
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:461
This struct is used to store sources of ShapeFrames that the CollisionGroup is subscribed to,...
Definition CollisionGroup.hpp:448
std::unordered_map< const Child *, ChildInfo > mChildren
The last known versions of the children related to this source.
Definition CollisionGroup.hpp:478
std::unordered_map< const dynamics::ShapeFrame *, ObjectInfo * > mObjects
The set of objects that pertain to this source.
Definition CollisionGroup.hpp:456