Merge branch 'tm_rotfinder_fixes'

This commit is contained in:
tamasmeszaros 2021-08-17 16:15:41 +02:00
commit 4e32863b99
3 changed files with 9 additions and 13 deletions

View File

@ -105,16 +105,13 @@ inline double get_supportedness_score(const Facestats &fc)
float cosphi = fc.normal.dot(DOWN); float cosphi = fc.normal.dot(DOWN);
float phi = 1.f - std::acos(cosphi) / float(PI); float phi = 1.f - std::acos(cosphi) / float(PI);
// Phi is raised by 1.0 to not be less than zero when squared in the next
// step. If phi is greater than 0.5 (slope is > 90 deg) make phi zero
// to not skip this face in the overall score.
phi = (1.f + phi) * (phi >= 0.5f);
// Make the huge slopes more significant than the smaller slopes // Make the huge slopes more significant than the smaller slopes
phi = phi * phi; phi = phi * phi * phi;
// Multiply with the area of the current face // Multiply with the square root of face area of the current face,
return fc.area * POINTS_PER_UNIT_AREA * phi; // the area is less important as it grows.
// This makes many smaller overhangs a bigger impact.
return std::sqrt(fc.area) * POINTS_PER_UNIT_AREA * phi;
} }
// Try to guess the number of support points needed to support a mesh // Try to guess the number of support points needed to support a mesh
@ -124,7 +121,6 @@ double get_supportedness_score(const TriangleMesh &mesh, const Transform3f &tr)
auto accessfn = [&mesh, &tr](size_t fi) { auto accessfn = [&mesh, &tr](size_t fi) {
Facestats fc{get_transformed_triangle(mesh, tr, fi)}; Facestats fc{get_transformed_triangle(mesh, tr, fi)};
return scaled<int_fast64_t>(get_supportedness_score(fc)); return scaled<int_fast64_t>(get_supportedness_score(fc));
}; };
@ -349,7 +345,7 @@ Vec2d find_best_misalignment_rotation(const ModelObject & mo,
// We are searching rotations around only two axes x, y. Thus the // We are searching rotations around only two axes x, y. Thus the
// problem becomes a 2 dimensional optimization task. // problem becomes a 2 dimensional optimization task.
// We can specify the bounds for a dimension in the following way: // We can specify the bounds for a dimension in the following way:
auto bounds = opt::bounds({ {-PI/2, PI/2}, {-PI/2, PI/2} }); auto bounds = opt::bounds({ {-PI, PI}, {-PI, PI} });
auto result = solver.to_max().optimize( auto result = solver.to_max().optimize(
[&mesh, &statusfn] (const XYRotation &rot) [&mesh, &statusfn] (const XYRotation &rot)

View File

@ -512,7 +512,7 @@ GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow(ImGuiWrapper * imgui,
y = std::min(y, alignment.bottom_limit - win_h); y = std::min(y, alignment.bottom_limit - win_h);
ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_Always); ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_Always);
ImGui::PushItemWidth(200.f); ImGui::PushItemWidth(300.f);
if (ImGui::BeginCombo(_L("Choose goal").c_str(), RotoptimizeJob::get_method_name(state.method_id).c_str())) { if (ImGui::BeginCombo(_L("Choose goal").c_str(), RotoptimizeJob::get_method_name(state.method_id).c_str())) {
for (size_t i = 0; i < RotoptimizeJob::get_methods_count(); ++i) { for (size_t i = 0; i < RotoptimizeJob::get_methods_count(); ++i) {

View File

@ -21,13 +21,13 @@ class RotoptimizeJob : public PlaterJob
= {{L("Best surface quality"), = {{L("Best surface quality"),
sla::find_best_misalignment_rotation, sla::find_best_misalignment_rotation,
L("Optimize object rotation for best surface quality.")}, L("Optimize object rotation for best surface quality.")},
{L("Least supports"), {L("Reduced overhang slopes"),
sla::find_least_supports_rotation, sla::find_least_supports_rotation,
L("Optimize object rotation to have minimum amount of overhangs needing support " L("Optimize object rotation to have minimum amount of overhangs needing support "
"structures.\nNote that this method will try to find the best surface of the object " "structures.\nNote that this method will try to find the best surface of the object "
"for touching the print bed if no elevation is set.")}, "for touching the print bed if no elevation is set.")},
// Just a min area bounding box that is done for all methods anyway. // Just a min area bounding box that is done for all methods anyway.
{L("Z axis only"), {L("Smallest bounding box (Z axis only)"),
nullptr, nullptr,
L("Rotate the object only in Z axis to have the smallest bounding box.")}}; L("Rotate the object only in Z axis to have the smallest bounding box.")}};