diff --git a/src/libslic3r/SLA/SupportTreeBuilder.hpp b/src/libslic3r/SLA/SupportTreeBuilder.hpp index 2b3ff91a06..aa8a4ea83b 100644 --- a/src/libslic3r/SLA/SupportTreeBuilder.hpp +++ b/src/libslic3r/SLA/SupportTreeBuilder.hpp @@ -58,12 +58,17 @@ template double distance(const Vec& pp1, const Vec& pp2) { return distance(p); } -const constexpr long ID_UNSET = -1; - const Vec3d DOWN = {0.0, 0.0, -1.0}; +struct SupportTreeNode +{ + static const constexpr long ID_UNSET = -1; + + long id = ID_UNSET; // For identification withing a tree. +}; + // A pinhead originating from a support point -struct Head { +struct Head: public SupportTreeNode { Vec3d dir = DOWN; Vec3d pos = {0, 0, 0}; @@ -71,10 +76,7 @@ struct Head { double r_pin_mm = 0.5; double width_mm = 2; double penetration_mm = 0.5; - - // For identification purposes. This will be used as the index into the - // container holding the head structures. See SLASupportTree::Impl - long id = ID_UNSET; + // If there is a pillar connecting to this head, then the id will be set. long pillar_id = ID_UNSET; @@ -115,21 +117,17 @@ struct Head { }; // A junction connecting bridges and pillars -struct Junction { +struct Junction: public SupportTreeNode { double r = 1; Vec3d pos; - - long id = ID_UNSET; Junction(const Vec3d &tr, double r_mm) : r(r_mm), pos(tr) {} }; -struct Pillar { +struct Pillar: public SupportTreeNode { double height, r; Vec3d endpt; - long id = ID_UNSET; - // If the pillar connects to a head, this is the id of that head bool starts_from_head = true; // Could start from a junction as well long start_junction_id = ID_UNSET; @@ -152,10 +150,9 @@ struct Pillar { }; // A base for pillars or bridges that end on the ground -struct Pedestal { +struct Pedestal: public SupportTreeNode { Vec3d pos; double height, r_bottom, r_top; - long id = ID_UNSET; Pedestal(const Vec3d &p, double h, double rbottom, double rtop) : pos{p}, height{h}, r_bottom{rbottom}, r_top{rtop} @@ -167,9 +164,8 @@ struct Pedestal { struct Anchor: public Head { using Head::Head; }; // A Bridge between two pillars (with junction endpoints) -struct Bridge { +struct Bridge: public SupportTreeNode { double r = 0.8; - long id = ID_UNSET; Vec3d startp = Vec3d::Zero(), endp = Vec3d::Zero(); Bridge(const Vec3d &j1, diff --git a/src/libslic3r/SLA/SupportTreeBuildsteps.cpp b/src/libslic3r/SLA/SupportTreeBuildsteps.cpp index c6b2884d26..00f09b8121 100644 --- a/src/libslic3r/SLA/SupportTreeBuildsteps.cpp +++ b/src/libslic3r/SLA/SupportTreeBuildsteps.cpp @@ -570,7 +570,7 @@ bool SupportTreeBuildsteps::create_ground_pillar(const Vec3d &jp, long head_id) { double sd = m_cfg.pillar_base_safety_distance_mm; - long pillar_id = ID_UNSET; + long pillar_id = SupportTreeNode::ID_UNSET; bool can_add_base = radius >= m_cfg.head_back_radius_mm; double base_r = can_add_base ? m_cfg.base_radius_mm : 0.; double gndlvl = m_builder.ground_level; @@ -1029,7 +1029,7 @@ bool SupportTreeBuildsteps::connect_to_ground(Head &head) bool SupportTreeBuildsteps::connect_to_model_body(Head &head) { - if (head.id <= ID_UNSET) return false; + if (head.id <= SupportTreeNode::ID_UNSET) return false; auto it = m_head_to_ground_scans.find(unsigned(head.id)); if (it == m_head_to_ground_scans.end()) return false; @@ -1084,7 +1084,7 @@ bool SupportTreeBuildsteps::search_pillar_and_connect(const Head &source) // We also need to remove elements progressively from the copied index. PointIndex spindex = m_pillar_index.guarded_clone(); - long nearest_id = ID_UNSET; + long nearest_id = SupportTreeNode::ID_UNSET; Vec3d querypt = source.junction_point(); @@ -1105,7 +1105,7 @@ bool SupportTreeBuildsteps::search_pillar_and_connect(const Head &source) if (size_t(nearest_id) < m_builder.pillarcount()) { if(!connect_to_nearpillar(source, nearest_id) || m_builder.pillar(nearest_id).r < source.r_back_mm) { - nearest_id = ID_UNSET; // continue searching + nearest_id = SupportTreeNode::ID_UNSET; // continue searching spindex.remove(ne); // without the current pillar } } diff --git a/src/libslic3r/SLA/SupportTreeBuildsteps.hpp b/src/libslic3r/SLA/SupportTreeBuildsteps.hpp index 51d8344480..e8f73149e3 100644 --- a/src/libslic3r/SLA/SupportTreeBuildsteps.hpp +++ b/src/libslic3r/SLA/SupportTreeBuildsteps.hpp @@ -293,7 +293,7 @@ class SupportTreeBuildsteps { bool create_ground_pillar(const Vec3d &jp, const Vec3d &sourcedir, double radius, - long head_id = ID_UNSET); + long head_id = SupportTreeNode::ID_UNSET); void add_pillar_base(long pid) { diff --git a/tests/sla_print/sla_test_utils.cpp b/tests/sla_print/sla_test_utils.cpp index 4cd94b7ed3..bc0cfb0cd1 100644 --- a/tests/sla_print/sla_test_utils.cpp +++ b/tests/sla_print/sla_test_utils.cpp @@ -175,8 +175,8 @@ void check_support_tree_integrity(const sla::SupportTreeBuilder &stree, double H2 = cfg.max_dual_pillar_height_mm; for (const sla::Head &head : stree.heads()) { - REQUIRE((!head.is_valid() || head.pillar_id != sla::ID_UNSET || - head.bridge_id != sla::ID_UNSET)); + REQUIRE((!head.is_valid() || head.pillar_id != sla::SupportTreeNode::ID_UNSET || + head.bridge_id != sla::SupportTreeNode::ID_UNSET)); } for (const sla::Pillar &pillar : stree.pillars()) {