diff --git a/stim/visualization/aabbn.h b/stim/visualization/aabbn.h new file mode 100644 index 0000000..087f8c2 --- /dev/null +++ b/stim/visualization/aabbn.h @@ -0,0 +1,54 @@ +#ifndef STIM_AABB3_H +#define STIM_AABB3_H + +#include +#include + +namespace stim{ + +/// Structure for a 3D axis aligned bounding box +template +struct aabbn{ + +//protected: + + T low[D]; //top left corner position + T high[D]; //dimensions along x and y and z + +//public: + + CUDA_CALLABLE aabbn(){ //initialize an axis aligned bounding box of size 0 at the given position + for(size_t d = 0; d < D; d++) + low[d] = high[d] = 0; + } + + CUDA_CALLABLE void init(T* init){ + for(size_t d = 0; d < D; d++) + low[d] = high[d] = init[d]; + } + + //insert a point into the bounding box, growing the box appropriately + CUDA_CALLABLE void insert(T* p){ + for(size_t d = 0; d < D; d++){ + if(p[d] < low[d]) low[d] = p[d]; + if(p[d] > high[d]) high[d] = p[d]; + } + } + + //trim the bounding box so that the lower bounds are b(x, y, z, ...) + CUDA_CALLABLE void trim_low(T* b){ + for(size_t d = 0; d < D; d++) + if(low[d] < b[d]) low[d] = b[d]; + } + + CUDA_CALLABLE void trim_high(T* b){ + for(size_t d = 0; d < D; d++) + if(low[d] > b[d]) low[d] = b[d]; + } + +}; + +} + + +#endif \ No newline at end of file -- libgit2 0.21.4