You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A C++/CUDA library to efficiently compute neighborhood information on the GPU for 3D point clouds within a fixed radius. Suitable for many applications, e.g. neighborhood search for SPH fluid simulations.
3
+
4
+
The library interface is similar to CompactNSearch (https://github.com/InteractiveComputerGraphics/CompactNSearch)
5
+
## Libraries using cuNSearch
6
+
7
+
*[SPlisHSPlasH](https://github.com/InteractiveComputerGraphics/SPlisHSPlasH) - A C++ library for the physically-based simulation of fluids using Smoothed Particle Hydrodynamics (see screenshot)
8
+
9
+

10
+
11
+
## Build Instructions
12
+
13
+
This project is based on [CMake](https://cmake.org/). Simply generate project, Makefiles, etc. using [CMake](https://cmake.org/) and compile the project with the compiler of your choice.
14
+
15
+
Requirements:
16
+
- CMake 3.12
17
+
- CUDA SDK 9.0 or newer
18
+
- C++ 11
19
+
20
+
The code was tested with the following configurations:
21
+
- Windows 10 64-bit, CMake 3.12.3, Visual Studio 2017, CUDA SDK 10.1
A data structure to perform a neighborhood search can be created by calling the constructor given a fixed search radius ```r```.
27
+
```c++
28
+
cuNSearch::NeighborhoodSearch nsearch(r);
29
+
```
30
+
An arbitrary number of point clouds can then be added to the data structure using the method ```add_point_set```. The library expects the point positions to be contiguously stored in an array-like structure. The method will return a unique id associated with the initialized point set.
31
+
```c++
32
+
std::vector<std::array<Real, 3>> positions;
33
+
// ... Fill array with 3 * n real numbers representing three-dimensional point positions.
34
+
unsigned int point_set_id = nsearch.add_point_set(positions.front().data(), positions.size());
35
+
nsearch.find_neighbors();
36
+
```
37
+
In order to generate the neighborhood information simply execute the following command
38
+
```c++
39
+
nsearch.find_neighbors();
40
+
```
41
+
Finally, the neighborhood information can be accessed as follows
// Return PointID of the jth neighbor of the ith particle in the 0th point set.
49
+
PointID const& pid = ps.neighbor(0, i, j);
50
+
// ...
51
+
// Do whatever you want with the point id. The id contains two indices.
52
+
// The first field pid.point_set_id represents the unique point set id returnd by add_point_set.
53
+
// The second field pid.point_id stands for the index of the neighboring particle within
54
+
// the containing point set.
55
+
// ...
56
+
}
57
+
}
58
+
```
59
+
60
+
Besides the basic functionality the library offers to compute a rule for reordering the points according to a space-filling Z curve. The reordering will improve the performance of future neighborhood queries and accesses. The rule can be computed via
61
+
```c++
62
+
nsearch.z_sort();
63
+
```
64
+
Please note that the actual reordering must be invoked by the user by
65
+
```c++
66
+
ps.sort_field(positions.data());
67
+
```
68
+
Assuming that there is additional information stored per-point (e.g. velocity, color, mass etc.) the information **must** also be reorded using the same method to maintain consistency. Subsequently, the ```find_neighbors``` function has to be invoked again to update the neighborhood information.
69
+
70
+
Another self-explaining (benchmark) [demo](demo/main.cu) is contained in the project.
71
+
72
+
## Activation Table
73
+
74
+
When maintaining multiple it is sometimes desired that only certain point sets can find points from other point sets. Therefore an activation table is implemented where the user can specify whether a point set i searches points in another point set j. When nothing else is specified all point sets will search points in all other point sets. The activation table can be modified with e.g.
75
+
```c++
76
+
nsearch.set_active(i, j, false)
77
+
```
78
+
79
+
## Common mistakes and issues
80
+
81
+
Visual Studio may not detect changes in ".cu" files.
82
+
83
+
Use of thrust library in cpp files: Some thrust classes can only be used when the file is compiled by the nvidia compiler nvcc.
84
+
This is usually solved by change the file ending to .cu to mark the file for the nvcc compiler.
85
+
86
+
## References
87
+
88
+
* R. Hoetzlein, 2014. "Fast Fixed-Radius Nearest Neighbors: Interactive Million-Particle Fluids", GPU Technology Conference (GTC), Santa Clara, CA.
0 commit comments