Merge branch 'master' of https://github.com/prusa3d/Slic3r into scene_manipulators

This commit is contained in:
Enrico Turri 2018-05-18 09:55:30 +02:00
commit 5224acad59
4 changed files with 138 additions and 201 deletions

View File

@ -458,6 +458,19 @@ offset2_ex(const Polygons &polygons, const float delta1, const float delta2,
return ClipperPaths_to_Slic3rExPolygons(output); return ClipperPaths_to_Slic3rExPolygons(output);
} }
//FIXME Vojtech: This functon may likely be optimized to avoid some of the Slic3r to Clipper
// conversions and unnecessary Clipper calls.
ExPolygons offset2_ex(const ExPolygons &expolygons, const float delta1,
const float delta2, ClipperLib::JoinType joinType, double miterLimit)
{
Polygons polys;
for (const ExPolygon &expoly : expolygons)
append(polys,
offset(offset_ex(expoly, delta1, joinType, miterLimit),
delta2, joinType, miterLimit));
return union_ex(polys);
}
template <class T> template <class T>
T T
_clipper_do(const ClipperLib::ClipType clipType, const Polygons &subject, _clipper_do(const ClipperLib::ClipType clipType, const Polygons &subject,
@ -650,8 +663,7 @@ union_pt_chained(const Polygons &subject, bool safety_offset_)
return retval; return retval;
} }
void void traverse_pt(ClipperLib::PolyNodes &nodes, Polygons* retval)
traverse_pt(ClipperLib::PolyNodes &nodes, Polygons* retval)
{ {
/* use a nearest neighbor search to order these children /* use a nearest neighbor search to order these children
TODO: supply start_near to chained_path() too? */ TODO: supply start_near to chained_path() too? */
@ -677,8 +689,7 @@ traverse_pt(ClipperLib::PolyNodes &nodes, Polygons* retval)
} }
} }
Polygons Polygons simplify_polygons(const Polygons &subject, bool preserve_collinear)
simplify_polygons(const Polygons &subject, bool preserve_collinear)
{ {
// convert into Clipper polygons // convert into Clipper polygons
ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject); ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject);
@ -698,13 +709,11 @@ simplify_polygons(const Polygons &subject, bool preserve_collinear)
return ClipperPaths_to_Slic3rPolygons(output); return ClipperPaths_to_Slic3rPolygons(output);
} }
ExPolygons ExPolygons simplify_polygons_ex(const Polygons &subject, bool preserve_collinear)
simplify_polygons_ex(const Polygons &subject, bool preserve_collinear)
{ {
if (!preserve_collinear) { if (! preserve_collinear)
return union_ex(simplify_polygons(subject, preserve_collinear)); return union_ex(simplify_polygons(subject, false));
}
// convert into Clipper polygons // convert into Clipper polygons
ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject); ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject);

View File

