DART 6.6.2
Loading...
Searching...
No Matches
CollisionGroup.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2018, 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_COLLISIONGROUP_HPP_
34#define DART_COLLISION_COLLISIONGROUP_HPP_
35
36#include <map>
37#include <vector>
44
45namespace dart {
46namespace collision {
47
49{
50public:
51
53 CollisionGroup(const CollisionDetectorPtr& collisionDetector);
54 // CollisionGroup also can be created from CollisionDetector::create()
55
57 virtual ~CollisionGroup() = default;
58
61
65
67 void addShapeFrame(const dynamics::ShapeFrame* shapeFrame);
68
70 void addShapeFrames(
71 const std::vector<const dynamics::ShapeFrame*>& shapeFrames);
72
81 template <typename... Others>
82 void addShapeFramesOf(const dynamics::ShapeFrame* shapeFrame,
83 const Others*... others);
84
86 template <typename... Others>
88 const std::vector<const dynamics::ShapeFrame*>& shapeFrames,
89 const Others*... others);
90
93 template <typename... Others>
94 void addShapeFramesOf(const CollisionGroup* otherGroup,
95 const Others*... others);
96
99 template <typename... Others>
100 void addShapeFramesOf(const dynamics::BodyNode* bodyNode,
101 const Others*... others);
102
105 template <typename... Others>
106 void addShapeFramesOf(const dynamics::MetaSkeleton* skeleton,
107 const Others*... others);
108
111 void addShapeFramesOf();
112
114 void removeShapeFrame(const dynamics::ShapeFrame* shapeFrame);
115
118 const std::vector<const dynamics::ShapeFrame*>& shapeFrames);
119
128 template <typename... Others>
129 void removeShapeFramesOf(const dynamics::ShapeFrame* shapeFrame,
130 const Others*... others);
131
133 template <typename... Others>
135 const std::vector<const dynamics::ShapeFrame*>& shapeFrames,
136 const Others*... others);
137
140 template <typename... Others>
141 void removeShapeFramesOf(const CollisionGroup* otherGroup,
142 const Others*... others);
143
146 template <typename... Others>
147 void removeShapeFramesOf(const dynamics::BodyNode* bodyNode,
148 const Others*... others);
149
152 template <typename... Others>
153 void removeShapeFramesOf(const dynamics::MetaSkeleton* skeleton,
154 const Others*... others);
155
158 void removeShapeFramesOf();
159
162
164 bool hasShapeFrame(const dynamics::ShapeFrame* shapeFrame) const;
165
167 std::size_t getNumShapeFrames() const;
168
170 const dynamics::ShapeFrame* getShapeFrame(std::size_t index) const;
171
173 bool collide(
174 const CollisionOption& option = CollisionOption(false, 1u, nullptr),
175 CollisionResult* result = nullptr);
176
181 bool collide(
182 CollisionGroup* otherGroup,
183 const CollisionOption& option = CollisionOption(false, 1u, nullptr),
184 CollisionResult* result = nullptr);
185
194 double distance(
195 const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
196 DistanceResult* result = nullptr);
197
210 double distance(
211 CollisionGroup* otherGroup,
212 const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
213 DistanceResult* result = nullptr);
214
215protected:
216
219 void updateEngineData();
220
224 virtual void initializeEngineData() = 0;
225
228
231 const std::vector<CollisionObject*>& collObjects) = 0;
232
235
238
242
243protected:
244
247 // CollisionGroup shares the ownership of CollisionDetector with other
248 // CollisionGroups created from the same CollisionDetector so that the
249 // CollisionDetector doesn't get destroyed as long as at least one
250 // CollisionGroup is alive.
251
253 std::vector<std::pair<const dynamics::ShapeFrame*,
255 // CollisionGroup also shares the ownership of CollisionObjects across other
256 // CollisionGroups for the same reason with above.
257 //
258 // Dev note: This was supposed to be std::map rather than std::vector for
259 // better search performance. The reason we use std::vector is to get
260 // deterministic contact results regardless of the order of CollisionObjects
261 // in this container for FCLCollisionDetector.
262 //
263 // fcl's collision result is dependent on the order of objects in the broad
264 // phase classes. If we use std::map, the orders of element between the
265 // original and copy are not guranteed to be the same as we copy std::map
266 // (e.g., by world cloning).
267
268};
269
270} // namespace collision
271} // namespace dart
272
274
275#endif // DART_COLLISION_COLLISIONGROUP_HPP_
const CollisionOption & option
Collision option of DART.
Definition FCLCollisionDetector.cpp:154
CollisionResult * result
Collision result of DART.
Definition FCLCollisionDetector.cpp:157
std::size_t index
Definition SkelParser.cpp:1617
Definition CollisionGroup.hpp:49
virtual void addCollisionObjectToEngine(CollisionObject *object)=0
Add CollisionObject to the collision detection engine.
std::vector< std::pair< const dynamics::ShapeFrame *, CollisionObjectPtr > > mShapeFrameMap
ShapeFrames and CollisionOjbects added to this CollisionGroup.
Definition CollisionGroup.hpp:254
void addShapeFramesOf()
Do nothing.
Definition CollisionGroup.cpp:89
bool collide(const CollisionOption &option=CollisionOption(false, 1u, nullptr), CollisionResult *result=nullptr)
Perform collision check within this CollisionGroup.
Definition CollisionGroup.cpp:165
CollisionDetectorPtr mCollisionDetector
Collision detector.
Definition CollisionGroup.hpp:246
void removeShapeFrames(const std::vector< const dynamics::ShapeFrame * > &shapeFrames)
Remove ShapeFrames from this CollisionGroup.
Definition CollisionGroup.cpp:115
virtual void initializeEngineData()=0
Initialize the collision detection engine data such as broadphase algorithm.
void addShapeFrames(const std::vector< const dynamics::ShapeFrame * > &shapeFrames)
Add ShapeFrames to this CollisionGroup.
Definition CollisionGroup.cpp:81
double distance(const DistanceOption &option=DistanceOption(false, 0.0, nullptr), DistanceResult *result=nullptr)
Get the minimum signed distance between the Shape pairs in this CollisionGroup.
Definition CollisionGroup.cpp:181
virtual void removeAllCollisionObjectsFromEngine()=0
Remove all the CollisionObjects from the collision detection engine.
void removeAllShapeFrames()
Remove all the ShapeFrames in this CollisionGroup.
Definition CollisionGroup.cpp:129
void addShapeFrame(const dynamics::ShapeFrame *shapeFrame)
Add a ShapeFrame to this CollisionGroup.
Definition CollisionGroup.cpp:65
virtual void updateCollisionGroupEngineData()=0
Update the collision detection engine data such as broadphase algorithm.
void removeShapeFrame(const dynamics::ShapeFrame *shapeFrame)
Remove a ShapeFrame from this CollisionGroup.
Definition CollisionGroup.cpp:95
virtual void addCollisionObjectsToEngine(const std::vector< CollisionObject * > &collObjects)=0
Add CollisionObjects to the collision detection engine.
void updateEngineData()
Update engine data.
Definition CollisionGroup.cpp:197
virtual void removeCollisionObjectFromEngine(CollisionObject *object)=0
Remove CollisionObject from the collision detection engine.
virtual ~CollisionGroup()=default
Destructor.
bool hasShapeFrame(const dynamics::ShapeFrame *shapeFrame) const
Return true if this CollisionGroup contains shapeFrame.
Definition CollisionGroup.cpp:137
std::size_t getNumShapeFrames() const
Return number of ShapeFrames added to this CollisionGroup.
Definition CollisionGroup.cpp:148
void removeShapeFramesOf()
Do nothing.
Definition CollisionGroup.cpp:123
CollisionDetectorPtr getCollisionDetector()
Return collision detection engine associated with this CollisionGroup.
Definition CollisionGroup.cpp:53
const dynamics::ShapeFrame * getShapeFrame(std::size_t index) const
Get the ShapeFrame corresponding to the given index.
Definition CollisionGroup.cpp:154
Definition CollisionObject.hpp:45
Definition CollisionResult.hpp:52
BodyNode class represents a single node of the skeleton.
Definition BodyNode.hpp:78
MetaSkeleton is a pure abstract base class that provides a common interface for obtaining data (such ...
Definition MetaSkeleton.hpp:62
Definition ShapeFrame.hpp:164
std::shared_ptr< const CollisionDetector > ConstCollisionDetectorPtr
Definition SmartPointer.hpp:41
std::shared_ptr< CollisionDetector > CollisionDetectorPtr
Definition SmartPointer.hpp:41
std::shared_ptr< CollisionObject > CollisionObjectPtr
Definition SmartPointer.hpp:45
Definition BulletCollisionDetector.cpp:63
Definition CollisionOption.hpp:45
Definition DistanceOption.hpp:45
Definition DistanceResult.hpp:47