MUDA
Loading...
Searching...
No Matches
sparse_spatial_hash.h
1#pragma once
2#include <muda/ext/geo/spatial_hash/sparse_spatial_hash_impl.h>
3
4namespace muda::spatial_hash
5{
7{
8 public:
9 __device__ bool operator()(int i, int j) { return true; }
10};
11
12template <typename Hash = Morton<uint32_t>>
14{
15 // algorithm comes from:
16 // https://developer.nvidia.com/gpugems/gpugems3/part-v-physics-simulation/chapter-32-broad-phase-collision-detection-cuda
17 private:
19
20 Impl m_impl;
21
22 public:
23 SparseSpatialHash(muda::Stream& stream = muda::Stream::Default())
24 : m_impl(stream)
25 {
26 }
27
40 template <typename Pred = DefaultPredication>
42 DeviceBuffer<CollisionPair>& collisionPairs,
43 Pred&& pred = {})
44 {
45 m_impl.level = 0;
46 m_impl.detect(spheres, false, collisionPairs, std::forward<Pred>(pred));
47 }
48
91 template <typename Pred = DefaultPredication>
92 void detect(int level,
94 DeviceBuffer<CollisionPair>& collisionPairs,
95 Pred&& pred = {})
96 {
97 MUDA_KERNEL_ASSERT(level >= 0, "invalid level");
98 m_impl.level = level;
99 m_impl.detect(spheres, true, collisionPairs, std::forward<Pred>(pred));
100 }
101};
102} // namespace muda::spatial_hash
Definition buffer_view.h:24
A std::vector like wrapper of cuda device memory, allows user to:
Definition device_buffer.h:46
RAII wrapper for cudaStream.
Definition stream.h:18
Definition sparse_spatial_hash.h:7
Definition sparse_spatial_hash.h:14
void detect(CBufferView< BoundingSphere > spheres, DeviceBuffer< CollisionPair > &collisionPairs, Pred &&pred={})
Detect collision pairs from bounding spheres. Note that:
Definition sparse_spatial_hash.h:41
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 hiera...
Definition sparse_spatial_hash.h:92
Definition sparse_spatial_hash_impl.h:169