Use index-based access for split predicates

This commit is contained in:
JacksonCampolattaro 2023-06-21 17:34:26 +02:00
parent b09e4d0fa6
commit d1ac73d087
5 changed files with 39 additions and 6 deletions

View File

@ -126,7 +126,7 @@ public:
/*!
* \brief A predicate that determines whether a node must be split when refining a tree.
*/
typedef std::function<bool(Node)> Split_predicate;
typedef std::function<bool(Node_index, const Self &)> 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;

View File

@ -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);

View File

@ -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<typename Node_index, typename Tree>
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<typename Node_index, typename Tree>
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<typename Node_index, typename Tree>
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

View File

@ -24,6 +24,11 @@ public:
bool operator()(const Node& node) const {
return (node.depth() == 1 && node.local_coordinates().to_ulong() == m_n);
}
template<typename Node_index, typename Tree>
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() {

View File

@ -72,7 +72,7 @@ bool test_level_9_nodes() {
octree.refine(10, 1);
// Create the range
auto nodes = octree.traverse_indices<Level_traversal>(1);
auto nodes = octree.traverse_indices<Level_traversal>(static_cast<std::size_t>(1));
// Check each item in the range
auto iter = nodes.begin();