DART  6.10.1
CollisionDetector.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_COLLISIONDETECTOR_HPP_
34 #define DART_COLLISION_COLLISIONDETECTOR_HPP_
35 
36 #include <map>
37 #include <vector>
38 
39 #include <Eigen/Dense>
40 
49 #include "dart/common/Factory.hpp"
51 
52 namespace dart {
53 namespace collision {
54 
55 class CollisionObject;
56 
57 class CollisionDetector : public std::enable_shared_from_this<CollisionDetector>
58 {
59 public:
60  friend class CollisionObject;
61  friend class CollisionGroup;
62 
64  std::string,
66  std::shared_ptr<CollisionDetector>>;
67 
69 
70  template <typename Derived>
72  std::string,
74  Derived,
75  std::shared_ptr<CollisionDetector>>;
76 
78  static Factory* getFactory();
79 
81  virtual ~CollisionDetector() = default;
82 
85  virtual std::shared_ptr<CollisionDetector> cloneWithoutCollisionObjects()
86  const = 0;
87 
89  virtual const std::string& getType() const = 0;
90 
92  virtual std::unique_ptr<CollisionGroup> createCollisionGroup() = 0;
93 
99  std::shared_ptr<CollisionGroup> createCollisionGroupAsSharedPtr();
100 
110  template <typename... Args>
111  std::unique_ptr<CollisionGroup> createCollisionGroup(const Args&... args);
112 
114  template <typename... Args>
115  std::shared_ptr<CollisionGroup> createCollisionGroupAsSharedPtr(
116  const Args&... args);
117 
121  virtual bool collide(
122  CollisionGroup* group,
123  const CollisionOption& option = CollisionOption(false, 1u, nullptr),
124  CollisionResult* result = nullptr)
125  = 0;
126 
130  virtual bool collide(
131  CollisionGroup* group1,
132  CollisionGroup* group2,
133  const CollisionOption& option = CollisionOption(false, 1u, nullptr),
134  CollisionResult* result = nullptr)
135  = 0;
136 
145  virtual double distance(
146  CollisionGroup* group,
147  const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
148  DistanceResult* result = nullptr)
149  = 0;
150 
163  virtual double distance(
164  CollisionGroup* group1,
165  CollisionGroup* group2,
166  const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
167  DistanceResult* result = nullptr)
168  = 0;
169 
178  virtual bool raycast(
179  CollisionGroup* group,
180  const Eigen::Vector3d& from,
181  const Eigen::Vector3d& to,
183  RaycastResult* result = nullptr);
184 
185 protected:
189 
191  CollisionDetector() = default;
192 
195  std::shared_ptr<CollisionObject> claimCollisionObject(
196  const dynamics::ShapeFrame* shapeFrame);
197 
199  virtual std::unique_ptr<CollisionObject> createCollisionObject(
200  const dynamics::ShapeFrame* shapeFrame)
201  = 0;
202 
204  virtual void refreshCollisionObject(CollisionObject* object) = 0;
205 
207  virtual void notifyCollisionObjectDestroying(CollisionObject* object);
208 
209 protected:
210  std::unique_ptr<CollisionObjectManager> mCollisionObjectManager;
211 };
212 
213 //==============================================================================
215 {
216 public:
219 
222  virtual std::shared_ptr<CollisionObject> claimCollisionObject(
223  const dynamics::ShapeFrame* shapeFrame)
224  = 0;
225 
228 
230  virtual ~CollisionObjectManager() = default;
231 
232 protected:
234 };
235 
236 //==============================================================================
239 {
240 public:
243 
244  // Documentation inherited
245  std::shared_ptr<CollisionObject> claimCollisionObject(
246  const dynamics::ShapeFrame* shapeFrame);
247 
248 private:
252  {
254 
256 
257  void operator()(CollisionObject* object) const;
258  };
259 
261 };
262 
263 //==============================================================================
266 {
267 public:
270 
273 
274  // Documentation inherited
275  std::shared_ptr<CollisionObject> claimCollisionObject(
276  const dynamics::ShapeFrame* shapeFrame);
277 
278 private:
282  {
284 
286 
287  void operator()(CollisionObject* object) const;
288  };
289 
291 
293  = std::map<const dynamics::ShapeFrame*, std::weak_ptr<CollisionObject>>;
294 
296 };
297 
298 } // namespace collision
299 } // namespace dart
300 
302 
303 #endif // DART_COLLISION_COLLISIONDETECTOR_HPP_
const CollisionOption & option
Collision option of DART.
Definition: FCLCollisionDetector.cpp:157
CollisionResult * result
Collision result of DART.
Definition: FCLCollisionDetector.cpp:160
virtual std::shared_ptr< CollisionObject > claimCollisionObject(const dynamics::ShapeFrame *shapeFrame)=0
Claim CollisionObject associated with shapeFrame.
CollisionObjectManager(CollisionDetector *cd)
Constructor.
Definition: CollisionDetector.cpp:91
CollisionDetector * getCollisionDetector()
Returns collision detector.
Definition: CollisionDetector.cpp:100
CollisionDetector * mCollisionDetector
Definition: CollisionDetector.hpp:233
virtual ~CollisionObjectManager()=default
Virtual destructor.
CollisionObjectMap mCollisionObjectMap
Definition: CollisionDetector.hpp:295
ManagerForSharableCollisionObjects(CollisionDetector *cd)
Constructor.
Definition: CollisionDetector.cpp:146
std::shared_ptr< CollisionObject > claimCollisionObject(const dynamics::ShapeFrame *shapeFrame)
Claim CollisionObject associated with shapeFrame.
Definition: CollisionDetector.cpp:161
std::map< const dynamics::ShapeFrame *, std::weak_ptr< CollisionObject > > CollisionObjectMap
Definition: CollisionDetector.hpp:293
virtual ~ManagerForSharableCollisionObjects()
Destructor.
Definition: CollisionDetector.cpp:154
const CollisionObjectDeleter mCollisionObjectDeleter
Definition: CollisionDetector.hpp:290
ManagerForUnsharableCollisionObjects(CollisionDetector *cd)
Constructor.
Definition: CollisionDetector.cpp:107
std::shared_ptr< CollisionObject > claimCollisionObject(const dynamics::ShapeFrame *shapeFrame)
Claim CollisionObject associated with shapeFrame.
Definition: CollisionDetector.cpp:115
const CollisionObjectDeleter mCollisionObjectDeleter
Definition: CollisionDetector.hpp:260
Definition: CollisionDetector.hpp:58
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:73
virtual void notifyCollisionObjectDestroying(CollisionObject *object)
Notify that a CollisionObject is destroying. Do nothing by default.
Definition: CollisionDetector.cpp:84
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 bool raycast(CollisionGroup *group, const Eigen::Vector3d &from, const Eigen::Vector3d &to, const RaycastOption &option=RaycastOption(), RaycastResult *result=nullptr)
Performs raycast to a collision group.
Definition: CollisionDetector.cpp:60
static Factory * getFactory()
Returns the singleton factory.
Definition: CollisionDetector.cpp:47
virtual ~CollisionDetector()=default
Destructor.
virtual std::shared_ptr< CollisionDetector > cloneWithoutCollisionObjects() const =0
Create a clone of this CollisionDetector.
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:210
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:53
Definition: CollisionObject.hpp:45
Definition: CollisionResult.hpp:52
Helper class to register a object creator function to the Singleton.
Definition: Factory.hpp:125
Implementation of the Abstract Factory Pattern.
Definition: Factory.hpp:63
Singleton template class.
Definition: Singleton.hpp:51
Definition: ShapeFrame.hpp:192
::fcl::CollisionObject CollisionObject
Definition: BackwardCompatibility.hpp:161
Definition: BulletCollisionDetector.cpp:65
This deleter is responsible for deleting CollisionObject and removing it from mCollisionObjectMap whe...
Definition: CollisionDetector.hpp:282
void operator()(CollisionObject *object) const
Definition: CollisionDetector.cpp:195
ManagerForSharableCollisionObjects * mCollisionObjectManager
Definition: CollisionDetector.hpp:283
CollisionObjectDeleter(ManagerForSharableCollisionObjects *mgr)
Definition: CollisionDetector.cpp:187
This deleter is responsible for deleting CollisionObject and removing it from mCollisionObjectMap whe...
Definition: CollisionDetector.hpp:252
CollisionObjectDeleter(ManagerForUnsharableCollisionObjects *mgr)
Definition: CollisionDetector.cpp:127
ManagerForUnsharableCollisionObjects * mCollisionObjectManager
Definition: CollisionDetector.hpp:253
void operator()(CollisionObject *object) const
Definition: CollisionDetector.cpp:136
Definition: CollisionOption.hpp:45
Definition: DistanceOption.hpp:45
Definition: DistanceResult.hpp:47
Definition: RaycastOption.hpp:43
Definition: RaycastResult.hpp:63