mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-17 11:05:56 +08:00
Try to increase query size with each failed attempt
TODO: check performance gain
This commit is contained in:
parent
e6d49b75de
commit
de3cbd483d
@ -11,14 +11,15 @@ namespace Slic3r { namespace branchingtree {
|
|||||||
|
|
||||||
void build_tree(PointCloud &nodes, Builder &builder)
|
void build_tree(PointCloud &nodes, Builder &builder)
|
||||||
{
|
{
|
||||||
constexpr size_t ReachablesToExamine = 5;
|
constexpr size_t initK = 5;
|
||||||
|
|
||||||
auto ptsqueue = nodes.start_queue();
|
auto ptsqueue = nodes.start_queue();
|
||||||
auto &properties = nodes.properties();
|
auto &properties = nodes.properties();
|
||||||
|
|
||||||
struct NodeDistance { size_t node_id = Node::ID_NONE; float distance = NaNf; };
|
struct NodeDistance { size_t node_id = Node::ID_NONE; float distance = NaNf; };
|
||||||
auto distances = reserve_vector<NodeDistance>(ReachablesToExamine);
|
auto distances = reserve_vector<NodeDistance>(initK);
|
||||||
double prev_dist_max = 0.;
|
double prev_dist_max = 0.;
|
||||||
|
size_t K = initK;
|
||||||
|
|
||||||
while (!ptsqueue.empty() && builder.is_valid()) {
|
while (!ptsqueue.empty() && builder.is_valid()) {
|
||||||
size_t node_id = ptsqueue.top();
|
size_t node_id = ptsqueue.top();
|
||||||
@ -27,13 +28,13 @@ void build_tree(PointCloud &nodes, Builder &builder)
|
|||||||
nodes.mark_unreachable(node_id);
|
nodes.mark_unreachable(node_id);
|
||||||
|
|
||||||
distances.clear();
|
distances.clear();
|
||||||
|
distances.reserve(K);
|
||||||
|
|
||||||
nodes.foreach_reachable<ReachablesToExamine>(
|
nodes.foreach_reachable(
|
||||||
node.pos,
|
node.pos,
|
||||||
[&distances](size_t id, float distance) {
|
[&distances](size_t id, float distance) {
|
||||||
distances.emplace_back(NodeDistance{id, distance});
|
distances.emplace_back(NodeDistance{id, distance});
|
||||||
},
|
}, K, prev_dist_max);
|
||||||
prev_dist_max);
|
|
||||||
|
|
||||||
std::sort(distances.begin(), distances.end(),
|
std::sort(distances.begin(), distances.end(),
|
||||||
[](auto &a, auto &b) { return a.distance < b.distance; });
|
[](auto &a, auto &b) { return a.distance < b.distance; });
|
||||||
@ -41,11 +42,13 @@ void build_tree(PointCloud &nodes, Builder &builder)
|
|||||||
if (distances.empty()) {
|
if (distances.empty()) {
|
||||||
builder.report_unroutable(node);
|
builder.report_unroutable(node);
|
||||||
ptsqueue.pop();
|
ptsqueue.pop();
|
||||||
|
K = initK;
|
||||||
prev_dist_max = 0.;
|
prev_dist_max = 0.;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_dist_max = distances.back().distance;
|
prev_dist_max = distances.back().distance;
|
||||||
|
K *= 2;
|
||||||
|
|
||||||
auto closest_it = distances.begin();
|
auto closest_it = distances.begin();
|
||||||
bool routed = false;
|
bool routed = false;
|
||||||
@ -146,6 +149,7 @@ void build_tree(PointCloud &nodes, Builder &builder)
|
|||||||
if (routed) {
|
if (routed) {
|
||||||
ptsqueue.pop();
|
ptsqueue.pop();
|
||||||
prev_dist_max = 0.;
|
prev_dist_max = 0.;
|
||||||
|
K = initK;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,11 @@ public:
|
|||||||
|
|
||||||
size_t reachable_count() const { return m_reachable_cnt; }
|
size_t reachable_count() const { return m_reachable_cnt; }
|
||||||
|
|
||||||
template<size_t K, class Fn>
|
template<class Fn>
|
||||||
void foreach_reachable(const Vec3f &pos, Fn &&visitor, double min_dist = 0.)
|
void foreach_reachable(const Vec3f &pos,
|
||||||
|
Fn &&visitor,
|
||||||
|
size_t k,
|
||||||
|
double min_dist = 0.)
|
||||||
{
|
{
|
||||||
// Fake output iterator
|
// Fake output iterator
|
||||||
struct Output {
|
struct Output {
|
||||||
@ -203,14 +206,15 @@ public:
|
|||||||
|
|
||||||
namespace bgi = boost::geometry::index;
|
namespace bgi = boost::geometry::index;
|
||||||
|
|
||||||
size_t cnt = 0;
|
size_t cnt = 0;
|
||||||
auto filter = bgi::satisfies([this, &pos, min_dist, &cnt](const PointIndexEl &e) {
|
auto filter = bgi::satisfies(
|
||||||
double d = get_distance(pos, e.second);
|
[this, &pos, min_dist, &cnt](const PointIndexEl &e) {
|
||||||
cnt++;
|
cnt++;
|
||||||
return m_searchable_indices[e.second] && !isinf(d) && d > min_dist;
|
double d = get_distance(pos, e.second);
|
||||||
});
|
return m_searchable_indices[e.second] && !isinf(d) && d > min_dist;
|
||||||
|
});
|
||||||
|
|
||||||
m_ktree.query(bgi::nearest(pos, K) && filter, Output{this, pos, visitor});
|
m_ktree.query(bgi::nearest(pos, k) && filter, Output{this, pos, visitor});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto start_queue()
|
auto start_queue()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user