From 849d41576c64527c2b9c0bfffdec37f29ed9b68b Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 11 Dec 2024 16:39:36 +0800 Subject: [PATCH] FIX: top z distance disappears in some cases jira: STUDIO-8883 github: #5334 Change-Id: Ie70f6dada19cc17cd74fa6aa116d1ca4fb4a07d7 --- src/libslic3r/Support/TreeSupport.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Support/TreeSupport.cpp b/src/libslic3r/Support/TreeSupport.cpp index 493b9ea75..ac0706bf0 100644 --- a/src/libslic3r/Support/TreeSupport.cpp +++ b/src/libslic3r/Support/TreeSupport.cpp @@ -3258,9 +3258,11 @@ std::vector TreeSupport::plan_layer_heights() for (int layer_nr = 0; layer_nr < contact_nodes.size(); layer_nr++) { if (contact_nodes[layer_nr].empty()) continue; SupportNode *node1 = contact_nodes[layer_nr].front(); - auto it = z_heights.lower_bound(node1->print_z + EPSILON); - if (it == z_heights.end()) it = std::prev(it); - int layer_nr2 = std::distance(z_heights.begin(), it); + auto it = std::min_element(layer_heights.begin(), layer_heights.end(), [node1](const LayerHeightData &l1, const LayerHeightData &l2) { + return std::abs(l1.print_z - node1->print_z) < std::abs(l2.print_z - node1->print_z); + }); + if (it == layer_heights.end()) it = std::prev(it); + int layer_nr2 = std::distance(layer_heights.begin(), it); contact_nodes2[layer_nr2].insert(contact_nodes2[layer_nr2].end(), contact_nodes[layer_nr].begin(), contact_nodes[layer_nr].end()); } contact_nodes = contact_nodes2; @@ -3284,7 +3286,7 @@ std::vector TreeSupport::plan_layer_heights() if (accum_height > node1->height - EPSILON) break; } } - BOOST_LOG_TRIVIAL(debug) << format("plan_layer_heights adjust node's height %d %.2f: (%.3f,%d)->(%.3f,%.3f,%d)", layer_nr, node1->print_z, + BOOST_LOG_TRIVIAL(debug) << format("plan_layer_heights adjust node's height print_z[%d]=%.2f: (%.3f,%d)->(%.3f,%.3f,%d)", layer_nr, node1->print_z, node1->height, node1->distance_to_top, new_height, accum_height, -num_layers); for (SupportNode *node : contact_nodes[layer_nr]) { node->height = new_height;