Commit c17d9f44423617cb3e74f827fcc6f892c8c63cd4
1 parent
41100e51
add aabbn for stimlib
Showing
1 changed file
with
54 additions
and
0 deletions
Show diff stats
1 | +#ifndef STIM_AABB3_H | ||
2 | +#define STIM_AABB3_H | ||
3 | + | ||
4 | +#include <vector> | ||
5 | +#include <stim/cuda/cudatools/callable.h> | ||
6 | + | ||
7 | +namespace stim{ | ||
8 | + | ||
9 | +/// Structure for a 3D axis aligned bounding box | ||
10 | +template<typename T, size_t D> | ||
11 | +struct aabbn{ | ||
12 | + | ||
13 | +//protected: | ||
14 | + | ||
15 | + T low[D]; //top left corner position | ||
16 | + T high[D]; //dimensions along x and y and z | ||
17 | + | ||
18 | +//public: | ||
19 | + | ||
20 | + CUDA_CALLABLE aabbn(){ //initialize an axis aligned bounding box of size 0 at the given position | ||
21 | + for(size_t d = 0; d < D; d++) | ||
22 | + low[d] = high[d] = 0; | ||
23 | + } | ||
24 | + | ||
25 | + CUDA_CALLABLE void init(T* init){ | ||
26 | + for(size_t d = 0; d < D; d++) | ||
27 | + low[d] = high[d] = init[d]; | ||
28 | + } | ||
29 | + | ||
30 | + //insert a point into the bounding box, growing the box appropriately | ||
31 | + CUDA_CALLABLE void insert(T* p){ | ||
32 | + for(size_t d = 0; d < D; d++){ | ||
33 | + if(p[d] < low[d]) low[d] = p[d]; | ||
34 | + if(p[d] > high[d]) high[d] = p[d]; | ||
35 | + } | ||
36 | + } | ||
37 | + | ||
38 | + //trim the bounding box so that the lower bounds are b(x, y, z, ...) | ||
39 | + CUDA_CALLABLE void trim_low(T* b){ | ||
40 | + for(size_t d = 0; d < D; d++) | ||
41 | + if(low[d] < b[d]) low[d] = b[d]; | ||
42 | + } | ||
43 | + | ||
44 | + CUDA_CALLABLE void trim_high(T* b){ | ||
45 | + for(size_t d = 0; d < D; d++) | ||
46 | + if(low[d] > b[d]) low[d] = b[d]; | ||
47 | + } | ||
48 | + | ||
49 | +}; | ||
50 | + | ||
51 | +} | ||
52 | + | ||
53 | + | ||
54 | +#endif | ||
0 | \ No newline at end of file | 55 | \ No newline at end of file |