Replace children() helper with individual child() access

This commit is contained in:
JacksonCampolattaro 2023-04-25 13:48:21 +02:00
parent 33358ae838
commit e7f236678e
9 changed files with 118 additions and 136 deletions

View File

@ -514,9 +514,9 @@ public:
return traverse<Traversal>({*this, std::forward<Args>(args)...}); return traverse<Traversal>({*this, std::forward<Args>(args)...});
} }
template <typename Traversal> template <typename Traversal, typename ...Args>
Node_index_range traverse_indices() const { Node_index_range traverse_indices(Args&& ...args) const {
return traverse_indices<Traversal>({*this}); return traverse_indices<Traversal>({*this, std::forward<Args>(args)...});
} }
/*! /*!
@ -740,24 +740,6 @@ public:
using Children = typename Node::Children; using Children = typename Node::Children;
using Children_const = typename Node::Children_const; using Children_const = typename Node::Children_const;
Children children(Node& node) {
CGAL_precondition (!node.is_leaf());
return Children{&m_nodes[node.m_children_index.get()], Degree::value};
}
Children children(Node_index node) {
return children(m_nodes[node]);
}
Children_const children(const Node& node) const {
CGAL_precondition (!node.is_leaf());
return Children_const{&m_nodes[node.m_children_index.get()], Degree::value};
}
Children_const children(Node_index node) const {
return children(m_nodes[node]);
}
const boost::optional<Node_index> next_sibling(Node_index n) const { const boost::optional<Node_index> next_sibling(Node_index n) const {
// Root node has no siblings // Root node has no siblings

View File

@ -78,7 +78,7 @@ public:
} else { } else {
// todo: this shouldn't be necessary, I'd prefer to directly get m_orthtree[n].m_children_index // todo: this shouldn't be necessary, I'd prefer to directly get m_orthtree[n].m_children_index
return m_orthtree.index(m_orthtree.children(n)[0]); return m_orthtree.child(n, 0);
} }
} }

View File

@ -50,30 +50,29 @@ int main(void) {
assert(!octree.adjacent_node(octree.index(octree.root()), 5)); assert(!octree.adjacent_node(octree.index(octree.root()), 5));
// Left Top Front node should have siblings to the Right, Down, and Back // Left Top Front node should have siblings to the Right, Down, and Back
auto left_top_back = octree.index(octree.children(octree.root())[Traits::LEFT_TOP_BACK]); auto left_top_back = octree.child(octree.index(octree.root()), Traits::LEFT_TOP_BACK);
assert(octree.index(&octree.children(octree.root())[Traits::RIGHT_TOP_BACK]) == assert(octree.child(octree.index(octree.root()), Traits::RIGHT_TOP_BACK) ==
octree.adjacent_node(left_top_back, Traits::RIGHT)); octree.adjacent_node(left_top_back, Traits::RIGHT).get());
assert( assert(octree.child(octree.index(octree.root()), Traits::LEFT_BOTTOM_BACK) ==
octree.index(&octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK]) == octree.adjacent_node(left_top_back, Traits::DOWN).get());
octree.adjacent_node(left_top_back, Traits::DOWN)); assert(octree.child(octree.index(octree.root()), Traits::LEFT_TOP_FRONT) ==
assert(octree.index(&octree.children(octree.root())[Traits::LEFT_TOP_FRONT]) ==
octree.adjacent_node(left_top_back, Traits::FRONT)); octree.adjacent_node(left_top_back, Traits::FRONT));
assert(!octree.adjacent_node(left_top_back, Traits::LEFT)); assert(!octree.adjacent_node(left_top_back, Traits::LEFT));
assert(!octree.adjacent_node(left_top_back, Traits::UP)); assert(!octree.adjacent_node(left_top_back, Traits::UP));
assert(!octree.adjacent_node(left_top_back, Traits::BACK)); assert(!octree.adjacent_node(left_top_back, Traits::BACK));
std::cout << octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK] << std::endl; std::cout << octree[octree.child(octree.index(octree.root()), Traits::LEFT_BOTTOM_BACK)] << std::endl;
auto right_top_back_of_left_bottom_back = auto right_top_back_of_left_bottom_back =
octree.index(octree.children(octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK])[Traits::RIGHT_TOP_BACK]); octree.child(octree.child(octree.index(octree.root()), Traits::LEFT_BOTTOM_BACK), Traits::RIGHT_TOP_BACK);
assert( assert(
octree.index(&octree.children(octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK])[Traits::LEFT_TOP_BACK]) == octree.child(octree.child(octree.index(octree.root()), Traits::LEFT_BOTTOM_BACK), Traits::LEFT_TOP_BACK) ==
octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::LEFT) octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::LEFT)
); );
assert( assert(
octree.index(&octree.children(octree.root())[Traits::RIGHT_BOTTOM_BACK]) == octree.child(octree.index(octree.root()), Traits::RIGHT_BOTTOM_BACK) ==
octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::RIGHT) octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::RIGHT)
); );
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::RIGHT).has_value()); assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::RIGHT).has_value());

View File

@ -37,11 +37,11 @@ int main(void) {
Octree octree(points, points.point_map()); Octree octree(points, points.point_map());
octree.refine(10, 1); octree.refine(10, 1);
std::cout << "root: " << octree.root().local_coordinates() << std::endl; std::cout << "root: " << octree.local_coordinates(octree.index(octree.root())) << std::endl;
std::cout << "first child: " << octree.children(octree.root())[0].local_coordinates() << std::endl; std::cout << "first child: " << octree.local_coordinates(octree.child(octree.index(octree.root()), 0)) << std::endl;
std::cout << "fifth child: " << octree.children(octree.root())[4].local_coordinates() << std::endl; std::cout << "fifth child: " << octree.local_coordinates(octree.child(octree.index(octree.root()), 4)) << std::endl;
std::cout << "fifth child of first child: " std::cout << "fifth child of first child: "
<< octree.children(octree.children(octree.root())[0])[4].local_coordinates() << std::endl; << octree.local_coordinates(octree.child(octree.child(octree.index(octree.root()), 0), 4)) << std::endl;
// TODO // TODO

View File

@ -42,14 +42,14 @@ void test_9_nodes() {
assert(octree.bbox(octree.root()) == CGAL::Bbox_3(-1.1, -1.1, -1.1, 1.1, 1.1, 1.1)); assert(octree.bbox(octree.root()) == CGAL::Bbox_3(-1.1, -1.1, -1.1, 1.1, 1.1, 1.1));
// Compare the child nodes // Compare the child nodes
assert(octree.bbox(octree.children(octree.root())[0]) == CGAL::Bbox_3(-1.1, -1.1, -1.1, 0, 0, 0)); assert(octree.bbox(octree.child(octree.index(octree.root()), 0)) == CGAL::Bbox_3(-1.1, -1.1, -1.1, 0, 0, 0));
assert(octree.bbox(octree.children(octree.root())[1]) == CGAL::Bbox_3(0, -1.1, -1.1, 1.1, 0, 0)); assert(octree.bbox(octree.child(octree.index(octree.root()), 1)) == CGAL::Bbox_3(0, -1.1, -1.1, 1.1, 0, 0));
assert(octree.bbox(octree.children(octree.root())[2]) == CGAL::Bbox_3(-1.1, 0, -1.1, 0, 1.1, 0)); assert(octree.bbox(octree.child(octree.index(octree.root()), 2)) == CGAL::Bbox_3(-1.1, 0, -1.1, 0, 1.1, 0));
assert(octree.bbox(octree.children(octree.root())[3]) == CGAL::Bbox_3(0, 0, -1.1, 1.1, 1.1, 0)); assert(octree.bbox(octree.child(octree.index(octree.root()), 3)) == CGAL::Bbox_3(0, 0, -1.1, 1.1, 1.1, 0));
assert(octree.bbox(octree.children(octree.root())[4]) == CGAL::Bbox_3(-1.1, -1.1, 0, 0, 0, 1.1)); assert(octree.bbox(octree.child(octree.index(octree.root()), 4)) == CGAL::Bbox_3(-1.1, -1.1, 0, 0, 0, 1.1));
assert(octree.bbox(octree.children(octree.root())[5]) == CGAL::Bbox_3(0, -1.1, 0, 1.1, 0, 1.1)); assert(octree.bbox(octree.child(octree.index(octree.root()), 5)) == CGAL::Bbox_3(0, -1.1, 0, 1.1, 0, 1.1));
assert(octree.bbox(octree.children(octree.root())[6]) == CGAL::Bbox_3(-1.1, 0, 0, 0, 1.1, 1.1)); assert(octree.bbox(octree.child(octree.index(octree.root()), 6)) == CGAL::Bbox_3(-1.1, 0, 0, 0, 1.1, 1.1));
assert(octree.bbox(octree.children(octree.root())[7]) == CGAL::Bbox_3(0, 0, 0, 1.1, 1.1, 1.1)); assert(octree.bbox(octree.child(octree.index(octree.root()), 7)) == CGAL::Bbox_3(0, 0, 0, 1.1, 1.1, 1.1));
} }
void test_25_nodes() { void test_25_nodes() {
@ -69,49 +69,49 @@ void test_25_nodes() {
assert(octree.bbox(octree.root()) == CGAL::Bbox_3(-1.5, -1.5, -1.5, 1.5, 1.5, 1.5)); assert(octree.bbox(octree.root()) == CGAL::Bbox_3(-1.5, -1.5, -1.5, 1.5, 1.5, 1.5));
// Compare the child nodes // Compare the child nodes
assert(octree.bbox(octree.children(octree.root())[0]) == CGAL::Bbox_3(-1.5, -1.5, -1.5, 0, 0, 0)); assert(octree.bbox(octree.child(octree.index(octree.root()), 0)) == CGAL::Bbox_3(-1.5, -1.5, -1.5, 0, 0, 0));
assert(octree.bbox(octree.children(octree.root())[1]) == CGAL::Bbox_3(0, -1.5, -1.5, 1.5, 0, 0)); assert(octree.bbox(octree.child(octree.index(octree.root()), 1)) == CGAL::Bbox_3(0, -1.5, -1.5, 1.5, 0, 0));
assert(octree.bbox(octree.children(octree.root())[2]) == CGAL::Bbox_3(-1.5, 0, -1.5, 0, 1.5, 0)); assert(octree.bbox(octree.child(octree.index(octree.root()), 2)) == CGAL::Bbox_3(-1.5, 0, -1.5, 0, 1.5, 0));
assert(octree.bbox(octree.children(octree.root())[3]) == CGAL::Bbox_3(0, 0, -1.5, 1.5, 1.5, 0)); assert(octree.bbox(octree.child(octree.index(octree.root()), 3)) == CGAL::Bbox_3(0, 0, -1.5, 1.5, 1.5, 0));
assert(octree.bbox(octree.children(octree.root())[4]) == CGAL::Bbox_3(-1.5, -1.5, 0, 0, 0, 1.5)); assert(octree.bbox(octree.child(octree.index(octree.root()), 4)) == CGAL::Bbox_3(-1.5, -1.5, 0, 0, 0, 1.5));
assert(octree.bbox(octree.children(octree.root())[5]) == CGAL::Bbox_3(0, -1.5, 0, 1.5, 0, 1.5)); assert(octree.bbox(octree.child(octree.index(octree.root()), 5)) == CGAL::Bbox_3(0, -1.5, 0, 1.5, 0, 1.5));
assert(octree.bbox(octree.children(octree.root())[6]) == CGAL::Bbox_3(-1.5, 0, 0, 0, 1.5, 1.5)); assert(octree.bbox(octree.child(octree.index(octree.root()), 6)) == CGAL::Bbox_3(-1.5, 0, 0, 0, 1.5, 1.5));
assert(octree.bbox(octree.children(octree.root())[7]) == CGAL::Bbox_3(0, 0, 0, 1.5, 1.5, 1.5)); assert(octree.bbox(octree.child(octree.index(octree.root()), 7)) == CGAL::Bbox_3(0, 0, 0, 1.5, 1.5, 1.5));
// Compare children of the first child // Compare children of the first child
assert(octree.bbox(octree.children(octree.children(octree.root())[0])[0]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 0)) ==
CGAL::Bbox_3(-1.5, -1.5, -1.5, -0.75, -0.75, -0.75)); CGAL::Bbox_3(-1.5, -1.5, -1.5, -0.75, -0.75, -0.75));
assert(octree.bbox(octree.children(octree.children(octree.root())[0])[1]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 1)) ==
CGAL::Bbox_3(-0.75, -1.5, -1.5, 0, -0.75, -0.75)); CGAL::Bbox_3(-0.75, -1.5, -1.5, 0, -0.75, -0.75));
assert(octree.bbox(octree.children(octree.children(octree.root())[0])[2]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 2)) ==
CGAL::Bbox_3(-1.5, -0.75, -1.5, -0.75, 0, -0.75)); CGAL::Bbox_3(-1.5, -0.75, -1.5, -0.75, 0, -0.75));
assert(octree.bbox(octree.children(octree.children(octree.root())[0])[3]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 3)) ==
CGAL::Bbox_3(-0.75, -0.75, -1.5, 0, 0, -0.75)); CGAL::Bbox_3(-0.75, -0.75, -1.5, 0, 0, -0.75));
assert(octree.bbox(octree.children(octree.children(octree.root())[0])[4]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 4)) ==
CGAL::Bbox_3(-1.5, -1.5, -0.75, -0.75, -0.75, 0)); CGAL::Bbox_3(-1.5, -1.5, -0.75, -0.75, -0.75, 0));
assert(octree.bbox(octree.children(octree.children(octree.root())[0])[5]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 5)) ==
CGAL::Bbox_3(-0.75, -1.5, -0.75, 0, -0.75, 0)); CGAL::Bbox_3(-0.75, -1.5, -0.75, 0, -0.75, 0));
assert(octree.bbox(octree.children(octree.children(octree.root())[0])[6]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 6)) ==
CGAL::Bbox_3(-1.5, -0.75, -0.75, -0.75, 0, 0)); CGAL::Bbox_3(-1.5, -0.75, -0.75, -0.75, 0, 0));
assert(octree.bbox(octree.children(octree.children(octree.root())[0])[7]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 7)) ==
CGAL::Bbox_3(-0.75, -0.75, -0.75, 0, 0, 0)); CGAL::Bbox_3(-0.75, -0.75, -0.75, 0, 0, 0));
// Compare children of the last child // Compare children of the last child
assert(octree.bbox(octree.children(octree.children(octree.root())[7])[0]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 0)) ==
CGAL::Bbox_3(0, 0, 0, 0.75, 0.75, 0.75)); CGAL::Bbox_3(0, 0, 0, 0.75, 0.75, 0.75));
assert(octree.bbox(octree.children(octree.children(octree.root())[7])[1]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 1)) ==
CGAL::Bbox_3(0.75, 0, 0, 1.5, 0.75, 0.75)); CGAL::Bbox_3(0.75, 0, 0, 1.5, 0.75, 0.75));
assert(octree.bbox(octree.children(octree.children(octree.root())[7])[2]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 2)) ==
CGAL::Bbox_3(0, 0.75, 0, 0.75, 1.5, 0.75)); CGAL::Bbox_3(0, 0.75, 0, 0.75, 1.5, 0.75));
assert(octree.bbox(octree.children(octree.children(octree.root())[7])[3]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 3)) ==
CGAL::Bbox_3(0.75, 0.75, 0, 1.5, 1.5, 0.75)); CGAL::Bbox_3(0.75, 0.75, 0, 1.5, 1.5, 0.75));
assert(octree.bbox(octree.children(octree.children(octree.root())[7])[4]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 4)) ==
CGAL::Bbox_3(0, 0, 0.75, 0.75, 0.75, 1.5)); CGAL::Bbox_3(0, 0, 0.75, 0.75, 0.75, 1.5));
assert(octree.bbox(octree.children(octree.children(octree.root())[7])[5]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 5)) ==
CGAL::Bbox_3(0.75, 0, 0.75, 1.5, 0.75, 1.5)); CGAL::Bbox_3(0.75, 0, 0.75, 1.5, 0.75, 1.5));
assert(octree.bbox(octree.children(octree.children(octree.root())[7])[6]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 6)) ==
CGAL::Bbox_3(0, 0.75, 0.75, 0.75, 1.5, 1.5)); CGAL::Bbox_3(0, 0.75, 0.75, 0.75, 1.5, 1.5));
assert(octree.bbox(octree.children(octree.children(octree.root())[7])[7]) == assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 7)) ==
CGAL::Bbox_3(0.75, 0.75, 0.75, 1.5, 1.5, 1.5)); CGAL::Bbox_3(0.75, 0.75, 0.75, 1.5, 1.5, 1.5));
} }

View File

@ -68,10 +68,10 @@ int main(void) {
// Check the results // Check the results
assert(4 == nodes.size()); assert(4 == nodes.size());
assert(octree.index(octree.children(octree.root())[Octree::Traits::RIGHT_TOP_BACK]) == nodes[0]); assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_TOP_BACK) == nodes[0]);
assert(octree.index(octree.children(octree.root())[Octree::Traits::RIGHT_BOTTOM_FRONT]) == nodes[1]); assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_BOTTOM_FRONT) == nodes[1]);
assert(octree.index(octree.children(octree.root())[Octree::Traits::LEFT_TOP_FRONT]) == nodes[2]); assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_TOP_FRONT) == nodes[2]);
assert(octree.index(octree.children(octree.root())[Octree::Traits::RIGHT_TOP_FRONT]) == nodes[3]); assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_TOP_FRONT) == nodes[3]);
} }
// Intersection with a ray // Intersection with a ray
@ -86,18 +86,19 @@ int main(void) {
// Check the results // Check the results
assert(8 == nodes.size()); assert(8 == nodes.size());
assert(octree.index(octree.children(octree.root())[Octree::Traits::LEFT_BOTTOM_BACK]) == nodes[0]); assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_BOTTOM_BACK) == nodes[0]);
assert( assert(
octree.index(octree.children( octree.child(octree.child(octree.index(octree.root()),
octree.children(octree.root())[Octree::Traits::RIGHT_BOTTOM_BACK])[Octree::Traits::LEFT_TOP_FRONT]) Octree::Traits::RIGHT_BOTTOM_BACK),
Octree::Traits::LEFT_TOP_FRONT)
== nodes[1] == nodes[1]
); );
assert(octree.index(octree.children(octree.root())[Octree::Traits::LEFT_TOP_BACK]) == nodes[2]); assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_TOP_BACK) == nodes[2]);
assert(octree.index(octree.children(octree.root())[Octree::Traits::RIGHT_TOP_BACK]) == nodes[3]); assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_TOP_BACK) == nodes[3]);
assert(octree.index(octree.children(octree.root())[Octree::Traits::LEFT_BOTTOM_FRONT]) == nodes[4]); assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_BOTTOM_FRONT) == nodes[4]);
assert(octree.index(octree.children(octree.root())[Octree::Traits::RIGHT_BOTTOM_FRONT]) == nodes[5]); assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_BOTTOM_FRONT) == nodes[5]);
assert(octree.index(octree.children(octree.root())[Octree::Traits::LEFT_TOP_FRONT]) == nodes[6]); assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_TOP_FRONT) == nodes[6]);
assert(octree.index(octree.children(octree.root())[Octree::Traits::RIGHT_TOP_FRONT]) == nodes[7]); assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_TOP_FRONT) == nodes[7]);
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -52,24 +52,24 @@ void test_8_points() {
octree.refine(10, 1); octree.refine(10, 1);
// Existing points should end up in the same place // Existing points should end up in the same place
assert(octree.index(octree.children(octree.root())[0]) == octree.locate({-1, -1, -1})); assert(octree.child(octree.index(octree.root()), 0) == octree.locate({-1, -1, -1}));
assert(octree.index(octree.children(octree.root())[1]) == octree.locate({1, -1, -1})); assert(octree.child(octree.index(octree.root()), 1) == octree.locate({1, -1, -1}));
assert(octree.index(octree.children(octree.root())[2]) == octree.locate({-1, 1, -1})); assert(octree.child(octree.index(octree.root()), 2) == octree.locate({-1, 1, -1}));
assert(octree.index(octree.children(octree.root())[3]) == octree.locate({1, 1, -1})); assert(octree.child(octree.index(octree.root()), 3) == octree.locate({1, 1, -1}));
assert(octree.index(octree.children(octree.root())[4]) == octree.locate({-1, -1, 1})); assert(octree.child(octree.index(octree.root()), 4) == octree.locate({-1, -1, 1}));
assert(octree.index(octree.children(octree.root())[5]) == octree.locate({1, -1, 1})); assert(octree.child(octree.index(octree.root()), 5) == octree.locate({1, -1, 1}));
assert(octree.index(octree.children(octree.root())[6]) == octree.locate({-1, 1, 1})); assert(octree.child(octree.index(octree.root()), 6) == octree.locate({-1, 1, 1}));
assert(octree.index(octree.children(octree.root())[7]) == octree.locate({1, 1, 1})); assert(octree.child(octree.index(octree.root()), 7) == octree.locate({1, 1, 1}));
// Points adjacent to the existing points should also end up in the same place // Points adjacent to the existing points should also end up in the same place
assert(octree.index(octree.children(octree.root())[0]) == octree.locate({-1.1, -1.1, -1.1})); assert(octree.child(octree.index(octree.root()), 0) == octree.locate({-1.1, -1.1, -1.1}));
assert(octree.index(octree.children(octree.root())[1]) == octree.locate({1.1, -1.1, -1.1})); assert(octree.child(octree.index(octree.root()), 1) == octree.locate({1.1, -1.1, -1.1}));
assert(octree.index(octree.children(octree.root())[2]) == octree.locate({-1.1, 1.1, -1.1})); assert(octree.child(octree.index(octree.root()), 2) == octree.locate({-1.1, 1.1, -1.1}));
assert(octree.index(octree.children(octree.root())[3]) == octree.locate({1.1, 1.1, -1.1})); assert(octree.child(octree.index(octree.root()), 3) == octree.locate({1.1, 1.1, -1.1}));
assert(octree.index(octree.children(octree.root())[4]) == octree.locate({-1.1, -1.1, 1.1})); assert(octree.child(octree.index(octree.root()), 4) == octree.locate({-1.1, -1.1, 1.1}));
assert(octree.index(octree.children(octree.root())[5]) == octree.locate({1.1, -1.1, 1.1})); assert(octree.child(octree.index(octree.root()), 5) == octree.locate({1.1, -1.1, 1.1}));
assert(octree.index(octree.children(octree.root())[6]) == octree.locate({-1.1, 1.1, 1.1})); assert(octree.child(octree.index(octree.root()), 6) == octree.locate({-1.1, 1.1, 1.1}));
assert(octree.index(octree.children(octree.root())[7]) == octree.locate({1.1, 1.1, 1.1})); assert(octree.child(octree.index(octree.root()), 7) == octree.locate({1.1, 1.1, 1.1}));
} }
@ -93,28 +93,28 @@ void test_10_points() {
octree.refine(10, 1); octree.refine(10, 1);
// Existing points should end up in the same place // Existing points should end up in the same place
assert(octree.index(octree.children(octree.root())[0]) == octree.locate({-1, -1, -1})); assert(octree.child(octree.index(octree.root()), 0) == octree.locate({-1, -1, -1}));
assert(octree.index(octree.children(octree.root())[1]) == octree.locate({1, -1, -1})); assert(octree.child(octree.index(octree.root()), 1) == octree.locate({1, -1, -1}));
assert(octree.index(octree.children(octree.root())[2]) == octree.locate({-1, 1, -1})); assert(octree.child(octree.index(octree.root()), 2) == octree.locate({-1, 1, -1}));
assert(octree.index(octree.children(octree.children(octree.children(octree.root())[3])[3])[3]) == assert(octree.child(octree.child(octree.child(octree.index(octree.root()), 3), 3), 3) ==
octree.locate({1, 1, -1})); octree.locate({1, 1, -1}));
assert(octree.index(octree.children(octree.children(octree.children(octree.root())[4])[4])[4]) == assert(octree.child(octree.child(octree.child(octree.index(octree.root()), 4), 4), 4) ==
octree.locate({-1, -1, 1})); octree.locate({-1, -1, 1}));
assert(octree.index(octree.children(octree.root())[5]) == octree.locate({1, -1, 1})); assert(octree.child(octree.index(octree.root()), 5) == octree.locate({1, -1, 1}));
assert(octree.index(octree.children(octree.root())[6]) == octree.locate({-1, 1, 1})); assert(octree.child(octree.index(octree.root()), 6) == octree.locate({-1, 1, 1}));
assert(octree.index(octree.children(octree.root())[7]) == octree.locate({1, 1, 1})); assert(octree.child(octree.index(octree.root()), 7) == octree.locate({1, 1, 1}));
// Points adjacent to the existing points might end up in different places // Points adjacent to the existing points might end up in different places
assert(octree.index(octree.children(octree.root())[0]) == octree.locate({-1.1, -1.1, -1.1})); assert(octree.child(octree.index(octree.root()), 0) == octree.locate({-1.1, -1.1, -1.1}));
assert(octree.index(octree.children(octree.root())[1]) == octree.locate({1.1, -1.1, -1.1})); assert(octree.child(octree.index(octree.root()), 1) == octree.locate({1.1, -1.1, -1.1}));
assert(octree.index(octree.children(octree.root())[2]) == octree.locate({-1.1, 1.1, -1.1})); assert(octree.child(octree.index(octree.root()), 2) == octree.locate({-1.1, 1.1, -1.1}));
assert(octree.index(octree.children(octree.children(octree.children(octree.root())[3])[3])[3]) == assert(octree.child(octree.child(octree.child(octree.index(octree.root()), 3), 3), 3) ==
octree.locate({1.1, 1.1, -1.1})); octree.locate({1.1, 1.1, -1.1}));
assert(octree.index(octree.children(octree.children(octree.children(octree.root())[4])[4])[4]) == assert(octree.child(octree.child(octree.child(octree.index(octree.root()), 4), 4), 4) ==
octree.locate({-1.1, -1.1, 1.1})); octree.locate({-1.1, -1.1, 1.1}));
assert(octree.index(octree.children(octree.root())[5]) == octree.locate({1.1, -1.1, 1.1})); assert(octree.child(octree.index(octree.root()), 5) == octree.locate({1.1, -1.1, 1.1}));
assert(octree.index(octree.children(octree.root())[6]) == octree.locate({-1.1, 1.1, 1.1})); assert(octree.child(octree.index(octree.root()), 6) == octree.locate({-1.1, 1.1, 1.1}));
assert(octree.index(octree.children(octree.root())[7]) == octree.locate({1.1, 1.1, 1.1})); assert(octree.child(octree.index(octree.root()), 7) == octree.locate({1.1, 1.1, 1.1}));
} }

View File

@ -74,14 +74,14 @@ void test_4_points() {
// The octree should have been split once on the first level, and twice on the second // The octree should have been split once on the first level, and twice on the second
Octree other(points, points.point_map()); Octree other(points, points.point_map());
other.split(other.index(other.root())); other.split(other.index(other.root()));
other.split(other.index(other.children(other.root())[3])); other.split(other.child(other.index(other.root()), 3));
other.split(other.index(other.children(other.root())[7])); other.split(other.child(other.index(other.root()), 7));
assert(Octree::is_topology_equal(other, octree)); assert(Octree::is_topology_equal(other, octree));
assert(2 == octree.depth()); assert(2 == octree.depth());
// Applying another splitting criterion shouldn't reset the tree. // Applying another splitting criterion shouldn't reset the tree.
octree.refine(Split_nth_child_of_root(2)); octree.refine(Split_nth_child_of_root(2));
other.split(other.index(other.children(other.root())[2])); other.split(other.child(other.index(other.root()), 2));
assert(Octree::is_topology_equal(other, octree)); assert(Octree::is_topology_equal(other, octree));
} }

View File

@ -26,11 +26,11 @@ bool test_preorder_1_node() {
octree.refine(10, 1); octree.refine(10, 1);
// Create the range // Create the range
auto nodes = octree.traverse<Preorder_traversal>(); auto nodes = octree.traverse_indices<Preorder_traversal>();
// Check each item in the range // Check each item in the range
auto iter = nodes.begin(); auto iter = nodes.begin();
assert(*iter == octree.root()); assert(*iter == octree.index(octree.root()));
return true; return true;
} }
@ -47,14 +47,14 @@ bool test_preorder_9_nodes() {
octree.refine(10, 1); octree.refine(10, 1);
// Create the range // Create the range
auto nodes = octree.traverse<Preorder_traversal>(); auto nodes = octree.traverse_indices<Preorder_traversal>();
// Check each item in the range // Check each item in the range
auto iter = nodes.begin(); auto iter = nodes.begin();
assert(*iter == octree.root()); assert(*iter == octree.index(octree.root()));
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
iter++; iter++;
assert((*iter == octree.children(octree.root())[i])); assert(*iter == octree.child(octree.index(octree.root()), i));
} }
return true; return true;
@ -72,12 +72,12 @@ bool test_level_9_nodes() {
octree.refine(10, 1); octree.refine(10, 1);
// Create the range // Create the range
auto nodes = octree.traverse<Level_traversal>(1); auto nodes = octree.traverse_indices<Level_traversal>(1);
// Check each item in the range // Check each item in the range
auto iter = nodes.begin(); auto iter = nodes.begin();
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
assert((*iter == octree.children(octree.root())[i])); assert(*iter == octree.child(octree.index(octree.root()), i));
iter++; iter++;
} }
@ -98,34 +98,34 @@ bool test_preorder_25_nodes() {
octree.refine(10, 1); octree.refine(10, 1);
// Create the range // Create the range
auto nodes = octree.traverse<Preorder_traversal>(); auto nodes = octree.traverse_indices<Preorder_traversal>();
// Check each item in the range // Check each item in the range
auto iter = nodes.begin(); auto iter = nodes.begin();
assert(*iter == octree.root()); assert(*iter == octree.index(octree.root()));
iter++; iter++;
assert((*iter == octree.children(octree.root())[0])); assert(*iter == octree.child(octree.index(octree.root()), 0));
iter++; iter++;
assert((*iter == octree.children(octree.root())[1])); assert(*iter == octree.child(octree.index(octree.root()), 1));
iter++; iter++;
assert((*iter == octree.children(octree.root())[2])); assert((*iter == octree.child(octree.index(octree.root()), 2)));
iter++; iter++;
assert((*iter == octree.children(octree.root())[3])); assert(*iter == octree.child(octree.index(octree.root()), 3));
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
iter++; iter++;
assert((*iter == octree.children(octree.children(octree.root())[3])[i])); assert(*iter == octree.child(octree.child(octree.index(octree.root()), 3), i));
} }
iter++; iter++;
assert((*iter == octree.children(octree.root())[4])); assert((*iter == octree.child(octree.index(octree.root()), 4)));
iter++; iter++;
assert((*iter == octree.children(octree.root())[5])); assert((*iter == octree.child(octree.index(octree.root()), 5)));
iter++; iter++;
assert((*iter == octree.children(octree.root())[6])); assert((*iter == octree.child(octree.index(octree.root()), 6)));
iter++; iter++;
assert((*iter == octree.children(octree.root())[7])); assert((*iter == octree.child(octree.index(octree.root()), 7)));
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
iter++; iter++;
assert((*iter == octree.children(octree.children(octree.root())[7])[i])); assert(*iter == octree.child(octree.child(octree.index(octree.root()), 7), i));
} }
return true; return true;