From 234167534bcc0597b02feed48530ff7972469c63 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 15 Dec 2022 16:25:31 +0100 Subject: [PATCH] wip on branching tree avoidance again --- src/libslic3r/BranchingTree/BranchingTree.cpp | 12 +++++- src/libslic3r/BranchingTree/BranchingTree.hpp | 6 +++ src/libslic3r/SLA/BranchingTreeSLA.cpp | 43 +++++++++++++++++-- src/libslic3r/SLA/SupportTreeUtils.hpp | 2 +- src/libslic3r/SLAPrint.cpp | 19 ++++++++ 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/BranchingTree/BranchingTree.cpp b/src/libslic3r/BranchingTree/BranchingTree.cpp index 72ecf8c86..8f1d322a1 100644 --- a/src/libslic3r/BranchingTree/BranchingTree.cpp +++ b/src/libslic3r/BranchingTree/BranchingTree.cpp @@ -76,7 +76,17 @@ void build_tree(PointCloud &nodes, Builder &builder) switch (type) { case BED: { closest_node.weight = w; - if ((routed = builder.add_ground_bridge(node, closest_node))) { + if (closest_it->dst_branching > nodes.properties().max_branch_length()) { + auto hl_br_len = float(nodes.properties().max_branch_length()) / 2.f; + Node new_node {{node.pos.x(), node.pos.y(), node.pos.z() - hl_br_len}, node.Rmin}; + new_node.id = int(nodes.next_junction_id()); + new_node.weight = nodes.get(node_id).weight + hl_br_len; + new_node.left = node.id; + if ((routed = builder.add_bridge(node, new_node))) { + size_t new_idx = nodes.insert_junction(new_node); + ptsqueue.push(new_idx); + } + } else if ((routed = builder.add_ground_bridge(node, closest_node))) { closest_node.left = closest_node.right = node_id; nodes.get(closest_node_id) = closest_node; nodes.mark_unreachable(closest_node_id); diff --git a/src/libslic3r/BranchingTree/BranchingTree.hpp b/src/libslic3r/BranchingTree/BranchingTree.hpp index 2d372452b..06ee3ee14 100644 --- a/src/libslic3r/BranchingTree/BranchingTree.hpp +++ b/src/libslic3r/BranchingTree/BranchingTree.hpp @@ -105,6 +105,12 @@ public: // Add an anchor bridge to the model body virtual bool add_mesh_bridge(const Node &from, const Node &to) = 0; + virtual std::optional suggest_avoidance(const Node &from, + float max_bridge_len) + { + return {}; + } + // Report nodes that can not be routed to an endpoint (model or ground) virtual void report_unroutable(const Node &j) = 0; diff --git a/src/libslic3r/SLA/BranchingTreeSLA.cpp b/src/libslic3r/SLA/BranchingTreeSLA.cpp index d88bdb1b0..d4778a0ac 100644 --- a/src/libslic3r/SLA/BranchingTreeSLA.cpp +++ b/src/libslic3r/SLA/BranchingTreeSLA.cpp @@ -29,7 +29,7 @@ class BranchingTreeBuilder: public branchingtree::Builder { // Scaling of the input value 'widening_factor:<0, 1>' to produce resonable // widening behaviour - static constexpr double WIDENING_SCALE = 0.02; + static constexpr double WIDENING_SCALE = 0.05; double get_radius(const branchingtree::Node &j) const { @@ -99,9 +99,10 @@ class BranchingTreeBuilder: public branchingtree::Builder { int suppid_left = branchingtree::Node::ID_NONE; int suppid_right = branchingtree::Node::ID_NONE; + double glvl = ground_level(m_sm); branchingtree::Node dst = node; - dst.weight += node.pos.z(); - dst.Rmin = std::max(node.Rmin, dst.Rmin); + dst.pos.z() = glvl; + dst.weight += node.pos.z() - glvl; if (node.left >= 0 && add_ground_bridge(m_cloud.get(node.left), dst)) ret.to_left = false; @@ -144,8 +145,18 @@ public: bool add_mesh_bridge(const branchingtree::Node &from, const branchingtree::Node &to) override; + std::optional suggest_avoidance(const branchingtree::Node &from, + float max_bridge_len) override;; + void report_unroutable(const branchingtree::Node &j) override { + double glvl = ground_level(m_sm); + branchingtree::Node dst = j; + dst.pos.z() = glvl; + dst.weight += j.pos.z() - glvl; + if (add_ground_bridge(j, dst)) + return; + BOOST_LOG_TRIVIAL(warning) << "Cannot route junction at " << j.pos.x() << " " << j.pos.y() << " " << j.pos.z(); @@ -279,6 +290,32 @@ bool BranchingTreeBuilder::add_mesh_bridge(const branchingtree::Node &from, return bool(anchor); } +static std::optional get_avoidance(const GroundConnection &conn, + float maxdist) +{ + return {}; +} + +std::optional BranchingTreeBuilder::suggest_avoidance( + const branchingtree::Node &from, float max_bridge_len) +{ + double glvl = ground_level(m_sm); + branchingtree::Node dst = from; + dst.pos.z() = glvl; + dst.weight += from.pos.z() - glvl; + bool succ = add_ground_bridge(from, dst); + + std::optional ret; + + if (succ) { + auto it = m_gnd_connections.find(from.id); + if (it != m_gnd_connections.end()) + ret = get_avoidance(it->second, max_bridge_len); + } + + return ret; +} + inline void build_pillars(SupportTreeBuilder &builder, BranchingTreeBuilder &vbuilder, const SupportableMesh &sm) diff --git a/src/libslic3r/SLA/SupportTreeUtils.hpp b/src/libslic3r/SLA/SupportTreeUtils.hpp index a47f8d662..6c1707953 100644 --- a/src/libslic3r/SLA/SupportTreeUtils.hpp +++ b/src/libslic3r/SLA/SupportTreeUtils.hpp @@ -547,7 +547,7 @@ Vec3d check_ground_route( auto gndhit = beam_mesh_hit(policy, sm.emesh, gndbeam, sd); double gnd_hit_d = std::min(gndhit.distance(), down_l + EPSILON); - if (std::isinf(gndhit.distance()) && sm.cfg.object_elevation_mm < EPSILON) { + if (gndhit.distance() > down_l && sm.cfg.object_elevation_mm < EPSILON) { // Dealing with zero elevation mode, to not route pillars // into the gap between the optional pad and the model double gap = std::sqrt(sm.emesh.squared_distance(gp)); diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 6bdf415f9..d991dfe05 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -862,6 +862,7 @@ bool SLAPrintObject::invalidate_state_by_config_options(const std::vector