diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d326be0304..e85b52dc50 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,7 +50,6 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/Fill/FillHoneycomb.cpp ${LIBDIR}/libslic3r/Fill/FillPlanePath.cpp ${LIBDIR}/libslic3r/Fill/FillRectilinear.cpp - ${LIBDIR}/libslic3r/Fill/FillRectilinear2.cpp ${LIBDIR}/libslic3r/Flow.cpp ${LIBDIR}/libslic3r/GCode.cpp ${LIBDIR}/libslic3r/GCodeSender.cpp diff --git a/t/fill.t b/t/fill.t index af17c86ff0..aec533f233 100644 --- a/t/fill.t +++ b/t/fill.t @@ -2,7 +2,7 @@ use Test::More; use strict; use warnings; -plan tests => 43; +plan tests => 92; BEGIN { use FindBin; @@ -11,8 +11,8 @@ BEGIN { use List::Util qw(first sum); use Slic3r; -use Slic3r::Geometry qw(PI X Y scale unscale convex_hull); -use Slic3r::Geometry::Clipper qw(union diff diff_ex offset offset2_ex); +use Slic3r::Geometry qw(PI X Y scaled_epsilon scale unscale convex_hull); +use Slic3r::Geometry::Clipper qw(union diff diff_ex offset offset2_ex diff_pl); use Slic3r::Surface qw(:types); use Slic3r::Test; @@ -26,6 +26,67 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ } is $surface_width % $distance, 0, 'adjusted solid distance'; } +{ + my $filler = Slic3r::Filler->new_from_type('rectilinear'); + $filler->set_angle(-(PI)/2); + $filler->set_spacing(5); + $filler->set_dont_adjust(1); + $filler->set_endpoints_overlap(0); + + my $test = sub { + my ($expolygon) = @_; + my $surface = Slic3r::Surface->new( + surface_type => S_TYPE_TOP, + expolygon => $expolygon, + ); + return $filler->fill_surface($surface); + }; + + # square + $filler->set_density($filler->spacing / 50); + for my $i (0..3) { + # check that it works regardless of the points order + my @points = ([0,0], [100,0], [100,100], [0,100]); + @points = (@points[$i..$#points], @points[0..($i-1)]); + my $paths = $test->(my $e = Slic3r::ExPolygon->new([ scale_points @points ])); + + is(scalar @$paths, 1, 'one continuous path') or done_testing, exit; + ok abs($paths->[0]->length - scale(3*100 + 2*50)) - scaled_epsilon, 'path has expected length'; + } + + # diamond with endpoints on grid + { + my $paths = $test->(my $e = Slic3r::ExPolygon->new([ scale_points [0,0], [100,0], [150,50], [100,100], [0,100], [-50,50] ])); + is(scalar @$paths, 1, 'one continuous path') or done_testing, exit; + } + + # square with hole + for my $angle (-(PI/2), -(PI/4), -(PI), PI/2, PI) { + for my $spacing (25, 5, 7.5, 8.5) { + $filler->set_density($filler->spacing / $spacing); + $filler->set_angle($angle); + my $paths = $test->(my $e = Slic3r::ExPolygon->new( + [ scale_points [0,0], [100,0], [100,100], [0,100] ], + [ scale_points reverse [25,25], [75,25], [75,75], [25,75] ], + )); + + if (0) { + require "Slic3r/SVG.pm"; + Slic3r::SVG::output( + "fill.svg", + no_arrows => 1, + expolygons => [$e], + polylines => $paths, + ); + } + + ok(@$paths >= 2 && @$paths <= 3, '2 or 3 continuous paths') or done_testing, exit; + ok(!@{diff_pl($paths->arrayref, offset(\@$e, +scaled_epsilon*10))}, + 'paths don\'t cross hole') or done_testing, exit; + } + } +} + { my $expolygon = Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,50], [0,50] ]); my $filler = Slic3r::Filler->new_from_type('rectilinear'); @@ -41,6 +102,7 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ } nozzle_diameter => 0.50, ); $filler->set_spacing($flow->spacing); + $filler->set_density(1); foreach my $angle (0, 45) { $surface->expolygon->rotate(Slic3r::Geometry::deg2rad($angle), [0,0]); my $paths = $filler->fill_surface($surface, layer_height => 0.4, density => 0.4); @@ -55,6 +117,7 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ } my $filler = Slic3r::Filler->new_from_type('rectilinear'); $filler->set_bounding_box($expolygon->bounding_box); $filler->set_angle($angle // 0); + $filler->set_dont_adjust(0); my $surface = Slic3r::Surface->new( surface_type => S_TYPE_BOTTOM, expolygon => $expolygon, diff --git a/xs/MANIFEST b/xs/MANIFEST index 963dde283e..733bd09e08 100644 --- a/xs/MANIFEST +++ b/xs/MANIFEST @@ -40,8 +40,6 @@ src/libslic3r/Fill/FillPlanePath.cpp src/libslic3r/Fill/FillPlanePath.hpp src/libslic3r/Fill/FillRectilinear.cpp src/libslic3r/Fill/FillRectilinear.hpp -src/libslic3r/Fill/FillRectilinear2.cpp -src/libslic3r/Fill/FillRectilinear2.hpp src/libslic3r/Flow.cpp src/libslic3r/Flow.hpp src/libslic3r/GCode.cpp diff --git a/xs/src/libslic3r/Fill/Fill.cpp b/xs/src/libslic3r/Fill/Fill.cpp index 6f7b5486d7..82a392943e 100644 --- a/xs/src/libslic3r/Fill/Fill.cpp +++ b/xs/src/libslic3r/Fill/Fill.cpp @@ -11,7 +11,6 @@ #include "Fill3DHoneycomb.hpp" #include "FillPlanePath.hpp" #include "FillRectilinear.hpp" -#include "FillRectilinear2.hpp" namespace Slic3r { @@ -24,12 +23,9 @@ Fill::new_from_type(const InfillPattern type) case ip3DHoneycomb: return new Fill3DHoneycomb(); case ipRectilinear: return new FillRectilinear(); - case ipLine: return new FillLine(); - case ipGrid: return new FillGrid(); case ipAlignedRectilinear: return new FillAlignedRectilinear(); + case ipGrid: return new FillGrid(); - case ipRectilinear2: return new FillRectilinear2(); - case ipGrid2: return new FillGrid2(); case ipTriangles: return new FillTriangles(); case ipStars: return new FillStars(); case ipCubic: return new FillCubic(); @@ -80,11 +76,10 @@ Fill::adjust_solid_spacing(const coord_t width, const coord_t distance) { assert(width >= 0); assert(distance > 0); - // floor(width / distance) - coord_t number_of_intervals = floor(width / distance); - coord_t distance_new = (number_of_intervals == 0) - ? distance - : (width / number_of_intervals); + const int number_of_intervals = floor(width / distance); + if (number_of_intervals == 0) return distance; + + coord_t distance_new = (width / number_of_intervals); const coordf_t factor = coordf_t(distance_new) / coordf_t(distance); assert(factor > 1. - 1e-5); @@ -94,12 +89,14 @@ Fill::adjust_solid_spacing(const coord_t width, const coord_t distance) if (factor > factor_max) distance_new = floor((double)distance * factor_max + 0.5); + assert((distance_new * number_of_intervals) <= width); + return distance_new; } // Returns orientation of the infill and the reference point of the infill pattern. // For a normal print, the reference point is the center of a bounding box of the STL. -std::pair +Fill::direction_t Fill::_infill_direction(const Surface &surface) const { // set infill angle @@ -133,7 +130,7 @@ Fill::_infill_direction(const Surface &surface) const } out_angle += float(M_PI/2.); - return std::pair(out_angle, out_shift); + return direction_t(out_angle, out_shift); } } // namespace Slic3r diff --git a/xs/src/libslic3r/Fill/Fill.hpp b/xs/src/libslic3r/Fill/Fill.hpp index 266dad4c69..a733a870db 100644 --- a/xs/src/libslic3r/Fill/Fill.hpp +++ b/xs/src/libslic3r/Fill/Fill.hpp @@ -29,6 +29,9 @@ public: // in unscaled coordinates coordf_t spacing; + // overlap over spacing for extrusion endpoints + float endpoints_overlap; + // in radians, ccw, 0 = East float angle; @@ -80,6 +83,7 @@ protected: layer_id(size_t(-1)), z(0.f), spacing(0.f), + endpoints_overlap(0.3f), angle(0), link_max_length(0), loop_clipping(0), @@ -89,10 +93,12 @@ protected: complete(false) {}; + typedef std::pair direction_t; + // The expolygon may be modified by the method to avoid a copy. virtual void _fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out) {}; @@ -101,7 +107,7 @@ protected: return (idx % 2) == 0 ? (M_PI/2.) : 0; }; - std::pair _infill_direction(const Surface &surface) const; + direction_t _infill_direction(const Surface &surface) const; }; } // namespace Slic3r diff --git a/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp b/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp index 1c316e9209..3f523b27c9 100644 --- a/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp +++ b/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp @@ -150,7 +150,7 @@ makeGrid(coord_t z, coord_t gridSize, size_t gridWidth, size_t gridHeight, size_ void Fill3DHoneycomb::_fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out) { diff --git a/xs/src/libslic3r/Fill/Fill3DHoneycomb.hpp b/xs/src/libslic3r/Fill/Fill3DHoneycomb.hpp index 82699397ff..43d43ab838 100644 --- a/xs/src/libslic3r/Fill/Fill3DHoneycomb.hpp +++ b/xs/src/libslic3r/Fill/Fill3DHoneycomb.hpp @@ -21,7 +21,7 @@ public: protected: virtual void _fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out); }; diff --git a/xs/src/libslic3r/Fill/FillConcentric.cpp b/xs/src/libslic3r/Fill/FillConcentric.cpp index bf537e532d..cb09993b9e 100644 --- a/xs/src/libslic3r/Fill/FillConcentric.cpp +++ b/xs/src/libslic3r/Fill/FillConcentric.cpp @@ -9,7 +9,7 @@ namespace Slic3r { void FillConcentric::_fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out) { diff --git a/xs/src/libslic3r/Fill/FillConcentric.hpp b/xs/src/libslic3r/Fill/FillConcentric.hpp index 7bb7687f5d..f19a5d2b1d 100644 --- a/xs/src/libslic3r/Fill/FillConcentric.hpp +++ b/xs/src/libslic3r/Fill/FillConcentric.hpp @@ -14,7 +14,7 @@ protected: virtual Fill* clone() const { return new FillConcentric(*this); }; virtual void _fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out); diff --git a/xs/src/libslic3r/Fill/FillHoneycomb.cpp b/xs/src/libslic3r/Fill/FillHoneycomb.cpp index 127d7a8105..df4e62a3d1 100644 --- a/xs/src/libslic3r/Fill/FillHoneycomb.cpp +++ b/xs/src/libslic3r/Fill/FillHoneycomb.cpp @@ -9,7 +9,7 @@ namespace Slic3r { void FillHoneycomb::_fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out) { diff --git a/xs/src/libslic3r/Fill/FillHoneycomb.hpp b/xs/src/libslic3r/Fill/FillHoneycomb.hpp index 8fdb00265f..b048a3b2f4 100644 --- a/xs/src/libslic3r/Fill/FillHoneycomb.hpp +++ b/xs/src/libslic3r/Fill/FillHoneycomb.hpp @@ -18,7 +18,7 @@ protected: virtual Fill* clone() const { return new FillHoneycomb(*this); }; virtual void _fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out ); diff --git a/xs/src/libslic3r/Fill/FillPlanePath.cpp b/xs/src/libslic3r/Fill/FillPlanePath.cpp index 3dad299f41..09b0ea7000 100644 --- a/xs/src/libslic3r/Fill/FillPlanePath.cpp +++ b/xs/src/libslic3r/Fill/FillPlanePath.cpp @@ -8,7 +8,7 @@ namespace Slic3r { void FillPlanePath::_fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out) { diff --git a/xs/src/libslic3r/Fill/FillPlanePath.hpp b/xs/src/libslic3r/Fill/FillPlanePath.hpp index 04fb225a8a..7e308aac53 100644 --- a/xs/src/libslic3r/Fill/FillPlanePath.hpp +++ b/xs/src/libslic3r/Fill/FillPlanePath.hpp @@ -21,7 +21,7 @@ public: protected: virtual void _fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out); diff --git a/xs/src/libslic3r/Fill/FillRectilinear.cpp b/xs/src/libslic3r/Fill/FillRectilinear.cpp index 8fa3114712..632314d22e 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear.cpp @@ -2,138 +2,479 @@ #include "../ExPolygon.hpp" #include "../PolylineCollection.hpp" #include "../Surface.hpp" +#include +#include #include "FillRectilinear.hpp" +//#define DEBUG_RECTILINEAR +#ifdef DEBUG_RECTILINEAR + #include "../SVG.hpp" +#endif + namespace Slic3r { -void FillRectilinear::_fill_surface_single( - unsigned int thickness_layers, - const std::pair &direction, - ExPolygon &expolygon, - Polylines* polylines_out) +void +FillRectilinear::_fill_single_direction(ExPolygon expolygon, + const direction_t &direction, coord_t x_shift, Polylines* out) { - assert(this->density > 0.0001f && this->density <= 1.f); - // rotate polygons so that we can work with vertical lines here expolygon.rotate(-direction.first); - this->_min_spacing = scale_(this->spacing); - this->_line_spacing = coord_t(coordf_t(this->_min_spacing) / this->density); - this->_diagonal_distance = this->_line_spacing * 2; - this->_line_oscillation = this->_line_spacing - this->_min_spacing; // only for Line infill + assert(this->density > 0.0001f && this->density <= 1.f); + const coord_t min_spacing = scale_(this->spacing); + coord_t line_spacing = (double) min_spacing / this->density; // We ignore this->bounding_box because it doesn't matter; we're doing align_to_grid below. BoundingBox bounding_box = expolygon.contour.bounding_box(); + // Due to integer rounding, rotated polygons might not preserve verticality + // (i.e. when rotating by PI/2 two points having the same x coordinate + // they might get different y coordinates), thus the first line will be skipped. + bounding_box.offset(-1); + // define flow spacing according to requested density if (this->density > 0.9999f && !this->dont_adjust) { - this->_line_spacing = this->adjust_solid_spacing(bounding_box.size().x, this->_line_spacing); - this->spacing = unscale(this->_line_spacing); + line_spacing = this->adjust_solid_spacing(bounding_box.size().x, line_spacing); + this->spacing = unscale(line_spacing); } else { // extend bounding box so that our pattern will be aligned with other layers // Transform the reference point to the rotated coordinate system. + Point p = direction.second.rotated(-direction.first); + p.x -= x_shift > 0 ? x_shift : (x_shift + line_spacing); bounding_box.min.align_to_grid( - Point(this->_line_spacing, this->_line_spacing), - direction.second.rotated(-direction.first) + Point(line_spacing, line_spacing), + p ); } - - // generate the basic pattern - const coord_t x_max = bounding_box.max.x + SCALED_EPSILON; - Lines lines; - for (coord_t x = bounding_box.min.x; x <= x_max; x += this->_line_spacing) - lines.push_back(this->_line(lines.size(), x, bounding_box.min.y, bounding_box.max.y)); - if (this->_horizontal_lines()) { - const coord_t y_max = bounding_box.max.y + SCALED_EPSILON; - for (coord_t y = bounding_box.min.y; y <= y_max; y += this->_line_spacing) - lines.push_back(Line(Point(bounding_box.min.x, y), Point(bounding_box.max.x, y))); - } - - // clip paths against a slightly larger expolygon, so that the first and last paths - // are kept even if the expolygon has vertical sides - // the minimum offset for preventing edge lines from being clipped is SCALED_EPSILON; - // however we use a larger offset to support expolygons with slightly skewed sides and - // not perfectly straight - Polylines polylines = intersection_pl( - to_polylines(lines), - offset(expolygon, scale_(0.02)), - false - ); - - // FIXME Vojtech: This is only performed for horizontal lines, not for the vertical lines! - const float INFILL_OVERLAP_OVER_SPACING = 0.3f; + // Find all the polygons points intersecting the rectilinear vertical lines and store + // them in an std::map<> (grid) which orders them automatically by x and y. + // For each intersection point we store its position (upper/lower): upper means it's + // the upper endpoint of an intersection line, and vice versa. + // Whenever between two intersection points we find vertices of the original polygon, + // store them in the 'skipped' member of the latter point. - // How much to extend an infill path from expolygon outside? - const coord_t extra = coord_t(floor(this->_min_spacing * INFILL_OVERLAP_OVER_SPACING + 0.5f)); - for (Polylines::iterator it_polyline = polylines.begin(); - it_polyline != polylines.end(); ++ it_polyline) { - Point *first_point = &it_polyline->points.front(); - Point *last_point = &it_polyline->points.back(); - if (first_point->y > last_point->y) - std::swap(first_point, last_point); - first_point->y -= extra; - last_point->y += extra; - } - - size_t n_polylines_out_old = polylines_out->size(); - - // connect lines - if (!this->dont_connect && !polylines.empty()) { // prevent calling leftmost_point() on empty collections - // offset the expolygon by max(min_spacing/2, extra) - ExPolygon expolygon_off; - { - ExPolygons expolygons_off = offset_ex(expolygon, this->_min_spacing/2); - if (!expolygons_off.empty()) { - // When expanding a polygon, the number of islands could only shrink. - // Therefore the offset_ex shall generate exactly one expanded island - // for one input island. - assert(expolygons_off.size() == 1); - std::swap(expolygon_off, expolygons_off.front()); - } - } - Polylines chained = PolylineCollection::chained_path_from( - STDMOVE(polylines), - PolylineCollection::leftmost_point(polylines), - false // reverse allowed - ); - bool first = true; - for (Polylines::iterator it_polyline = chained.begin(); it_polyline != chained.end(); ++ it_polyline) { - if (!first) { - // Try to connect the lines. - Points &pts_end = polylines_out->back().points; - const Point &first_point = it_polyline->points.front(); - const Point &last_point = pts_end.back(); - // Distance in X, Y. - const Vector distance = first_point.vector_to(last_point); - // TODO: we should also check that both points are on a fill_boundary to avoid - // connecting paths on the boundaries of internal regions - if (this->_can_connect(std::abs(distance.x), std::abs(distance.y)) - && expolygon_off.contains(Line(last_point, first_point))) { - // Append the polyline. - append_to(pts_end, it_polyline->points); + grid_t grid; + { + const Polygons polygons = expolygon; + for (Polygons::const_iterator polygon = polygons.begin(); polygon != polygons.end(); ++polygon) { + const Points &points = polygon->points; + + // This vector holds the original polygon vertices found after the last intersection + // point. We'll flush it as soon as we find the next intersection point. + Points skipped_points; + + // This vector holds the coordinates of the intersection points found while + // looping through the polygon. + Points ips; + + for (Points::const_iterator p = points.begin(); p != points.end(); ++p) { + const Point &prev = p == points.begin() ? *(points.end()-1) : *(p-1); + const Point &next = p == points.end()-1 ? *points.begin() : *(p+1); + + // Does the p-next line belong to an intersection line? + if (p->x == next.x && ((p->x - bounding_box.min.x) % line_spacing) == 0) { + if (p->y == next.y) continue; // skip coinciding points + vertical_t &v = grid[p->x]; + + // Detect line direction. + IntersectionPoint::ipType p_type = IntersectionPoint::ipTypeLower; + IntersectionPoint::ipType n_type = IntersectionPoint::ipTypeUpper; + if (p->y > next.y) std::swap(p_type, n_type); // line goes downwards + + // Do we already have 'p' in our grid? + vertical_t::iterator pit = v.find(p->y); + if (pit != v.end()) { + // Yes, we have it. If its not of the same type, it means it's + // an intermediate point of a longer line. We store this information + // for now and we'll remove it later. + if (pit->second.type != p_type) + pit->second.type = IntersectionPoint::ipTypeMiddle; + } else { + // Store the point. + IntersectionPoint ip(p->x, p->y, p_type); + v[p->y] = ip; + ips.push_back(ip); + } + + // Do we already have 'next' in our grid? + pit = v.find(next.y); + if (pit != v.end()) { + // Yes, we have it. If its not of the same type, it means it's + // an intermediate point of a longer line. We store this information + // for now and we'll remove it later. + if (pit->second.type != n_type) + pit->second.type = IntersectionPoint::ipTypeMiddle; + } else { + // Store the point. + IntersectionPoint ip(next.x, next.y, n_type); + v[next.y] = ip; + ips.push_back(ip); + } continue; } + + // We're going to look for intersection points within this line. + // First, let's sort its x coordinates regardless of the original line direction. + const coord_t min_x = std::min(p->x, next.x); + const coord_t max_x = std::max(p->x, next.x); + + // Now find the leftmost intersection point belonging to the line. + const coord_t min_x2 = bounding_box.min.x + ceil((double) (min_x - bounding_box.min.x) / (double)line_spacing) * (double)line_spacing; + assert(min_x2 >= min_x); + + // In case this coordinate does not belong to this line, we have no intersection points. + if (min_x2 > max_x) { + // Store the two skipped points and move on. + skipped_points.push_back(*p); + skipped_points.push_back(next); + continue; + } + + // Find the rightmost intersection point belonging to the line. + const coord_t max_x2 = bounding_box.min.x + floor((double) (max_x - bounding_box.min.x) / (double) line_spacing) * (double)line_spacing; + assert(max_x2 <= max_x); + + // We're now going past the first point, so save it. + const bool line_goes_right = next.x > p->x; + if (line_goes_right ? (p->x < min_x2) : (p->x > max_x2)) + skipped_points.push_back(*p); + + // Now loop through those intersection points according the original direction + // of the line (because we need to store them in this order). + for (coord_t x = line_goes_right ? min_x2 : max_x2; + x >= min_x && x <= max_x; + x += line_goes_right ? +line_spacing : -line_spacing) { + + // Is this intersection an endpoint of the original line *and* is the + // intersection just a tangent point? If so, just skip it. + if (x == p->x && ((prev.x > x && next.x > x) || (prev.x < x && next.x < x))) { + skipped_points.push_back(*p); + continue; + } + if (x == next.x) { + const Point &next2 = p == (points.end()-2) ? *points.begin() + : p == (points.end()-1) ? *(points.begin()+1) : *(p+2); + if ((p->x > x && next2.x > x) || (p->x < x && next2.x < x)) { + skipped_points.push_back(next); + continue; + } + } + + // Calculate the y coordinate of this intersection. + IntersectionPoint ip( + x, + p->y + double(next.y - p->y) * double(x - p->x) / double(next.x - p->x), + line_goes_right ? IntersectionPoint::ipTypeLower : IntersectionPoint::ipTypeUpper + ); + vertical_t &v = grid[ip.x]; + + // Did we already find this point? + // (We might have found it as the endpoint of a vertical line.) + { + vertical_t::iterator pit = v.find(ip.y); + if (pit != v.end()) { + // Yes, we have it. If its not of the same type, it means it's + // an intermediate point of a longer line. We store this information + // for now and we'll remove it later. + if (pit->second.type != ip.type) + pit->second.type = IntersectionPoint::ipTypeMiddle; + continue; + } + } + + // Store the skipped polygon vertices along with this point. + ip.skipped = skipped_points; + skipped_points.clear(); + + #ifdef DEBUG_RECTILINEAR + printf("NEW POINT at %f,%f\n", unscale(ip.x), unscale(ip.y)); + for (Points::const_iterator it = ip.skipped.begin(); it != ip.skipped.end(); ++it) + printf(" skipped: %f,%f\n", unscale(it->x), unscale(it->y)); + #endif + + // Store the point. + v[ip.y] = ip; + ips.push_back(ip); + } + + // We're now going past the final point, so save it. + if (line_goes_right ? (next.x > max_x2) : (next.x < min_x2)) + skipped_points.push_back(next); + } + + if (!this->dont_connect) { + // We'll now build connections between the vertical intersection lines. + // Each intersection point will be connected to the first intersection point + // found along the original polygon having a greater x coordinate (or the same + // x coordinate: think about two vertical intersection lines having the same x + // separated by a hole polygon: we'll connect them with the hole portion). + // We will sweep only from left to right, so we only need to build connections + // in this direction. + for (Points::const_iterator it = ips.begin(); it != ips.end(); ++it) { + IntersectionPoint &ip = grid[it->x][it->y]; + IntersectionPoint &next = it == ips.end()-1 ? grid[ips.begin()->x][ips.begin()->y] : grid[(it+1)->x][(it+1)->y]; + + #ifdef DEBUG_RECTILINEAR + printf("CONNECTING %f,%f to %f,%f\n", + unscale(ip.x), unscale(ip.y), + unscale(next.x), unscale(next.y) + ); + #endif + + // We didn't flush the skipped_points vector after completing the loop above: + // it now contains the polygon vertices between the last and the first + // intersection points. + if (it == ips.begin()) + ip.skipped.insert(ip.skipped.begin(), skipped_points.begin(), skipped_points.end()); + + if (ip.x <= next.x) { + // Link 'ip' to 'next' ---> + if (ip.next.empty()) { + ip.next = next.skipped; + ip.next.push_back(next); + } + } else if (next.x < ip.x) { + // Link 'next' to 'ip' ---> + if (next.next.empty()) { + next.next = next.skipped; + std::reverse(next.next.begin(), next.next.end()); + next.next.push_back(ip); + } + } + } + } + + // Do some cleanup: remove the 'skipped' points we used for building + // connections and also remove the middle intersection points. + for (Points::const_iterator it = ips.begin(); it != ips.end(); ++it) { + vertical_t &v = grid[it->x]; + IntersectionPoint &ip = v[it->y]; + ip.skipped.clear(); + if (ip.type == IntersectionPoint::ipTypeMiddle) + v.erase(it->y); } - // The lines cannot be connected. - #if SLIC3R_CPPVER >= 11 - polylines_out->push_back(std::move(*it_polyline)); - #else - polylines_out->push_back(Polyline()); - std::swap(polylines_out->back(), *it_polyline); - #endif - first = false; } } - - // paths must be rotated back - for (Polylines::iterator it = polylines_out->begin() + n_polylines_out_old; - it != polylines_out->end(); ++ it) { - // No need to translate, the absolute position is irrelevant. - // it->translate(- direction.second.x, - direction.second.y); - it->rotate(direction.first); + + #ifdef DEBUG_RECTILINEAR + SVG svg("grid.svg"); + svg.draw(expolygon); + + printf("GRID:\n"); + for (grid_t::const_iterator it = grid.begin(); it != grid.end(); ++it) { + printf("x = %f:\n", unscale(it->first)); + for (vertical_t::const_iterator v = it->second.begin(); v != it->second.end(); ++v) { + const IntersectionPoint &ip = v->second; + printf(" y = %f (%s, next = %f,%f, extra = %zu)\n", unscale(v->first), + ip.type == IntersectionPoint::ipTypeLower ? "lower" + : ip.type == IntersectionPoint::ipTypeMiddle ? "middle" : "upper", + (ip.next.empty() ? -1 : unscale(ip.next.back().x)), + (ip.next.empty() ? -1 : unscale(ip.next.back().y)), + (ip.next.empty() ? 0 : ip.next.size()-1) + ); + svg.draw(ip, ip.type == IntersectionPoint::ipTypeLower ? "blue" + : ip.type == IntersectionPoint::ipTypeMiddle ? "yellow" : "red"); + } } + printf("\n"); + + svg.Close(); + #endif + + // Calculate the extension of the vertical endpoints according to the configured value. + const coord_t extra_y = floor((double)min_spacing * this->endpoints_overlap + 0.5f); + + // Store the number of polygons already existing in the output container. + const size_t n_polylines_out_old = out->size(); + + // Loop until we have no more vertical lines available. + while (!grid.empty()) { + // Get the first x coordinate. + vertical_t &v = grid.begin()->second; + + // If this x coordinate does not have any y coordinate, remove it. + if (v.empty()) { + grid.erase(grid.begin()); + continue; + } + + // We expect every x coordinate to contain an even number of y coordinates + // because they are the endpoints of vertical intersection lines: + // lower/upper, lower/upper etc. + assert(v.size() % 2 == 0); + + // Get the first lower point. + vertical_t::iterator it = v.begin(); // minimum x,y + IntersectionPoint p = it->second; + assert(p.type == IntersectionPoint::ipTypeLower); + + // Start our polyline. + Polyline polyline; + polyline.append(p); + polyline.points.back().y -= extra_y; + + while (true) { + // Complete the vertical line by finding the corresponding upper or lower point. + if (p.type == IntersectionPoint::ipTypeUpper) { + // find first point along c.x with y < c.y + assert(it != grid[p.x].begin()); + --it; + } else { + // find first point along c.x with y > c.y + ++it; + assert(it != grid[p.x].end()); + } + + // Append the point to our polyline. + IntersectionPoint b = it->second; + assert(b.type != p.type); + polyline.append(b); + polyline.points.back().y += extra_y * (b.type == IntersectionPoint::ipTypeUpper ? 1 : -1); + + // Remove the two endpoints of this vertical line from the grid. + { + vertical_t &v = grid[p.x]; + v.erase(p.y); + v.erase(it); + if (v.empty()) grid.erase(p.x); + } + // Do we have a connection starting from here? + // If not, stop the polyline. + if (b.next.empty()) + break; + + // If we have a connection, append it to the polyline. + // We apply the y extension to the whole connection line. This works well when + // the connection is straight and horizontal, but doesn't work well when the + // connection is articulated and also has vertical parts. + { + // TODO: here's where we should check for overextrusion. We should only add + // connection points while they are not generating vertical lines within the + // extrusion thickness of the main vertical lines. We should also check whether + // a previous run of this method occupied this polygon portion (derived infill + // patterns doing multiple runs at different angles generate overlapping connections). + // In both cases, we should just stop the connection and break the polyline here. + const size_t n = polyline.points.size(); + polyline.append(b.next); + for (Points::iterator pit = polyline.points.begin()+n; pit != polyline.points.end(); ++pit) + pit->y += extra_y * (b.type == IntersectionPoint::ipTypeUpper ? 1 : -1); + } + + // Is the final point still available? + if (grid.count(b.next.back().x) == 0 + || grid[b.next.back().x].count(b.next.back().y) == 0) + // We already used this point or we might have removed this + // point while building the grid because it's collinear (middle); in either + // cases the connection line from the previous one is legit and worth having. + break; + + // Retrieve the intersection point. The next loop will find the correspondent + // endpoint of the vertical line. + it = grid[ b.next.back().x ].find(b.next.back().y); + p = it->second; + + // If the connection brought us to another x coordinate, we expect the point + // type to be the same. + assert((p.type == b.type && p.x > b.x) + || (p.type != b.type && p.x == b.x)); + } + + // Yay, we have a polyline! + if (polyline.is_valid()) + out->push_back(polyline); + } + + // paths must be rotated back + for (Polylines::iterator it = out->begin() + n_polylines_out_old; + it != out->end(); ++it) + it->rotate(direction.first); +} + +void FillRectilinear::_fill_surface_single( + unsigned int thickness_layers, + const direction_t &direction, + ExPolygon &expolygon, + Polylines* out) +{ + this->_fill_single_direction(expolygon, direction, 0, out); +} + +void FillGrid::_fill_surface_single( + unsigned int thickness_layers, + const direction_t &direction, + ExPolygon &expolygon, + Polylines* out) +{ + FillGrid fill2 = *this; + fill2.density /= 2.; + + direction_t direction2 = direction; + direction2.first += PI/2; + fill2._fill_single_direction(expolygon, direction, 0, out); + fill2._fill_single_direction(expolygon, direction2, 0, out); +} + +void FillTriangles::_fill_surface_single( + unsigned int thickness_layers, + const direction_t &direction, + ExPolygon &expolygon, + Polylines* out) +{ + FillTriangles fill2 = *this; + fill2.density /= 3.; + direction_t direction2 = direction; + + fill2._fill_single_direction(expolygon, direction2, 0, out); + + direction2.first += PI/3; + fill2._fill_single_direction(expolygon, direction2, 0, out); + + direction2.first += PI/3; + fill2._fill_single_direction(expolygon, direction2, 0, out); +} + +void FillStars::_fill_surface_single( + unsigned int thickness_layers, + const direction_t &direction, + ExPolygon &expolygon, + Polylines* out) +{ + FillStars fill2 = *this; + fill2.density /= 3.; + direction_t direction2 = direction; + + fill2._fill_single_direction(expolygon, direction2, 0, out); + + direction2.first += PI/3; + fill2._fill_single_direction(expolygon, direction2, 0, out); + + direction2.first += PI/3; + const coord_t x_shift = 0.5 * scale_(fill2.spacing) / fill2.density; + fill2._fill_single_direction(expolygon, direction2, x_shift, out); +} + +void FillCubic::_fill_surface_single( + unsigned int thickness_layers, + const direction_t &direction, + ExPolygon &expolygon, + Polylines* out) +{ + FillCubic fill2 = *this; + fill2.density /= 3.; + direction_t direction2 = direction; + + const coord_t range = scale_(this->spacing / this->density); + const coord_t x_shift = abs(( (coord_t)(scale_(this->z) + range) % (coord_t)(range * 2)) - range); + + fill2._fill_single_direction(expolygon, direction2, -x_shift, out); + + direction2.first += PI/3; + fill2._fill_single_direction(expolygon, direction2, +x_shift, out); + + direction2.first += PI/3; + fill2._fill_single_direction(expolygon, direction2, -x_shift, out); } } // namespace Slic3r diff --git a/xs/src/libslic3r/Fill/FillRectilinear.hpp b/xs/src/libslic3r/Fill/FillRectilinear.hpp index d2bd8d7775..6d493fbc71 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear.hpp +++ b/xs/src/libslic3r/Fill/FillRectilinear.hpp @@ -16,61 +16,33 @@ public: protected: virtual void _fill_surface_single( unsigned int thickness_layers, - const std::pair &direction, + const direction_t &direction, ExPolygon &expolygon, Polylines* polylines_out); - - coord_t _min_spacing; - coord_t _line_spacing; - // distance threshold for allowing the horizontal infill lines to be connected into a continuous path - coord_t _diagonal_distance; - // only for line infill - coord_t _line_oscillation; - - // Enabled for the grid infill, disabled for the rectilinear and line infill. - virtual bool _horizontal_lines() const { return false; }; - - virtual Line _line(int i, coord_t x, coord_t y_min, coord_t y_max) const - { return Line(Point(x, y_min), Point(x, y_max)); }; - - virtual bool _can_connect(coord_t dist_X, coord_t dist_Y) { - return dist_X <= this->_diagonal_distance - && dist_Y <= this->_diagonal_distance; + + void _fill_single_direction(ExPolygon expolygon, const direction_t &direction, + coord_t x_shift, Polylines* out); + + struct IntersectionPoint : Point { + enum ipType { ipTypeLower, ipTypeUpper, ipTypeMiddle }; + ipType type; + + // skipped contains the polygon points accumulated between the previous intersection + // point and the current one, in the original polygon winding order (does not contain + // either points) + Points skipped; + + // next contains a polygon portion connecting this point to the first intersection + // point found following the polygon in any direction but having: + // x > this->x || (x == this->x && y > this->y) + // (it doesn't contain *this but it contains the target intersection point) + Points next; + + IntersectionPoint() : Point() {}; + IntersectionPoint(coord_t x, coord_t y, ipType _type) : Point(x,y), type(_type) {}; }; -}; - -class FillLine : public FillRectilinear -{ -public: - virtual Fill* clone() const { return new FillLine(*this); }; - virtual ~FillLine() {} - -protected: - virtual Line _line(int i, coord_t x, coord_t y_min, coord_t y_max) const { - coord_t osc = (i & 1) ? this->_line_oscillation : 0; - return Line(Point(x - osc, y_min), Point(x + osc, y_max)); - }; - - virtual bool _can_connect(coord_t dist_X, coord_t dist_Y) - { - coord_t TOLERANCE = 10 * SCALED_EPSILON; - return (dist_X >= (this->_line_spacing - this->_line_oscillation) - TOLERANCE) - && (dist_X <= (this->_line_spacing + this->_line_oscillation) + TOLERANCE) - && (dist_Y <= this->_diagonal_distance); - }; -}; - -class FillGrid : public FillRectilinear -{ -public: - virtual Fill* clone() const { return new FillGrid(*this); }; - virtual ~FillGrid() {} - -protected: - // The grid fill will keep the angle constant between the layers,; see the implementation of Slic3r::Fill. - virtual float _layer_angle(size_t idx) const { return 0.f; } - // Flag for Slic3r::Fill::Rectilinear to fill both directions. - virtual bool _horizontal_lines() const { return true; }; + typedef std::map vertical_t; // + typedef std::map grid_t; // > }; class FillAlignedRectilinear : public FillRectilinear @@ -84,6 +56,74 @@ protected: virtual float _layer_angle(size_t idx) const { return 0.f; }; }; +class FillGrid : public FillRectilinear +{ +public: + virtual Fill* clone() const { return new FillGrid(*this); }; + virtual ~FillGrid() {} + +protected: + // The grid fill will keep the angle constant between the layers,; see the implementation of Slic3r::Fill. + virtual float _layer_angle(size_t idx) const { return 0.f; } + + virtual void _fill_surface_single( + unsigned int thickness_layers, + const std::pair &direction, + ExPolygon &expolygon, + Polylines* polylines_out); +}; + +class FillTriangles : public FillRectilinear +{ +public: + virtual Fill* clone() const { return new FillTriangles(*this); }; + virtual ~FillTriangles() {} + +protected: + // The grid fill will keep the angle constant between the layers,; see the implementation of Slic3r::Fill. + virtual float _layer_angle(size_t idx) const { return 0.f; } + + virtual void _fill_surface_single( + unsigned int thickness_layers, + const std::pair &direction, + ExPolygon &expolygon, + Polylines* polylines_out); +}; + +class FillStars : public FillRectilinear +{ +public: + virtual Fill* clone() const { return new FillStars(*this); }; + virtual ~FillStars() {} + +protected: + // The grid fill will keep the angle constant between the layers,; see the implementation of Slic3r::Fill. + virtual float _layer_angle(size_t idx) const { return 0.f; } + + virtual void _fill_surface_single( + unsigned int thickness_layers, + const std::pair &direction, + ExPolygon &expolygon, + Polylines* polylines_out); +}; + +class FillCubic : public FillRectilinear +{ +public: + virtual Fill* clone() const { return new FillCubic(*this); }; + virtual ~FillCubic() {} + +protected: + // The grid fill will keep the angle constant between the layers,; see the implementation of Slic3r::Fill. + virtual float _layer_angle(size_t idx) const { return 0.f; } + + virtual void _fill_surface_single( + unsigned int thickness_layers, + const std::pair &direction, + ExPolygon &expolygon, + Polylines* polylines_out); +}; + }; // namespace Slic3r #endif // slic3r_FillRectilinear_hpp_ diff --git a/xs/src/libslic3r/Fill/FillRectilinear2.cpp b/xs/src/libslic3r/Fill/FillRectilinear2.cpp deleted file mode 100644 index 653bb789ee..0000000000 --- a/xs/src/libslic3r/Fill/FillRectilinear2.cpp +++ /dev/null @@ -1,1712 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -#include "../ClipperUtils.hpp" -#include "../ExPolygon.hpp" -#include "../Surface.hpp" - -#include "FillRectilinear2.hpp" - -// #define SLIC3R_DEBUG - -// Make assert active if SLIC3R_DEBUG -#ifdef SLIC3R_DEBUG - #undef NDEBUG - #include "SVG.hpp" -#endif - -#include - -// We want our version of assert. -#include "../libslic3r.h" - -#ifndef myassert -#define myassert assert -#endif - -namespace Slic3r { - -#ifndef clamp -template -static inline T clamp(T low, T high, T x) -{ - return std::max(low, std::min(high, x)); -} -#endif /* clamp */ - -#ifndef sqr -template -static inline T sqr(T x) -{ - return x * x; -} -#endif /* sqr */ - -#ifndef mag2 -static inline coordf_t mag2(const Point &p) -{ - return sqr(coordf_t(p.x)) + sqr(coordf_t(p.y)); -} -#endif /* mag2 */ - -#ifndef mag -static inline coordf_t mag(const Point &p) -{ - return std::sqrt(mag2(p)); -} -#endif /* mag */ - -enum Orientation -{ - ORIENTATION_CCW = 1, - ORIENTATION_CW = -1, - ORIENTATION_COLINEAR = 0 -}; - -// Return orientation of the three points (clockwise, counter-clockwise, colinear) -// The predicate is exact for the coord_t type, using 64bit signed integers for the temporaries. -//FIXME Make sure the temporaries do not overflow, -// which means, the coord_t types must not have some of the topmost bits utilized. -static inline Orientation orient(const Point &a, const Point &b, const Point &c) -{ - // BOOST_STATIC_ASSERT(sizeof(coord_t) * 2 == sizeof(int64_t)); - int64_t u = int64_t(b.x) * int64_t(c.y) - int64_t(b.y) * int64_t(c.x); - int64_t v = int64_t(a.x) * int64_t(c.y) - int64_t(a.y) * int64_t(c.x); - int64_t w = int64_t(a.x) * int64_t(b.y) - int64_t(a.y) * int64_t(b.x); - int64_t d = u - v + w; - return (d > 0) ? ORIENTATION_CCW : ((d == 0) ? ORIENTATION_COLINEAR : ORIENTATION_CW); -} - -// Return orientation of the polygon. -// The input polygon must not contain duplicate points. -static inline bool is_ccw(const Polygon &poly) -{ - // The polygon shall be at least a triangle. - myassert(poly.points.size() >= 3); - if (poly.points.size() < 3) - return true; - - // 1) Find the lowest lexicographical point. - size_t imin = 0; - for (size_t i = 1; i < poly.points.size(); ++ i) { - const Point &pmin = poly.points[imin]; - const Point &p = poly.points[i]; - if (p.x < pmin.x || (p.x == pmin.x && p.y < pmin.y)) - imin = i; - } - - // 2) Detect the orientation of the corner imin. - size_t iPrev = ((imin == 0) ? poly.points.size() : imin) - 1; - size_t iNext = ((imin + 1 == poly.points.size()) ? 0 : imin + 1); - Orientation o = orient(poly.points[iPrev], poly.points[imin], poly.points[iNext]); - // The lowest bottom point must not be collinear if the polygon does not contain duplicate points - // or overlapping segments. - myassert(o != ORIENTATION_COLINEAR); - return o == ORIENTATION_CCW; -} - -// Having a segment of a closed polygon, calculate its Euclidian length. -// The segment indices seg1 and seg2 signify an end point of an edge in the forward direction of the loop, -// therefore the point p1 lies on poly.points[seg1-1], poly.points[seg1] etc. -static inline coordf_t segment_length(const Polygon &poly, size_t seg1, const Point &p1, size_t seg2, const Point &p2) -{ -#ifdef SLIC3R_DEBUG - // Verify that p1 lies on seg1. This is difficult to verify precisely, - // but at least verify, that p1 lies in the bounding box of seg1. - for (size_t i = 0; i < 2; ++ i) { - size_t seg = (i == 0) ? seg1 : seg2; - Point px = (i == 0) ? p1 : p2; - Point pa = poly.points[((seg == 0) ? poly.points.size() : seg) - 1]; - Point pb = poly.points[seg]; - if (pa.x > pb.x) - std::swap(pa.x, pb.x); - if (pa.y > pb.y) - std::swap(pa.y, pb.y); - myassert(px.x >= pa.x && px.x <= pb.x); - myassert(px.y >= pa.y && px.y <= pb.y); - } -#endif /* SLIC3R_DEBUG */ - const Point *pPrev = &p1; - const Point *pThis = NULL; - coordf_t len = 0; - if (seg1 <= seg2) { - for (size_t i = seg1; i < seg2; ++ i, pPrev = pThis) - len += pPrev->distance_to(*(pThis = &poly.points[i])); - } else { - for (size_t i = seg1; i < poly.points.size(); ++ i, pPrev = pThis) - len += pPrev->distance_to(*(pThis = &poly.points[i])); - for (size_t i = 0; i < seg2; ++ i, pPrev = pThis) - len += pPrev->distance_to(*(pThis = &poly.points[i])); - } - len += pPrev->distance_to(p2); - return len; -} - -// Append a segment of a closed polygon to a polyline. -// The segment indices seg1 and seg2 signify an end point of an edge in the forward direction of the loop. -// Only insert intermediate points between seg1 and seg2. -static inline void polygon_segment_append(Points &out, const Polygon &polygon, size_t seg1, size_t seg2) -{ - if (seg1 == seg2) { - // Nothing to append from this segment. - } else if (seg1 < seg2) { - // Do not append a point pointed to by seg2. - out.insert(out.end(), polygon.points.begin() + seg1, polygon.points.begin() + seg2); - } else { - out.reserve(out.size() + seg2 + polygon.points.size() - seg1); - out.insert(out.end(), polygon.points.begin() + seg1, polygon.points.end()); - // Do not append a point pointed to by seg2. - out.insert(out.end(), polygon.points.begin(), polygon.points.begin() + seg2); - } -} - -// Append a segment of a closed polygon to a polyline. -// The segment indices seg1 and seg2 signify an end point of an edge in the forward direction of the loop, -// but this time the segment is traversed backward. -// Only insert intermediate points between seg1 and seg2. -static inline void polygon_segment_append_reversed(Points &out, const Polygon &polygon, size_t seg1, size_t seg2) -{ - if (seg1 >= seg2) { - out.reserve(seg1 - seg2); - for (size_t i = seg1; i > seg2; -- i) - out.push_back(polygon.points[i - 1]); - } else { - // it could be, that seg1 == seg2. In that case, append the complete loop. - out.reserve(out.size() + seg2 + polygon.points.size() - seg1); - for (size_t i = seg1; i > 0; -- i) - out.push_back(polygon.points[i - 1]); - for (size_t i = polygon.points.size(); i > seg2; -- i) - out.push_back(polygon.points[i - 1]); - } -} - -// Intersection point of a vertical line with a polygon segment. -class SegmentIntersection -{ -public: - SegmentIntersection() : - iContour(0), - iSegment(0), - pos_p(0), - pos_q(1), - type(UNKNOWN), - consumed_vertical_up(false), - consumed_perimeter_right(false) - {} - - // Index of a contour in ExPolygonWithOffset, with which this vertical line intersects. - size_t iContour; - // Index of a segment in iContour, with which this vertical line intersects. - size_t iSegment; - // y position of the intersection, ratinal number. - int64_t pos_p; - uint32_t pos_q; - - coord_t pos() const { - // Division rounds both positive and negative down to zero. - // Add half of q for an arithmetic rounding effect. - int64_t p = pos_p; - if (p < 0) - p -= int64_t(pos_q>>1); - else - p += int64_t(pos_q>>1); - return coord_t(p / int64_t(pos_q)); - } - - // Kind of intersection. With the original contour, or with the inner offestted contour? - // A vertical segment will be at least intersected by OUTER_LOW, OUTER_HIGH, - // but it could be intersected with OUTER_LOW, INNER_LOW, INNER_HIGH, OUTER_HIGH, - // and there may be more than one pair of INNER_LOW, INNER_HIGH between OUTER_LOW, OUTER_HIGH. - enum SegmentIntersectionType { - OUTER_LOW = 0, - OUTER_HIGH = 1, - INNER_LOW = 2, - INNER_HIGH = 3, - UNKNOWN = -1 - }; - SegmentIntersectionType type; - - // Was this segment along the y axis consumed? - // Up means up along the vertical segment. - bool consumed_vertical_up; - // Was a segment of the inner perimeter contour consumed? - // Right means right from the vertical segment. - bool consumed_perimeter_right; - - // For the INNER_LOW type, this point may be connected to another INNER_LOW point following a perimeter contour. - // For the INNER_HIGH type, this point may be connected to another INNER_HIGH point following a perimeter contour. - // If INNER_LOW is connected to INNER_HIGH or vice versa, - // one has to make sure the vertical infill line does not overlap with the connecting perimeter line. - bool is_inner() const { return type == INNER_LOW || type == INNER_HIGH; } - bool is_outer() const { return type == OUTER_LOW || type == OUTER_HIGH; } - bool is_low () const { return type == INNER_LOW || type == OUTER_LOW; } - bool is_high () const { return type == INNER_HIGH || type == OUTER_HIGH; } - - // Compare two y intersection points given by rational numbers. - // Note that the rational number is given as pos_p/pos_q, where pos_p is int64 and pos_q is uint32. - // This function calculates pos_p * other.pos_q < other.pos_p * pos_q as a 48bit number. - // We don't use 128bit intrinsic data types as these are usually not supported by 32bit compilers and - // we don't need the full 128bit precision anyway. - bool operator<(const SegmentIntersection &other) const - { - assert(pos_q > 0); - assert(other.pos_q > 0); - if (pos_p == 0 || other.pos_p == 0) { - // Because the denominators are positive and one of the nominators is zero, - // following simple statement holds. - return pos_p < other.pos_p; - } else { - // None of the nominators is zero. - char sign1 = (pos_p > 0) ? 1 : -1; - char sign2 = (other.pos_p > 0) ? 1 : -1; - char signs = sign1 * sign2; - assert(signs == 1 || signs == -1); - if (signs < 0) { - // The nominators have different signs. - return sign1 < 0; - } else { - // The nominators have the same sign. - // Absolute values - uint64_t p1, p2; - if (sign1 > 0) { - p1 = uint64_t(pos_p); - p2 = uint64_t(other.pos_p); - } else { - p1 = uint64_t(- pos_p); - p2 = uint64_t(- other.pos_p); - }; - // Multiply low and high 32bit words of p1 by other_pos.q - // 32bit x 32bit => 64bit - // l_hi and l_lo overlap by 32 bits. - uint64_t l_hi = (p1 >> 32) * uint64_t(other.pos_q); - uint64_t l_lo = (p1 & 0xffffffffll) * uint64_t(other.pos_q); - l_hi += (l_lo >> 32); - uint64_t r_hi = (p2 >> 32) * uint64_t(pos_q); - uint64_t r_lo = (p2 & 0xffffffffll) * uint64_t(pos_q); - r_hi += (r_lo >> 32); - // Compare the high 64 bits. - if (l_hi == r_hi) { - // Compare the low 32 bits. - l_lo &= 0xffffffffll; - r_lo &= 0xffffffffll; - return (sign1 < 0) ? (l_lo > r_lo) : (l_lo < r_lo); - } - return (sign1 < 0) ? (l_hi > r_hi) : (l_hi < r_hi); - } - } - } - - bool operator==(const SegmentIntersection &other) const - { - assert(pos_q > 0); - assert(other.pos_q > 0); - if (pos_p == 0 || other.pos_p == 0) { - // Because the denominators are positive and one of the nominators is zero, - // following simple statement holds. - return pos_p == other.pos_p; - } - - // None of the nominators is zero, none of the denominators is zero. - bool positive = pos_p > 0; - if (positive != (other.pos_p > 0)) - return false; - // The nominators have the same sign. - // Absolute values - uint64_t p1 = positive ? uint64_t(pos_p) : uint64_t(- pos_p); - uint64_t p2 = positive ? uint64_t(other.pos_p) : uint64_t(- other.pos_p); - // Multiply low and high 32bit words of p1 by other_pos.q - // 32bit x 32bit => 64bit - // l_hi and l_lo overlap by 32 bits. - uint64_t l_lo = (p1 & 0xffffffffll) * uint64_t(other.pos_q); - uint64_t r_lo = (p2 & 0xffffffffll) * uint64_t(pos_q); - if (l_lo != r_lo) - return false; - uint64_t l_hi = (p1 >> 32) * uint64_t(other.pos_q); - uint64_t r_hi = (p2 >> 32) * uint64_t(pos_q); - return l_hi + (l_lo >> 32) == r_hi + (r_lo >> 32); - } -}; - -// A vertical line with intersection points with polygons. -class SegmentedIntersectionLine -{ -public: - // Index of this vertical intersection line. - size_t idx; - // x position of this vertical intersection line. - coord_t pos; - // List of intersection points with polygons, sorted increasingly by the y axis. - std::vector intersections; -}; - -// A container maintaining an expolygon with its inner offsetted polygon. -// The purpose of the inner offsetted polygon is to provide segments to connect the infill lines. -struct ExPolygonWithOffset -{ -public: - ExPolygonWithOffset( - const ExPolygon &expolygon, - float angle, - coord_t aoffset1, - coord_t aoffset2) - { - // Copy and rotate the source polygons. - polygons_src = expolygon; - polygons_src.contour.rotate(angle); - for (Polygons::iterator it = polygons_src.holes.begin(); it != polygons_src.holes.end(); ++ it) - it->rotate(angle); - - double mitterLimit = 3.; - // for the infill pattern, don't cut the corners. - // default miterLimt = 3 - //double mitterLimit = 10.; - myassert(aoffset1 < 0); - myassert(aoffset2 < 0); - myassert(aoffset2 < aoffset1); -// bool sticks_removed = remove_sticks(polygons_src); -// if (sticks_removed) printf("Sticks removed!\n"); - polygons_outer = offset(polygons_src, aoffset1, - CLIPPER_OFFSET_SCALE, - ClipperLib::jtMiter, - mitterLimit); - polygons_inner = offset(polygons_outer, aoffset2 - aoffset1, - CLIPPER_OFFSET_SCALE, - ClipperLib::jtMiter, - mitterLimit); - // Filter out contours with zero area or small area, contours with 2 points only. - const double min_area_threshold = 0.01 * aoffset2 * aoffset2; - remove_small(polygons_outer, min_area_threshold); - remove_small(polygons_inner, min_area_threshold); - remove_sticks(polygons_outer); - remove_sticks(polygons_inner); - n_contours_outer = polygons_outer.size(); - n_contours_inner = polygons_inner.size(); - n_contours = n_contours_outer + n_contours_inner; - polygons_ccw.assign(n_contours, false); - for (size_t i = 0; i < n_contours; ++ i) { - contour(i).remove_duplicate_points(); - myassert(! contour(i).has_duplicate_points()); - polygons_ccw[i] = is_ccw(contour(i)); - } - } - - // Any contour with offset1 - bool is_contour_outer(size_t idx) const { return idx < n_contours_outer; } - // Any contour with offset2 - bool is_contour_inner(size_t idx) const { return idx >= n_contours_outer; } - - const Polygon& contour(size_t idx) const - { return is_contour_outer(idx) ? polygons_outer[idx] : polygons_inner[idx - n_contours_outer]; } - - Polygon& contour(size_t idx) - { return is_contour_outer(idx) ? polygons_outer[idx] : polygons_inner[idx - n_contours_outer]; } - - bool is_contour_ccw(size_t idx) const { return polygons_ccw[idx]; } - -#ifdef SLIC3R_DEBUG - void export_to_svg(Slic3r::SVG &svg) { - //svg.draw_outline(polygons_src, "black"); - //svg.draw_outline(polygons_outer, "green"); - //svg.draw_outline(polygons_inner, "brown"); - } -#endif /* SLIC3R_DEBUG */ - - ExPolygon polygons_src; - Polygons polygons_outer; - Polygons polygons_inner; - - size_t n_contours_outer; - size_t n_contours_inner; - size_t n_contours; - -protected: - // For each polygon of polygons_inner, remember its orientation. - std::vector polygons_ccw; -}; - -static inline int distance_of_segmens(const Polygon &poly, size_t seg1, size_t seg2, bool forward) -{ - int d = int(seg2) - int(seg1); - if (! forward) - d = - d; - if (d < 0) - d += int(poly.points.size()); - return d; -} - -// For a vertical line, an inner contour and an intersection point, -// find an intersection point on the previous resp. next vertical line. -// The intersection point is connected with the prev resp. next intersection point with iInnerContour. -// Return -1 if there is no such point on the previous resp. next vertical line. -static inline int intersection_on_prev_next_vertical_line( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection, - bool dir_is_next) -{ - size_t iVerticalLineOther = iVerticalLine; - if (dir_is_next) { - if (++ iVerticalLineOther == segs.size()) - // No successive vertical line. - return -1; - } else if (iVerticalLineOther -- == 0) { - // No preceding vertical line. - return -1; - } - - const SegmentedIntersectionLine &il = segs[iVerticalLine]; - const SegmentIntersection &itsct = il.intersections[iIntersection]; - const SegmentedIntersectionLine &il2 = segs[iVerticalLineOther]; - const Polygon &poly = poly_with_offset.contour(iInnerContour); -// const bool ccw = poly_with_offset.is_contour_ccw(iInnerContour); - const bool forward = itsct.is_low() == dir_is_next; - // Resulting index of an intersection point on il2. - int out = -1; - // Find an intersection point on iVerticalLineOther, intersecting iInnerContour - // at the same orientation as iIntersection, and being closest to iIntersection - // in the number of contour segments, when following the direction of the contour. - int dmin = std::numeric_limits::max(); - for (size_t i = 0; i < il2.intersections.size(); ++ i) { - const SegmentIntersection &itsct2 = il2.intersections[i]; - if (itsct.iContour == itsct2.iContour && itsct.type == itsct2.type) { - /* - if (itsct.is_low()) { - myassert(itsct.type == SegmentIntersection::INNER_LOW); - myassert(iIntersection > 0); - myassert(il.intersections[iIntersection-1].type == SegmentIntersection::OUTER_LOW); - myassert(i > 0); - if (il2.intersections[i-1].is_inner()) - // Take only the lowest inner intersection point. - continue; - myassert(il2.intersections[i-1].type == SegmentIntersection::OUTER_LOW); - } else { - myassert(itsct.type == SegmentIntersection::INNER_HIGH); - myassert(iIntersection+1 < il.intersections.size()); - myassert(il.intersections[iIntersection+1].type == SegmentIntersection::OUTER_HIGH); - myassert(i+1 < il2.intersections.size()); - if (il2.intersections[i+1].is_inner()) - // Take only the highest inner intersection point. - continue; - myassert(il2.intersections[i+1].type == SegmentIntersection::OUTER_HIGH); - } - */ - // The intersection points lie on the same contour and have the same orientation. - // Find the intersection point with a shortest path in the direction of the contour. - int d = distance_of_segmens(poly, itsct.iSegment, itsct2.iSegment, forward); - if (d < dmin) { - out = i; - dmin = d; - } - } - } - //FIXME this routine is not asymptotic optimal, it will be slow if there are many intersection points along the line. - return out; -} - -static inline int intersection_on_prev_vertical_line( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection) -{ - return intersection_on_prev_next_vertical_line(poly_with_offset, segs, iVerticalLine, iInnerContour, iIntersection, false); -} - -static inline int intersection_on_next_vertical_line( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection) -{ - return intersection_on_prev_next_vertical_line(poly_with_offset, segs, iVerticalLine, iInnerContour, iIntersection, true); -} - -enum IntersectionTypeOtherVLine { - // There is no connection point on the other vertical line. - INTERSECTION_TYPE_OTHER_VLINE_UNDEFINED = -1, - // Connection point on the other vertical segment was found - // and it could be followed. - INTERSECTION_TYPE_OTHER_VLINE_OK = 0, - // The connection segment connects to a middle of a vertical segment. - // Cannot follow. - INTERSECTION_TYPE_OTHER_VLINE_INNER, - // Cannot extend the contor to this intersection point as either the connection segment - // or the succeeding vertical segment were already consumed. - INTERSECTION_TYPE_OTHER_VLINE_CONSUMED, - // Not the first intersection along the contor. This intersection point - // has been preceded by an intersection point along the vertical line. - INTERSECTION_TYPE_OTHER_VLINE_NOT_FIRST, -}; - -// Find an intersection on a previous line, but return -1, if the connecting segment of a perimeter was already extruded. -static inline IntersectionTypeOtherVLine intersection_type_on_prev_next_vertical_line( - const std::vector &segs, - size_t iVerticalLine, - size_t iIntersection, - int iIntersectionOther, - bool dir_is_next) -{ - // This routine will propose a connecting line even if the connecting perimeter segment intersects - // iVertical line multiple times before reaching iIntersectionOther. - if (iIntersectionOther == -1) - return INTERSECTION_TYPE_OTHER_VLINE_UNDEFINED; - myassert(dir_is_next ? (iVerticalLine + 1 < segs.size()) : (iVerticalLine > 0)); - const SegmentedIntersectionLine &il_this = segs[iVerticalLine]; - const SegmentIntersection &itsct_this = il_this.intersections[iIntersection]; - const SegmentedIntersectionLine &il_other = segs[dir_is_next ? (iVerticalLine+1) : (iVerticalLine-1)]; - const SegmentIntersection &itsct_other = il_other.intersections[iIntersectionOther]; - myassert(itsct_other.is_inner()); - myassert(iIntersectionOther > 0); - myassert(iIntersectionOther + 1 < (int)il_other.intersections.size()); - // Is iIntersectionOther at the boundary of a vertical segment? - const SegmentIntersection &itsct_other2 = il_other.intersections[itsct_other.is_low() ? iIntersectionOther - 1 : iIntersectionOther + 1]; - if (itsct_other2.is_inner()) - // Cannot follow a perimeter segment into the middle of another vertical segment. - // Only perimeter segments connecting to the end of a vertical segment are followed. - return INTERSECTION_TYPE_OTHER_VLINE_INNER; - myassert(itsct_other.is_low() == itsct_other2.is_low()); - if (dir_is_next ? itsct_this.consumed_perimeter_right : itsct_other.consumed_perimeter_right) - // This perimeter segment was already consumed. - return INTERSECTION_TYPE_OTHER_VLINE_CONSUMED; - if (itsct_other.is_low() ? itsct_other.consumed_vertical_up : il_other.intersections[iIntersectionOther-1].consumed_vertical_up) - // This vertical segment was already consumed. - return INTERSECTION_TYPE_OTHER_VLINE_CONSUMED; - return INTERSECTION_TYPE_OTHER_VLINE_OK; -} - -static inline IntersectionTypeOtherVLine intersection_type_on_prev_vertical_line( - const std::vector &segs, - size_t iVerticalLine, - size_t iIntersection, - size_t iIntersectionPrev) -{ - return intersection_type_on_prev_next_vertical_line(segs, iVerticalLine, iIntersection, iIntersectionPrev, false); -} - -static inline IntersectionTypeOtherVLine intersection_type_on_next_vertical_line( - const std::vector &segs, - size_t iVerticalLine, - size_t iIntersection, - size_t iIntersectionNext) -{ - return intersection_type_on_prev_next_vertical_line(segs, iVerticalLine, iIntersection, iIntersectionNext, true); -} - -// Measure an Euclidian length of a perimeter segment when going from iIntersection to iIntersection2. -static inline coordf_t measure_perimeter_prev_next_segment_length( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection, - size_t iIntersection2, - bool dir_is_next) -{ - size_t iVerticalLineOther = iVerticalLine; - if (dir_is_next) { - if (++ iVerticalLineOther == segs.size()) - // No successive vertical line. - return coordf_t(-1); - } else if (iVerticalLineOther -- == 0) { - // No preceding vertical line. - return coordf_t(-1); - } - - const SegmentedIntersectionLine &il = segs[iVerticalLine]; - const SegmentIntersection &itsct = il.intersections[iIntersection]; - const SegmentedIntersectionLine &il2 = segs[iVerticalLineOther]; - const SegmentIntersection &itsct2 = il2.intersections[iIntersection2]; - const Polygon &poly = poly_with_offset.contour(iInnerContour); -// const bool ccw = poly_with_offset.is_contour_ccw(iInnerContour); - myassert(itsct.type == itsct2.type); - myassert(itsct.iContour == itsct2.iContour); - myassert(itsct.is_inner()); - const bool forward = itsct.is_low() == dir_is_next; - - Point p1(il.pos, itsct.pos()); - Point p2(il2.pos, itsct2.pos()); - return forward ? - segment_length(poly, itsct .iSegment, p1, itsct2.iSegment, p2) : - segment_length(poly, itsct2.iSegment, p2, itsct .iSegment, p1); -} - -static inline coordf_t measure_perimeter_prev_segment_length( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection, - size_t iIntersection2) -{ - return measure_perimeter_prev_next_segment_length(poly_with_offset, segs, iVerticalLine, iInnerContour, iIntersection, iIntersection2, false); -} - -static inline coordf_t measure_perimeter_next_segment_length( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection, - size_t iIntersection2) -{ - return measure_perimeter_prev_next_segment_length(poly_with_offset, segs, iVerticalLine, iInnerContour, iIntersection, iIntersection2, true); -} - -// Append the points of a perimeter segment when going from iIntersection to iIntersection2. -// The first point (the point of iIntersection) will not be inserted, -// the last point will be inserted. -static inline void emit_perimeter_prev_next_segment( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection, - size_t iIntersection2, - Polyline &out, - bool dir_is_next) -{ - size_t iVerticalLineOther = iVerticalLine; - if (dir_is_next) { - ++ iVerticalLineOther; - myassert(iVerticalLineOther < segs.size()); - } else { - myassert(iVerticalLineOther > 0); - -- iVerticalLineOther; - } - - const SegmentedIntersectionLine &il = segs[iVerticalLine]; - const SegmentIntersection &itsct = il.intersections[iIntersection]; - const SegmentedIntersectionLine &il2 = segs[iVerticalLineOther]; - const SegmentIntersection &itsct2 = il2.intersections[iIntersection2]; - const Polygon &poly = poly_with_offset.contour(iInnerContour); -// const bool ccw = poly_with_offset.is_contour_ccw(iInnerContour); - myassert(itsct.type == itsct2.type); - myassert(itsct.iContour == itsct2.iContour); - myassert(itsct.is_inner()); - const bool forward = itsct.is_low() == dir_is_next; - // Do not append the first point. - // out.points.push_back(Point(il.pos, itsct.pos)); - if (forward) - polygon_segment_append(out.points, poly, itsct.iSegment, itsct2.iSegment); - else - polygon_segment_append_reversed(out.points, poly, itsct.iSegment, itsct2.iSegment); - // Append the last point. - out.points.push_back(Point(il2.pos, itsct2.pos())); -} - -static inline coordf_t measure_perimeter_segment_on_vertical_line_length( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection, - size_t iIntersection2, - bool forward) -{ - const SegmentedIntersectionLine &il = segs[iVerticalLine]; - const SegmentIntersection &itsct = il.intersections[iIntersection]; - const SegmentIntersection &itsct2 = il.intersections[iIntersection2]; - const Polygon &poly = poly_with_offset.contour(iInnerContour); - myassert(itsct.is_inner()); - myassert(itsct2.is_inner()); - myassert(itsct.type != itsct2.type); - myassert(itsct.iContour == iInnerContour); - myassert(itsct.iContour == itsct2.iContour); - Point p1(il.pos, itsct.pos()); - Point p2(il.pos, itsct2.pos()); - return forward ? - segment_length(poly, itsct .iSegment, p1, itsct2.iSegment, p2) : - segment_length(poly, itsct2.iSegment, p2, itsct .iSegment, p1); -} - -// Append the points of a perimeter segment when going from iIntersection to iIntersection2. -// The first point (the point of iIntersection) will not be inserted, -// the last point will be inserted. -static inline void emit_perimeter_segment_on_vertical_line( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t iVerticalLine, - size_t iInnerContour, - size_t iIntersection, - size_t iIntersection2, - Polyline &out, - bool forward) -{ - const SegmentedIntersectionLine &il = segs[iVerticalLine]; - const SegmentIntersection &itsct = il.intersections[iIntersection]; - const SegmentIntersection &itsct2 = il.intersections[iIntersection2]; - const Polygon &poly = poly_with_offset.contour(iInnerContour); - myassert(itsct.is_inner()); - myassert(itsct2.is_inner()); - myassert(itsct.type != itsct2.type); - myassert(itsct.iContour == iInnerContour); - myassert(itsct.iContour == itsct2.iContour); - // Do not append the first point. - // out.points.push_back(Point(il.pos, itsct.pos)); - if (forward) - polygon_segment_append(out.points, poly, itsct.iSegment, itsct2.iSegment); - else - polygon_segment_append_reversed(out.points, poly, itsct.iSegment, itsct2.iSegment); - // Append the last point. - out.points.push_back(Point(il.pos, itsct2.pos())); -} - -//TBD: For precise infill, measure the area of a slab spanned by an infill line. -/* -static inline float measure_outer_contour_slab( - const ExPolygonWithOffset &poly_with_offset, - const std::vector &segs, - size_t i_vline, - size_t iIntersection) -{ - const SegmentedIntersectionLine &il = segs[i_vline]; - const SegmentIntersection &itsct = il.intersections[i_vline]; - const SegmentIntersection &itsct2 = il.intersections[iIntersection2]; - const Polygon &poly = poly_with_offset.contour((itsct.iContour); - myassert(itsct.is_outer()); - myassert(itsct2.is_outer()); - myassert(itsct.type != itsct2.type); - myassert(itsct.iContour == itsct2.iContour); - if (! itsct.is_outer() || ! itsct2.is_outer() || itsct.type == itsct2.type || itsct.iContour != itsct2.iContour) - // Error, return zero area. - return 0.f; - - // Find possible connection points on the previous / next vertical line. - int iPrev = intersection_on_prev_vertical_line(poly_with_offset, segs, i_vline, itsct.iContour, i_intersection); - int iNext = intersection_on_next_vertical_line(poly_with_offset, segs, i_vline, itsct.iContour, i_intersection); - // Find possible connection points on the same vertical line. - int iAbove = iBelow = -1; - // Does the perimeter intersect the current vertical line above intrsctn? - for (size_t i = i_intersection + 1; i + 1 < seg.intersections.size(); ++ i) - if (seg.intersections[i].iContour == itsct.iContour) - { iAbove = i; break; } - // Does the perimeter intersect the current vertical line below intrsctn? - for (int i = int(i_intersection) - 1; i > 0; -- i) - if (seg.intersections[i].iContour == itsct.iContour) - { iBelow = i; break; } - - if (iSegAbove != -1 && seg.intersections[iAbove].type == SegmentIntersection::OUTER_HIGH) { - // Invalidate iPrev resp. iNext, if the perimeter crosses the current vertical line earlier than iPrev resp. iNext. - // The perimeter contour orientation. - const Polygon &poly = poly_with_offset.contour(itsct.iContour); - { - int d_horiz = (iPrev == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, segs[i_vline-1].intersections[iPrev].iSegment, itsct.iSegment, true); - int d_down = (iBelow == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, iSegBelow, itsct.iSegment, true); - int d_up = (iAbove == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, iSegAbove, itsct.iSegment, true); - if (intrsctn_type_prev == INTERSECTION_TYPE_OTHER_VLINE_OK && d_horiz > std::min(d_down, d_up)) - // The vertical crossing comes eralier than the prev crossing. - // Disable the perimeter going back. - intrsctn_type_prev = INTERSECTION_TYPE_OTHER_VLINE_NOT_FIRST; - if (d_up > std::min(d_horiz, d_down)) - // The horizontal crossing comes earlier than the vertical crossing. - vert_seg_dir_valid_mask &= ~DIR_BACKWARD; - } - { - int d_horiz = (iNext == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, itsct.iSegment, segs[i_vline+1].intersections[iNext].iSegment, true); - int d_down = (iSegBelow == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, itsct.iSegment, iSegBelow, true); - int d_up = (iSegAbove == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, itsct.iSegment, iSegAbove, true); - if (d_up > std::min(d_horiz, d_down)) - // The horizontal crossing comes earlier than the vertical crossing. - vert_seg_dir_valid_mask &= ~DIR_FORWARD; - } - } -} -*/ - -enum DirectionMask -{ - DIR_FORWARD = 1, - DIR_BACKWARD = 2 -}; - -bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, float angleBase, float pattern_shift, Polylines &polylines_out) -{ - // At the end, only the new polylines will be rotated back. - size_t n_polylines_out_initial = polylines_out.size(); - - // Shrink the input polygon a bit first to not push the infill lines out of the perimeters. -// const float INFILL_OVERLAP_OVER_SPACING = 0.3f; - const float INFILL_OVERLAP_OVER_SPACING = 0.45f; - myassert(INFILL_OVERLAP_OVER_SPACING > 0 && INFILL_OVERLAP_OVER_SPACING < 0.5f); - - // Rotate polygons so that we can work with vertical lines here - std::pair rotate_vector = this->_infill_direction(*surface); - rotate_vector.first += angleBase; - - myassert(this->density > 0.0001f && this->density <= 1.f); - coord_t line_spacing = coord_t(scale_(this->spacing) / this->density); - - // On the polygons of poly_with_offset, the infill lines will be connected. - ExPolygonWithOffset poly_with_offset( - surface->expolygon, - - rotate_vector.first, - scale_(- (0.5 - INFILL_OVERLAP_OVER_SPACING) * this->spacing), - scale_(- 0.5 * this->spacing)); - if (poly_with_offset.n_contours_inner == 0) { - // Not a single infill line fits. - //FIXME maybe one shall trigger the gap fill here? - return true; - } - - BoundingBox bounding_box(poly_with_offset.polygons_src); - - // define flow spacing according to requested density - bool full_infill = this->density > 0.9999f; - if (full_infill && !this->dont_adjust) { - line_spacing = this->adjust_solid_spacing(bounding_box.size().x, line_spacing); - this->spacing = unscale(line_spacing); - } else { - // extend bounding box so that our pattern will be aligned with other layers - // Transform the reference point to the rotated coordinate system. - Point refpt = rotate_vector.second.rotated(- rotate_vector.first); - // _align_to_grid will not work correctly with positive pattern_shift. - coord_t pattern_shift_scaled = coord_t(scale_(pattern_shift)) % line_spacing; - refpt.x -= (pattern_shift_scaled > 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled); - bounding_box.min.align_to_grid( - Point(line_spacing, line_spacing), - refpt - ); - } - - // Intersect a set of euqally spaced vertical lines wiht expolygon. - // n_vlines = ceil(bbox_width / line_spacing) - size_t n_vlines = (bounding_box.max.x - bounding_box.min.x + line_spacing - 1) / line_spacing; - coord_t x0 = bounding_box.min.x + (line_spacing + SCALED_EPSILON) / 2; - -#ifdef SLIC3R_DEBUG - static int iRun = 0; - BoundingBox bbox_svg(to_points(poly_with_offset.polygons_outer)); - //::Slic3r::SVG svg(debug_out_path("FillRectilinear2-%d.svg", iRun), bbox_svg); // , scale_(1.)); - //poly_with_offset.export_to_svg(svg); - { - //::Slic3r::SVG svg(debug_out_path("FillRectilinear2-initial-%d.svg", iRun), bbox_svg); // , scale_(1.)); - //poly_with_offset.export_to_svg(svg); - } - iRun ++; -#endif /* SLIC3R_DEBUG */ - - // For each contour - // Allocate storage for the segments. - std::vector segs(n_vlines, SegmentedIntersectionLine()); - for (size_t i = 0; i < n_vlines; ++ i) { - segs[i].idx = i; - segs[i].pos = x0 + i * line_spacing; - } - for (size_t iContour = 0; iContour < poly_with_offset.n_contours; ++ iContour) { - const Points &contour = poly_with_offset.contour(iContour).points; - if (contour.size() < 2) - continue; - // For each segment - for (size_t iSegment = 0; iSegment < contour.size(); ++ iSegment) { - size_t iPrev = ((iSegment == 0) ? contour.size() : iSegment) - 1; - const Point &p1 = contour[iPrev]; - const Point &p2 = contour[iSegment]; - // Which of the equally spaced vertical lines is intersected by this segment? - coord_t l = p1.x; - coord_t r = p2.x; - if (l > r) - std::swap(l, r); - // il, ir are the left / right indices of vertical lines intersecting a segment - int il = (l - x0) / line_spacing; - while (il * line_spacing + x0 < l) - ++ il; - il = std::max(int(0), il); - int ir = (r - x0 + line_spacing) / line_spacing; - while (ir * line_spacing + x0 > r) - -- ir; - ir = std::min(int(segs.size()) - 1, ir); - if (il > ir) - // No vertical line intersects this segment. - continue; - myassert(il >= 0 && il < (int)segs.size()); - myassert(ir >= 0 && ir < (int)segs.size()); - for (int i = il; i <= ir; ++ i) { - coord_t this_x = segs[i].pos; - assert(this_x == i * line_spacing + x0); - SegmentIntersection is; - is.iContour = iContour; - is.iSegment = iSegment; - myassert(l <= this_x); - myassert(r >= this_x); - // Calculate the intersection position in y axis. x is known. - if (p1.x == this_x) { - if (p2.x == this_x) { - // Ignore strictly vertical segments. - continue; - } - is.pos_p = p1.y; - is.pos_q = 1; - } else if (p2.x == this_x) { - is.pos_p = p2.y; - is.pos_q = 1; - } else { - // First calculate the intersection parameter 't' as a rational number with non negative denominator. - if (p2.x > p1.x) { - is.pos_p = this_x - p1.x; - is.pos_q = p2.x - p1.x; - } else { - is.pos_p = p1.x - this_x; - is.pos_q = p1.x - p2.x; - } - myassert(is.pos_p >= 0 && is.pos_p <= is.pos_q); - // Make an intersection point from the 't'. - is.pos_p *= int64_t(p2.y - p1.y); - is.pos_p += p1.y * int64_t(is.pos_q); - } - // +-1 to take rounding into account. - myassert(is.pos() + 1 >= std::min(p1.y, p2.y)); - myassert(is.pos() <= std::max(p1.y, p2.y) + 1); - segs[i].intersections.push_back(is); - } - } - } - - // Sort the intersections along their segments, specify the intersection types. - for (size_t i_seg = 0; i_seg < segs.size(); ++ i_seg) { - SegmentedIntersectionLine &sil = segs[i_seg]; - // Sort the intersection points using exact rational arithmetic. - std::sort(sil.intersections.begin(), sil.intersections.end()); - -#if 0 - // Verify the order, bubble sort the intersections until sorted. - bool modified = false; - do { - modified = false; - for (size_t i = 1; i < sil.intersections.size(); ++ i) { - size_t iContour1 = sil.intersections[i-1].iContour; - size_t iContour2 = sil.intersections[i].iContour; - const Points &contour1 = poly_with_offset.contour(iContour1).points; - const Points &contour2 = poly_with_offset.contour(iContour2).points; - size_t iSegment1 = sil.intersections[i-1].iSegment; - size_t iPrev1 = ((iSegment1 == 0) ? contour1.size() : iSegment1) - 1; - size_t iSegment2 = sil.intersections[i].iSegment; - size_t iPrev2 = ((iSegment2 == 0) ? contour2.size() : iSegment2) - 1; - bool swap = false; - if (iContour1 == iContour2 && iSegment1 == iSegment2) { - // The same segment, it has to be vertical. - myassert(iPrev1 == iPrev2); - swap = contour1[iPrev1].y > contour1[iContour1].y; - #ifdef SLIC3R_DEBUG - if (swap) - printf("Swapping when single vertical segment\n"); - #endif - } else { - // Segments are in a general position. Here an exact airthmetics may come into play. - coord_t y1max = std::max(contour1[iPrev1].y, contour1[iSegment1].y); - coord_t y2min = std::min(contour2[iPrev2].y, contour2[iSegment2].y); - if (y1max < y2min) { - // The segments are separated, nothing to do. - } else { - // Use an exact predicate to verify, that segment1 is below segment2. - const Point *a = &contour1[iPrev1]; - const Point *b = &contour1[iSegment1]; - const Point *c = &contour2[iPrev2]; - const Point *d = &contour2[iSegment2]; -#ifdef SLIC3R_DEBUG - const Point x1(sil.pos, sil.intersections[i-1].pos); - const Point x2(sil.pos, sil.intersections[i ].pos); - bool successive = false; -#endif /* SLIC3R_DEBUG */ - // Sort the points in the two segments by x. - if (a->x > b->x) - std::swap(a, b); - if (c->x > d->x) - std::swap(c, d); - myassert(a->x <= sil.pos); - myassert(c->x <= sil.pos); - myassert(b->x >= sil.pos); - myassert(d->x >= sil.pos); - // Sort the two segments, so the segment will be on the left of . - bool upper_more_left = false; - if (a->x > c->x) { - upper_more_left = true; - std::swap(a, c); - std::swap(b, d); - } - if (a == c) { - // The segments iSegment1 and iSegment2 are directly connected. - myassert(iContour1 == iContour2); - myassert(iSegment1 == iPrev2 || iPrev1 == iSegment2); - std::swap(c, d); - myassert(a != c && b != c); -#ifdef SLIC3R_DEBUG - successive = true; -#endif /* SLIC3R_DEBUG */ - } -#ifdef SLIC3R_DEBUG - else if (b == d) { - // The segments iSegment1 and iSegment2 are directly connected. - myassert(iContour1 == iContour2); - myassert(iSegment1 == iPrev2 || iPrev1 == iSegment2); - myassert(a != c && b != c); - successive = true; - } -#endif /* SLIC3R_DEBUG */ - Orientation o = orient(*a, *b, *c); - myassert(o != ORIENTATION_COLINEAR); - swap = upper_more_left != (o == ORIENTATION_CW); -#ifdef SLIC3R_DEBUG - if (swap) - printf(successive ? - "Swapping when iContour1 == iContour2 and successive segments\n" : - "Swapping when exact predicate\n"); -#endif - } - } - if (swap) { - // Swap the intersection points, but keep the original positions, so they stay sorted by the y axis. - std::swap(sil.intersections[i-1], sil.intersections[i]); - std::swap(sil.intersections[i-1].pos_p, sil.intersections[i].pos_p); - std::swap(sil.intersections[i-1].pos_q, sil.intersections[i].pos_q); - modified = true; - } - } - } while (modified); -#endif - - // Assign the intersection types, remove duplicate or overlapping intersection points. - // When a loop vertex touches a vertical line, intersection point is generated for both segments. - // If such two segments are oriented equally, then one of them is removed. - // Otherwise the vertex is tangential to the vertical line and both segments are removed. - // The same rule applies, if the loop is pinched into a single point and this point touches the vertical line: - // The loop has a zero vertical size at the vertical line, therefore the intersection point is removed. - size_t j = 0; - for (size_t i = 0; i < sil.intersections.size(); ++ i) { - // What is the orientation of the segment at the intersection point? - size_t iContour = sil.intersections[i].iContour; - const Points &contour = poly_with_offset.contour(iContour).points; - size_t iSegment = sil.intersections[i].iSegment; - size_t iPrev = ((iSegment == 0) ? contour.size() : iSegment) - 1; - coord_t dir = contour[iSegment].x - contour[iPrev].x; - // bool ccw = poly_with_offset.is_contour_ccw(iContour); - // bool low = (dir > 0) == ccw; - bool low = dir > 0; - sil.intersections[i].type = poly_with_offset.is_contour_outer(iContour) ? - (low ? SegmentIntersection::OUTER_LOW : SegmentIntersection::OUTER_HIGH) : - (low ? SegmentIntersection::INNER_LOW : SegmentIntersection::INNER_HIGH); - if (j > 0 && - sil.intersections[i].pos() == sil.intersections[j-1].pos() && - sil.intersections[i].iContour == sil.intersections[j-1].iContour) { - if (sil.intersections[i].type == sil.intersections[j-1].type) { - // This has to be a corner point crossing the vertical line. - // Remove the second intersection point. - #ifdef SLIC3R_DEBUG - size_t iSegment2 = sil.intersections[j-1].iSegment; - size_t iPrev2 = ((iSegment2 == 0) ? contour.size() : iSegment2) - 1; - myassert(iSegment == iPrev2 || iSegment2 == iPrev); - #endif /* SLIC3R_DEBUG */ - } else { - // This is a loop returning to the same point. - // It may as well be a vertex of a loop touching this vertical line. - // Remove both the lines. - -- j; - } - } else { - if (j < i) - sil.intersections[j] = sil.intersections[i]; - ++ j; - } - //FIXME solve a degenerate case, where there is a vertical segment on this vertical line and the contour - // follows from left to right or vice versa, leading to low,low or high,high intersections. - } - // Shrink the list of intersections, if any of the intersection was removed during the classification. - if (j < sil.intersections.size()) - sil.intersections.erase(sil.intersections.begin() + j, sil.intersections.end()); - } - - // Verify the segments. If something is wrong, give up. -#define ASSERT_OR_RETURN(CONDITION) do { assert(CONDITION); if (! (CONDITION)) return false; } while (0) - for (size_t i_seg = 0; i_seg < segs.size(); ++ i_seg) { - SegmentedIntersectionLine &sil = segs[i_seg]; - // The intersection points have to be even. - ASSERT_OR_RETURN((sil.intersections.size() & 1) == 0); - for (size_t i = 0; i < sil.intersections.size();) { - // An intersection segment crossing the bigger contour may cross the inner offsetted contour even number of times. - ASSERT_OR_RETURN(sil.intersections[i].type == SegmentIntersection::OUTER_LOW); - size_t j = i + 1; - ASSERT_OR_RETURN(j < sil.intersections.size()); - ASSERT_OR_RETURN(sil.intersections[j].type == SegmentIntersection::INNER_LOW || sil.intersections[j].type == SegmentIntersection::OUTER_HIGH); - for (; j < sil.intersections.size() && sil.intersections[j].is_inner(); ++ j) ; - ASSERT_OR_RETURN(j < sil.intersections.size()); - ASSERT_OR_RETURN((j & 1) == 1); - ASSERT_OR_RETURN(sil.intersections[j].type == SegmentIntersection::OUTER_HIGH); - ASSERT_OR_RETURN(i + 1 == j || sil.intersections[j - 1].type == SegmentIntersection::INNER_HIGH); - i = j + 1; - } - } -#undef ASSERT_OR_RETURN - -#ifdef SLIC3R_DEBUG - // Paint the segments and finalize the SVG file. - for (size_t i_seg = 0; i_seg < segs.size(); ++ i_seg) { - SegmentedIntersectionLine &sil = segs[i_seg]; - for (size_t i = 0; i < sil.intersections.size();) { - size_t j = i + 1; - for (; j < sil.intersections.size() && sil.intersections[j].is_inner(); ++ j) ; - if (i + 1 == j) { - //svg.draw(Line(Point(sil.pos, sil.intersections[i].pos()), Point(sil.pos, sil.intersections[j].pos())), "blue"); - } else { - //svg.draw(Line(Point(sil.pos, sil.intersections[i].pos()), Point(sil.pos, sil.intersections[i+1].pos())), "green"); - //svg.draw(Line(Point(sil.pos, sil.intersections[i+1].pos()), Point(sil.pos, sil.intersections[j-1].pos())), (j - i + 1 > 4) ? "yellow" : "magenta"); - //svg.draw(Line(Point(sil.pos, sil.intersections[j-1].pos()), Point(sil.pos, sil.intersections[j].pos())), "green"); - } - i = j + 1; - } - } - //svg.Close(); -#endif /* SLIC3R_DEBUG */ - - // For each outer only chords, measure their maximum distance to the bow of the outer contour. - // Mark an outer only chord as consumed, if the distance is low. - for (size_t i_vline = 0; i_vline < segs.size(); ++ i_vline) { - SegmentedIntersectionLine &seg = segs[i_vline]; - for (size_t i_intersection = 0; i_intersection + 1 < seg.intersections.size(); ++ i_intersection) { - if (seg.intersections[i_intersection].type == SegmentIntersection::OUTER_LOW && - seg.intersections[i_intersection+1].type == SegmentIntersection::OUTER_HIGH) { - bool consumed = false; -// if (full_infill) { -// measure_outer_contour_slab(poly_with_offset, segs, i_vline, i_ntersection); -// } else - consumed = true; - seg.intersections[i_intersection].consumed_vertical_up = consumed; - } - } - } - - // Now construct a graph. - // Find the first point. - // Naively one would expect to achieve best results by chaining the paths by the shortest distance, - // but that procedure does not create the longest continuous paths. - // A simple "sweep left to right" procedure achieves better results. - size_t i_vline = 0; - size_t i_intersection = size_t(-1); - // Follow the line, connect the lines into a graph. - // Until no new line could be added to the output path: - Point pointLast; - Polyline *polyline_current = NULL; - if (! polylines_out.empty()) - pointLast = polylines_out.back().points.back(); - for (;;) { - if (i_intersection == size_t(-1)) { - // The path has been interrupted. Find a next starting point, closest to the previous extruder position. - coordf_t dist2min = std::numeric_limits().max(); - for (size_t i_vline2 = 0; i_vline2 < segs.size(); ++ i_vline2) { - const SegmentedIntersectionLine &seg = segs[i_vline2]; - if (! seg.intersections.empty()) { - myassert(seg.intersections.size() > 1); - // Even number of intersections with the loops. - myassert((seg.intersections.size() & 1) == 0); - myassert(seg.intersections.front().type == SegmentIntersection::OUTER_LOW); - for (size_t i = 0; i < seg.intersections.size(); ++ i) { - const SegmentIntersection &intrsctn = seg.intersections[i]; - if (intrsctn.is_outer()) { - myassert(intrsctn.is_low() || i > 0); - bool consumed = intrsctn.is_low() ? - intrsctn.consumed_vertical_up : - seg.intersections[i-1].consumed_vertical_up; - if (! consumed) { - coordf_t dist2 = sqr(coordf_t(pointLast.x - seg.pos)) + sqr(coordf_t(pointLast.y - intrsctn.pos())); - if (dist2 < dist2min) { - dist2min = dist2; - i_vline = i_vline2; - i_intersection = i; - //FIXME We are taking the first left point always. Verify, that the caller chains the paths - // by a shortest distance, while reversing the paths if needed. - //if (polylines_out.empty()) - // Initial state, take the first line, which is the first from the left. - goto found; - } - } - } - } - } - } - if (i_intersection == size_t(-1)) - // We are finished. - break; - found: - // Start a new path. - polylines_out.push_back(Polyline()); - polyline_current = &polylines_out.back(); - // Emit the first point of a path. - pointLast = Point(segs[i_vline].pos, segs[i_vline].intersections[i_intersection].pos()); - polyline_current->points.push_back(pointLast); - } - - // From the initial point (i_vline, i_intersection), follow a path. - SegmentedIntersectionLine &seg = segs[i_vline]; - SegmentIntersection *intrsctn = &seg.intersections[i_intersection]; - bool going_up = intrsctn->is_low(); - bool try_connect = false; - if (going_up) { - myassert(! intrsctn->consumed_vertical_up); - myassert(i_intersection + 1 < seg.intersections.size()); - // Step back to the beginning of the vertical segment to mark it as consumed. - if (intrsctn->is_inner()) { - myassert(i_intersection > 0); - -- intrsctn; - -- i_intersection; - } - // Consume the complete vertical segment up to the outer contour. - do { - intrsctn->consumed_vertical_up = true; - ++ intrsctn; - ++ i_intersection; - myassert(i_intersection < seg.intersections.size()); - } while (intrsctn->type != SegmentIntersection::OUTER_HIGH); - if ((intrsctn - 1)->is_inner()) { - // Step back. - -- intrsctn; - -- i_intersection; - myassert(intrsctn->type == SegmentIntersection::INNER_HIGH); - try_connect = true; - } - } else { - // Going down. - myassert(intrsctn->is_high()); - myassert(i_intersection > 0); - myassert(! (intrsctn - 1)->consumed_vertical_up); - // Consume the complete vertical segment up to the outer contour. - if (intrsctn->is_inner()) - intrsctn->consumed_vertical_up = true; - do { - myassert(i_intersection > 0); - -- intrsctn; - -- i_intersection; - intrsctn->consumed_vertical_up = true; - } while (intrsctn->type != SegmentIntersection::OUTER_LOW); - if ((intrsctn + 1)->is_inner()) { - // Step back. - ++ intrsctn; - ++ i_intersection; - myassert(intrsctn->type == SegmentIntersection::INNER_LOW); - try_connect = true; - } - } - if (try_connect) { - // Decide, whether to finish the segment, or whether to follow the perimeter. - - // 1) Find possible connection points on the previous / next vertical line. - int iPrev = intersection_on_prev_vertical_line(poly_with_offset, segs, i_vline, intrsctn->iContour, i_intersection); - int iNext = intersection_on_next_vertical_line(poly_with_offset, segs, i_vline, intrsctn->iContour, i_intersection); - IntersectionTypeOtherVLine intrsctn_type_prev = intersection_type_on_prev_vertical_line(segs, i_vline, i_intersection, iPrev); - IntersectionTypeOtherVLine intrsctn_type_next = intersection_type_on_next_vertical_line(segs, i_vline, i_intersection, iNext); - - // 2) Find possible connection points on the same vertical line. - int iAbove = -1; - int iBelow = -1; - int iSegAbove = -1; - int iSegBelow = -1; - { -// SegmentIntersection::SegmentIntersectionType type_crossing = (intrsctn->type == SegmentIntersection::INNER_LOW) ? -// SegmentIntersection::INNER_HIGH : SegmentIntersection::INNER_LOW; - // Does the perimeter intersect the current vertical line above intrsctn? - for (size_t i = i_intersection + 1; i + 1 < seg.intersections.size(); ++ i) -// if (seg.intersections[i].iContour == intrsctn->iContour && seg.intersections[i].type == type_crossing) { - if (seg.intersections[i].iContour == intrsctn->iContour) { - iAbove = i; - iSegAbove = seg.intersections[i].iSegment; - break; - } - // Does the perimeter intersect the current vertical line below intrsctn? - for (size_t i = i_intersection - 1; i > 0; -- i) -// if (seg.intersections[i].iContour == intrsctn->iContour && seg.intersections[i].type == type_crossing) { - if (seg.intersections[i].iContour == intrsctn->iContour) { - iBelow = i; - iSegBelow = seg.intersections[i].iSegment; - break; - } - } - - // 3) Sort the intersection points, clear iPrev / iNext / iSegBelow / iSegAbove, - // if it is preceded by any other intersection point along the contour. - unsigned int vert_seg_dir_valid_mask = - (going_up ? - (iSegAbove != -1 && seg.intersections[iAbove].type == SegmentIntersection::INNER_LOW) : - (iSegBelow != -1 && seg.intersections[iBelow].type == SegmentIntersection::INNER_HIGH)) ? - (DIR_FORWARD | DIR_BACKWARD) : - 0; - { - // Invalidate iPrev resp. iNext, if the perimeter crosses the current vertical line earlier than iPrev resp. iNext. - // The perimeter contour orientation. - const bool forward = intrsctn->is_low(); // == poly_with_offset.is_contour_ccw(intrsctn->iContour); - const Polygon &poly = poly_with_offset.contour(intrsctn->iContour); - { - int d_horiz = (iPrev == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, segs[i_vline-1].intersections[iPrev].iSegment, intrsctn->iSegment, forward); - int d_down = (iSegBelow == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, iSegBelow, intrsctn->iSegment, forward); - int d_up = (iSegAbove == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, iSegAbove, intrsctn->iSegment, forward); - if (intrsctn_type_prev == INTERSECTION_TYPE_OTHER_VLINE_OK && d_horiz > std::min(d_down, d_up)) - // The vertical crossing comes eralier than the prev crossing. - // Disable the perimeter going back. - intrsctn_type_prev = INTERSECTION_TYPE_OTHER_VLINE_NOT_FIRST; - if (going_up ? (d_up > std::min(d_horiz, d_down)) : (d_down > std::min(d_horiz, d_up))) - // The horizontal crossing comes earlier than the vertical crossing. - vert_seg_dir_valid_mask &= ~(forward ? DIR_BACKWARD : DIR_FORWARD); - } - { - int d_horiz = (iNext == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, intrsctn->iSegment, segs[i_vline+1].intersections[iNext].iSegment, forward); - int d_down = (iSegBelow == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, intrsctn->iSegment, iSegBelow, forward); - int d_up = (iSegAbove == -1) ? std::numeric_limits::max() : - distance_of_segmens(poly, intrsctn->iSegment, iSegAbove, forward); - if (intrsctn_type_next == INTERSECTION_TYPE_OTHER_VLINE_OK && d_horiz > std::min(d_down, d_up)) - // The vertical crossing comes eralier than the prev crossing. - // Disable the perimeter going forward. - intrsctn_type_next = INTERSECTION_TYPE_OTHER_VLINE_NOT_FIRST; - if (going_up ? (d_up > std::min(d_horiz, d_down)) : (d_down > std::min(d_horiz, d_up))) - // The horizontal crossing comes earlier than the vertical crossing. - vert_seg_dir_valid_mask &= ~(forward ? DIR_FORWARD : DIR_BACKWARD); - } - } - - // 4) Try to connect to a previous or next vertical line, making a zig-zag pattern. - if (intrsctn_type_prev == INTERSECTION_TYPE_OTHER_VLINE_OK || intrsctn_type_next == INTERSECTION_TYPE_OTHER_VLINE_OK) { - coordf_t distPrev = (intrsctn_type_prev != INTERSECTION_TYPE_OTHER_VLINE_OK) ? std::numeric_limits::max() : - measure_perimeter_prev_segment_length(poly_with_offset, segs, i_vline, intrsctn->iContour, i_intersection, iPrev); - coordf_t distNext = (intrsctn_type_next != INTERSECTION_TYPE_OTHER_VLINE_OK) ? std::numeric_limits::max() : - measure_perimeter_next_segment_length(poly_with_offset, segs, i_vline, intrsctn->iContour, i_intersection, iNext); - // Take the shorter path. - //FIXME this may not be always the best strategy to take the shortest connection line now. - bool take_next = (intrsctn_type_prev == INTERSECTION_TYPE_OTHER_VLINE_OK && intrsctn_type_next == INTERSECTION_TYPE_OTHER_VLINE_OK) ? - (distNext < distPrev) : - intrsctn_type_next == INTERSECTION_TYPE_OTHER_VLINE_OK; - myassert(intrsctn->is_inner()); - bool skip = this->dont_connect || (link_max_length > 0 && (take_next ? distNext : distPrev) > link_max_length); - if (skip) { - // Just skip the connecting contour and start a new path. - goto dont_connect; - polyline_current->points.push_back(Point(seg.pos, intrsctn->pos())); - polylines_out.push_back(Polyline()); - polyline_current = &polylines_out.back(); - const SegmentedIntersectionLine &il2 = segs[take_next ? (i_vline + 1) : (i_vline - 1)]; - polyline_current->points.push_back(Point(il2.pos, il2.intersections[take_next ? iNext : iPrev].pos())); - } else { - polyline_current->points.push_back(Point(seg.pos, intrsctn->pos())); - emit_perimeter_prev_next_segment(poly_with_offset, segs, i_vline, intrsctn->iContour, i_intersection, take_next ? iNext : iPrev, *polyline_current, take_next); - } - // Mark both the left and right connecting segment as consumed, because one cannot go to this intersection point as it has been consumed. - if (iPrev != -1) - segs[i_vline-1].intersections[iPrev].consumed_perimeter_right = true; - if (iNext != -1) - intrsctn->consumed_perimeter_right = true; - //FIXME consume the left / right connecting segments at the other end of this line? Currently it is not critical because a perimeter segment is not followed if the vertical segment at the other side has already been consumed. - // Advance to the neighbor line. - if (take_next) { - ++ i_vline; - i_intersection = iNext; - } else { - -- i_vline; - i_intersection = iPrev; - } - continue; - } - - // 5) Try to connect to a previous or next point on the same vertical line. - if (vert_seg_dir_valid_mask) { - bool valid = true; - // Verify, that there is no intersection with the inner contour up to the end of the contour segment. - // Verify, that the successive segment has not been consumed yet. - if (going_up) { - if (seg.intersections[iAbove].consumed_vertical_up) { - valid = false; - } else { - for (int i = (int)i_intersection + 1; i < iAbove && valid; ++i) - if (seg.intersections[i].is_inner()) - valid = false; - } - } else { - if (seg.intersections[iBelow-1].consumed_vertical_up) { - valid = false; - } else { - for (int i = iBelow + 1; i < (int)i_intersection && valid; ++i) - if (seg.intersections[i].is_inner()) - valid = false; - } - } - if (valid) { - const Polygon &poly = poly_with_offset.contour(intrsctn->iContour); - int iNext = going_up ? iAbove : iBelow; - int iSegNext = going_up ? iSegAbove : iSegBelow; - bool dir_forward = (vert_seg_dir_valid_mask == (DIR_FORWARD | DIR_BACKWARD)) ? - // Take the shorter length between the current and the next intersection point. - (distance_of_segmens(poly, intrsctn->iSegment, iSegNext, true) < - distance_of_segmens(poly, intrsctn->iSegment, iSegNext, false)) : - (vert_seg_dir_valid_mask == DIR_FORWARD); - // Skip this perimeter line? - bool skip = this->dont_connect; - if (! skip && link_max_length > 0) { - coordf_t link_length = measure_perimeter_segment_on_vertical_line_length( - poly_with_offset, segs, i_vline, intrsctn->iContour, i_intersection, iNext, dir_forward); - skip = link_length > link_max_length; - } - polyline_current->points.push_back(Point(seg.pos, intrsctn->pos())); - if (skip) { - // Just skip the connecting contour and start a new path. - polylines_out.push_back(Polyline()); - polyline_current = &polylines_out.back(); - polyline_current->points.push_back(Point(seg.pos, seg.intersections[iNext].pos())); - } else { - // Consume the connecting contour and the next segment. - emit_perimeter_segment_on_vertical_line(poly_with_offset, segs, i_vline, intrsctn->iContour, i_intersection, iNext, *polyline_current, dir_forward); - } - // Mark both the left and right connecting segment as consumed, because one cannot go to this intersection point as it has been consumed. - // If there are any outer intersection points skipped (bypassed) by the contour, - // mark them as processed. - if (going_up) { - for (int i = (int)i_intersection; i < iAbove; ++ i) - seg.intersections[i].consumed_vertical_up = true; - } else { - for (int i = iBelow; i < (int)i_intersection; ++ i) - seg.intersections[i].consumed_vertical_up = true; - } -// seg.intersections[going_up ? i_intersection : i_intersection - 1].consumed_vertical_up = true; - intrsctn->consumed_perimeter_right = true; - i_intersection = iNext; - if (going_up) - ++ intrsctn; - else - -- intrsctn; - intrsctn->consumed_perimeter_right = true; - continue; - } - } - dont_connect: - // No way to continue the current polyline. Take the rest of the line up to the outer contour. - // This will finish the polyline, starting another polyline at a new point. - if (going_up) - ++ intrsctn; - else - -- intrsctn; - } - - // Finish the current vertical line, - // reset the current vertical line to pick a new starting point in the next round. - myassert(intrsctn->is_outer()); - myassert(intrsctn->is_high() == going_up); - pointLast = Point(seg.pos, intrsctn->pos()); - polyline_current->points.push_back(pointLast); - // Handle duplicate points and zero length segments. - polyline_current->remove_duplicate_points(); - myassert(! polyline_current->has_duplicate_points()); - // Handle nearly zero length edges. - if (polyline_current->points.size() <= 1 || - (polyline_current->points.size() == 2 && - std::abs(polyline_current->points.front().x - polyline_current->points.back().x) < SCALED_EPSILON && - std::abs(polyline_current->points.front().y - polyline_current->points.back().y) < SCALED_EPSILON)) - polylines_out.pop_back(); - intrsctn = NULL; - i_intersection = -1; - polyline_current = NULL; - } - -#ifdef SLIC3R_DEBUG - { - { - //::Slic3r::SVG svg(debug_out_path("FillRectilinear2-final-%03d.svg", iRun), bbox_svg); // , scale_(1.)); - //poly_with_offset.export_to_svg(svg); - //for (size_t i = n_polylines_out_initial; i < polylines_out.size(); ++ i) - //svg.draw(polylines_out[i].lines(), "black"); - } - // Paint a picture per polyline. This makes it easier to discover the order of the polylines and their overlap. - for (size_t i_polyline = n_polylines_out_initial; i_polyline < polylines_out.size(); ++ i_polyline) { - //::Slic3r::SVG svg(debug_out_path("FillRectilinear2-final-%03d-%03d.svg", iRun, i_polyline), bbox_svg); // , scale_(1.)); - //svg.draw(polylines_out[i_polyline].lines(), "black"); - } - } -#endif /* SLIC3R_DEBUG */ - - // paths must be rotated back - for (Polylines::iterator it = polylines_out.begin() + n_polylines_out_initial; it != polylines_out.end(); ++ it) { - // No need to translate, the absolute position is irrelevant. - // it->translate(- rotate_vector.second.x, - rotate_vector.second.y); - myassert(! it->has_duplicate_points()); - it->rotate(rotate_vector.first); - //FIXME rather simplify the paths to avoid very short edges? - //myassert(! it->has_duplicate_points()); - it->remove_duplicate_points(); - } - -#ifdef SLIC3R_DEBUG - // Verify, that there are no duplicate points in the sequence. - for (Polylines::iterator it = polylines_out.begin(); it != polylines_out.end(); ++ it) - myassert(! it->has_duplicate_points()); -#endif /* SLIC3R_DEBUG */ - - return true; -} - -Polylines FillRectilinear2::fill_surface(const Surface &surface) -{ - Polylines polylines_out; - if (! fill_surface_by_lines(&surface, 0.f, 0.f, polylines_out)) { - printf("FillRectilinear2::fill_surface() failed to fill a region.\n"); - } - return polylines_out; -} - -Polylines FillGrid2::fill_surface(const Surface &surface) -{ - // Each linear fill covers half of the target coverage. - FillGrid2 fill2 = *this; - fill2.density *= 0.5f; - Polylines polylines_out; - if (! fill2.fill_surface_by_lines(&surface, 0.f, 0.f, polylines_out) || - ! fill2.fill_surface_by_lines(&surface, float(M_PI / 2.), 0.f, polylines_out)) { - printf("FillGrid2::fill_surface() failed to fill a region.\n"); - } - return polylines_out; -} - -Polylines FillTriangles::fill_surface(const Surface &surface) -{ - // Each linear fill covers 1/3 of the target coverage. - FillTriangles fill2 = *this; - fill2.density *= 0.333333333f; - Polylines polylines_out; - if (! fill2.fill_surface_by_lines(&surface, 0.f, 0., polylines_out) || - ! fill2.fill_surface_by_lines(&surface, float(M_PI / 3.), 0., polylines_out) || - ! fill2.fill_surface_by_lines(&surface, float(2. * M_PI / 3.), 0.5 * this->spacing / fill2.density, polylines_out)) { - printf("FillTriangles::fill_surface() failed to fill a region.\n"); - } - return polylines_out; -} - -Polylines FillStars::fill_surface(const Surface &surface) -{ - // Each linear fill covers 1/3 of the target coverage. - FillStars fill2 = *this; - fill2.density *= 0.333333333f; - Polylines polylines_out; - if (! fill2.fill_surface_by_lines(&surface, 0.f, 0., polylines_out) || - ! fill2.fill_surface_by_lines(&surface, float(M_PI / 3.), 0., polylines_out) || - ! fill2.fill_surface_by_lines(&surface, float(2. * M_PI / 3.), 0., polylines_out)) { - printf("FillStars::fill_surface() failed to fill a region.\n"); - } - return polylines_out; -} - -Polylines FillCubic::fill_surface(const Surface &surface) -{ - // Each linear fill covers 1/3 of the target coverage. - FillCubic fill2 = *this; - fill2.density *= 0.333333333f; - Polylines polylines_out; - if (! fill2.fill_surface_by_lines(&surface, 0.f, z, polylines_out) || - ! fill2.fill_surface_by_lines(&surface, float(M_PI / 3.), -z, polylines_out) || - // Rotated by PI*2/3 + PI to achieve reverse sloping wall. - ! fill2.fill_surface_by_lines(&surface, float(M_PI * 2. / 3.), z, polylines_out)) { - printf("FillCubic::fill_surface() failed to fill a region.\n"); - } - return polylines_out; -} - -static inline bool is_stick(const Point &p1, const Point &p2, const Point &p3) -{ - Point v1 = p2 - p1; - Point v2 = p3 - p2; - int64_t dir = int64_t(v1.x) * int64_t(v2.x) + int64_t(v1.y) * int64_t(v2.y); - if (dir > 0) - // p3 does not turn back to p1. Do not remove p2. - return false; - double l2_1 = double(v1.x) * double(v1.x) + double(v1.y) * double(v1.y); - double l2_2 = double(v2.x) * double(v2.x) + double(v2.y) * double(v2.y); - if (dir == 0) - // p1, p2, p3 may make a perpendicular corner, or there is a zero edge length. - // Remove p2 if it is coincident with p1 or p2. - return l2_1 == 0 || l2_2 == 0; - // p3 turns back to p1 after p2. Are p1, p2, p3 collinear? - // Calculate distance from p3 to a segment (p1, p2) or from p1 to a segment(p2, p3), - // whichever segment is longer - double cross = double(v1.x) * double(v2.y) - double(v2.x) * double(v1.y); - double dist2 = cross * cross / std::max(l2_1, l2_2); - return dist2 < EPSILON * EPSILON; -} - -bool remove_sticks(Polygon &poly) -{ - bool modified = false; - size_t j = 1; - for (size_t i = 1; i + 1 < poly.points.size(); ++ i) { - if (! is_stick(poly[j-1], poly[i], poly[i+1])) { - // Keep the point. - if (j < i) - poly.points[j] = poly.points[i]; - ++ j; - } - } - if (++ j < poly.points.size()) { - poly.points[j-1] = poly.points.back(); - poly.points.erase(poly.points.begin() + j, poly.points.end()); - modified = true; - } - while (poly.points.size() >= 3 && is_stick(poly.points[poly.points.size()-2], poly.points.back(), poly.points.front())) { - poly.points.pop_back(); - modified = true; - } - while (poly.points.size() >= 3 && is_stick(poly.points.back(), poly.points.front(), poly.points[1])) - poly.points.erase(poly.points.begin()); - return modified; -} - -bool remove_sticks(Polygons &polys) -{ - bool modified = false; - size_t j = 0; - for (size_t i = 0; i < polys.size(); ++ i) { - modified |= remove_sticks(polys[i]); - if (polys[i].points.size() >= 3) { - if (j < i) - std::swap(polys[i].points, polys[j].points); - ++ j; - } - } - if (j < polys.size()) - polys.erase(polys.begin() + j, polys.end()); - return modified; -} - -bool remove_sticks(ExPolygon &poly) -{ - return remove_sticks(poly.contour) || remove_sticks(poly.holes); -} - -bool remove_small(Polygons &polys, double min_area) -{ - bool modified = false; - size_t j = 0; - for (size_t i = 0; i < polys.size(); ++ i) { - if (std::abs(polys[i].area()) >= min_area) { - if (j < i) - std::swap(polys[i].points, polys[j].points); - ++ j; - } else - modified = true; - } - if (j < polys.size()) - polys.erase(polys.begin() + j, polys.end()); - return modified; -} - - - -} // namespace Slic3r diff --git a/xs/src/libslic3r/Fill/FillRectilinear2.hpp b/xs/src/libslic3r/Fill/FillRectilinear2.hpp deleted file mode 100644 index 50ecf6c38c..0000000000 --- a/xs/src/libslic3r/Fill/FillRectilinear2.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef slic3r_FillRectilinear2_hpp_ -#define slic3r_FillRectilinear2_hpp_ - -#include "../libslic3r.h" - -#include "Fill.hpp" - -namespace Slic3r { - -class Surface; - -class FillRectilinear2 : public Fill -{ -public: - virtual Fill* clone() const { return new FillRectilinear2(*this); }; - virtual ~FillRectilinear2() {} - virtual Polylines fill_surface(const Surface &surface); - -protected: - bool fill_surface_by_lines(const Surface *surface, float angleBase, float pattern_shift, Polylines &polylines_out); -}; - -class FillGrid2 : public FillRectilinear2 -{ -public: - virtual Fill* clone() const { return new FillGrid2(*this); }; - virtual ~FillGrid2() {} - virtual Polylines fill_surface(const Surface &surface); - -protected: - // The grid fill will keep the angle constant between the layers, see the implementation of Slic3r::Fill. - virtual float _layer_angle(size_t idx) const { return 0.f; } -}; - -class FillTriangles : public FillRectilinear2 -{ -public: - virtual Fill* clone() const { return new FillTriangles(*this); }; - virtual ~FillTriangles() {} - virtual Polylines fill_surface(const Surface &surface); - -protected: - // The grid fill will keep the angle constant between the layers, see the implementation of Slic3r::Fill. - virtual float _layer_angle(size_t idx) const { return 0.f; } -}; - -class FillStars : public FillRectilinear2 -{ -public: - virtual Fill* clone() const { return new FillStars(*this); }; - virtual ~FillStars() {} - virtual Polylines fill_surface(const Surface &surface); - -protected: - // The grid fill will keep the angle constant between the layers, see the implementation of Slic3r::Fill. - virtual float _layer_angle(size_t idx) const { return 0.f; } -}; - -class FillCubic : public FillRectilinear2 -{ -public: - virtual Fill* clone() const { return new FillCubic(*this); }; - virtual ~FillCubic() {} - virtual Polylines fill_surface(const Surface &surface); - -protected: - // The grid fill will keep the angle constant between the layers, see the implementation of Slic3r::Fill. - virtual float _layer_angle(size_t idx) const { return 0.f; } -}; - - -// Remove sticks (tentacles with zero area) from the polygon. -extern bool remove_sticks(Polygon &poly); -extern bool remove_sticks(Polygons &polys); -extern bool remove_sticks(ExPolygon &poly); -extern bool remove_small(Polygons &polys, double min_area); - - -}; // namespace Slic3r - -#endif // slic3r_FillRectilinear2_hpp_ diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index 629129b1e7..2ca3088b24 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -549,25 +549,6 @@ MedialAxis::build(ThickPolylines* polylines) // append polyline to result polylines->push_back(polyline); } - - #ifdef SLIC3R_DEBUG - { - char path[2048]; - static int iRun = 0; - sprintf(path, "out/MedialAxis-%d.svg", iRun ++); - //dump_voronoi_to_svg(this->lines, this->vd, polylines, path); - - - printf("Thick lines: "); - for (ThickPolylines::const_iterator it = polylines->begin(); it != polylines->end(); ++ it) { - ThickLines lines = it->thicklines(); - for (ThickLines::const_iterator it2 = lines.begin(); it2 != lines.end(); ++ it2) { - printf("%f,%f ", it2->a_width, it2->b_width); - } - } - printf("\n"); - } - #endif /* SLIC3R_DEBUG */ } void diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 6771733ba1..036e80e191 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -391,9 +391,6 @@ PrintConfigDef::PrintConfigDef() def->enum_values.push_back("rectilinear"); def->enum_values.push_back("alignedrectilinear"); def->enum_values.push_back("grid"); - def->enum_values.push_back("line"); - def->enum_values.push_back("rectilinear2"); - def->enum_values.push_back("grid2"); def->enum_values.push_back("triangles"); def->enum_values.push_back("stars"); def->enum_values.push_back("cubic"); @@ -406,9 +403,6 @@ PrintConfigDef::PrintConfigDef() def->enum_labels.push_back("Rectilinear"); def->enum_labels.push_back("Aligned Rectilinear"); def->enum_labels.push_back("Grid"); - def->enum_labels.push_back("Line"); - def->enum_labels.push_back("Rectilinear 2"); - def->enum_labels.push_back("Grid 2"); def->enum_labels.push_back("Triangles"); def->enum_labels.push_back("Stars"); def->enum_labels.push_back("Cubic"); @@ -418,7 +412,7 @@ PrintConfigDef::PrintConfigDef() def->enum_labels.push_back("Hilbert Curve"); def->enum_labels.push_back("Archimedean Chords"); def->enum_labels.push_back("Octagram Spiral"); - def->default_value = new ConfigOptionEnum(ipHoneycomb); + def->default_value = new ConfigOptionEnum(ipStars); def = this->add("first_layer_acceleration", coFloat); def->label = "First layer"; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 4e7f14e160..6bc2b6099b 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -30,8 +30,8 @@ enum GCodeFlavor { }; enum InfillPattern { - ipRectilinear, ipGrid, ipLine, ipAlignedRectilinear, - ipRectilinear2, ipGrid2, ipTriangles, ipStars, ipCubic, + ipRectilinear, ipGrid, ipAlignedRectilinear, + ipTriangles, ipStars, ipCubic, ipConcentric, ipHoneycomb, ip3DHoneycomb, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, }; @@ -63,9 +63,6 @@ template<> inline t_config_enum_values ConfigOptionEnum::get_enum keys_map["rectilinear"] = ipRectilinear; keys_map["alignedrectilinear"] = ipAlignedRectilinear; keys_map["grid"] = ipGrid; - keys_map["line"] = ipLine; - keys_map["rectilinear2"] = ipRectilinear2; - keys_map["grid2"] = ipGrid2; keys_map["triangles"] = ipTriangles; keys_map["stars"] = ipStars; keys_map["cubic"] = ipCubic; diff --git a/xs/t/15_config.t b/xs/t/15_config.t index a4c5d59250..3a7ad0de66 100644 --- a/xs/t/15_config.t +++ b/xs/t/15_config.t @@ -97,8 +97,8 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintCo $config->set_deserialize('gcode_flavor', 'machinekit'); is $config->get('gcode_flavor'), 'machinekit', 'deserialize enum (gcode_flavor)'; - $config->set_deserialize('fill_pattern', 'line'); - is $config->get('fill_pattern'), 'line', 'deserialize enum (fill_pattern)'; + $config->set_deserialize('fill_pattern', 'stars'); + is $config->get('fill_pattern'), 'stars', 'deserialize enum (fill_pattern)'; $config->set_deserialize('support_material_pattern', 'pillars'); is $config->get('support_material_pattern'), 'pillars', 'deserialize enum (support_material_pattern)'; @@ -199,12 +199,12 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintCo { my $config = Slic3r::Config->new; - $config->set('fill_pattern', 'line'); + $config->set('fill_pattern', 'stars'); my $config2 = Slic3r::Config->new; $config2->set('fill_pattern', 'hilbertcurve'); - is $config->get('fill_pattern'), 'line', 'no interferences between DynamicConfig objects'; + is $config->get('fill_pattern'), 'stars', 'no interferences between DynamicConfig objects'; } { diff --git a/xs/xsp/Filler.xsp b/xs/xsp/Filler.xsp index bd223a6808..7a3e995d34 100644 --- a/xs/xsp/Filler.xsp +++ b/xs/xsp/Filler.xsp @@ -13,10 +13,17 @@ void set_bounding_box(BoundingBox *bbox) %code{% THIS->fill->bounding_box = *bbox; %}; + void set_spacing(coordf_t spacing) %code{% THIS->fill->spacing = spacing; %}; coordf_t spacing() %code{% RETVAL = THIS->fill->spacing; %}; + + void set_endpoints_overlap(float overlap) + %code{% THIS->fill->endpoints_overlap = overlap; %}; + float endpoints_overlap() + %code{% RETVAL = THIS->fill->endpoints_overlap; %}; + void set_layer_id(size_t layer_id) %code{% THIS->fill->layer_id = layer_id; %}; void set_z(coordf_t z)