Merge branch 'tm_sla_efc_SPE-1080'

This commit is contained in:
tamasmeszaros 2020-02-18 17:39:56 +01:00
commit fcaa498abd
11 changed files with 130 additions and 47 deletions

View File

@ -524,11 +524,10 @@ static inline void smooth_compensation_banded(const Points &contour, float band,
} }
} }
ExPolygon elephant_foot_compensation(const ExPolygon &input_expoly, const Flow &external_perimeter_flow, const double compensation) ExPolygon elephant_foot_compensation(const ExPolygon &input_expoly, double min_contour_width, const double compensation)
{ {
// The contour shall be wide enough to apply the external perimeter plus compensation on both sides.
double min_contour_width = double(external_perimeter_flow.scaled_width() + external_perimeter_flow.scaled_spacing());
double scaled_compensation = scale_(compensation); double scaled_compensation = scale_(compensation);
min_contour_width = scale_(min_contour_width);
double min_contour_width_compensated = min_contour_width + 2. * scaled_compensation; double min_contour_width_compensated = min_contour_width + 2. * scaled_compensation;
// Make the search radius a bit larger for the averaging in contour_distance over a fan of rays to work. // Make the search radius a bit larger for the averaging in contour_distance over a fan of rays to work.
double search_radius = min_contour_width_compensated + min_contour_width * 0.5; double search_radius = min_contour_width_compensated + min_contour_width * 0.5;
@ -594,9 +593,20 @@ ExPolygon elephant_foot_compensation(const ExPolygon &input_expoly, const Flow &
} }
} }
// FIXME: orientations are messed up (Tamas)
out.contour.make_counter_clockwise();
for (auto &h : out.holes) h.make_clockwise();
return out; return out;
} }
ExPolygon elephant_foot_compensation(const ExPolygon &input, const Flow &external_perimeter_flow, const double compensation)
{
// The contour shall be wide enough to apply the external perimeter plus compensation on both sides.
double min_contour_width = double(external_perimeter_flow.width + external_perimeter_flow.spacing());
return elephant_foot_compensation(input, min_contour_width, compensation);
}
ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &external_perimeter_flow, const double compensation) ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &external_perimeter_flow, const double compensation)
{ {
ExPolygons out; ExPolygons out;
@ -606,4 +616,13 @@ ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &exter
return out; return out;
} }
ExPolygons elephant_foot_compensation(const ExPolygons &input, double min_contour_width, const double compensation)
{
ExPolygons out;
out.reserve(input.size());
for (const ExPolygon &expoly : input)
out.emplace_back(elephant_foot_compensation(expoly, min_contour_width, compensation));
return out;
}
} // namespace Slic3r } // namespace Slic3r

View File

@ -8,6 +8,8 @@ namespace Slic3r {
class Flow; class Flow;
ExPolygon elephant_foot_compensation(const ExPolygon &input, double min_countour_width, const double compensation);
ExPolygons elephant_foot_compensation(const ExPolygons &input, double min_countour_width, const double compensation);
ExPolygon elephant_foot_compensation(const ExPolygon &input, const Flow &external_perimeter_flow, const double compensation); ExPolygon elephant_foot_compensation(const ExPolygon &input, const Flow &external_perimeter_flow, const double compensation);
ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &external_perimeter_flow, const double compensation); ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &external_perimeter_flow, const double compensation);

View File

