3 #include "core/geo/box.h" 4 #include "core/indexing.h" 5 #include "core/spatial_division/range.h" 14 typename aabb_type = detail::range_t<n>,
15 typename next_boundaries_type = std::array<aabb_type, (1 << n)>>
16 next_boundaries_type next_boundaries(
const aabb_type& parent) {
17 using vt = detail::range_value_t<n>;
19 const auto c = centre(parent);
21 const auto root_aabb = aabb_type(parent.get_min(), c);
22 const auto d = dimensions(root_aabb);
24 next_boundaries_type ret;
26 for (
size_t i = 0; i != ret.size(); ++i) {
27 const auto relative = indexing::relative_position<n>(i);
28 ret[i] = root_aabb + d * vt{relative};
41 using node_array = std::array<ndim_tree, (1 << n)>;
45 using item_checker = std::function<bool(size_t, const aabb_type& aabb)>;
50 const util::aligned::vector<size_t>& to_test,
51 const aabb_type&
aabb)
53 , items_{compute_contained_items(callback, to_test,
aabb)}
54 , nodes_{compute_nodes(depth, callback, items_,
aabb)} {}
56 aabb_type get_aabb()
const {
return aabb_; }
57 bool has_nodes()
const {
return nodes_ !=
nullptr; }
58 const node_array& get_nodes()
const {
return *nodes_; }
59 util::aligned::vector<size_t> get_items()
const {
return items_; }
61 size_t get_side()
const {
62 return nodes_ ? 2 * nodes_->front().get_side() : 1;
66 using next_boundaries_type = std::array<aabb_type, (1 << n)>;
68 static util::aligned::vector<size_t> compute_contained_items(
70 const util::aligned::vector<size_t>& to_test,
71 const aabb_type&
aabb) {
72 util::aligned::vector<size_t> ret;
73 std::copy_if(begin(to_test),
75 std::back_inserter(ret),
76 [&](
auto i) {
return callback(i, aabb); });
80 static std::unique_ptr<node_array> compute_nodes(
83 const util::aligned::vector<size_t>& to_test,
84 const aabb_type& aabb) {
89 const auto next = detail::next_boundaries<n>(aabb);
90 auto ret = std::make_unique<std::array<ndim_tree, (1 << n)>>();
92 begin(next), end(next), ret->begin(), [&](
const auto& i) {
93 return ndim_tree(depth - 1, callback, to_test, i);
99 util::aligned::vector<size_t> items_;
100 std::unique_ptr<node_array> nodes_;
std::function< bool(size_t, const aabb_type &aabb)> item_checker
Definition: ndim_tree.h:45
A generic interface for spatial division algorithms (octree, quadtree)
Definition: ndim_tree.h:38
Definition: voxel_structs.h:9
Definition: capsule_base.h:9