Make branching tree algorithm cancellable

This commit is contained in:
tamasmeszaros 2022-06-09 17:14:08 +02:00
parent 725f5c05e3
commit e6d49b75de
3 changed files with 7 additions and 2 deletions

View File

@ -20,7 +20,7 @@ void build_tree(PointCloud &nodes, Builder &builder)
auto distances = reserve_vector<NodeDistance>(ReachablesToExamine); auto distances = reserve_vector<NodeDistance>(ReachablesToExamine);
double prev_dist_max = 0.; double prev_dist_max = 0.;
while (!ptsqueue.empty()) { while (!ptsqueue.empty() && builder.is_valid()) {
size_t node_id = ptsqueue.top(); size_t node_id = ptsqueue.top();
Node node = nodes.get(node_id); Node node = nodes.get(node_id);
@ -49,7 +49,7 @@ void build_tree(PointCloud &nodes, Builder &builder)
auto closest_it = distances.begin(); auto closest_it = distances.begin();
bool routed = false; bool routed = false;
while (closest_it != distances.end() && !routed) { while (closest_it != distances.end() && !routed && builder.is_valid()) {
size_t closest_node_id = closest_it->node_id; size_t closest_node_id = closest_it->node_id;
Node closest_node = nodes.get(closest_node_id); Node closest_node = nodes.get(closest_node_id);

View File

@ -102,6 +102,9 @@ public:
// Report nodes that can not be routed to an endpoint (model or ground) // Report nodes that can not be routed to an endpoint (model or ground)
virtual void report_unroutable(const Node &j) = 0; virtual void report_unroutable(const Node &j) = 0;
// If returns false, the tree building process shall stop
virtual bool is_valid() const { return true; }
}; };
// Build the actual tree. // Build the actual tree.

View File

@ -111,6 +111,8 @@ public:
{ {
return m_unroutable_pinheads; return m_unroutable_pinheads;
} }
bool is_valid() const override { return !m_builder.ctl().stopcondition(); }
}; };
bool BranchingTreeBuilder::add_bridge(const branchingtree::Node &from, bool BranchingTreeBuilder::add_bridge(const branchingtree::Node &from,