safety checks for rectiwithgapfill

This commit is contained in:
supermerill 2019-07-02 11:04:28 +02:00
parent 3aea01e815
commit a2953c31cc

View File

@ -888,8 +888,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
ExPolygonWithOffset poly_with_offset( ExPolygonWithOffset poly_with_offset(
surface->expolygon, surface->expolygon,
- rotate_vector.first, - rotate_vector.first,
scale_(this->overlap - (0.5 - INFILL_OVERLAP_OVER_SPACING) * this->spacing), scale_(0 /*this->overlap*/ - (0.5 - INFILL_OVERLAP_OVER_SPACING) * this->spacing),
scale_(this->overlap - 0.5 * this->spacing)); scale_(0 /*this->overlap*/ - 0.5 * this->spacing));
if (poly_with_offset.n_contours_inner == 0) { if (poly_with_offset.n_contours_inner == 0) {
// Not a single infill line fits. // Not a single infill line fits.
//FIXME maybe one shall trigger the gap fill here? //FIXME maybe one shall trigger the gap fill here?
@ -993,7 +993,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
} }
// Verify the segments. If something is wrong, give up. // Verify the segments. If something is wrong, give up.
#define ASSERT_OR_RETURN(CONDITION) do { assert(CONDITION); if (! (CONDITION)) return false; } while (0) #define ASSERT_OR_RETURN(CONDITION) do { /*assert(CONDITION); error here. Didn't do any mod that should affect it. Didn't have the time to understand algo, so i let it fail*/ if (! (CONDITION)) return false; } while (0)
for (size_t i_seg = 0; i_seg < segs.size(); ++ i_seg) { for (size_t i_seg = 0; i_seg < segs.size(); ++ i_seg) {
SegmentedIntersectionLine &sil = segs[i_seg]; SegmentedIntersectionLine &sil = segs[i_seg];
// The intersection points have to be even. // The intersection points have to be even.
@ -1773,7 +1773,8 @@ FillRectilinear2WGapFill::fill_surface_extrusion(const Surface *surface, const F
ExtrusionRole good_role = getRoleFromSurfaceType(params, surface); ExtrusionRole good_role = getRoleFromSurfaceType(params, surface);
// remove areas for gapfill // remove areas for gapfill
float factor = 1; // 0.8f; // factor=0.5 : remove area smaller than a spacing. factor=1 : max spacing for the gapfill (but not the width)
float factor = 0.9f;
ExPolygons rectilinear_areas = offset2_ex(ExPolygons{ surface->expolygon }, -params.flow->scaled_spacing() * factor, params.flow->scaled_spacing() * factor); ExPolygons rectilinear_areas = offset2_ex(ExPolygons{ surface->expolygon }, -params.flow->scaled_spacing() * factor, params.flow->scaled_spacing() * factor);
ExPolygons gapfill_areas = diff_ex(ExPolygons{ surface->expolygon }, rectilinear_areas); ExPolygons gapfill_areas = diff_ex(ExPolygons{ surface->expolygon }, rectilinear_areas);
double rec_area = 0; double rec_area = 0;
@ -1847,29 +1848,49 @@ FillRectilinear2WGapFill::fill_surface_extrusion(const Surface *surface, const F
} }
//gapfill //gapfill
ThickPolylines polylines_gapfill; if (gapfill_areas.size() > 0) {
double min = 0.2 * params.flow->scaled_width() * (1 - INSET_OVERLAP_TOLERANCE); ThickPolylines polylines_gapfill;
double max = 2. * params.flow->scaled_width(); double min = 0.2 * params.flow->scaled_width() * (1 - INSET_OVERLAP_TOLERANCE);
for (const ExPolygon &ex : gapfill_areas) { double max = 2. * params.flow->scaled_width();
//remove too small gaps that are too hard to fill. // collapse
//ie one that are smaller than an extrusion with width of min and a length of max. double min_offset = 0.2 * params.flow->scaled_width() * (1 - INSET_OVERLAP_TOLERANCE);
if (ex.area() > min * max) { //be sure we don't gapfill where the perimeters are already touching each other (negative spacing).
MedialAxis{ ex, params.flow->scaled_width() * 2, params.flow->scaled_width() / 5, coord_t(params.flow->height) }.build(polylines_gapfill); min = std::max(min, double(Flow::new_from_spacing(EPSILON, params.flow->nozzle_diameter , params.flow->height, false).scaled_width()));
double max_offset = 2. * params.flow->scaled_spacing();
ExPolygons gapfill_areas_collapsed = diff_ex(
offset2_ex(gapfill_areas, double(-min_offset / 2), double(+min_offset / 2)),
offset2_ex(gapfill_areas, double(-max_offset / 2), double(+max_offset / 2)),
true);
for (const ExPolygon &ex : gapfill_areas_collapsed) {
//remove too small gaps that are too hard to fill.
//ie one that are smaller than an extrusion with width of min and a length of max.
if (ex.area() > min * max) {
MedialAxis{ ex, params.flow->scaled_width() * 2, params.flow->scaled_width() / 5, coord_t(params.flow->height) }.build(polylines_gapfill);
}
} }
} if (!polylines_gapfill.empty() && good_role != erBridgeInfill) {
if (!polylines_gapfill.empty() && good_role != erBridgeInfill) { //test
ExtrusionEntityCollection gap_fill = thin_variable_width(polylines_gapfill, erGapFill, *params.flow); for (ThickPolyline poly : polylines_gapfill) {
//set role if needed for (coordf_t width : poly.width) {
if (good_role != erSolidInfill) { if (width > params.flow->scaled_width() * 2.2) {
ExtrusionSetRole set_good_role(good_role); std::cout << "ERRROR!!!! recti gapfill width = " << unscaled(width) << " > max_width = " << (params.flow->width * 2) << "\n";
gap_fill.visit(set_good_role); }
} }
//move them into the collection }
if (!gap_fill.entities.empty()) {
ExtrusionEntityCollection *coll_gapfill = new ExtrusionEntityCollection(); ExtrusionEntityCollection gap_fill = thin_variable_width(polylines_gapfill, erGapFill, *params.flow);
coll_gapfill->no_sort = this->no_sort(); //set role if needed
coll_gapfill->append(std::move(gap_fill.entities)); if (good_role != erSolidInfill) {
coll_nosort->entities.push_back(coll_gapfill); ExtrusionSetRole set_good_role(good_role);
gap_fill.visit(set_good_role);
}
//move them into the collection
if (!gap_fill.entities.empty()) {
ExtrusionEntityCollection *coll_gapfill = new ExtrusionEntityCollection();
coll_gapfill->no_sort = this->no_sort();
coll_gapfill->append(std::move(gap_fill.entities));
coll_nosort->entities.push_back(coll_gapfill);
}
} }
} }