Skip to content

Class muda::spatial_hash::SparseSpatialHash

template <typename Hash>

ClassList > muda > spatial_hash > SparseSpatialHash

Public Functions

Type Name
SparseSpatialHash (muda::Stream & stream=muda::Stream::Default())
void detect (CBufferView< BoundingSphere > spheres, DeviceBuffer< CollisionPair > & collisionPairs, Pred && pred={})
Detect collision pairs from bounding spheres. Note that:
void detect (int level, CBufferView< BoundingSphere > spheres, DeviceBuffer< CollisionPair > & collisionPairs, Pred && pred={})
Detect collision pairs from bounding spheres at a specific level (level >= 0). This is used for hierarchical spatial hashing collision detection. Its user's responsibility to set level value to a bounding sphere. Normally, higher level means larger bounding sphere. Users should decide a proper range of radius for each level, like:

Public Functions Documentation

function SparseSpatialHash

inline muda::spatial_hash::SparseSpatialHash::SparseSpatialHash (
    muda::Stream & stream=muda::Stream::Default()
) 

function detect [1/2]

Detect collision pairs from bounding spheres. Note that:

template<typename Pred>
inline void muda::spatial_hash::SparseSpatialHash::detect (
    CBufferView < BoundingSphere > spheres,
    DeviceBuffer < CollisionPair > & collisionPairs,
    Pred && pred={}
) 

  • The collision pairs are unique but not sorted.
  • All (i,j) pairs in collisionPairs satisfy i < j.

Parameters:

  • spheres bounding spheres
  • collisionPairs output collision pairs
  • pred predication function. f: __device__ (int i, int j) -> bool. If pred(i,j) is true, then the collision pair (i,j) is recorded, else the collision pair is discarded.

See also: DefaultPredication


function detect [2/2]

Detect collision pairs from bounding spheres at a specific level (level >= 0). This is used for hierarchical spatial hashing collision detection. Its user's responsibility to set level value to a bounding sphere. Normally, higher level means larger bounding sphere. Users should decide a proper range of radius for each level, like:

template<typename Pred>
inline void muda::spatial_hash::SparseSpatialHash::detect (
    int level,
    CBufferView < BoundingSphere > spheres,
    DeviceBuffer < CollisionPair > & collisionPairs,
    Pred && pred={}
) 

BoundingSphere s{o,r};
if (r < r0) s.level = 0;
else if (r < r1) s.level = 1;
else s.level = 2;
...
Note that: * For a level L, any bounding spheres has a level <= L will be taken into account. * The collision pairs are unique but not sorted. * All (i,j) pairs in collisionPairs satisfy i < j. * The collisionPairs will be appended with new collision pairs (not cleared).

Typical usage:

DeviceBuffer<BoundingSphere> spheres;

// Your code to fill spheres with proper level
// ...

DeviceBuffer<CollisionPair> collisionPairs;

for (int level = 0; level < level_count; ++level)
{
    detect(level, spheres, collisionPairs);
}

Parameters:

  • level the hierarchy level we want to detect
  • spheres bounding spheres
  • collisionPairs appended output collision pairs
  • pred predication function. f: __device__ (int i, int j) -> bool. If pred(i,j) is true, then the collision pair (i,j) is recorded, else the collision pair is discarded.

See also: DefaultPredication



The documentation for this class was generated from the following file src/muda/ext/geo/spatial_hash/sparse_spatial_hash.h