3 #include "core/geo/rect.h" 4 #include "core/indexing.h" 5 #include "core/spatial_division/ndim_tree.h" 10 using voxel = util::aligned::vector<size_t>;
19 using nested_type =
typename prev_type::data_type;
20 using data_type = util::aligned::vector<nested_type>;
21 static data_type get_blank(
size_t size) {
22 return data_type(size, prev_type::get_blank(size));
28 using data_type = voxel;
29 static data_type get_blank(
size_t) {
return data_type{}; }
33 using voxel_data_t =
typename voxel_data_trait<n>::data_type;
38 inline const voxel& index(
const typename voxel_data_trait<n>::data_type& data,
39 indexing::index_t<n> i) {
40 return index<n - 1>(data[indexing::back<n>(i)], indexing::reduce<n>(i));
44 inline const voxel& index<1>(
45 const typename voxel_data_trait<1>::data_type& data,
46 indexing::index_t<1> i) {
51 inline voxel& index(
typename voxel_data_trait<n>::data_type& data,
52 indexing::index_t<n> i) {
53 return index<n - 1>(data[indexing::back<n>(i)], indexing::reduce<n>(i));
57 inline voxel& index<1>(
typename voxel_data_trait<1>::data_type& data,
58 indexing::index_t<1> i) {
66 const indexing::index_t<n>& position,
67 voxel_data_t<n>& ret) {
68 if (!tree.has_nodes()) {
69 index<n>(ret, position) = tree.get_items();
71 for (
size_t i = 0; i != tree.get_nodes().size(); ++i) {
72 const auto relative = indexing::relative_position<n>(i) *
73 static_cast<unsigned>(tree.get_side() / 2);
74 voxelise(tree.get_nodes()[i], position + relative, ret);
82 voxelise(tree, indexing::index_t<n>{0}, ret);
98 using data_type = detail::voxel_data_t<n>;
102 : aabb_{tree.get_aabb()}
103 , data_{detail::voxelise(tree)} {}
105 aabb_type get_aabb()
const {
return aabb_; }
106 size_t get_side()
const {
return data_.size(); }
107 const auto& get_voxel(indexing::index_t<n> i)
const {
108 return detail::index<n>(data_, i);
110 auto& get_voxel(indexing::index_t<n> i) {
111 return detail::index<n>(data_, i);
123 return dimensions(voxels.get_aabb()) /
124 static_cast<float>(voxels.get_side());
130 const auto dim = voxel_dimensions(voxels);
131 const auto root = voxels.get_aabb().get_min() + (dim * decltype(dim){i});
132 return vt(root, root + dim);
144 using traversal_callback =
145 std::function<bool(const geo::ray&, const voxel&, float, float)>;
153 const traversal_callback& fun);
Definition: geometry_structs.h:11
I would do this with a struct, but rays have an invariant:
Definition: geometric.h:19
A generic interface for spatial division algorithms (octree, quadtree)
Definition: ndim_tree.h:38
Definition: voxel_collection.h:95
voxel_collection(const ndim_tree< n > &tree)
Construct directly from an existing tree.
Definition: voxel_collection.h:101
Definition: capsule_base.h:9
Definition: voxel_collection.h:17