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

View File

@ -171,38 +171,40 @@ 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");
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(),
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);
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);
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);
ImGui::NewLine();
ImGui::SameLine(window_width - buttons_width - m_imgui->scaled(0.5f));
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,
m_smart_support_patch_spacing, m_smart_support_islands_tolerance);
compute_smart_support_placement(m_smart_support_limit_angle_deg, m_smart_support_patch_size * 0.1f,
m_smart_support_patch_spacing * 0.1f, m_smart_support_islands_tolerance * 0.01f);
}
if (m_imgui->button(m_desc.at("remove_all"))) {
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset selection"), UndoRedo::SnapshotType::GizmoAction);
ModelObject *mo = m_c->selection_info()->model_object();
int idx = -1;
for (ModelVolume *mv : mo->volumes)
if (mv->is_model_part()) {
++idx;
m_triangle_selectors[idx]->reset();
m_triangle_selectors[idx]->request_update_render_data();
}
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset selection"),
UndoRedo::SnapshotType::GizmoAction);
ModelObject *mo = m_c->selection_info()->model_object();
int idx = -1;
for (ModelVolume *mv : mo->volumes)
if (mv->is_model_part()) {
++idx;
m_triangle_selectors[idx]->reset();
m_triangle_selectors[idx]->request_update_render_data();
}
update_model_object();
m_parent.set_as_dirty();
}
update_model_object();
m_parent.set_as_dirty();
}
}