Refactored Fill / Flow for readability.

Added an "overlap" member variable to fill classes in the preparation
for futher move of the "infill / perimeter" overlap to the Fill class.
Moved the orientation predicates from Fill to Geometry.
This commit is contained in:
bubnikv 2017-07-19 15:53:43 +02:00
parent 9c1b1829cf
commit 2f2c0ddc99
7 changed files with 180 additions and 150 deletions

View file

@ -15,11 +15,11 @@ namespace Slic3r {
struct SurfaceGroupAttrib
{
SurfaceGroupAttrib() : is_solid(false), fw(0.f), pattern(-1) {}
SurfaceGroupAttrib() : is_solid(false), flow_width(0.f), pattern(-1) {}
bool operator==(const SurfaceGroupAttrib &other) const
{ return is_solid == other.is_solid && fw == other.fw && pattern == other.pattern; }
{ return is_solid == other.is_solid && flow_width == other.flow_width && pattern == other.pattern; }
bool is_solid;
float fw;
float flow_width;
// pattern is of type InfillPattern, -1 for an unset pattern.
int pattern;
};
@ -68,7 +68,7 @@ void make_fill(LayerRegion &layerm, ExtrusionEntityCollection &out)
const Surface &surface = *groups[i].front();
if (surface.is_solid() && (!surface.is_bridge() || layerm.layer()->id() == 0)) {
group_attrib[i].is_solid = true;
group_attrib[i].fw = (surface.surface_type == stTop) ? top_solid_infill_flow.width : solid_infill_flow.width;
group_attrib[i].flow_width = (surface.surface_type == stTop) ? top_solid_infill_flow.width : solid_infill_flow.width;
group_attrib[i].pattern = surface.is_external() ? layerm.region()->config.external_fill_pattern.value : ipRectilinear;
}
}

View file

@ -45,7 +45,7 @@ Fill* Fill::new_from_type(const std::string &type)
Polylines Fill::fill_surface(const Surface *surface, const FillParams &params)
{
// Perform offset.
Slic3r::ExPolygons expp = offset_ex(surface->expolygon, float(-0.5*scale_(this->spacing)));
Slic3r::ExPolygons expp = offset_ex(surface->expolygon, float(scale_(this->overlap - 0.5 * this->spacing)));
// Create the infills for each of the regions.
Polylines polylines_out;
for (size_t i = 0; i < expp.size(); ++ i)

View file

@ -22,6 +22,8 @@ struct FillParams
dont_adjust = true;
}
bool full_infill() const { return density > 0.9999f; }
// Fill density, fraction in <0, 1>
float density;
@ -46,6 +48,8 @@ public:
coordf_t z;
// in unscaled coordinates
coordf_t spacing;
// infill / perimeter overlap, in unscaled coordinates
coordf_t overlap;
// in radians, ccw, 0 = East
float angle;
// In scaled coordinates. Maximum lenght of a perimeter segment connecting two infill lines.
@ -77,8 +81,10 @@ public:
protected:
Fill() :
layer_id(size_t(-1)),
z(0.f),
spacing(0.f),
z(0.),
spacing(0.),
// Infill / perimeter overlap.
overlap(0.),
// Initial angle is undefined.
angle(FLT_MAX),
link_max_length(0),

View file

@ -9,6 +9,7 @@
#include "../ClipperUtils.hpp"
#include "../ExPolygon.hpp"
#include "../Geometry.hpp"
#include "../Surface.hpp"
#include "FillRectilinear2.hpp"
@ -62,55 +63,6 @@ static inline coordf_t mag(const Point &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.
int 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.
@ -390,7 +342,7 @@ public:
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));
polygons_ccw[i] = Slic3r::Geometry::is_ccw(contour(i));
}
}
@ -861,8 +813,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
ExPolygonWithOffset poly_with_offset(
surface->expolygon,
- rotate_vector.first,
scale_(- (0.5 - INFILL_OVERLAP_OVER_SPACING) * this->spacing),
scale_(- 0.5 * this->spacing));
scale_(this->overlap - (0.5 - INFILL_OVERLAP_OVER_SPACING) * this->spacing),
scale_(this->overlap - 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?
@ -872,8 +824,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
BoundingBox bounding_box = poly_with_offset.bounding_box_src();
// define flow spacing according to requested density
bool full_infill = params.density > 0.9999f;
if (full_infill && !params.dont_adjust) {
if (params.full_infill() && !params.dont_adjust) {
line_spacing = this->_adjust_solid_spacing(bounding_box.size().x, line_spacing);
this->spacing = unscale(line_spacing);
} else {
@ -893,7 +844,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
// 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;
if (full_infill)
if (params.full_infill())
x0 += (line_spacing + SCALED_EPSILON) / 2;
#ifdef SLIC3R_DEBUG
@ -1108,7 +1059,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
if (seg.intersections[i_intersection].type == SegmentIntersection::OUTER_LOW &&
seg.intersections[i_intersection+1].type == SegmentIntersection::OUTER_HIGH) {
bool consumed = false;
// if (full_infill) {
// if (params.full_infill()) {
// measure_outer_contour_slab(poly_with_offset, segs, i_vline, i_ntersection);
// } else
consumed = true;