Skip to content

Commit

Permalink
gap_fill_extension and gap_fill_min_length
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jul 23, 2022
1 parent d16b7d1 commit 1b8190e
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 11 deletions.
8 changes: 5 additions & 3 deletions resources/ui_layout/default/print.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ group:label_width$12:Overhangs
setting:sidetext_width$2:overhangs_reverse
setting:label_width$12:width$5:overhangs_reverse_threshold
end_line
group:Advanced
group:sidetext_width$5:Advanced
setting:width$25:no_perimeter_unsupported_algo
line:Gap Fill
setting:label$_:gap_fill_enabled
setting:width$5:gap_fill_last
setting:width$5:gap_fill_extension
end_line
line:Gap Fill threshold
setting:width$5:gap_fill_min_width
setting:width$5:gap_fill_max_width
setting:width$5:gap_fill_min_area
setting:width$5:sidetext_width$6:gap_fill_min_area
setting:width$5:gap_fill_min_length
end_line
line:Seam
setting:tags$Simple$Advanced$Expert$Prusa$SuSi:script:enum$corners$Corners$nearest$Nearest$random$Random$aligned$Aligned$rear$Rear$custom$Custom:depends$seam_position$seam_angle_cost$seam_travel_cost:label$Seam position:label_width$12:sidetext_width$0:tooltip$Position of perimeters' starting points.\nCustom can be defined in Advanced or Expert mode. Cost-based settings let you choose the angle and travel cost. A high angle cost will place the seam where it can be hidden by a corner, the travel cost place the seam near the last position (often at the end of the previous infill).:s_seam_position
Expand All @@ -87,7 +89,7 @@ group:Advanced
line:Fuzzy skin (experimental)
setting:sidetext_width$1:label$_:fuzzy_skin
setting:width$6:sidetext_width$6:fuzzy_skin_thickness
setting:width$6:sidetext_width$5:fuzzy_skin_point_dist
setting:width$6:fuzzy_skin_point_dist
end_line
group:External perimeter first
setting:label$Activate:external_perimeters_first
Expand Down
28 changes: 24 additions & 4 deletions src/libslic3r/Geometry/MedialAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,23 @@ MedialAxis::extends_line(ThickPolyline& polyline, const ExPolygons& anchors, con
}
}

void
MedialAxis::extends_line_extra(ThickPolylines& pp) {
// opening : offset2-+
for (size_t i = 0; i < pp.size(); ++i) {
ThickPolyline& polyline = pp[i];

if (polyline.endpoints.first) {
polyline.extend_start(this->extension_length);
}
if (polyline.endpoints.second) {
polyline.extend_end(this->extension_length);
}
}
}



