diff --git a/Orthtree/include/CGAL/Orthtree.h b/Orthtree/include/CGAL/Orthtree.h index 8751c15e97e..2d00bd383a8 100644 --- a/Orthtree/include/CGAL/Orthtree.h +++ b/Orthtree/include/CGAL/Orthtree.h @@ -126,7 +126,7 @@ public: /*! * \brief A predicate that determines whether a node must be split when refining a tree. */ - typedef std::function Split_predicate; + typedef std::function Split_predicate; /*! * \brief A model of `ConstRange` whose value type is `Node`. @@ -342,7 +342,7 @@ public: todo.pop(); // Check if this node needs to be processed - if (split_predicate(m_nodes[current])) { + if (split_predicate(current, *this)) { // Check if we've reached a new max depth if (depth(current) == depth()) { @@ -458,7 +458,6 @@ public: \return a const reference to the root node of the tree. */ - // todo: return index instead of ref Node_index root() const { return 0; } Node_index index(const Node& node) const { @@ -819,7 +818,7 @@ public: // Split the node to create children using Local_coordinates = typename Node::Local_coordinates; for (int i = 0; i < Degree::value; i++) { - m_nodes.emplace_back(n, global_coordinates(n), depth(n) + 1, Local_coordinates{i}); + m_nodes.emplace_back(n, global_coordinates(n), depth(n) + 1, Local_coordinates{(unsigned long) i}); } // todo: this assumes that the new nodes are always allocated at the end m_nodes[n].m_children_index = m_nodes.size() - Degree::value; diff --git a/Orthtree/include/CGAL/Orthtree/Node.h b/Orthtree/include/CGAL/Orthtree/Node.h index ca6bce35e5a..c94a1019c4c 100644 --- a/Orthtree/include/CGAL/Orthtree/Node.h +++ b/Orthtree/include/CGAL/Orthtree/Node.h @@ -229,7 +229,7 @@ public: * \param rhs node to compare with * \return whether the nodes have different topology. */ - bool operator==(const Self& rhs) const = default; + bool operator==(const Self& rhs) const = default; // todo: this doesn't work in C++17 friend std::ostream& operator<<(std::ostream& os, const Self& node) { return internal::print_orthtree_node(os, node); diff --git a/Orthtree/include/CGAL/Orthtree/Split_predicates.h b/Orthtree/include/CGAL/Orthtree/Split_predicates.h index e8d93415d5e..766a76e3570 100644 --- a/Orthtree/include/CGAL/Orthtree/Split_predicates.h +++ b/Orthtree/include/CGAL/Orthtree/Split_predicates.h @@ -45,6 +45,15 @@ public: bool operator()(const Node &n) const { return (n.size() > m_bucket_size); } + + /*! + \brief returns `true` if `i` should be split, `false` otherwise. + */ + template + bool operator()(Node_index i, const Tree &tree) const { + return (tree.points(i).size() > m_bucket_size); + } + }; /*! @@ -71,6 +80,15 @@ public: bool operator()(const Node &n) const { return n.depth() < m_max_depth; } + + /*! + \brief returns `true` if `i` should be split, `false` otherwise. + */ + template + bool operator()(Node_index i, const Tree &tree) const { + return (tree.depth(i) < m_max_depth); + } + }; /*! @@ -108,6 +126,17 @@ public: std::size_t depth = n.depth(); return (num_points > m_bucket_size && depth < m_max_depth); } + + /*! + \brief returns `true` if `i` should be split, `false` otherwise. + */ + template + bool operator()(Node_index i, const Tree &tree) const { + std::size_t num_points = tree.points(i).size(); + std::size_t depth = tree.depth(i); + return (num_points > m_bucket_size && depth < m_max_depth); + } + }; } // Orthtrees diff --git a/Orthtree/test/Orthtree/test_octree_refine.cpp b/Orthtree/test/Orthtree/test_octree_refine.cpp index 543c99a5a6e..2e248262a11 100644 --- a/Orthtree/test/Orthtree/test_octree_refine.cpp +++ b/Orthtree/test/Orthtree/test_octree_refine.cpp @@ -24,6 +24,11 @@ public: bool operator()(const Node& node) const { return (node.depth() == 1 && node.local_coordinates().to_ulong() == m_n); } + + template + bool operator()(Node_index i, const Tree &tree) const { + return (tree.depth(i) == 1 && tree.local_coordinates(i).to_ulong() == m_n); + } }; void test_1_point() { diff --git a/Orthtree/test/Orthtree/test_octree_traverse.cpp b/Orthtree/test/Orthtree/test_octree_traverse.cpp index f26625db46a..5ad71f57f53 100644 --- a/Orthtree/test/Orthtree/test_octree_traverse.cpp +++ b/Orthtree/test/Orthtree/test_octree_traverse.cpp @@ -72,7 +72,7 @@ bool test_level_9_nodes() { octree.refine(10, 1); // Create the range - auto nodes = octree.traverse_indices(1); + auto nodes = octree.traverse_indices(static_cast(1)); // Check each item in the range auto iter = nodes.begin();