@ -80,6 +80,9 @@ Slic3r::Polygons offset2(const Slic3r::Polygons &polygons, const float delta1,
Slic3r::ExPolygons offset2_ex(const Slic3r::Polygons &polygons, const float delta1, Slic3r::ExPolygons offset2_ex(const Slic3r::Polygons &polygons, const float delta1,
const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
double miterLimit = 3); double miterLimit = 3);
Slic3r::ExPolygons offset2_ex(const Slic3r::ExPolygons &expolygons, const float delta1,
const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
double miterLimit = 3);
Slic3r::Polygons _clipper(ClipperLib::ClipType clipType, Slic3r::Polygons _clipper(ClipperLib::ClipType clipType,
const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false); const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);

View File

@ -168,52 +168,42 @@ ExPolygon::overlaps(const ExPolygon &other) const
return ! other.contour.points.empty() && this->contains_b(other.contour.points.front()); return ! other.contour.points.empty() && this->contains_b(other.contour.points.front());
} }
void void ExPolygon::simplify_p(double tolerance, Polygons* polygons) const
ExPolygon::simplify_p(double tolerance, Polygons* polygons) const
{ {
Polygons pp = this->simplify_p(tolerance); Polygons pp = this->simplify_p(tolerance);
polygons->insert(polygons->end(), pp.begin(), pp.end()); polygons->insert(polygons->end(), pp.begin(), pp.end());
} }
Polygons Polygons ExPolygon::simplify_p(double tolerance) const
ExPolygon::simplify_p(double tolerance) const
{ {
Polygons pp; Polygons pp;
pp.reserve(this->holes.size() + 1); pp.reserve(this->holes.size() + 1);
// contour // contour
{ {
Polygon p = this->contour; Polygon p = this->contour;
p.points.push_back(p.points.front()); p.points.push_back(p.points.front());
p.points = MultiPoint::_douglas_peucker(p.points, tolerance); p.points = MultiPoint::_douglas_peucker(p.points, tolerance);
p.points.pop_back(); p.points.pop_back();
pp.push_back(p); pp.emplace_back(std::move(p));
} }
// holes // holes
for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) { for (Polygon p : this->holes) {
Polygon p = *it;
p.points.push_back(p.points.front()); p.points.push_back(p.points.front());
p.points = MultiPoint::_douglas_peucker(p.points, tolerance); p.points = MultiPoint::_douglas_peucker(p.points, tolerance);
p.points.pop_back(); p.points.pop_back();
pp.push_back(p); pp.emplace_back(std::move(p));
} }
pp = simplify_polygons(pp); return simplify_polygons(pp);
return pp;
} }
ExPolygons ExPolygons ExPolygon::simplify(double tolerance) const
ExPolygon::simplify(double tolerance) const
{ {
Polygons pp = this->simplify_p(tolerance); return union_ex(this->simplify_p(tolerance));
return union_ex(pp);
} }
void void ExPolygon::simplify(double tolerance, ExPolygons* expolygons) const
ExPolygon::simplify(double tolerance, ExPolygons* expolygons) const
{ {
ExPolygons ep = this->simplify(tolerance); append(*expolygons, this->simplify(tolerance));
expolygons->insert(expolygons->end(), ep.begin(), ep.end());
} }
void void

View File