@ -113,6 +113,16 @@ void PrintConfigDef::init_common_params()
"If left blank, the default OS CA certificate repository is used."); "If left blank, the default OS CA certificate repository is used.");
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionString("")); def->set_default_value(new ConfigOptionString(""));
def = this->add("elefant_foot_compensation", coFloat);
def->label = L("Elephant foot compensation");
def->category = L("Advanced");
def->tooltip = L("The first layer will be shrunk in the XY plane by the configured value "
"to compensate for the 1st layer squish aka an Elephant Foot effect.");
def->sidetext = L("mm");
def->min = 0;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.2));
} }
void PrintConfigDef::init_fff_params() void PrintConfigDef::init_fff_params()
@ -371,16 +381,6 @@ void PrintConfigDef::init_fff_params()
def->min = 0; def->min = 0;
def->set_default_value(new ConfigOptionFloat(6)); def->set_default_value(new ConfigOptionFloat(6));
def = this->add("elefant_foot_compensation", coFloat);
def->label = L("Elephant foot compensation");
def->category = L("Advanced");
def->tooltip = L("The first layer will be shrunk in the XY plane by the configured value "
"to compensate for the 1st layer squish aka an Elephant Foot effect.");
def->sidetext = L("mm");
def->min = 0;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0));
def = this->add("end_gcode", coString); def = this->add("end_gcode", coString);
def->label = L("End G-code"); def->label = L("End G-code");
def->tooltip = L("This end procedure is inserted at the end of the output file. " def->tooltip = L("This end procedure is inserted at the end of the output file. "
@ -2443,6 +2443,15 @@ void PrintConfigDef::init_sla_params()
def->mode = comExpert; def->mode = comExpert;
def->set_default_value(new ConfigOptionFloat(0.0)); def->set_default_value(new ConfigOptionFloat(0.0));
def = this->add("elefant_foot_min_width", coFloat);
def->label = L("Elefant foot minimum width");
def->category = L("Advanced");
def->tooltip = L("Minimum with of features to maintain when doing EFC");
def->sidetext = L("mm");
def->min = 0;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0.2));
def = this->add("gamma_correction", coFloat); def = this->add("gamma_correction", coFloat);
def->label = L("Printer gamma correction"); def->label = L("Printer gamma correction");
def->full_label = L("Printer gamma correction"); def->full_label = L("Printer gamma correction");

View File

@ -1175,6 +1175,8 @@ public:
ConfigOptionBool display_mirror_y; ConfigOptionBool display_mirror_y;
ConfigOptionFloats relative_correction; ConfigOptionFloats relative_correction;
ConfigOptionFloat absolute_correction; ConfigOptionFloat absolute_correction;
ConfigOptionFloat elefant_foot_compensation;
ConfigOptionFloat elefant_foot_min_width;
ConfigOptionFloat gamma_correction; ConfigOptionFloat gamma_correction;
ConfigOptionFloat fast_tilt_time; ConfigOptionFloat fast_tilt_time;
ConfigOptionFloat slow_tilt_time; ConfigOptionFloat slow_tilt_time;
@ -1198,6 +1200,8 @@ protected:
OPT_PTR(display_orientation); OPT_PTR(display_orientation);
OPT_PTR(relative_correction); OPT_PTR(relative_correction);
OPT_PTR(absolute_correction); OPT_PTR(absolute_correction);
OPT_PTR(elefant_foot_compensation);
OPT_PTR(elefant_foot_min_width);
OPT_PTR(gamma_correction); OPT_PTR(gamma_correction);
OPT_PTR(fast_tilt_time); OPT_PTR(fast_tilt_time);
OPT_PTR(slow_tilt_time); OPT_PTR(slow_tilt_time);

View File

@ -785,6 +785,8 @@ bool SLAPrint::invalidate_state_by_config_options(const std::vector<t_config_opt
"material_correction", "material_correction",
"relative_correction", "relative_correction",
"absolute_correction", "absolute_correction",
"elefant_foot_compensation",
"elefant_foot_min_width",
"gamma_correction" "gamma_correction"
}; };
@ -1087,8 +1089,7 @@ const std::vector<ExPolygons> &SLAPrintObject::get_support_slices() const
const ExPolygons &SliceRecord::get_slice(SliceOrigin o) const const ExPolygons &SliceRecord::get_slice(SliceOrigin o) const
{ {
size_t idx = o == soModel ? m_model_slices_idx : size_t idx = o == soModel ? m_model_slices_idx : m_support_slices_idx;
m_support_slices_idx;
if(m_po == nullptr) return EMPTY_SLICE; if(m_po == nullptr) return EMPTY_SLICE;

View File

@ -152,6 +152,10 @@ public:
} }
const ExPolygons& get_slice(SliceOrigin o) const; const ExPolygons& get_slice(SliceOrigin o) const;
size_t get_slice_idx(SliceOrigin o) const
{
return o == soModel ? m_model_slices_idx : m_support_slices_idx;
}
}; };
private: private:

View File

