DART  6.7.3
BulletCollisionDetector.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_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 
49 class BulletCollisionObject;
50 
52 {
53 public:
55 
56  friend class CollisionDetector;
57 
58  static std::shared_ptr<BulletCollisionDetector> create();
59 
61  virtual ~BulletCollisionDetector();
62 
63  // Documentation inherited
64  std::shared_ptr<CollisionDetector> cloneWithoutCollisionObjects() override;
65 
66  // Documentation inherited
67  const std::string& getType() const override;
68 
70  static const std::string& getStaticType();
71 
72  // Documentation inherited
73  std::unique_ptr<CollisionGroup> createCollisionGroup() override;
74 
75  // Documentation inherited
76  bool collide(
77  CollisionGroup* group,
78  const CollisionOption& option = CollisionOption(false, 1u, nullptr),
79  CollisionResult* result = nullptr) override;
80 
81  // Documentation inherited
82  bool collide(
83  CollisionGroup* group1,
84  CollisionGroup* group2,
85  const CollisionOption& option = CollisionOption(false, 1u, nullptr),
86  CollisionResult* result = nullptr) override;
87 
88  // Documentation inherited
89  double distance(
90  CollisionGroup* group,
91  const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
92  DistanceResult* result = nullptr) override;
93 
94  // Documentation inherited
95  double distance(
96  CollisionGroup* group1,
97  CollisionGroup* group2,
98  const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
99  DistanceResult* result = nullptr) override;
100 
101 protected:
102 
105 
106  // Documentation inherited
107  std::unique_ptr<CollisionObject> createCollisionObject(
108  const dynamics::ShapeFrame* shapeFrame) override;
109 
110  // Documentation inherited
111  void refreshCollisionObject(CollisionObject* object) override;
112 
113  // Documentation inherited
114  void notifyCollisionObjectDestroying(CollisionObject* object) override;
115 
116 private:
117 
118  std::shared_ptr<BulletCollisionShape> claimBulletCollisionShape(
119  const dynamics::ConstShapePtr& shape);
120 
122  const dynamics::ConstShapePtr& shape);
123 
124  std::unique_ptr<BulletCollisionShape> createBulletCollisionShape(
125  const dynamics::ConstShapePtr& shape);
126 
131  {
132  public:
133 
136  const dynamics::ConstShapePtr& shape);
137 
138  void operator()(BulletCollisionShape* shape) const;
139 
140  private:
141 
143 
145 
146  };
147 
149  struct ShapeInfo final
150  {
152  std::weak_ptr<BulletCollisionShape> mShape;
153 
155  std::size_t mLastKnownVersion;
156  };
157 
158 private:
159 
160  std::map<dynamics::ConstShapePtr, ShapeInfo> mShapeMap;
161 
162  std::unique_ptr<BulletCollisionGroup> mGroupForFiltering;
163 
165 };
166 
167 } // namespace collision
168 } // namespace dart
169 
170 #endif // DART_COLLISION_BULLET_BULLETCOLLISIONDETECTOR_HPP_
const CollisionOption & option
Collision option of DART.
Definition: FCLCollisionDetector.cpp:154
CollisionResult * result
Collision result of DART.
Definition: FCLCollisionDetector.cpp:157
This deleter is responsible for deleting BulletCollsionShape objects and removing them from mShapeMap...
Definition: BulletCollisionDetector.hpp:131
dynamics::ConstShapePtr mShape
Definition: BulletCollisionDetector.hpp:144
void operator()(BulletCollisionShape *shape) const
Definition: BulletCollisionDetector.cpp:617
BulletCollisionShapeDeleter(BulletCollisionDetector *cd, const dynamics::ConstShapePtr &shape)
Definition: BulletCollisionDetector.cpp:606
BulletCollisionDetector * mBulletCollisionDetector
Definition: BulletCollisionDetector.hpp:142
Definition: BulletCollisionDetector.hpp:52
void notifyCollisionObjectDestroying(CollisionObject *object) override
Notify that a CollisionObject is destroying. Do nothing by default.
Definition: BulletCollisionDetector.cpp:353
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:213
std::unique_ptr< BulletCollisionShape > createBulletCollisionShape(const dynamics::ConstShapePtr &shape)
Definition: BulletCollisionDetector.cpp:402
BulletCollisionDetector()
Constructor.
Definition: BulletCollisionDetector.cpp:326
virtual ~BulletCollisionDetector()
Constructor.
Definition: BulletCollisionDetector.cpp:105
const std::string & getType() const override
Return collision detection engine type as a std::string.
Definition: BulletCollisionDetector.cpp:118
std::shared_ptr< BulletCollisionShape > claimBulletCollisionShape(const dynamics::ConstShapePtr &shape)
Definition: BulletCollisionDetector.cpp:361
static std::shared_ptr< BulletCollisionDetector > create()
Definition: BulletCollisionDetector.cpp:98
void refreshCollisionObject(CollisionObject *object) override
Update the collision geometry of a ShapeFrame.
Definition: BulletCollisionDetector.cpp:343
static Registrar< BulletCollisionDetector > mRegistrar
Definition: BulletCollisionDetector.hpp:164
void reclaimBulletCollisionShape(const dynamics::ConstShapePtr &shape)
Definition: BulletCollisionDetector.cpp:388
std::map< dynamics::ConstShapePtr, ShapeInfo > mShapeMap
Definition: BulletCollisionDetector.hpp:160
std::shared_ptr< CollisionDetector > cloneWithoutCollisionObjects() override
Create a clone of this CollisionDetector.
Definition: BulletCollisionDetector.cpp:112
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:301
static const std::string & getStaticType()
Get collision detector type for this class.
Definition: BulletCollisionDetector.cpp:124
std::unique_ptr< CollisionObject > createCollisionObject(const dynamics::ShapeFrame *shapeFrame) override
Create CollisionObject.
Definition: BulletCollisionDetector.cpp:333
std::unique_ptr< BulletCollisionGroup > mGroupForFiltering
Definition: BulletCollisionDetector.hpp:162
std::unique_ptr< CollisionGroup > createCollisionGroup() override
Create a collision group.
Definition: BulletCollisionDetector.cpp:132
Definition: CollisionDetector.hpp:56
virtual std::unique_ptr< CollisionGroup > createCollisionGroup()=0
Create a collision group.
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
Definition: ShapeFrame.hpp:164
std::shared_ptr< const Shape > ConstShapePtr
Definition: SmartPointer.hpp:81
Definition: BulletCollisionDetector.cpp:63
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