DART  6.7.3
CollisionDetector.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_COLLISIONDETECTOR_HPP_
34 #define DART_COLLISION_COLLISIONDETECTOR_HPP_
35 
36 #include <vector>
37 #include <map>
38 
39 #include <Eigen/Dense>
40 
41 #include "dart/common/Factory.hpp"
49 
50 namespace dart {
51 namespace collision {
52 
53 class CollisionObject;
54 
55 class CollisionDetector : public std::enable_shared_from_this<CollisionDetector>
56 {
57 public:
58 
59  friend class CollisionObject;
60  friend class CollisionGroup;
61 
63  std::string, CollisionDetector, std::shared_ptr<CollisionDetector>>;
64 
66 
67  template <typename Derived>
69  std::string, CollisionDetector, Derived, std::shared_ptr<CollisionDetector>>;
70 
72  static Factory* getFactory();
73 
75  virtual ~CollisionDetector() = default;
76 
79  virtual std::shared_ptr<CollisionDetector> cloneWithoutCollisionObjects() = 0;
80 
82  virtual const std::string& getType() const = 0;
83 
85  virtual std::unique_ptr<CollisionGroup> createCollisionGroup() = 0;
86 
92  std::shared_ptr<CollisionGroup> createCollisionGroupAsSharedPtr();
93 
103  template <typename... Args>
104  std::unique_ptr<CollisionGroup> createCollisionGroup(const Args&... args);
105 
107  template <typename... Args>
108  std::shared_ptr<CollisionGroup> createCollisionGroupAsSharedPtr(
109  const Args&... args);
110 
114  virtual bool collide(
115  CollisionGroup* group,
116  const CollisionOption& option = CollisionOption(false, 1u, nullptr),
117  CollisionResult* result = nullptr) = 0;
118 
122  virtual bool collide(
123  CollisionGroup* group1,
124  CollisionGroup* group2,
125  const CollisionOption& option = CollisionOption(false, 1u, nullptr),
126  CollisionResult* result = nullptr) = 0;
127 
136  virtual double distance(
137  CollisionGroup* group,
138  const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
139  DistanceResult* result = nullptr) = 0;
140 
153  virtual double distance(
154  CollisionGroup* group1,
155  CollisionGroup* group2,
156  const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
157  DistanceResult* result = nullptr) = 0;
158 
159 protected:
160 
164 
166  CollisionDetector() = default;
167 
170  std::shared_ptr<CollisionObject> claimCollisionObject(
171  const dynamics::ShapeFrame* shapeFrame);
172 
174  virtual std::unique_ptr<CollisionObject> createCollisionObject(
175  const dynamics::ShapeFrame* shapeFrame) = 0;
176 
178  virtual void refreshCollisionObject(CollisionObject* object) = 0;
179 
181  virtual void notifyCollisionObjectDestroying(CollisionObject* object);
182 
183 protected:
184 
185  std::unique_ptr<CollisionObjectManager> mCollisionObjectManager;
186 
187 };
188 
189 //==============================================================================
191 {
192 public:
193 
196 
199  virtual std::shared_ptr<CollisionObject> claimCollisionObject(
200  const dynamics::ShapeFrame* shapeFrame) = 0;
201 
204 
206  virtual ~CollisionObjectManager() = default;
207 
208 protected:
209 
211 
212 };
213 
214 //==============================================================================
217 {
218 public:
219 
222 
223  // Documentation inherited
224  std::shared_ptr<CollisionObject> claimCollisionObject(
225  const dynamics::ShapeFrame* shapeFrame);
226 
227 private:
228 
232  {
234 
236 
237  void operator()(CollisionObject* object) const;
238  };
239 
241 
242 };
243 
244 //==============================================================================
247 {
248 public:
249 
252 
255 
256  // Documentation inherited
257  std::shared_ptr<CollisionObject> claimCollisionObject(
258  const dynamics::ShapeFrame* shapeFrame);
259 
260 private:
261 
265  {
267 
269 
270  void operator()(CollisionObject* object) const;
271  };
272 
274 
275  using CollisionObjectMap = std::map<const dynamics::ShapeFrame*,
276  std::weak_ptr<CollisionObject>>;
277 
279 
280 };
281 
282 } // namespace collision
283 } // namespace dart
284 
286 
287 #endif // DART_COLLISION_COLLISIONDETECTOR_HPP_
const CollisionOption & option
Collision option of DART.
Definition: FCLCollisionDetector.cpp:154
CollisionResult * result
Collision result of DART.
Definition: FCLCollisionDetector.cpp:157
virtual std::shared_ptr< CollisionObject > claimCollisionObject(const dynamics::ShapeFrame *shapeFrame)=0
Claim CollisionObject associated with shapeFrame.
CollisionObjectManager(CollisionDetector *cd)
Constructor.
Definition: CollisionDetector.cpp:77
CollisionDetector * getCollisionDetector()
Returns collision detector.
Definition: CollisionDetector.cpp:86
CollisionDetector * mCollisionDetector
Definition: CollisionDetector.hpp:210
virtual ~CollisionObjectManager()=default
Virtual destructor.
CollisionObjectMap mCollisionObjectMap
Definition: CollisionDetector.hpp:278
ManagerForSharableCollisionObjects(CollisionDetector *cd)
Constructor.
Definition: CollisionDetector.cpp:135
std::shared_ptr< CollisionObject > claimCollisionObject(const dynamics::ShapeFrame *shapeFrame)
Claim CollisionObject associated with shapeFrame.
Definition: CollisionDetector.cpp:152
std::map< const dynamics::ShapeFrame *, std::weak_ptr< CollisionObject > > CollisionObjectMap
Definition: CollisionDetector.hpp:276
virtual ~ManagerForSharableCollisionObjects()
Destructor.
Definition: CollisionDetector.cpp:145
const CollisionObjectDeleter mCollisionObjectDeleter
Definition: CollisionDetector.hpp:273
ManagerForUnsharableCollisionObjects(CollisionDetector *cd)
Constructor.
Definition: CollisionDetector.cpp:93
std::shared_ptr< CollisionObject > claimCollisionObject(const dynamics::ShapeFrame *shapeFrame)
Claim CollisionObject associated with shapeFrame.
Definition: CollisionDetector.cpp:103
const CollisionObjectDeleter mCollisionObjectDeleter
Definition: CollisionDetector.hpp:240
Definition: CollisionDetector.hpp:56
virtual double distance(CollisionGroup *group, const DistanceOption &option=DistanceOption(false, 0.0, nullptr), DistanceResult *result=nullptr)=0
Get the minimum signed distance between the Shape pairs in the given CollisionGroup.
CollisionDetector()=default
Constructor.
std::shared_ptr< CollisionObject > claimCollisionObject(const dynamics::ShapeFrame *shapeFrame)
Claim CollisionObject associated with shapeFrame.
Definition: CollisionDetector.cpp:60
virtual void notifyCollisionObjectDestroying(CollisionObject *object)
Notify that a CollisionObject is destroying. Do nothing by default.
Definition: CollisionDetector.cpp:70
virtual bool collide(CollisionGroup *group, const CollisionOption &option=CollisionOption(false, 1u, nullptr), CollisionResult *result=nullptr)=0
Perform collision check for a single group.
virtual std::unique_ptr< CollisionObject > createCollisionObject(const dynamics::ShapeFrame *shapeFrame)=0
Create CollisionObject.
std::shared_ptr< CollisionGroup > createCollisionGroupAsSharedPtr()
Helper function that creates and returns CollisionGroup as a shared_ptr.
Definition: CollisionDetector.cpp:54
virtual const std::string & getType() const =0
Return collision detection engine type as a std::string.
virtual std::shared_ptr< CollisionDetector > cloneWithoutCollisionObjects()=0
Create a clone of this CollisionDetector.
static Factory * getFactory()
Returns the singleton factory.
Definition: CollisionDetector.cpp:47
virtual ~CollisionDetector()=default
Destructor.
virtual void refreshCollisionObject(CollisionObject *object)=0
Update the collision geometry of a ShapeFrame.
virtual bool collide(CollisionGroup *group1, CollisionGroup *group2, const CollisionOption &option=CollisionOption(false, 1u, nullptr), CollisionResult *result=nullptr)=0
Perform collision check for two groups.
std::unique_ptr< CollisionObjectManager > mCollisionObjectManager
Definition: CollisionDetector.hpp:185
virtual std::unique_ptr< CollisionGroup > createCollisionGroup()=0
Create a collision group.
virtual double distance(CollisionGroup *group1, CollisionGroup *group2, const DistanceOption &option=DistanceOption(false, 0.0, nullptr), DistanceResult *result=nullptr)=0
Get the minimum signed distance between the Shape pairs where a pair consist of two shapes from each ...
Definition: CollisionGroup.hpp:51
Definition: CollisionObject.hpp:45
Definition: CollisionResult.hpp:52
Helper class to register a object creator function to the Singleton.
Definition: Factory.hpp:121
Implementation of the Abstract Factory Pattern.
Definition: Factory.hpp:62
Singleton template class.
Definition: Singleton.hpp:51
Definition: ShapeFrame.hpp:164
::fcl::CollisionObject CollisionObject
Definition: BackwardCompatibility.hpp:152
Definition: BulletCollisionDetector.cpp:63
This deleter is responsible for deleting CollisionObject and removing it from mCollisionObjectMap whe...
Definition: CollisionDetector.hpp:265
void operator()(CollisionObject *object) const
Definition: CollisionDetector.cpp:188
ManagerForSharableCollisionObjects * mCollisionObjectManager
Definition: CollisionDetector.hpp:266
CollisionObjectDeleter(ManagerForSharableCollisionObjects *mgr)
Definition: CollisionDetector.cpp:178
This deleter is responsible for deleting CollisionObject and removing it from mCollisionObjectMap whe...
Definition: CollisionDetector.hpp:232
CollisionObjectDeleter(ManagerForUnsharableCollisionObjects *mgr)
Definition: CollisionDetector.cpp:115
ManagerForUnsharableCollisionObjects * mCollisionObjectManager
Definition: CollisionDetector.hpp:233
void operator()(CollisionObject *object) const
Definition: CollisionDetector.cpp:125
Definition: CollisionOption.hpp:45
Definition: DistanceOption.hpp:45
Definition: DistanceResult.hpp:47