@ -8,6 +8,8 @@
#include <libslic3r/SLA/Pad.hpp> #include <libslic3r/SLA/Pad.hpp>
#include <libslic3r/SLA/SupportPointGenerator.hpp> #include <libslic3r/SLA/SupportPointGenerator.hpp>
#include <libslic3r/ElephantFootCompensation.hpp>
#include <libslic3r/ClipperUtils.hpp> #include <libslic3r/ClipperUtils.hpp>
// For geometry algorithms with native Clipper types (no copies and conversions) // For geometry algorithms with native Clipper types (no copies and conversions)
@ -78,6 +80,40 @@ SLAPrint::Steps::Steps(SLAPrint *print)
, objectstep_scale{(max_objstatus - min_objstatus) / (objcount * 100.0)} , objectstep_scale{(max_objstatus - min_objstatus) / (objcount * 100.0)}
{} {}
void SLAPrint::Steps::apply_printer_corrections(SLAPrintObject &po, SliceOrigin o)
{
if (o == soSupport && !po.m_supportdata) return;
auto faded_lyrs = size_t(po.m_config.faded_layers.getInt());
double min_w = m_print->m_printer_config.elefant_foot_min_width.getFloat() / 2.;
double start_efc = m_print->m_printer_config.elefant_foot_compensation.getFloat();
double doffs = m_print->m_printer_config.absolute_correction.getFloat();
coord_t clpr_offs = scaled(doffs);
faded_lyrs = std::min(po.m_slice_index.size(), faded_lyrs);
auto efc = [start_efc, faded_lyrs](size_t pos) {
return (faded_lyrs - 1 - pos) * start_efc / (faded_lyrs - 1);
};
std::vector<ExPolygons> &slices = o == soModel ?
po.m_model_slices :
po.m_supportdata->support_slices;
if (clpr_offs != 0) for (size_t i = 0; i < po.m_slice_index.size(); ++i) {
size_t idx = po.m_slice_index[i].get_slice_idx(o);
if (idx < slices.size())
slices[idx] = offset_ex(slices[idx], float(clpr_offs));
}
if (start_efc > 0.) for (size_t i = 0; i < faded_lyrs; ++i) {
size_t idx = po.m_slice_index[i].get_slice_idx(o);
if (idx < slices.size())
slices[idx] = elephant_foot_compensation(slices[idx], min_w, efc(i));
}
}
void SLAPrint::Steps::hollow_model(SLAPrintObject &po) void SLAPrint::Steps::hollow_model(SLAPrintObject &po)
{ {
po.m_hollowing_data.reset(); po.m_hollowing_data.reset();
@ -236,20 +272,15 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
} }
auto mit = slindex_it; auto mit = slindex_it;
double doffs = m_print->m_printer_config.absolute_correction.getFloat(); for (size_t id = 0;
coord_t clpr_offs = scaled(doffs);
for(size_t id = 0;
id < po.m_model_slices.size() && mit != po.m_slice_index.end(); id < po.m_model_slices.size() && mit != po.m_slice_index.end();
id++) id++) {
{
// We apply the printer correction offset here.
if(clpr_offs != 0)
po.m_model_slices[id] =
offset_ex(po.m_model_slices[id], float(clpr_offs));
mit->set_model_slice_idx(po, id); ++mit; mit->set_model_slice_idx(po, id); ++mit;
} }
// We apply the printer correction offset here.
apply_printer_corrections(po, soModel);
if(po.m_config.supports_enable.getBool() || po.m_config.pad_enable.getBool()) if(po.m_config.supports_enable.getBool() || po.m_config.pad_enable.getBool())
{ {
po.m_supportdata.reset(new SLAPrintObject::SupportData(mesh)); po.m_supportdata.reset(new SLAPrintObject::SupportData(mesh));
@ -448,19 +479,13 @@ void SLAPrint::Steps::slice_supports(SLAPrintObject &po) {
for(auto& rec : po.m_slice_index) heights.emplace_back(rec.slice_level()); for(auto& rec : po.m_slice_index) heights.emplace_back(rec.slice_level());
sd->support_slices = sd->support_tree_ptr->slice( sd->support_slices = sd->support_tree_ptr->slice(
heights, float(po.config().slice_closing_radius.value)); heights, float(po.config().slice_closing_radius.value));
} }
double doffs = m_print->m_printer_config.absolute_correction.getFloat(); for (size_t i = 0; i < sd->support_slices.size() && i < po.m_slice_index.size(); ++i)
coord_t clpr_offs = scaled(doffs);
for (size_t i = 0; i < sd->support_slices.size() && i < po.m_slice_index.size(); ++i) {
// We apply the printer correction offset here.
if (clpr_offs != 0)
sd->support_slices[i] = offset_ex(sd->support_slices[i], float(clpr_offs));
po.m_slice_index[i].set_support_slice_idx(po, i); po.m_slice_index[i].set_support_slice_idx(po, i);
}
apply_printer_corrections(po, soSupport);
// Using RELOAD_SLA_PREVIEW to tell the Plater to pass the update // Using RELOAD_SLA_PREVIEW to tell the Plater to pass the update
// status to the 3D preview to load the SLA slices. // status to the 3D preview to load the SLA slices.

View File

@ -43,6 +43,8 @@ private:
bool canceled() const { return m_print->canceled(); } bool canceled() const { return m_print->canceled(); }
void initialize_printer_input(); void initialize_printer_input();
void apply_printer_corrections(SLAPrintObject &po, SliceOrigin o);
public: public:
Steps(SLAPrint *print); Steps(SLAPrint *print);

View File

@ -557,6 +557,8 @@ const std::vector<std::string>& Preset::sla_printer_options()
"fast_tilt_time", "slow_tilt_time", "area_fill", "fast_tilt_time", "slow_tilt_time", "area_fill",
"relative_correction", "relative_correction",
"absolute_correction", "absolute_correction",
"elefant_foot_compensation",
"elefant_foot_min_width",
"gamma_correction", "gamma_correction",
"min_exposure_time", "max_exposure_time", "min_exposure_time", "max_exposure_time",
"min_initial_exposure_time", "max_initial_exposure_time", "min_initial_exposure_time", "max_initial_exposure_time",

View File

@ -2112,6 +2112,8 @@ void TabPrinter::build_sla()
} }
optgroup->append_line(line); optgroup->append_line(line);
optgroup->append_single_option_line("absolute_correction"); optgroup->append_single_option_line("absolute_correction");
optgroup->append_single_option_line("elefant_foot_compensation");
optgroup->append_single_option_line("elefant_foot_min_width");
optgroup->append_single_option_line("gamma_correction"); optgroup->append_single_option_line("gamma_correction");
optgroup = page->new_optgroup(_(L("Exposure"))); optgroup = page->new_optgroup(_(L("Exposure")));