@ -6,8 +6,7 @@
namespace Slic3r { namespace Slic3r {
void void PerimeterGenerator::process()
PerimeterGenerator::process()
{ {
// other perimeters // other perimeters
this->_mm3_per_mm = this->perimeter_flow.mm3_per_mm(); this->_mm3_per_mm = this->perimeter_flow.mm3_per_mm();
@ -45,7 +44,6 @@ PerimeterGenerator::process()
// lower layer, so we take lower slices and offset them by half the nozzle diameter used // lower layer, so we take lower slices and offset them by half the nozzle diameter used
// in the current layer // in the current layer
double nozzle_diameter = this->print_config->nozzle_diameter.get_at(this->config->perimeter_extruder-1); double nozzle_diameter = this->print_config->nozzle_diameter.get_at(this->config->perimeter_extruder-1);
this->_lower_slices_p = offset(*this->lower_slices, float(scale_(+nozzle_diameter/2))); this->_lower_slices_p = offset(*this->lower_slices, float(scale_(+nozzle_diameter/2)));
} }
@ -53,149 +51,115 @@ PerimeterGenerator::process()
// extra perimeters for each one // extra perimeters for each one
for (const Surface &surface : this->slices->surfaces) { for (const Surface &surface : this->slices->surfaces) {
// detect how many perimeters must be generated for this island // detect how many perimeters must be generated for this island
const int loop_number = this->config->perimeters + surface.extra_perimeters -1; // 0-indexed loops int loop_number = this->config->perimeters + surface.extra_perimeters - 1; // 0-indexed loops
ExPolygons last = union_ex(surface.expolygon.simplify_p(SCALED_RESOLUTION));
Polygons gaps; ExPolygons gaps;
if (loop_number >= 0) {
Polygons last = surface.expolygon.simplify_p(SCALED_RESOLUTION); // In case no perimeters are to be generated, loop_number will equal to -1.
if (loop_number >= 0) { // no loops = -1
std::vector<PerimeterGeneratorLoops> contours(loop_number+1); // depth => loops std::vector<PerimeterGeneratorLoops> contours(loop_number+1); // depth => loops
std::vector<PerimeterGeneratorLoops> holes(loop_number+1); // depth => loops std::vector<PerimeterGeneratorLoops> holes(loop_number+1); // depth => loops
ThickPolylines thin_walls; ThickPolylines thin_walls;
// we loop one time more than needed in order to find gaps after the last perimeter was applied // we loop one time more than needed in order to find gaps after the last perimeter was applied
for (int i = 0; i <= loop_number+1; ++i) { // outer loop is 0 for (int i = 0;; ++ i) { // outer loop is 0
Polygons offsets; // Calculate next onion shell of perimeters.
ExPolygons offsets;
if (i == 0) { if (i == 0) {
// the minimum thickness of a single loop is: // the minimum thickness of a single loop is:
// ext_width/2 + ext_spacing/2 + spacing/2 + width/2 // ext_width/2 + ext_spacing/2 + spacing/2 + width/2
if (this->config->thin_walls) { offsets = this->config->thin_walls ?
offsets = offset2( offset2_ex(
last, last,
-(ext_perimeter_width / 2 + ext_min_spacing / 2 - 1), -(ext_perimeter_width / 2 + ext_min_spacing / 2 - 1),
+(ext_min_spacing/2 - 1) +(ext_min_spacing / 2 - 1)) :
); offset_ex(last, - ext_perimeter_width / 2);
} else {
offsets = offset(last, - ext_perimeter_width / 2);
}
// look for thin walls // look for thin walls
if (this->config->thin_walls) { if (this->config->thin_walls) {
Polygons diffpp = diff(
last,
offset(offsets, ext_perimeter_width / 2),
true // medial axis requires non-overlapping geometry
);
// the following offset2 ensures almost nothing in @thin_walls is narrower than $min_width // the following offset2 ensures almost nothing in @thin_walls is narrower than $min_width
// (actually, something larger than that still may exist due to mitering or other causes) // (actually, something larger than that still may exist due to mitering or other causes)
coord_t min_width = scale_(this->ext_perimeter_flow.nozzle_diameter / 3); coord_t min_width = scale_(this->ext_perimeter_flow.nozzle_diameter / 3);
ExPolygons expp = offset2_ex(diffpp, -min_width/2, +min_width/2); ExPolygons expp = offset2_ex(
// medial axis requires non-overlapping geometry
diff_ex(to_polygons(last),
offset(offsets, ext_perimeter_width / 2),
true),
- min_width / 2, min_width / 2);
// the maximum thickness of our thin wall area is equal to the minimum thickness of a single loop // the maximum thickness of our thin wall area is equal to the minimum thickness of a single loop
for (ExPolygons::const_iterator ex = expp.begin(); ex != expp.end(); ++ex) for (ExPolygon &ex : expp)
ex->medial_axis(ext_perimeter_width + ext_perimeter_spacing2, min_width, &thin_walls); ex.medial_axis(ext_perimeter_width + ext_perimeter_spacing2, min_width, &thin_walls);
#ifdef DEBUG
printf(" " PRINTF_ZU " thin walls detected\n", thin_walls.size());
#endif
/*
if (false) {
require "Slic3r/SVG.pm";
Slic3r::SVG::output(
"medial_axis.svg",
no_arrows => 1,
#expolygons => \@expp,
polylines => \@thin_walls,
);
}
*/
} }
} else { } else {
//FIXME Is this offset correct if the line width of the inner perimeters differs //FIXME Is this offset correct if the line width of the inner perimeters differs
// from the line width of the infill? // from the line width of the infill?
coord_t distance = (i == 1) ? ext_perimeter_spacing2 : perimeter_spacing; coord_t distance = (i == 1) ? ext_perimeter_spacing2 : perimeter_spacing;
offsets = this->config->thin_walls ?
if (this->config->thin_walls) {
// This path will ensure, that the perimeters do not overfill, as in // This path will ensure, that the perimeters do not overfill, as in
// prusa3d/Slic3r GH #32, but with the cost of rounding the perimeters // prusa3d/Slic3r GH #32, but with the cost of rounding the perimeters
// excessively, creating gaps, which then need to be filled in by the not very // excessively, creating gaps, which then need to be filled in by the not very
// reliable gap fill algorithm. // reliable gap fill algorithm.
// Also the offset2(perimeter, -x, x) may sometimes lead to a perimeter, which is larger than // Also the offset2(perimeter, -x, x) may sometimes lead to a perimeter, which is larger than
// the original. // the original.
offsets = offset2( offset2_ex(last,
last, - (distance + min_spacing / 2 - 1),
-(distance + min_spacing/2 - 1), min_spacing / 2 - 1) :
+(min_spacing/2 - 1)
);
} else {
// If "detect thin walls" is not enabled, this paths will be entered, which // If "detect thin walls" is not enabled, this paths will be entered, which
// leads to overflows, as in prusa3d/Slic3r GH #32 // leads to overflows, as in prusa3d/Slic3r GH #32
offsets = offset( offset_ex(last, - distance);
last,
-distance
);
}
// look for gaps // look for gaps
if (this->config->gap_fill_speed.value > 0 && this->config->fill_density.value > 0) { if (this->config->gap_fill_speed.value > 0 && this->config->fill_density.value > 0)
// not using safety offset here would "detect" very narrow gaps // not using safety offset here would "detect" very narrow gaps
// (but still long enough to escape the area threshold) that gap fill // (but still long enough to escape the area threshold) that gap fill
// won't be able to fill but we'd still remove from infill area // won't be able to fill but we'd still remove from infill area
Polygons diff_pp = diff( append(gaps, diff_ex(
offset(last, -0.5*distance), offset(last, -0.5 * distance),
offset(offsets, +0.5*distance + 10) // safety offset offset(offsets, 0.5 * distance + 10))); // safety offset
); }
gaps.insert(gaps.end(), diff_pp.begin(), diff_pp.end()); if (offsets.empty()) {
} // Store the number of loops actually generated.
} loop_number = i - 1;
// No region left to be filled in.
if (offsets.empty()) break; last.clear();
if (i > loop_number) break; // we were only looking for gaps this time break;
} else if (i > loop_number) {
last = offsets; // If i > loop_number, we were looking just for gaps.
for (Polygons::const_iterator polygon = offsets.begin(); polygon != offsets.end(); ++polygon) { break;
PerimeterGeneratorLoop loop(*polygon, i); }
loop.is_contour = polygon->is_counter_clockwise(); for (const ExPolygon &expolygon : offsets) {
if (loop.is_contour) { contours[i].emplace_back(PerimeterGeneratorLoop(expolygon.contour, i, true));
contours[i].push_back(loop); if (! expolygon.holes.empty()) {
} else { holes[i].reserve(holes[i].size() + expolygon.holes.size());
holes[i].push_back(loop); for (const Polygon &hole : expolygon.holes)
holes[i].emplace_back(PerimeterGeneratorLoop(hole, i, false));
} }
} }
last = std::move(offsets);
} }
// nest loops: holes first // nest loops: holes first
for (int d = 0; d <= loop_number; ++d) { for (int d = 0; d <= loop_number; ++ d) {
PerimeterGeneratorLoops &holes_d = holes[d]; PerimeterGeneratorLoops &holes_d = holes[d];
// loop through all holes having depth == d // loop through all holes having depth == d
for (int i = 0; i < (int)holes_d.size(); ++i) { for (int i = 0; i < (int)holes_d.size(); ++ i) {
const PerimeterGeneratorLoop &loop = holes_d[i]; const PerimeterGeneratorLoop &loop = holes_d[i];
// find the hole loop that contains this one, if any // find the hole loop that contains this one, if any
for (int t = d+1; t <= loop_number; ++t) { for (int t = d + 1; t <= loop_number; ++ t) {
for (int j = 0; j < (int)holes[t].size(); ++j) { for (int j = 0; j < (int)holes[t].size(); ++ j) {
PerimeterGeneratorLoop &candidate_parent = holes[t][j]; PerimeterGeneratorLoop &candidate_parent = holes[t][j];
if (candidate_parent.polygon.contains(loop.polygon.first_point())) { if (candidate_parent.polygon.contains(loop.polygon.first_point())) {
candidate_parent.children.push_back(loop); candidate_parent.children.push_back(loop);
holes_d.erase(holes_d.begin() + i); holes_d.erase(holes_d.begin() + i);
--i; -- i;
goto NEXT_LOOP; goto NEXT_LOOP;
} }
} }
} }
// if no hole contains this hole, find the contour loop that contains it // if no hole contains this hole, find the contour loop that contains it
for (int t = loop_number; t >= 0; --t) { for (int t = loop_number; t >= 0; -- t) {
for (int j = 0; j < (int)contours[t].size(); ++j) { for (int j = 0; j < (int)contours[t].size(); ++ j) {
PerimeterGeneratorLoop &candidate_parent = contours[t][j]; PerimeterGeneratorLoop &candidate_parent = contours[t][j];
if (candidate_parent.polygon.contains(loop.polygon.first_point())) { if (candidate_parent.polygon.contains(loop.polygon.first_point())) {
candidate_parent.children.push_back(loop); candidate_parent.children.push_back(loop);
holes_d.erase(holes_d.begin() + i); holes_d.erase(holes_d.begin() + i);
--i; -- i;
goto NEXT_LOOP; goto NEXT_LOOP;
} }
} }
@ -203,75 +167,57 @@ PerimeterGenerator::process()
NEXT_LOOP: ; NEXT_LOOP: ;
} }
} }
// nest contour loops // nest contour loops
for (int d = loop_number; d >= 1; --d) { for (int d = loop_number; d >= 1; -- d) {
PerimeterGeneratorLoops &contours_d = contours[d]; PerimeterGeneratorLoops &contours_d = contours[d];
// loop through all contours having depth == d // loop through all contours having depth == d
for (int i = 0; i < (int)contours_d.size(); ++i) { for (int i = 0; i < (int)contours_d.size(); ++ i) {
const PerimeterGeneratorLoop &loop = contours_d[i]; const PerimeterGeneratorLoop &loop = contours_d[i];
// find the contour loop that contains it // find the contour loop that contains it
for (int t = d-1; t >= 0; --t) { for (int t = d - 1; t >= 0; -- t) {
for (int j = 0; j < contours[t].size(); ++j) { for (int j = 0; j < contours[t].size(); ++ j) {
PerimeterGeneratorLoop &candidate_parent = contours[t][j]; PerimeterGeneratorLoop &candidate_parent = contours[t][j];
if (candidate_parent.polygon.contains(loop.polygon.first_point())) { if (candidate_parent.polygon.contains(loop.polygon.first_point())) {
candidate_parent.children.push_back(loop); candidate_parent.children.push_back(loop);
contours_d.erase(contours_d.begin() + i); contours_d.erase(contours_d.begin() + i);
--i; -- i;
goto NEXT_CONTOUR; goto NEXT_CONTOUR;
} }
} }
} }
NEXT_CONTOUR: ; NEXT_CONTOUR: ;
} }
} }
// at this point, all loops should be in contours[0] // at this point, all loops should be in contours[0]
ExtrusionEntityCollection entities = this->_traverse_loops(contours.front(), thin_walls); ExtrusionEntityCollection entities = this->_traverse_loops(contours.front(), thin_walls);
// if brim will be printed, reverse the order of perimeters so that // if brim will be printed, reverse the order of perimeters so that
// we continue inwards after having finished the brim // we continue inwards after having finished the brim
// TODO: add test for perimeter order // TODO: add test for perimeter order
if (this->config->external_perimeters_first if (this->config->external_perimeters_first ||
|| (this->layer_id == 0 && this->print_config->brim_width.value > 0)) (this->layer_id == 0 && this->print_config->brim_width.value > 0))
entities.reverse(); entities.reverse();
// append perimeters for this slice as a collection // append perimeters for this slice as a collection
if (!entities.empty()) if (! entities.empty())
this->loops->append(entities); this->loops->append(entities);
} // for each loop of an island } // for each loop of an island
// fill gaps // fill gaps
if (!gaps.empty()) { if (! gaps.empty()) {
/*
SVG svg("gaps.svg");
svg.draw(union_ex(gaps));
svg.Close();
*/
// collapse // collapse
double min = 0.2 * perimeter_width * (1 - INSET_OVERLAP_TOLERANCE); double min = 0.2 * perimeter_width * (1 - INSET_OVERLAP_TOLERANCE);
double max = 2. * perimeter_spacing; double max = 2. * perimeter_spacing;
ExPolygons gaps_ex = diff_ex( ExPolygons gaps_ex = diff_ex(
offset2(gaps, -min/2, +min/2), //FIXME offset2 would be enough and cheaper.
offset2(gaps, -max/2, +max/2), offset2_ex(gaps, -min/2, +min/2),
true offset2_ex(gaps, -max/2, +max/2),
); true);
ThickPolylines polylines; ThickPolylines polylines;
for (ExPolygons::const_iterator ex = gaps_ex.begin(); ex != gaps_ex.end(); ++ex) for (const ExPolygon &ex : gaps_ex)
ex->medial_axis(max, min, &polylines); ex.medial_axis(max, min, &polylines);
if (! polylines.empty()) {
if (!polylines.empty()) {
ExtrusionEntityCollection gap_fill = this->_variable_width(polylines, ExtrusionEntityCollection gap_fill = this->_variable_width(polylines,
erGapFill, this->solid_infill_flow); erGapFill, this->solid_infill_flow);
this->gap_fill->append(gap_fill.entities); this->gap_fill->append(gap_fill.entities);
/* Make sure we don't infill narrow parts that are already gap-filled /* Make sure we don't infill narrow parts that are already gap-filled
(we only consider this surface's gaps to reduce the diff() complexity). (we only consider this surface's gaps to reduce the diff() complexity).
Growing actual extrusions ensures that gaps not filled by medial axis Growing actual extrusions ensures that gaps not filled by medial axis
@ -280,7 +226,7 @@ PerimeterGenerator::process()
and use zigzag). */ and use zigzag). */
//FIXME Vojtech: This grows by a rounded extrusion width, not by line spacing, //FIXME Vojtech: This grows by a rounded extrusion width, not by line spacing,
// therefore it may cover the area, but no the volume. // therefore it may cover the area, but no the volume.
last = diff(last, gap_fill.polygons_covered_by_width(10.f)); last = diff_ex(to_polygons(last), gap_fill.polygons_covered_by_width(10.f));
} }
} }
@ -288,36 +234,34 @@ PerimeterGenerator::process()
// we offset by half the perimeter spacing (to get to the actual infill boundary) // we offset by half the perimeter spacing (to get to the actual infill boundary)
// and then we offset back and forth by half the infill spacing to only consider the // and then we offset back and forth by half the infill spacing to only consider the
// non-collapsing regions // non-collapsing regions
coord_t inset = 0; coord_t inset =
if (loop_number == 0) { (loop_number < 0) ? 0 :
// one loop (loop_number == 0) ?
inset += ext_perimeter_spacing / 2; // one loop
} else if (loop_number > 0) { ext_perimeter_spacing / 2 :
// two or more loops // two or more loops?
inset += perimeter_spacing / 2; perimeter_spacing / 2;
}
// only apply infill overlap if we actually have one perimeter // only apply infill overlap if we actually have one perimeter
if (inset > 0) if (inset > 0)
inset -= this->config->get_abs_value("infill_overlap", inset + solid_infill_spacing / 2); inset -= this->config->get_abs_value("infill_overlap", inset + solid_infill_spacing / 2);
// simplify infill contours according to resolution // simplify infill contours according to resolution
Polygons pp; Polygons pp;
for (ExPolygon &ex : union_ex(last)) for (ExPolygon &ex : last)
ex.simplify_p(SCALED_RESOLUTION, &pp); ex.simplify_p(SCALED_RESOLUTION, &pp);
// collapse too narrow infill areas // collapse too narrow infill areas
coord_t min_perimeter_infill_spacing = solid_infill_spacing * (1 - INSET_OVERLAP_TOLERANCE); coord_t min_perimeter_infill_spacing = solid_infill_spacing * (1. - INSET_OVERLAP_TOLERANCE);
// append infill areas to fill_surfaces // append infill areas to fill_surfaces
this->fill_surfaces->append( this->fill_surfaces->append(
offset2_ex( offset2_ex(
pp, union_ex(pp),
-inset -min_perimeter_infill_spacing/2, - inset - min_perimeter_infill_spacing / 2,
+min_perimeter_infill_spacing/2), min_perimeter_infill_spacing / 2),
stInternal); stInternal);
} // for each island } // for each island
} }
ExtrusionEntityCollection ExtrusionEntityCollection PerimeterGenerator::_traverse_loops(
PerimeterGenerator::_traverse_loops(const PerimeterGeneratorLoops &loops, const PerimeterGeneratorLoops &loops, ThickPolylines &thin_walls) const
ThickPolylines &thin_walls) const
{ {
// loops is an arrayref of ::Loop objects // loops is an arrayref of ::Loop objects
// turn each one into an ExtrusionLoop object // turn each one into an ExtrusionLoop object
@ -422,8 +366,7 @@ PerimeterGenerator::_traverse_loops(const PerimeterGeneratorLoops &loops,
return entities; return entities;
} }
ExtrusionEntityCollection ExtrusionEntityCollection PerimeterGenerator::_variable_width(const ThickPolylines &polylines, ExtrusionRole role, Flow flow) const
PerimeterGenerator::_variable_width(const ThickPolylines &polylines, ExtrusionRole role, Flow flow) const
{ {
// this value determines granularity of adaptive width, as G-code does not allow // this value determines granularity of adaptive width, as G-code does not allow
// variable extrusion within a single move; this value shall only affect the amount // variable extrusion within a single move; this value shall only affect the amount
@ -431,10 +374,10 @@ PerimeterGenerator::_variable_width(const ThickPolylines &polylines, ExtrusionRo
const double tolerance = scale_(0.05); const double tolerance = scale_(0.05);
ExtrusionEntityCollection coll; ExtrusionEntityCollection coll;
for (ThickPolylines::const_iterator p = polylines.begin(); p != polylines.end(); ++p) { for (const ThickPolyline &p : polylines) {
ExtrusionPaths paths; ExtrusionPaths paths;
ExtrusionPath path(role); ExtrusionPath path(role);
ThickLines lines = p->thicklines(); ThickLines lines = p.thicklines();
for (int i = 0; i < (int)lines.size(); ++i) { for (int i = 0; i < (int)lines.size(); ++i) {
const ThickLine& line = lines[i]; const ThickLine& line = lines[i];
@ -474,12 +417,11 @@ PerimeterGenerator::_variable_width(const ThickPolylines &polylines, ExtrusionRo
lines.insert(lines.begin() + i + j, new_line); lines.insert(lines.begin() + i + j, new_line);
} }
--i; -- i;
continue; continue;
} }
const double w = fmax(line.a_width, line.b_width); const double w = fmax(line.a_width, line.b_width);
if (path.polyline.points.empty()) { if (path.polyline.points.empty()) {
path.polyline.append(line.a); path.polyline.append(line.a);
path.polyline.append(line.b); path.polyline.append(line.b);
@ -497,21 +439,19 @@ PerimeterGenerator::_variable_width(const ThickPolylines &polylines, ExtrusionRo
if (thickness_delta <= tolerance) { if (thickness_delta <= tolerance) {
// the width difference between this line and the current flow width is // the width difference between this line and the current flow width is
// within the accepted tolerance // within the accepted tolerance
path.polyline.append(line.b); path.polyline.append(line.b);
} else { } else {
// we need to initialize a new line // we need to initialize a new line
paths.push_back(path); paths.emplace_back(std::move(path));
path = ExtrusionPath(role); path = ExtrusionPath(role);
--i; -- i;
} }
} }
} }
if (path.polyline.is_valid()) if (path.polyline.is_valid())
paths.push_back(path); paths.emplace_back(std::move(path));
// Append paths to collection.
// append paths to collection if (! paths.empty()) {
if (!paths.empty()) {
if (paths.front().first_point().coincides_with(paths.back().last_point())) if (paths.front().first_point().coincides_with(paths.back().last_point()))
coll.append(ExtrusionLoop(paths)); coll.append(ExtrusionLoop(paths));
else else
@ -522,20 +462,15 @@ PerimeterGenerator::_variable_width(const ThickPolylines &polylines, ExtrusionRo
return coll; return coll;
} }
bool bool PerimeterGeneratorLoop::is_internal_contour() const
PerimeterGeneratorLoop::is_internal_contour() const
{ {
if (this->is_contour) { // An internal contour is a contour containing no other contours
// an internal contour is a contour containing no other contours if (! this->is_contour)
for (std::vector<PerimeterGeneratorLoop>::const_iterator loop = this->children.begin(); return false;
loop != this->children.end(); ++loop) { for (const PerimeterGeneratorLoop &loop : this->children)
if (loop->is_contour) { if (loop.is_contour)
return false; return false;
} return true;
}
return true;
}
return false;
} }
} }