Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2021-03-26 20:22:53 +0300
committertamasmeszaros <meszaros.q@gmail.com>2021-04-07 13:51:02 +0300
commit773116b777fa771420c884f7ec38b03c7587c340 (patch)
tree9fb9705ec1778f41f0e8edee67a1df60b76a5a8b /src/libslic3r/SLA
parent5443f77489e5f673dd77b7f78e30b7600295fd95 (diff)
Allow auto-rotation of objects not completely inside bed.
Don't use SLAPrintObject as the input for optimization. Use ModelObject and pass the print config to the optimization in RotoptimizeJob::prepare()
Diffstat (limited to 'src/libslic3r/SLA')
-rw-r--r--src/libslic3r/SLA/Rotfinder.cpp37
-rw-r--r--src/libslic3r/SLA/Rotfinder.hpp44
2 files changed, 56 insertions, 25 deletions
diff --git a/src/libslic3r/SLA/Rotfinder.cpp b/src/libslic3r/SLA/Rotfinder.cpp
index 89de1cf83..6e8a0ce6b 100644
--- a/src/libslic3r/SLA/Rotfinder.cpp
+++ b/src/libslic3r/SLA/Rotfinder.cpp
@@ -6,6 +6,7 @@
#include <libslic3r/Execution/ExecutionSeq.hpp>
#include <libslic3r/Optimize/BruteforceOptimizer.hpp>
+#include <libslic3r/Optimize/NLoptOptimizer.hpp>
#include "libslic3r/SLAPrint.hpp"
#include "libslic3r/PrintConfig.hpp"
@@ -192,10 +193,10 @@ XYRotation from_transform3f(const Transform3f &tr)
return {rot3.x(), rot3.y()};
}
-inline bool is_on_floor(const SLAPrintObject &mo)
+inline bool is_on_floor(const SLAPrintObjectConfig &cfg)
{
- auto opt_elevation = mo.config().support_object_elevation.getFloat();
- auto opt_padaround = mo.config().pad_around_object.getBool();
+ auto opt_elevation = cfg.support_object_elevation.getFloat();
+ auto opt_padaround = cfg.pad_around_object.getBool();
return opt_elevation < EPSILON || opt_padaround;
}
@@ -282,9 +283,8 @@ std::array<double, N> find_min_score(Fn &&fn, It from, It to, StopCond &&stopfn)
} // namespace
-Vec2d find_best_misalignment_rotation(const SLAPrintObject & po,
- float accuracy,
- RotOptimizeStatusCB statuscb)
+Vec2d find_best_misalignment_rotation(const ModelObject & mo,
+ const RotOptimizeParams &params)
{
static constexpr unsigned MAX_TRIES = 1000;
@@ -293,14 +293,16 @@ Vec2d find_best_misalignment_rotation(const SLAPrintObject & po,
// We will use only one instance of this converted mesh to examine different
// rotations
- TriangleMesh mesh = po.model_object()->raw_mesh();
+ TriangleMesh mesh = mo.raw_mesh();
mesh.require_shared_vertices();
// To keep track of the number of iterations
int status = 0;
// The maximum number of iterations
- auto max_tries = unsigned(accuracy * MAX_TRIES);
+ auto max_tries = unsigned(params.accuracy() * MAX_TRIES);
+
+ auto &statuscb = params.statuscb();
// call status callback with zero, because we are at the start
statuscb(status);
@@ -338,9 +340,8 @@ Vec2d find_best_misalignment_rotation(const SLAPrintObject & po,
return {rot[0], rot[1]};
}
-Vec2d find_least_supports_rotation(const SLAPrintObject & po,
- float accuracy,
- RotOptimizeStatusCB statuscb)
+Vec2d find_least_supports_rotation(const ModelObject & mo,
+ const RotOptimizeParams &params)
{
static const unsigned MAX_TRIES = 1000;
@@ -349,14 +350,16 @@ Vec2d find_least_supports_rotation(const SLAPrintObject & po,
// We will use only one instance of this converted mesh to examine different
// rotations
- TriangleMesh mesh = po.model_object()->raw_mesh();
+ TriangleMesh mesh = mo.raw_mesh();
mesh.require_shared_vertices();
// To keep track of the number of iterations
unsigned status = 0;
// The maximum number of iterations
- auto max_tries = unsigned(accuracy * MAX_TRIES);
+ auto max_tries = unsigned(params.accuracy() * MAX_TRIES);
+
+ auto &statuscb = params.statuscb();
// call status callback with zero, because we are at the start
statuscb(status);
@@ -370,8 +373,14 @@ Vec2d find_least_supports_rotation(const SLAPrintObject & po,
return ! statuscb(-1);
};
+ SLAPrintObjectConfig pocfg;
+ if (params.print_config())
+ pocfg.apply(*params.print_config(), true);
+
+ pocfg.apply(mo.config.get());
+
// Different search methods have to be used depending on the model elevation
- if (is_on_floor(po)) {
+ if (is_on_floor(pocfg)) {
std::vector<XYRotation> inputs = get_chull_rotations(mesh, max_tries);
max_tries = inputs.size();
diff --git a/src/libslic3r/SLA/Rotfinder.hpp b/src/libslic3r/SLA/Rotfinder.hpp
index c0007944a..77a39016d 100644
--- a/src/libslic3r/SLA/Rotfinder.hpp
+++ b/src/libslic3r/SLA/Rotfinder.hpp
@@ -8,13 +8,39 @@
namespace Slic3r {
+class ModelObject;
class SLAPrintObject;
class TriangleMesh;
+class DynamicPrintConfig;
namespace sla {
using RotOptimizeStatusCB = std::function<bool(int)>;
+class RotOptimizeParams {
+ float m_accuracy = 1.;
+ const DynamicPrintConfig *m_print_config = nullptr;
+ RotOptimizeStatusCB m_statuscb = [](int) { return true; };
+
+public:
+
+ RotOptimizeParams &accuracy(float a) { m_accuracy = a; return *this; }
+ RotOptimizeParams &print_config(const DynamicPrintConfig *c)
+ {
+ m_print_config = c;
+ return *this;
+ }
+ RotOptimizeParams &statucb(RotOptimizeStatusCB cb)
+ {
+ m_statuscb = std::move(cb);
+ return *this;
+ }
+
+ float accuracy() const { return m_accuracy; }
+ const DynamicPrintConfig * print_config() const { return m_print_config; }
+ const RotOptimizeStatusCB &statuscb() const { return m_statuscb; }
+};
+
/**
* The function should find the best rotation for SLA upside down printing.
*
@@ -31,17 +57,13 @@ using RotOptimizeStatusCB = std::function<bool(int)>;
*
* @return Returns the rotations around each axis (x, y, z)
*/
-Vec2d find_best_misalignment_rotation(
- const SLAPrintObject& modelobj,
- float accuracy = 1.0f,
- RotOptimizeStatusCB statuscb = [] (int) { return true; }
- );
-
-Vec2d find_least_supports_rotation(
- const SLAPrintObject& modelobj,
- float accuracy = 1.0f,
- RotOptimizeStatusCB statuscb = [] (int) { return true; }
- );
+Vec2d find_best_misalignment_rotation(const ModelObject &modelobj,
+ const RotOptimizeParams & = {});
+
+Vec2d find_least_supports_rotation(const ModelObject &modelobj,
+ const RotOptimizeParams & = {});
+
+double find_Z_fit_to_bed_rotation(const ModelObject &mo, const BoundingBox &bed);
} // namespace sla
} // namespace Slic3r