Unite cancel callback and status function
This commit is contained in:
parent
de8bb00fa9
commit
46fd722f3c
@ -92,10 +92,9 @@ Transform3f to_transform3f(const XYRotation &rot)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Vec2d find_best_rotation(const SLAPrintObject & po,
|
Vec2d find_best_rotation(const SLAPrintObject & po,
|
||||||
float accuracy,
|
float accuracy,
|
||||||
std::function<void(unsigned)> statuscb,
|
std::function<bool(int)> statuscb)
|
||||||
std::function<bool()> stopcond)
|
|
||||||
{
|
{
|
||||||
static const unsigned MAX_TRIES = 1000;
|
static const unsigned MAX_TRIES = 1000;
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ Vec2d find_best_rotation(const SLAPrintObject & po,
|
|||||||
mesh.require_shared_vertices();
|
mesh.require_shared_vertices();
|
||||||
|
|
||||||
// To keep track of the number of iterations
|
// To keep track of the number of iterations
|
||||||
unsigned status = 0;
|
int status = 0;
|
||||||
|
|
||||||
// The maximum number of iterations
|
// The maximum number of iterations
|
||||||
auto max_tries = unsigned(accuracy * MAX_TRIES);
|
auto max_tries = unsigned(accuracy * MAX_TRIES);
|
||||||
@ -118,7 +117,11 @@ Vec2d find_best_rotation(const SLAPrintObject & po,
|
|||||||
|
|
||||||
auto statusfn = [&statuscb, &status, &max_tries] {
|
auto statusfn = [&statuscb, &status, &max_tries] {
|
||||||
// report status
|
// report status
|
||||||
statuscb(unsigned(++status * 100.0/max_tries) );
|
statuscb(++status * 100.0/max_tries);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto stopcond = [&statuscb] {
|
||||||
|
return ! statuscb(-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Preparing the optimizer.
|
// Preparing the optimizer.
|
||||||
|
@ -19,19 +19,19 @@ namespace sla {
|
|||||||
* @param accuracy The optimization accuracy from 0.0f to 1.0f. Currently,
|
* @param accuracy The optimization accuracy from 0.0f to 1.0f. Currently,
|
||||||
* the nlopt genetic optimizer is used and the number of iterations is
|
* the nlopt genetic optimizer is used and the number of iterations is
|
||||||
* accuracy * 100000. This can change in the future.
|
* 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
|
* argument spanning from 0 to 100. May not reach 100 if the optimization finds
|
||||||
* an optimum before max iterations are reached.
|
* an optimum before max iterations are reached. It should return a boolean
|
||||||
* @param stopcond A function that if returns true, the search process will be
|
* signaling if the operation may continue (true) or not (false). A status
|
||||||
* terminated and the best solution found will be returned.
|
* 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)
|
* @return Returns the rotations around each axis (x, y, z)
|
||||||
*/
|
*/
|
||||||
Vec2d find_best_rotation(
|
Vec2d find_best_rotation(
|
||||||
const SLAPrintObject& modelobj,
|
const SLAPrintObject& modelobj,
|
||||||
float accuracy = 1.0f,
|
float accuracy = 1.0f,
|
||||||
std::function<void(unsigned)> statuscb = [] (unsigned) {},
|
std::function<bool(int)> statuscb = [] (int) { return true; }
|
||||||
std::function<bool()> stopcond = [] () { return false; }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
double get_model_supportedness(const SLAPrintObject &mesh,
|
double get_model_supportedness(const SLAPrintObject &mesh,
|
||||||
|
@ -21,13 +21,12 @@ void RotoptimizeJob::process()
|
|||||||
|
|
||||||
if (!o || !po) return;
|
if (!o || !po) return;
|
||||||
|
|
||||||
Vec2d r = sla::find_best_rotation(*po, 0.75f,
|
Vec2d r = sla::find_best_rotation(*po, 0.75f, [this](int s) {
|
||||||
[this](unsigned s) {
|
if (s > 0 && s < 100)
|
||||||
if (s < 100)
|
update_status(s, _(L("Searching for optimal orientation")));
|
||||||
update_status(int(s), _(L("Searching for optimal orientation")));
|
|
||||||
},
|
|
||||||
[this] () { return was_canceled(); });
|
|
||||||
|
|
||||||
|
return !was_canceled();
|
||||||
|
});
|
||||||
|
|
||||||
double mindist = 6.0; // FIXME
|
double mindist = 6.0; // FIXME
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user