mirror of https://github.com/CGAL/cgal
Use index-based access for split predicates
This commit is contained in:
parent
b09e4d0fa6
commit
d1ac73d087
|
|
@ -126,7 +126,7 @@ public:
|
||||||
/*!
|
/*!
|
||||||
* \brief A predicate that determines whether a node must be split when refining a tree.
|
* \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`.
|
* \brief A model of `ConstRange` whose value type is `Node`.
|
||||||
|
|
@ -342,7 +342,7 @@ public:
|
||||||
todo.pop();
|
todo.pop();
|
||||||
|
|
||||||
// Check if this node needs to be processed
|
// 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
|
// Check if we've reached a new max depth
|
||||||
if (depth(current) == depth()) {
|
if (depth(current) == depth()) {
|
||||||
|
|
@ -458,7 +458,6 @@ public:
|
||||||
|
|
||||||
\return a const reference to the root node of the tree.
|
\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 root() const { return 0; }
|
||||||
|
|
||||||
Node_index index(const Node& node) const {
|
Node_index index(const Node& node) const {
|
||||||
|
|
@ -819,7 +818,7 @@ public:
|
||||||
// Split the node to create children
|
// Split the node to create children
|
||||||
using Local_coordinates = typename Node::Local_coordinates;
|
using Local_coordinates = typename Node::Local_coordinates;
|
||||||
for (int i = 0; i < Degree::value; i++) {
|
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
|
// todo: this assumes that the new nodes are always allocated at the end
|
||||||
m_nodes[n].m_children_index = m_nodes.size() - Degree::value;
|
m_nodes[n].m_children_index = m_nodes.size() - Degree::value;
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ public:
|
||||||
* \param rhs node to compare with
|
* \param rhs node to compare with
|
||||||
* \return whether the nodes have different topology.
|
* \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) {
|
friend std::ostream& operator<<(std::ostream& os, const Self& node) {
|
||||||
return internal::print_orthtree_node(os, node);
|
return internal::print_orthtree_node(os, node);
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,15 @@ public:
|
||||||
bool operator()(const Node &n) const {
|
bool operator()(const Node &n) const {
|
||||||
return (n.size() > m_bucket_size);
|
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 {
|
bool operator()(const Node &n) const {
|
||||||
return n.depth() < m_max_depth;
|
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();
|
std::size_t depth = n.depth();
|
||||||
return (num_points > m_bucket_size && depth < m_max_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
|
} // Orthtrees
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ public:
|
||||||
bool operator()(const Node& node) const {
|
bool operator()(const Node& node) const {
|
||||||
return (node.depth() == 1 && node.local_coordinates().to_ulong() == m_n);
|
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() {
|
void test_1_point() {
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ bool test_level_9_nodes() {
|
||||||
octree.refine(10, 1);
|
octree.refine(10, 1);
|
||||||
|
|
||||||
// Create the range
|
// 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
|
// Check each item in the range
|
||||||
auto iter = nodes.begin();
|
auto iter = nodes.begin();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue