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,10 +1848,20 @@ FillRectilinear2WGapFill::fill_surface_extrusion(const Surface *surface, const F
} }
//gapfill //gapfill
if (gapfill_areas.size() > 0) {
ThickPolylines polylines_gapfill; ThickPolylines polylines_gapfill;
double min = 0.2 * params.flow->scaled_width() * (1 - INSET_OVERLAP_TOLERANCE); double min = 0.2 * params.flow->scaled_width() * (1 - INSET_OVERLAP_TOLERANCE);
double max = 2. * params.flow->scaled_width(); double max = 2. * params.flow->scaled_width();
for (const ExPolygon &ex : gapfill_areas) { // collapse
double min_offset = 0.2 * params.flow->scaled_width() * (1 - INSET_OVERLAP_TOLERANCE);
//be sure we don't gapfill where the perimeters are already touching each other (negative spacing).
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. //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. //ie one that are smaller than an extrusion with width of min and a length of max.
if (ex.area() > min * max) { if (ex.area() > min * max) {
@ -1858,6 +1869,15 @@ FillRectilinear2WGapFill::fill_surface_extrusion(const Surface *surface, const F
} }
} }
if (!polylines_gapfill.empty() && good_role != erBridgeInfill) { if (!polylines_gapfill.empty() && good_role != erBridgeInfill) {
//test
for (ThickPolyline poly : polylines_gapfill) {
for (coordf_t width : poly.width) {
if (width > params.flow->scaled_width() * 2.2) {
std::cout << "ERRROR!!!! recti gapfill width = " << unscaled(width) << " > max_width = " << (params.flow->width * 2) << "\n";
}
}
}
ExtrusionEntityCollection gap_fill = thin_variable_width(polylines_gapfill, erGapFill, *params.flow); ExtrusionEntityCollection gap_fill = thin_variable_width(polylines_gapfill, erGapFill, *params.flow);
//set role if needed //set role if needed
if (good_role != erSolidInfill) { if (good_role != erSolidInfill) {
@ -1872,6 +1892,7 @@ FillRectilinear2WGapFill::fill_surface_extrusion(const Surface *surface, const F
coll_nosort->entities.push_back(coll_gapfill); coll_nosort->entities.push_back(coll_gapfill);
} }
} }
}
// === end === // === end ===
if (!coll_nosort->empty()) { if (!coll_nosort->empty()) {