void
MedialAxis::main_fusion(ThickPolylines& pp)
{
Expand Down Expand Up @@ -2059,7 +2076,7 @@ MedialAxis::concatenate_small_polylines(ThickPolylines& pp)
/*
new goal: ensure that if there is a too short segment, it will be connected with a sufficiently long one, to save it
*/
coordf_t shortest_size = (coordf_t)this->min_length;
const coordf_t shortest_size = (coordf_t)this->min_length;
std::set<size_t> deleted;
std::vector<size_t> idx_per_size;
//TODO: cache the length
Expand Down Expand Up @@ -2425,10 +2442,11 @@ MedialAxis::remove_too_short_polylines(ThickPolylines& pp)
// know how long will the endpoints be extended since it depends on polygon thickness
// which is variable - extension will be <= max_width/2 on each side)
if ((polyline.endpoints.first || polyline.endpoints.second)) {
coordf_t local_max_width = this->max_width / 2;
coordf_t local_min_length = this->max_width / 2;
for (coordf_t w : polyline.width)
local_max_width = std::max(local_max_width, w);
if (polyline.length() < local_max_width) {
local_min_length = std::max(local_min_length, w - SCALED_EPSILON);
local_min_length = std::max(local_min_length, shortest_size);
if (polyline.length() < local_min_length) {
if (shortest_size > polyline.length()) {
shortest_size = polyline.length();
shortest_idx = i;
Expand Down Expand Up @@ -2969,6 +2987,8 @@ MedialAxis::build(ThickPolylines& polylines_out)
// svg.Close();
//}

extends_line_extra(pp);

remove_too_short_polylines(pp);
//{
// std::stringstream stri;
Expand Down
3 changes: 3 additions & 0 deletions src/libslic3r/Geometry/MedialAxis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class MedialAxis {
MedialAxis& set_stop_at_min_width(const bool stop_at_min_width) { this->stop_at_min_width = stop_at_min_width; return *this; }
MedialAxis& set_min_length(const coord_t min_length) { this->min_length = min_length; return *this; }
MedialAxis& set_biggest_width(const coord_t biggest_width) { this->biggest_width = biggest_width; return *this; }
MedialAxis& set_extension_length(const coord_t extension_length) { this->extension_length = extension_length; return *this; }

private:

Expand All @@ -99,6 +100,8 @@ class MedialAxis {
coord_t taper_size;
//if true, remove_too_* can shorten the bits created by extends_line.
bool stop_at_min_width;
// arbitrary extra extension at ends.
coord_t extension_length = 0;

//voronoi stuff
class VD : public voronoi_diagram<double> {
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ void Layer::make_perimeters()
&& ((config.gap_fill_speed == other_config.gap_fill_speed) || !config.gap_fill_enabled)
&& config.gap_fill_last == other_config.gap_fill_last
&& config.gap_fill_flow_match_perimeter == other_config.gap_fill_flow_match_perimeter
&& config.gap_fill_extension == other_config.gap_fill_extension
&& config.gap_fill_max_width == other_config.gap_fill_max_width
&& config.gap_fill_min_area == other_config.gap_fill_min_area
&& config.gap_fill_min_length == other_config.gap_fill_min_length
&& config.gap_fill_min_width == other_config.gap_fill_min_width
&& config.gap_fill_overlap == other_config.gap_fill_overlap
&& config.infill_dense == other_config.infill_dense
Expand Down
14 changes: 11 additions & 3 deletions src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,15 @@ void PerimeterGenerator::process()
coordf_t real_max = 2.5 * perimeter_spacing;
const coordf_t minwidth = scale_d(this->config->gap_fill_min_width.get_abs_value(unscaled((double)perimeter_width)));
const coordf_t maxwidth = scale_d(this->config->gap_fill_max_width.get_abs_value(unscaled((double)perimeter_width)));
const coord_t minlength = scale_t(this->config->gap_fill_min_length.get_abs_value(unscaled((double)perimeter_width)));
if (minwidth > 0) {
min = std::max(min, minwidth);
}
coordf_t max = real_max;
if (maxwidth > 0) {
max = std::min(max, maxwidth);
}
const coord_t gapfill_extension = scale_t(this->config->gap_fill_extension.get_abs_value(unscaled((double)perimeter_width)));
//remove areas that are too big (shouldn't occur...)
ExPolygons too_big = offset2_ex(gaps, double(-max / 2), double(+max / 2));
ExPolygons gaps_ex_to_test = too_big.empty() ? gaps : diff_ex(gaps, too_big, ApplySafetyOffset::Yes);
Expand Down Expand Up @@ -1198,9 +1200,15 @@ void PerimeterGenerator::process()
// create lines from the area
ThickPolylines polylines;
for (const ExPolygon& ex : gaps_ex) {
Geometry::MedialAxis{ ex, coord_t(real_max), coord_t(min), coord_t(this->layer->height) }
.set_biggest_width(max)
.build(polylines);
Geometry::MedialAxis md{ ex, coord_t(real_max), coord_t(min), coord_t(this->layer->height) };
if (minlength > 0) {
md.set_min_length(minlength);
}
if (gapfill_extension > 0) {
md.set_extension_length(gapfill_extension);
}
md.set_biggest_width(max);
md.build(polylines);
}
// create extrusion from lines
if (!polylines.empty()) {
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,12 @@ static std::vector<std::string> s_Preset_print_options {
"max_volumetric_speed",
// gapfill
"gap_fill_enabled",
"gap_fill_extension",
"gap_fill_flow_match_perimeter",
"gap_fill_last",
"gap_fill_max_width",
"gap_fill_min_area",
"gap_fill_min_length",
"gap_fill_min_width",
"gap_fill_overlap",
"gap_fill_speed",
Expand Down
23 changes: 23 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,18 @@ void PrintConfigDef::init_fff_params()
def->mode = comExpert | comSuSi;
def->set_default_value(new ConfigOptionFloatOrPercent(0,false));

def = this->add("gap_fill_extension", coFloatOrPercent);
def->label = L("Extension");
def->full_label = L("Gapfill: extra extension");
def->category = OptionCategory::perimeter;
def->tooltip = L("Increase the length of all gapfills by this amount (may overextrude a little bit)\nCan be a % of the perimeter width");
def->ratio_over = "perimeter_width";
def->sidetext = L("mm or %");
def->min = 0;
def->max_literal = { 50, true };
def->mode = comExpert | comSuSi;
def->set_default_value(new ConfigOptionFloatOrPercent{ 0, false });

def = this->add("gap_fill_flow_match_perimeter", coPercent);
def->label = L("Cap with perimeter flow");
def->full_label = L("Gapfill: cap speed with perimeter flow");
Expand Down Expand Up @@ -2627,6 +2639,17 @@ void PrintConfigDef::init_fff_params()
def->mode = comExpert | comSuSi;
def->set_default_value(new ConfigOptionFloatOrPercent{ 100, true });

def = this->add("gap_fill_min_length", coFloatOrPercent);
def->label = L("Min length");
def->full_label = L("Gapfill: Min length");
def->category = OptionCategory::perimeter;
def->tooltip = L("This setting represents the minimum mm for a gapfill extrusion to be extruded.\nCan be a % of the perimeter width\n0 to auto");
def->ratio_over = "perimeter_width";
def->sidetext = L("mm or %");
def->min = 0;
def->mode = comExpert | comSuSi;
def->set_default_value(new ConfigOptionFloatOrPercent{ 0, false });

def = this->add("gap_fill_min_width", coFloatOrPercent);
def->label = L("Min width");
def->full_label = L("Gapfill: Min width");
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,12 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionPercent, fill_smooth_distribution))
((ConfigOptionFloatOrPercent, fill_smooth_width))
((ConfigOptionBool, gap_fill_enabled))
((ConfigOptionFloatOrPercent, gap_fill_extension))
((ConfigOptionPercent, gap_fill_flow_match_perimeter))
((ConfigOptionBool, gap_fill_last))
((ConfigOptionFloatOrPercent, gap_fill_max_width))
((ConfigOptionFloatOrPercent, gap_fill_min_area))
((ConfigOptionFloatOrPercent, gap_fill_min_length))
((ConfigOptionFloatOrPercent, gap_fill_min_width))
((ConfigOptionPercent, gap_fill_overlap))
((ConfigOptionFloatOrPercent, gap_fill_speed))
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/PrintObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,11 @@ bool PrintObject::invalidate_state_by_config_options(
for (const t_config_option_key& opt_key : opt_keys) {
if (
opt_key == "gap_fill_enabled"
|| opt_key == "gap_fill_extension"
|| opt_key == "gap_fill_last"
|| opt_key == "gap_fill_max_width"
|| opt_key == "gap_fill_min_area"
|| opt_key == "gap_fill_min_length"
|| opt_key == "gap_fill_min_width"
|| opt_key == "only_one_perimeter_first_layer"
|| opt_key == "only_one_perimeter_top"
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/ConfigManipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config)

toggle_field("perimeter_loop_seam", config->opt_bool("perimeter_loop"));

for (auto el : { "gap_fill_last", "gap_fill_max_width", "gap_fill_min_area", "gap_fill_min_width" })
for (auto el : { "gap_fill_extension", "gap_fill_last", "gap_fill_max_width", "gap_fill_min_area", "gap_fill_min_length", "gap_fill_min_width" })
toggle_field(el, config->opt_bool("gap_fill_enabled"));

for (auto el : { "fuzzy_skin_thickness", "fuzzy_skin_point_dist" })
Expand Down

0 comments on commit 1b8190e

Please sign in to comment.