From ef109ca170265f7fc25e8e7dbf3c867225635630 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 5 May 2023 12:05:24 +0800 Subject: [PATCH] FIX: tree support may generate floating circles Github: #1687 Change-Id: Ib762bd2f43e1a3671404a85e234c51a0f159d919 (cherry picked from commit adf84cb6e618b60eff57c66c9f4d2fc703a87cae) --- src/libslic3r/TreeSupport.cpp | 25 +++++++++---------------- src/libslic3r/TreeSupport.hpp | 11 +++++++++++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/libslic3r/TreeSupport.cpp b/src/libslic3r/TreeSupport.cpp index c96171ac62..d52e81da7b 100644 --- a/src/libslic3r/TreeSupport.cpp +++ b/src/libslic3r/TreeSupport.cpp @@ -25,7 +25,7 @@ #define TAU (2.0 * M_PI) #define NO_INDEX (std::numeric_limits::max()) -// #define SUPPORT_TREE_DEBUG_TO_SVG +//#define SUPPORT_TREE_DEBUG_TO_SVG #ifdef SUPPORT_TREE_DEBUG_TO_SVG #include "nlohmann/json.hpp" @@ -2714,20 +2714,17 @@ void TreeSupport::drop_nodes(std::vector>& contact_nodes) node_ = (node.dist_mm_to_top >= neighbour->dist_mm_to_top && p_node->parent) ? p_node : neighbour; else node_ = p_node->parent ? p_node : neighbour; + // Make sure the next pass doesn't drop down either of these (since that already happened). + node_->merged_neighbours.push_front(node_ == p_node ? neighbour : p_node); const bool to_buildplate = !is_inside_ex(m_ts_data->get_avoidance(0, layer_nr_next), next_position); - Node * next_node = new Node(next_position, node_->distance_to_top + 1, layer_nr_next, node_->support_roof_layers_below-1, to_buildplate, node_->parent, + Node * next_node = new Node(next_position, node_->distance_to_top + 1, layer_nr_next, node_->support_roof_layers_below-1, to_buildplate, node_, print_z_next, height_next); next_node->movement = next_position - node.position; get_max_move_dist(next_node); next_node->is_merged = true; contact_nodes[layer_nr_next].push_back(next_node); - // make sure the trees are all connected - if (node.parent) node.parent->child = next_node; - if (neighbour->parent) neighbour->parent->child = next_node; - // Make sure the next pass doesn't drop down either of these (since that already happened). - node.merged_neighbours.push_front(neighbour); to_delete.insert(neighbour); to_delete.insert(p_node); } @@ -3036,16 +3033,8 @@ void TreeSupport::smooth_nodes(std::vector> &contact_nodes) } } } -#ifdef SUPPORT_TREE_DEBUG_TO_SVG // save tree structure for viewing in python - struct TreeNode { - Vec3f pos; - std::vector children; // index of children in the storing vector - TreeNode(Point pt, float z) { - pos = { float(unscale_(pt.x())),float(unscale_(pt.y())),z }; - } - }; - std::vector tree_nodes; + auto& tree_nodes = m_ts_data->tree_nodes; std::map ptr2idx; std::map idx2ptr; for (int layer_nr = 0; layer_nr < contact_nodes.size(); layer_nr++) { @@ -3061,12 +3050,16 @@ void TreeSupport::smooth_nodes(std::vector> &contact_nodes) Node* p_node = idx2ptr[i]; if (p_node->child) tree_node.children.push_back(ptr2idx[p_node->child]); + if(p_node->parent) + tree_node.parents.push_back(ptr2idx[p_node->parent]); } +#ifdef SUPPORT_TREE_DEBUG_TO_SVG nlohmann::json jj; for (size_t i = 0; i < tree_nodes.size(); i++) { nlohmann::json j; j["pos"] = tree_nodes[i].pos; j["children"] = tree_nodes[i].children; + j["linked"] = !(tree_nodes[i].pos.z() > 0.205 && tree_nodes[i].children.empty()); jj.push_back(j); } diff --git a/src/libslic3r/TreeSupport.hpp b/src/libslic3r/TreeSupport.hpp index 169236ee7d..6119bc8906 100644 --- a/src/libslic3r/TreeSupport.hpp +++ b/src/libslic3r/TreeSupport.hpp @@ -30,6 +30,15 @@ struct LayerHeightData LayerHeightData(coordf_t z, coordf_t h, size_t next_layer) : print_z(z), height(h), next_layer_nr(next_layer) {} }; +struct TreeNode { + Vec3f pos; + std::vector children; // index of children in the storing vector + std::vector parents; // index of parents in the storing vector + TreeNode(Point pt, float z) { + pos = { float(unscale_(pt.x())),float(unscale_(pt.y())),z }; + } +}; + /*! * \brief Lazily generates tree guidance volumes. * @@ -90,6 +99,8 @@ public: std::vector layer_heights; + std::vector tree_nodes; + private: /*! * \brief Convenience typedef for the keys to the caches