38 #ifndef FCL_BROADPHASE_SPATIALHASH_INL_H 39 #define FCL_BROADPHASE_SPATIALHASH_INL_H 41 #include "fcl/broadphase/detail/spatial_hash.h" 48 struct SpatialHash<double>;
52 SpatialHash<S>::SpatialHash(
const AABB<S>& scene_limit_, S cell_size_)
53 : cell_size(cell_size_), scene_limit(scene_limit_)
55 width[0] = std::ceil(scene_limit.width() / cell_size);
56 width[1] = std::ceil(scene_limit.height() / cell_size);
57 width[2] = std::ceil(scene_limit.depth() / cell_size);
62 std::vector<unsigned int> SpatialHash<S>::operator()(
const AABB<S>& aabb)
const 64 int min_x = std::floor((aabb.min_[0] - scene_limit.min_[0]) / cell_size);
65 int max_x = std::ceil((aabb.max_[0] - scene_limit.min_[0]) / cell_size);
66 int min_y = std::floor((aabb.min_[1] - scene_limit.min_[1]) / cell_size);
67 int max_y = std::ceil((aabb.max_[1] - scene_limit.min_[1]) / cell_size);
68 int min_z = std::floor((aabb.min_[2] - scene_limit.min_[2]) / cell_size);
69 int max_z = std::ceil((aabb.max_[2] - scene_limit.min_[2]) / cell_size);
71 std::vector<unsigned int> keys((max_x - min_x) * (max_y - min_y) * (max_z - min_z));
73 for(
int x = min_x; x < max_x; ++x)
75 for(
int y = min_y; y < max_y; ++y)
77 for(
int z = min_z; z < max_z; ++z)
79 keys[
id++] = x + y * width[0] + z * width[0] * width[1];
Main namespace.
Definition: broadphase_bruteforce-inl.h:45