coal 3.0.1
Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library
Loading...
Searching...
No Matches
broadphase_spatialhash.h
Go to the documentation of this file.
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2011-2014, Willow Garage, Inc.
5 * Copyright (c) 2014-2016, Open Source Robotics Foundation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
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 * * Neither the name of Open Source Robotics Foundation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
38#ifndef COAL_BROADPHASE_BROADPAHSESPATIALHASH_H
39#define COAL_BROADPHASE_BROADPAHSESPATIALHASH_H
40
41#include <list>
42#include <map>
43#include "coal/BV/AABB.h"
48
49namespace coal {
50
52template <typename HashTable = detail::SimpleHashTable<AABB, CollisionObject*,
53 detail::SpatialHash> >
55 public:
57 using Base::getObjects;
58
59 SpatialHashingCollisionManager(Scalar cell_size, const Vec3s& scene_min,
60 const Vec3s& scene_max,
61 unsigned int default_table_size = 1000);
62
64
67
70
72 void setup();
73
75 virtual void update();
76
78 void update(CollisionObject* updated_obj);
79
81 void update(const std::vector<CollisionObject*>& updated_objs);
82
84 void clear();
85
87 void getObjects(std::vector<CollisionObject*>& objs) const;
88
91 void collide(CollisionObject* obj, CollisionCallBackBase* callback) const;
92
95 void distance(CollisionObject* obj, DistanceCallBackBase* callback) const;
96
99 void collide(CollisionCallBackBase* callback) const;
100
103 void distance(DistanceCallBackBase* callback) const;
104
106 void collide(BroadPhaseCollisionManager* other_manager,
107 CollisionCallBackBase* callback) const;
108
110 void distance(BroadPhaseCollisionManager* other_manager,
111 DistanceCallBackBase* callback) const;
112
114 bool empty() const;
115
117 size_t size() const;
118
120 static void computeBound(std::vector<CollisionObject*>& objs, Vec3s& l,
121 Vec3s& u);
122
123 protected:
126 bool collide_(CollisionObject* obj, CollisionCallBackBase* callback) const;
127
131 Scalar& min_dist) const;
132
134 std::list<CollisionObject*> objs;
135
138 std::list<CollisionObject*> objs_partially_penetrating_scene_limit;
139
141 std::list<CollisionObject*> objs_outside_scene_limit;
142
145
148 std::map<CollisionObject*, AABB> obj_aabb_map;
149
152 HashTable* hash_table;
153
154 private:
155 enum ObjectStatus { Inside, PartiallyPenetrating, Outside };
156
157 template <typename Container>
158 bool distanceObjectToObjects(CollisionObject* obj, const Container& objs,
159 DistanceCallBackBase* callback,
160 Scalar& min_dist) const;
161};
162
163} // namespace coal
164
166
167#endif
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition AABB.h:55
Base class for broad phase collision. It helps to accelerate the collision/distance between N objects...
Definition broadphase_collision_manager.h:53
virtual std::vector< CollisionObject * > getObjects() const
return the objects managed by the manager
Definition broadphase_collision_manager.h:87
the object for collision or distance computation, contains the geometry and the transform information
Definition collision_object.h:216
spatial hashing collision mananger
Definition broadphase_spatialhash.h:54
static void computeBound(std::vector< CollisionObject * > &objs, Vec3s &l, Vec3s &u)
compute the bound for the environent
Definition broadphase_spatialhash-inl.h:501
std::list< CollisionObject * > objs
all objects in the scene
Definition broadphase_spatialhash.h:134
void distance(CollisionObject *obj, DistanceCallBackBase *callback) const
perform distance computation between one object and all the objects belonging ot the manager
Definition broadphase_spatialhash-inl.h:262
~SpatialHashingCollisionManager()
Definition broadphase_spatialhash-inl.h:57
HashTable * hash_table
objects in the scene limit (given by scene_min and scene_max) are in the spatial hash table
Definition broadphase_spatialhash.h:152
bool empty() const
whether the manager is empty
Definition broadphase_spatialhash-inl.h:489
std::map< CollisionObject *, AABB > obj_aabb_map
store the map between objects and their aabbs. will make update more convenient
Definition broadphase_spatialhash.h:148
bool distance_(CollisionObject *obj, DistanceCallBackBase *callback, Scalar &min_dist) const
perform distance computation between one object and all the objects belonging ot the manager
Definition broadphase_spatialhash-inl.h:310
virtual void update()
update the condition of manager
Definition broadphase_spatialhash-inl.h:111
void clear()
clear the manager
Definition broadphase_spatialhash-inl.h:237
void unregisterObject(CollisionObject *obj)
remove one object from the manager
Definition broadphase_spatialhash-inl.h:84
AABB scene_limit
the size of the scene
Definition broadphase_spatialhash.h:144
void setup()
initialize the manager, related with the specific type of manager
Definition broadphase_spatialhash-inl.h:105
void collide(CollisionObject *obj, CollisionCallBackBase *callback) const
perform collision test between one object and all the objects belonging to the manager
Definition broadphase_spatialhash-inl.h:254
BroadPhaseCollisionManager Base
Definition broadphase_spatialhash.h:56
std::list< CollisionObject * > objs_outside_scene_limit
objects outside the scene limit are in another list
Definition broadphase_spatialhash.h:141
virtual std::vector< CollisionObject * > getObjects() const
return the objects managed by the manager
Definition broadphase_collision_manager.h:87
void registerObject(CollisionObject *obj)
add one object to the manager
Definition broadphase_spatialhash-inl.h:63
bool collide_(CollisionObject *obj, CollisionCallBackBase *callback) const
perform collision test between one object and all the objects belonging to the manager
Definition broadphase_spatialhash-inl.h:271
size_t size() const
the number of objects managed by the manager
Definition broadphase_spatialhash-inl.h:495
std::list< CollisionObject * > objs_partially_penetrating_scene_limit
objects partially penetrating (not totally inside nor outside) the scene limit are in another list
Definition broadphase_spatialhash.h:138
Main namespace.
Definition broadphase_bruteforce.h:44
Eigen::Matrix< Scalar, 3, 1 > Vec3s
Definition data_types.h:70
double Scalar
Definition data_types.h:68
Base callback class for collision queries. This class can be supersed by child classes to provide des...
Definition broadphase_callbacks.h:49
Base callback class for distance queries. This class can be supersed by child classes to provide desi...
Definition broadphase_callbacks.h:72