diff --git a/src/libslic3r/SLA/Rotfinder.cpp b/src/libslic3r/SLA/Rotfinder.cpp index f410eb0e1..79be5e1ec 100644 --- a/src/libslic3r/SLA/Rotfinder.cpp +++ b/src/libslic3r/SLA/Rotfinder.cpp @@ -92,10 +92,9 @@ Transform3f to_transform3f(const XYRotation &rot) } // namespace -Vec2d find_best_rotation(const SLAPrintObject & po, - float accuracy, - std::function statuscb, - std::function stopcond) +Vec2d find_best_rotation(const SLAPrintObject & po, + float accuracy, + std::function statuscb) { static const unsigned MAX_TRIES = 1000; @@ -108,7 +107,7 @@ Vec2d find_best_rotation(const SLAPrintObject & po, mesh.require_shared_vertices(); // To keep track of the number of iterations - unsigned status = 0; + int status = 0; // The maximum number of iterations auto max_tries = unsigned(accuracy * MAX_TRIES); @@ -118,7 +117,11 @@ Vec2d find_best_rotation(const SLAPrintObject & po, auto statusfn = [&statuscb, &status, &max_tries] { // report status - statuscb(unsigned(++status * 100.0/max_tries) ); + statuscb(++status * 100.0/max_tries); + }; + + auto stopcond = [&statuscb] { + return ! statuscb(-1); }; // Preparing the optimizer. diff --git a/src/libslic3r/SLA/Rotfinder.hpp b/src/libslic3r/SLA/Rotfinder.hpp index a6fde2c9d..2b92c52b8 100644 --- a/src/libslic3r/SLA/Rotfinder.hpp +++ b/src/libslic3r/SLA/Rotfinder.hpp @@ -19,19 +19,19 @@ namespace sla { * @param accuracy The optimization accuracy from 0.0f to 1.0f. Currently, * the nlopt genetic optimizer is used and the number of iterations is * accuracy * 100000. This can change in the future. - * @param statuscb A status indicator callback called with the unsigned + * @param statuscb A status indicator callback called with the int * argument spanning from 0 to 100. May not reach 100 if the optimization finds - * an optimum before max iterations are reached. - * @param stopcond A function that if returns true, the search process will be - * terminated and the best solution found will be returned. + * an optimum before max iterations are reached. It should return a boolean + * signaling if the operation may continue (true) or not (false). A status + * value lower than 0 shall not update the status but still return a valid + * continuation indicator. * * @return Returns the rotations around each axis (x, y, z) */ Vec2d find_best_rotation( const SLAPrintObject& modelobj, float accuracy = 1.0f, - std::function statuscb = [] (unsigned) {}, - std::function stopcond = [] () { return false; } + std::function statuscb = [] (int) { return true; } ); double get_model_supportedness(const SLAPrintObject &mesh, diff --git a/src/slic3r/GUI/Jobs/RotoptimizeJob.cpp b/src/slic3r/GUI/Jobs/RotoptimizeJob.cpp index ac737cafb..7e1bfaeeb 100644 --- a/src/slic3r/GUI/Jobs/RotoptimizeJob.cpp +++ b/src/slic3r/GUI/Jobs/RotoptimizeJob.cpp @@ -21,13 +21,12 @@ void RotoptimizeJob::process() if (!o || !po) return; - Vec2d r = sla::find_best_rotation(*po, 0.75f, - [this](unsigned s) { - if (s < 100) - update_status(int(s), _(L("Searching for optimal orientation"))); - }, - [this] () { return was_canceled(); }); + Vec2d r = sla::find_best_rotation(*po, 0.75f, [this](int s) { + if (s > 0 && s < 100) + update_status(s, _(L("Searching for optimal orientation"))); + return !was_canceled(); + }); double mindist = 6.0; // FIXME