View File

@ -413,6 +413,19 @@ static ExPolygon contour_with_hole()
return out; return out;
} }
static bool is_valid_orientation(const ExPolygon &p)
{
bool ret = p.contour.is_counter_clockwise();
for (auto &h : p.holes) ret = ret && h.is_clockwise();
return ret;
}
static bool is_efc_result_smaller(const ExPolygon &efc, const ExPolygon &orig)
{
double efc_area = efc.area();
return efc_area > 0. && efc_area < orig.area() && is_valid_orientation(efc);
}
SCENARIO("Elephant foot compensation", "[ElephantFoot]") { SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
GIVEN("Contour with hole") { GIVEN("Contour with hole") {
@ -426,7 +439,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
} }
@ -456,7 +469,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
} }
@ -471,7 +484,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
} }
@ -523,7 +536,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
WHEN("Fully compensated") { WHEN("Fully compensated") {
@ -534,7 +547,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
} }
@ -549,7 +562,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
} }
@ -566,7 +579,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
WHEN("Fully compensated") { WHEN("Fully compensated") {
@ -577,7 +590,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
WHEN("Brutally compensated") { WHEN("Brutally compensated") {
@ -588,7 +601,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
} }
@ -603,7 +616,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") {
{ { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } }); { { expoly_compensated }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
#endif /* TESTS_EXPORT_SVGS */ #endif /* TESTS_EXPORT_SVGS */
THEN("area of the compensated polygon is smaller") { THEN("area of the compensated polygon is smaller") {
REQUIRE(expoly_compensated.area() < expoly.area()); REQUIRE(is_efc_result_smaller(expoly_compensated, expoly));
} }
} }
} }