#612 add soft threshold for big holes XY compensation

This commit is contained in:
supermerill 2020-10-29 19:44:25 +01:00
parent 13586d6764
commit 151ea0a39f
6 changed files with 44 additions and 8 deletions

View File

@ -86,12 +86,15 @@ group:label_width$8:Modifying slices
setting:width$6:curve_smoothing_angle_concave
setting:width$6:curve_smoothing_cutoff_dist
end_line
setting:hole_to_polyhole
line:XY compensation
setting:width$6:xy_size_compensation
setting:width$6:xy_inner_size_compensation
setting:width$6:first_layer_size_compensation
end_line
line:Vertical Hole shrinking compensation
setting:hole_to_polyhole
setting:width$6:hole_size_compensation
setting:width$6:hole_size_threshold
end_line
group:Other
setting:clip_multipart_objects

View File

@ -3725,7 +3725,8 @@ void PrintConfigDef::init_fff_params()
def->category = OptionCategory::slicing;
def->tooltip = L("The object will be grown/shrunk in the XY plane by the configured value "
"(negative = inwards, positive = outwards). This might be useful for fine-tuning sizes."
"\nThis one only applies to the 'exterior' shell of the object");
"\nThis one only applies to the 'exterior' shell of the object."
"\n !!! it's recommended you put the same value into the 'Inner XY size compensation', unless you are sure you don't have horizontal holes. !!! ");
def->sidetext = L("mm");
def->mode = comExpert;
def->set_default_value(new ConfigOptionFloat(0));
@ -3736,7 +3737,7 @@ void PrintConfigDef::init_fff_params()
def->category = OptionCategory::slicing;
def->tooltip = L("The object will be grown/shrunk in the XY plane by the configured value "
"(negative = inwards, positive = outwards). This might be useful for fine-tuning sizes."
"\nThis one only applies to the 'inner' shell of the object");
"\nThis one only applies to the 'inner' shell of the object (!!! horizontal holes break the shell !!!)");
def->sidetext = L("mm");
def->mode = comExpert;
def->set_default_value(new ConfigOptionFloat(0));
@ -3753,6 +3754,17 @@ void PrintConfigDef::init_fff_params()
def->mode = comExpert;
def->set_default_value(new ConfigOptionFloat(0));
def = this->add("hole_size_threshold", coFloat);
def->label = L("Holes");
def->full_label = L("XY holes threshold");
def->category = OptionCategory::slicing;
def->tooltip = L("Maximum area for the hole where the hole_size_compensation will apply fully."
" After that, it will decraese down to 0 for four time this area."
" Set to 0 to let the hole_size_compensation apply fully for all detected holes");
def->sidetext = L("mm²");
def->mode = comExpert;
def->set_default_value(new ConfigOptionFloat(100));
def = this->add("hole_to_polyhole", coBool);
def->label = L("Convert round holes to polyholes");
def->full_label = L("Convert round holes to polyholes");

View File

@ -530,6 +530,7 @@ public:
ConfigOptionFloatOrPercent first_layer_height;
ConfigOptionFloat first_layer_size_compensation;
ConfigOptionFloat hole_size_compensation;
ConfigOptionFloat hole_size_threshold;
ConfigOptionBool infill_only_where_needed;
// Force the generation of solid shells between adjacent materials/volumes.
ConfigOptionBool interface_shells;
@ -592,6 +593,7 @@ protected:
OPT_PTR(exact_last_layer_height);
OPT_PTR(extrusion_width);
OPT_PTR(hole_size_compensation);
OPT_PTR(hole_size_threshold);
OPT_PTR(first_layer_height);
OPT_PTR(first_layer_size_compensation);
OPT_PTR(infill_only_where_needed);

View File

@ -646,6 +646,7 @@ bool PrintObject::invalidate_state_by_config_options(const std::vector<t_config_
|| opt_key == "support_material_contact_distance_bottom"
|| opt_key == "xy_size_compensation"
|| opt_key == "hole_size_compensation"
|| opt_key == "hole_size_threshold"
|| opt_key == "hole_to_polyhole"
|| opt_key == "z_step") {
steps.emplace_back(posSlice);
@ -2520,6 +2521,7 @@ end:
ExPolygons PrintObject::_shrink_contour_holes(double contour_delta, double default_delta, double convex_delta, const ExPolygons& polys) const {
ExPolygons new_ex_polys;
double max_hole_area = scale_d(scale_d(m_config.hole_size_threshold.value));
for (const ExPolygon& ex_poly : polys) {
Polygons contours;
Polygons holes;
@ -2538,12 +2540,26 @@ ExPolygons PrintObject::_shrink_contour_holes(double contour_delta, double defau
// check whether last point forms a convex angle
ok &= (hole.points.back().ccw_angle(*(hole.points.end() - 2), hole.points.front()) <= PI + 0.1);
if (ok) {
if (convex_delta != 0) {
for (Polygon &newHole : offset(hole, -convex_delta)) {
newHole.make_counter_clockwise();
holes.emplace_back(std::move(newHole));
//apply hole threshold cutoff
double convex_delta_adapted = convex_delta;
double area = -hole.area();
if (area > max_hole_area * 4) {
convex_delta_adapted = 0;
}else if (area > max_hole_area) {
// not a hard threshold, to avoid artefacts on slopped holes.
convex_delta_adapted = convex_delta * (max_hole_area * 4 - area) / (max_hole_area * 3);
}
if (convex_delta_adapted != 0) {
for (Polygon &newHole : offset(hole, -convex_delta_adapted)) {
newHole.make_counter_clockwise();
holes.emplace_back(std::move(newHole));
}
} else {
holes.push_back(hole);
holes.back().make_counter_clockwise();
}
} else {
holes.push_back(hole);

View File

@ -100,6 +100,8 @@ inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); }
inline double unscaled(double v) { return v * SCALING_FACTOR; }
inline coordf_t unscale_(coord_t v) { return v * SCALING_FACTOR; }
inline coord_t scale_t(coordf_t v) { return (coord_t)(v / SCALING_FACTOR); }
inline double scale_d(coordf_t v) { return (v / SCALING_FACTOR); }
inline double scale_d(coord_t v) { return ((double)v / SCALING_FACTOR); }
enum Axis {
X=0,

View File

@ -519,7 +519,8 @@ const std::vector<std::string>& Preset::print_options()
"first_layer_size_compensation",
"xy_size_compensation",
"xy_inner_size_compensation",
"hole_size_compensation",
"hole_size_compensation",
"hole_size_threshold",
"hole_to_polyhole",
"threads", "resolution",
"wipe_tower", "wipe_tower_x", "wipe_tower_y", "wipe_tower_width", "wipe_tower_rotation_angle", "wipe_tower_bridging",