16 #include <morton/morton.h>
25 Stack(uint64_t max_elements) {
data_.resize(max_elements); }
29 assert(
top_ <
static_cast<int64_t
>(
data_.size()));
33 assert(
top_ <
static_cast<int64_t
>(
data_.size()));
38 uint64_t
Size()
const {
return static_cast<uint64_t
>(
top_ + 1); }
56 num_boxes_ = num_boxes_axis[0] * num_boxes_axis[1] * num_boxes_axis[2];
57 std::array<uint64_t, 3> max_dimensions{
58 num_boxes_axis[0] - 1, num_boxes_axis[1] - 1, num_boxes_axis[2] - 1};
59 auto max_dim = std::max(num_boxes_axis[0],
60 std::max(num_boxes_axis[1], num_boxes_axis[2]));
62 static_cast<uint64_t
>(std::ceil(std::log(max_dim) / std::log(2)));
72 auto length =
static_cast<uint64_t
>(std::pow(2, max_depth - 1));
75 s.
Push({0, length, length, length, length});
81 while (s.
Size() != 0) {
85 if (c.index == 1 || c.index == 3 || c.index == 5 || c.index == 7) {
89 if ((c.index > 1 && c.index < 4) || c.index > 5) {
96 auto xmin = xmax - c.length;
97 auto ymin = ymax - c.length;
98 auto zmin = zmax - c.length;
100 if (max_dimensions[0] >= xmax - 1 && max_dimensions[1] >= ymax - 1 &&
101 max_dimensions[2] >= zmax - 1) {
107 box_cnt += c.length * c.length * c.length;
108 }
else if (max_dimensions[0] < xmin || max_dimensions[1] < ymin ||
109 max_dimensions[2] < zmin) {
112 auto elements = c.length * c.length * c.length;
115 auto next_length = c.length >> 1;
116 s.
Push({0, next_length, xmin + next_length, ymin + next_length,
117 zmin + next_length});
122 while (s.
Size() > 0 && ++(s.
Top().index) == 8) {
129 template <
typename T>
131 const T& container, uint64_t from,
133 if (container.size() == 0) {
137 if (container[from].first > search_val && from > 0) {
140 return {container[from].second, from};
143 auto m = (from + to) / 2;
144 if (container[m].first == search_val) {
145 return {container[m].second, m};
146 }
else if (container[m].first > search_val) {
164 uint64_t start_morton_code, uint64_t offset_pos,
165 const std::vector<std::pair<uint64_t, uint64_t>>& offset_index)
201 uint64_t start_index, uint64_t end_index,
205 MortonIterator it(start_index, end_index, start_index + result.first,