algorithm fix

This commit is contained in:
PavelMikus 2022-03-24 12:57:22 +01:00
parent 26bfb4e999
commit edf0e0a144
2 changed files with 34 additions and 41 deletions

View File

@ -119,44 +119,35 @@ void FDMSupportSpots::find_support_areas() {
bool visited_neighbour = false; bool visited_neighbour = false;
std::queue<int> neighbours { }; std::queue<int> neighbours { };
for (const auto &direct_neighbour_index : current.neighbours) { neighbours.push(current_index);
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) {
neighbourhood_unsupported_area = direct_neighbour.unsupported_weight;
group_id = direct_neighbour.group_id;
}
visited_neighbour = true;
}
std::set<int> explored { }; std::set<int> explored { };
while (!neighbours.empty() && !visited_neighbour) { while (!neighbours.empty() && neighbourhood_unsupported_area > 0) {
int neighbour_index = neighbours.front(); int neighbour_index = neighbours.front();
neighbours.pop(); neighbours.pop();
explored.insert(neighbour_index);
const Triangle &neighbour = this->m_triangles[neighbour_index]; const Triangle &neighbour = this->m_triangles[neighbour_index];
if (explored.find(neighbour_index) != explored.end() if (explored.find(neighbour_index) != explored.end()) {
|| triangle_vertices_shortest_distance(this->m_mesh, current.index, neighbour_index) continue;
}
explored.insert(neighbour_index);
if (triangle_vertices_shortest_distance(this->m_mesh, current.index, neighbour_index)
> this->m_config.islands_tolerance_distance) { > this->m_config.islands_tolerance_distance) {
// not visited, already explored, or too far
continue; continue;
} }
if (neighbour.visited) { if (neighbour.visited) {
visited_neighbour = true; visited_neighbour = true;
if (neighbourhood_unsupported_area >= neighbour.unsupported_weight) {
neighbourhood_unsupported_area = neighbour.unsupported_weight;
group_id = neighbour.group_id;
}
break; break;
} }
for (const auto &neighbour_index : neighbour.neighbours) { for (const auto &neighbour_index : neighbour.neighbours) {
if (neighbour_index < 0) { if (neighbour_index >= 0) {
continue;
}
neighbours.push(neighbour_index); neighbours.push(neighbour_index);
} }
}
} }
current.visited = true; current.visited = true;

View File

@ -171,26 +171,28 @@ 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," "Degree sign to use in the respective slider in FDM supports gizmo,"
"placed after the number with no whitespace in between."); "placed after the number with no whitespace in between.");
std::string mm = std::string("%.f") + I18N::translate_utf8("mm"); std::string tenth_mm = std::string("%.f") + I18N::translate_utf8(" * 0.1 (mm)");
std::string hundreth_mm = std::string("%.f") + I18N::translate_utf8(" * 0.01 (mm)");
m_imgui->slider_float("##angle_threshold_deg", &m_smart_support_limit_angle_deg, 0.f, 90.f, format_str.data(), m_imgui->slider_float("##angle_threshold_deg", &m_smart_support_limit_angle_deg, 0.f, 90.f, format_str.data(),
1.0f, true); 1.0f, true);
m_imgui->slider_float("##patch_size", &m_smart_support_patch_size, 0.f, 20.f, mm.data(), m_imgui->slider_float("##patch_size", &m_smart_support_patch_size, 0.f, 100.f, tenth_mm.data(),
1.0f, false); 1.0f, false);
m_imgui->slider_float("##patch_spacing", &m_smart_support_patch_spacing, 0.f, 20.f, mm.data(), m_imgui->slider_float("##patch_spacing", &m_smart_support_patch_spacing, 0.f, 100.f, tenth_mm.data(),
1.0f, false); 1.0f, false);
m_imgui->slider_float("##island_tolerance", &m_smart_support_islands_tolerance, 0.f, 10.f, mm.data(), m_imgui->slider_float("##island_tolerance", &m_smart_support_islands_tolerance, 0.f, 100.f, hundreth_mm.data(),
1.0f, false); 1.0f, false);
ImGui::NewLine(); ImGui::NewLine();
ImGui::SameLine(window_width - buttons_width - m_imgui->scaled(0.5f)); ImGui::SameLine(window_width - buttons_width - m_imgui->scaled(0.5f));
if (m_imgui->button(m_desc["enforce_button"], buttons_width, 0.f)) { if (m_imgui->button(m_desc["enforce_button"], buttons_width, 0.f)) {
compute_smart_support_placement(m_smart_support_limit_angle_deg, m_smart_support_patch_size, compute_smart_support_placement(m_smart_support_limit_angle_deg, m_smart_support_patch_size * 0.1f,
m_smart_support_patch_spacing, m_smart_support_islands_tolerance); m_smart_support_patch_spacing * 0.1f, m_smart_support_islands_tolerance * 0.01f);
} }
if (m_imgui->button(m_desc.at("remove_all"))) { if (m_imgui->button(m_desc.at("remove_all"))) {
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset selection"), UndoRedo::SnapshotType::GizmoAction); Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset selection"),
UndoRedo::SnapshotType::GizmoAction);
ModelObject *mo = m_c->selection_info()->model_object(); ModelObject *mo = m_c->selection_info()->model_object();
int idx = -1; int idx = -1;
for (ModelVolume *mv : mo->volumes) for (ModelVolume *mv : mo->volumes)