From 26bfb4e9999a3f284a7b64af58b1a8b2709c9410 Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Wed, 23 Mar 2022 17:37:22 +0100 Subject: [PATCH] more options, sorting by center --- src/libslic3r/FDMSupportSpots.cpp | 22 +++++++++++++------- src/libslic3r/FDMSupportSpots.hpp | 1 + src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp | 15 +++++++------ src/slic3r/GUI/Jobs/FDMSupportSpotsJob.cpp | 3 +++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/FDMSupportSpots.cpp b/src/libslic3r/FDMSupportSpots.cpp index cfffb1b6bb..ebfc1e5e8f 100644 --- a/src/libslic3r/FDMSupportSpots.cpp +++ b/src/libslic3r/FDMSupportSpots.cpp @@ -53,6 +53,7 @@ FDMSupportSpots::FDMSupportSpots(FDMSupportSpotsConfig config, indexed_triangle_ Triangle t { }; t.indices = mesh.indices[face_index]; t.normal = normal; + t.center = (vertices[0] + vertices[1] + vertices[2]) / 3.0f; t.downward_dot_value = normal.dot(down); t.index = face_index; t.neighbours = neighbours[face_index]; @@ -71,8 +72,11 @@ FDMSupportSpots::FDMSupportSpots(FDMSupportSpotsConfig config, indexed_triangle_ [&](const size_t &left, const size_t &right) { if (this->m_triangles[left].lowest_z_coord != this->m_triangles[right].lowest_z_coord) { return this->m_triangles[left].lowest_z_coord < this->m_triangles[right].lowest_z_coord; - } else { + } else if (this->m_triangles[left].edge_dot_value != this->m_triangles[right].edge_dot_value) { return this->m_triangles[left].edge_dot_value > this->m_triangles[right].edge_dot_value; + } else { + return (abs(this->m_triangles[left].center.x() + this->m_triangles[left].center.y()) < + abs(this->m_triangles[right].center.x() + this->m_triangles[right].center.y())); } }); @@ -81,8 +85,11 @@ FDMSupportSpots::FDMSupportSpots(FDMSupportSpotsConfig config, indexed_triangle_ } for (Triangle &triangle : this->m_triangles) { - std::sort(begin(triangle.neighbours), end(triangle.neighbours), [&](const size_t left, const size_t right) { - if (left < 0 || right < 0) { + std::sort(begin(triangle.neighbours), end(triangle.neighbours), [&](const int left, const int right) { + if (left < 0) { + return false; + } + if (right < 0) { return true; } return this->m_triangles[left].order_by_z < this->m_triangles[right].order_by_z; @@ -108,24 +115,24 @@ void FDMSupportSpots::find_support_areas() { Triangle ¤t = this->m_triangles[current_index]; size_t group_id = 0; - float neighbourhood_unsupported_area = 0; + float neighbourhood_unsupported_area = this->m_config.patch_spacing; bool visited_neighbour = false; std::queue neighbours { }; - std::set explored { }; for (const auto &direct_neighbour_index : current.neighbours) { if (direct_neighbour_index < 0 || !this->m_triangles[direct_neighbour_index].visited) { continue; } neighbours.push(direct_neighbour_index); const Triangle &direct_neighbour = this->m_triangles[direct_neighbour_index]; - if (neighbourhood_unsupported_area <= direct_neighbour.unsupported_weight) { + if (neighbourhood_unsupported_area >= direct_neighbour.unsupported_weight) { neighbourhood_unsupported_area = direct_neighbour.unsupported_weight; group_id = direct_neighbour.group_id; } visited_neighbour = true; } + std::set explored { }; while (!neighbours.empty() && !visited_neighbour) { int neighbour_index = neighbours.front(); neighbours.pop(); @@ -255,7 +262,7 @@ void FDMSupportSpots::debug_export() const { for (size_t i = 0; i < this->m_triangle_indexes_by_z.size(); ++i) { const Triangle &triangle = this->m_triangles[this->m_triangle_indexes_by_z[i]]; - Vec3f color = value_to_rgbf(0, 10, triangle.area); + Vec3f color = value_to_rgbf(0, this->m_config.patch_size, triangle.unsupported_weight); for (size_t index = 0; index < 3; ++index) { fprintf(fp, "v %f %f %f %f %f %f\n", this->m_mesh.vertices[triangle.indices[index]](0), this->m_mesh.vertices[triangle.indices[index]](1), @@ -294,4 +301,3 @@ void FDMSupportSpots::debug_export() const { } - diff --git a/src/libslic3r/FDMSupportSpots.hpp b/src/libslic3r/FDMSupportSpots.hpp index b7d90dfebe..ca362f89a5 100644 --- a/src/libslic3r/FDMSupportSpots.hpp +++ b/src/libslic3r/FDMSupportSpots.hpp @@ -22,6 +22,7 @@ namespace FDMSupportSpotsImpl { struct Triangle { stl_triangle_vertex_indices indices; Vec3f normal; + Vec3f center; float downward_dot_value; size_t index; Vec3i neighbours; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index 361678c827..914000462d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -171,13 +171,15 @@ void GLGizmoFdmSupports::on_render_input_window(float x, float y, float bottom_l "Degree sign to use in the respective slider in FDM supports gizmo," "placed after the number with no whitespace in between."); + std::string mm = std::string("%.f") + I18N::translate_utf8("mm"); + m_imgui->slider_float("##angle_threshold_deg", &m_smart_support_limit_angle_deg, 0.f, 90.f, format_str.data(), 1.0f, true); - m_imgui->slider_float("##patch_size", &m_smart_support_patch_size, 0.f, 20.f, format_str.data(), + m_imgui->slider_float("##patch_size", &m_smart_support_patch_size, 0.f, 20.f, mm.data(), 1.0f, false); - m_imgui->slider_float("##patch_spacing", &m_smart_support_patch_spacing, 0.f, 20.f, format_str.data(), + m_imgui->slider_float("##patch_spacing", &m_smart_support_patch_spacing, 0.f, 20.f, mm.data(), 1.0f, false); - m_imgui->slider_float("##island_tolerance", &m_smart_support_islands_tolerance, 0.f, 10.f, format_str.data(), + m_imgui->slider_float("##island_tolerance", &m_smart_support_islands_tolerance, 0.f, 10.f, mm.data(), 1.0f, false); ImGui::NewLine(); @@ -433,11 +435,12 @@ void GLGizmoFdmSupports::select_facets_by_angle(float threshold_deg, bool block) m_parent.set_as_dirty(); } -void GLGizmoFdmSupports::compute_smart_support_placement(float limit_angle_deg, float patch_size, float patch_spacing, float islands_tolerance) { - float threshold = (float(M_PI) / 180.f) * limit_angle_deg; +void GLGizmoFdmSupports::compute_smart_support_placement(float limit_angle_deg, float patch_size, float patch_spacing, + float islands_tolerance) { + float threshold = (float(M_PI) / 180.f) * (90.0f - limit_angle_deg); FDMSupportSpotsConfig support_spots_config { - threshold, patch_size, patch_spacing, islands_tolerance + threshold, patch_size, patch_spacing, islands_tolerance }; const Selection &selection = m_parent.get_selection(); diff --git a/src/slic3r/GUI/Jobs/FDMSupportSpotsJob.cpp b/src/slic3r/GUI/Jobs/FDMSupportSpotsJob.cpp index 057ae667b2..25df579881 100644 --- a/src/slic3r/GUI/Jobs/FDMSupportSpotsJob.cpp +++ b/src/slic3r/GUI/Jobs/FDMSupportSpotsJob.cpp @@ -52,6 +52,8 @@ void FDMSupportSpotsJob::process(Ctl &ctl) { } } + support_spots_alg.debug_export(); + this->m_computed_support_data.emplace(data.first, supported_face_indexes); } @@ -59,6 +61,7 @@ void FDMSupportSpotsJob::process(Ctl &ctl) { ctl.update_status(100, status_text_canceled); return; } + ctl.update_status(100, status_text_canceled); }