DART  6.10.1
BulletCollisionDetector.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_BULLET_BULLETCOLLISIONDETECTOR_HPP_
34 #define DART_COLLISION_BULLET_BULLETCOLLISIONDETECTOR_HPP_
35 
36 // Must be included before any Bullet headers.
37 #include "dart/config.hpp"
38 
39 #include <vector>
40 #include <assimp/scene.h>
41 #include <btBulletCollisionCommon.h>
45 
46 namespace dart {
47 namespace collision {
48 
50 {
51 public:
53 
54  friend class CollisionDetector;
55 
56  static std::shared_ptr<BulletCollisionDetector> create();
57 
59  ~BulletCollisionDetector() override;
60 
61  // Documentation inherited
62  std::shared_ptr<CollisionDetector> cloneWithoutCollisionObjects()
63  const override;
64 
65  // Documentation inherited
66  const std::string& getType() const override;
67 
69  static const std::string& getStaticType();
70 
71  // Documentation inherited
72  std::unique_ptr<CollisionGroup> createCollisionGroup() override;
73 
74  // Documentation inherited
75  bool collide(
76  CollisionGroup* group,
77  const CollisionOption& option = CollisionOption(false, 1u, nullptr),
78  CollisionResult* result = nullptr) override;
79 
80  // Documentation inherited
81  bool collide(
82  CollisionGroup* group1,
83  CollisionGroup* group2,
84  const CollisionOption& option = CollisionOption(false, 1u, nullptr),
85  CollisionResult* result = nullptr) override;
86 
87  // Documentation inherited
88  double distance(
89  CollisionGroup* group,
90  const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
91  DistanceResult* result = nullptr) override;
92 
93  // Documentation inherited
94  double distance(
95  CollisionGroup* group1,
96  CollisionGroup* group2,
97  const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
98  DistanceResult* result = nullptr) override;
99 
100  // Documentation inherited
101  bool raycast(
102  CollisionGroup* group,
103  const Eigen::Vector3d& from,
104  const Eigen::Vector3d& to,
106  RaycastResult* result = nullptr) override;
107 
108 protected:
111 
112  // Documentation inherited
113  std::unique_ptr<CollisionObject> createCollisionObject(
114  const dynamics::ShapeFrame* shapeFrame) override;
115 
116  // Documentation inherited
117  void refreshCollisionObject(CollisionObject* object) override;
118 
119  // Documentation inherited
120  void notifyCollisionObjectDestroying(CollisionObject* object) override;
121 
122 private:
123  std::shared_ptr<BulletCollisionShape> claimBulletCollisionShape(
124  const dynamics::ConstShapePtr& shape);
125 
127 
128  std::unique_ptr<BulletCollisionShape> createBulletCollisionShape(
129  const dynamics::ConstShapePtr& shape);
130 
135  {
136  public:
139 
140  void operator()(BulletCollisionShape* shape) const;
141 
142  private:
144 
146  };
147 
149  struct ShapeInfo final
150  {
152  std::weak_ptr<BulletCollisionShape> mShape;
153 
155  std::size_t mLastKnownVersion;
156  };
157 
158 private:
159  std::map<dynamics::ConstShapePtr, ShapeInfo> mShapeMap;
160 
161  std::unique_ptr<BulletCollisionGroup> mGroupForFiltering;
162 
164 };
165 
166 } // namespace collision
167 } // namespace dart
168 
169 #endif // DART_COLLISION_BULLET_BULLETCOLLISIONDETECTOR_HPP_
const CollisionOption & option
Collision option of DART.
Definition: FCLCollisionDetector.cpp:157
CollisionResult * result
Collision result of DART.
Definition: FCLCollisionDetector.cpp:160
This deleter is responsible for deleting BulletCollsionShape objects and removing them from mShapeMap...
Definition: BulletCollisionDetector.hpp:135
dynamics::ConstShapePtr mShape
Definition: BulletCollisionDetector.hpp:145
void operator()(BulletCollisionShape *shape) const
Definition: BulletCollisionDetector.cpp:709
BulletCollisionShapeDeleter(BulletCollisionDetector *cd, const dynamics::ConstShapePtr &shape)
Definition: BulletCollisionDetector.cpp:701
BulletCollisionDetector * mBulletCollisionDetector
Definition: BulletCollisionDetector.hpp:143
Definition: BulletCollisionDetector.hpp:50
void notifyCollisionObjectDestroying(CollisionObject *object) override
Notify that a CollisionObject is destroying. Do nothing by default.
Definition: BulletCollisionDetector.cpp:449
std::shared_ptr< CollisionDetector > cloneWithoutCollisionObjects() const override
Create a clone of this CollisionDetector.
Definition: BulletCollisionDetector.cpp:128
bool collide(CollisionGroup *group, const CollisionOption &option=CollisionOption(false, 1u, nullptr), CollisionResult *result=nullptr) override
Perform collision check for a single group.
Definition: BulletCollisionDetector.cpp:228
std::unique_ptr< BulletCollisionShape > createBulletCollisionShape(const dynamics::ConstShapePtr &shape)
Definition: BulletCollisionDetector.cpp:498
BulletCollisionDetector()
Constructor.
Definition: BulletCollisionDetector.cpp:423
const std::string & getType() const override
Return collision detection engine type as a std::string.
Definition: BulletCollisionDetector.cpp:134
std::shared_ptr< BulletCollisionShape > claimBulletCollisionShape(const dynamics::ConstShapePtr &shape)
Definition: BulletCollisionDetector.cpp:457
static std::shared_ptr< BulletCollisionDetector > create()
Definition: BulletCollisionDetector.cpp:114
~BulletCollisionDetector() override
Constructor.
Definition: BulletCollisionDetector.cpp:121
void refreshCollisionObject(CollisionObject *object) override
Update the collision geometry of a ShapeFrame.
Definition: BulletCollisionDetector.cpp:439
static Registrar< BulletCollisionDetector > mRegistrar
Definition: BulletCollisionDetector.hpp:163
void reclaimBulletCollisionShape(const dynamics::ConstShapePtr &shape)
Definition: BulletCollisionDetector.cpp:484
std::map< dynamics::ConstShapePtr, ShapeInfo > mShapeMap
Definition: BulletCollisionDetector.hpp:159
double distance(CollisionGroup *group, const DistanceOption &option=DistanceOption(false, 0.0, nullptr), DistanceResult *result=nullptr) override
Get the minimum signed distance between the Shape pairs in the given CollisionGroup.
Definition: BulletCollisionDetector.cpp:325
static const std::string & getStaticType()
Get collision detector type for this class.
Definition: BulletCollisionDetector.cpp:140
std::unique_ptr< CollisionObject > createCollisionObject(const dynamics::ShapeFrame *shapeFrame) override
Create CollisionObject.
Definition: BulletCollisionDetector.cpp:429
std::unique_ptr< BulletCollisionGroup > mGroupForFiltering
Definition: BulletCollisionDetector.hpp:161
std::unique_ptr< CollisionGroup > createCollisionGroup() override
Create a collision group.
Definition: BulletCollisionDetector.cpp:147
bool raycast(CollisionGroup *group, const Eigen::Vector3d &from, const Eigen::Vector3d &to, const RaycastOption &option=RaycastOption(), RaycastResult *result=nullptr) override
Performs raycast to a collision group.
Definition: BulletCollisionDetector.cpp:362
Definition: CollisionDetector.hpp:58
virtual std::unique_ptr< CollisionGroup > createCollisionGroup()=0
Create a collision group.
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
Definition: ShapeFrame.hpp:192
std::shared_ptr< const Shape > ConstShapePtr
Definition: SmartPointer.hpp:81
Definition: BulletCollisionDetector.cpp:65
Information for a shape that was generated by this collision detector.
Definition: BulletCollisionDetector.hpp:150
std::size_t mLastKnownVersion
The last version of the shape, as known by this collision detector.
Definition: BulletCollisionDetector.hpp:155
std::weak_ptr< BulletCollisionShape > mShape
A weak reference to the shape.
Definition: BulletCollisionDetector.hpp:152
Definition: BulletCollisionShape.hpp:47
Definition: CollisionOption.hpp:45
Definition: DistanceOption.hpp:45
Definition: DistanceResult.hpp:47
Definition: RaycastOption.hpp:43
Definition: RaycastResult.hpp:63