Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
No (more) need for a separate FillParams class
  • Loading branch information
alranel committed Nov 30, 2016
1 parent 3e04877 commit ea98d97
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 115 deletions.
5 changes: 3 additions & 2 deletions xs/src/libslic3r/Fill/Fill.cpp
Expand Up @@ -51,16 +51,17 @@ Fill::new_from_type(const std::string &type)
}

Polylines
Fill::fill_surface(const Surface &surface, const FillParams &params)
Fill::fill_surface(const Surface &surface)
{
if (this->density == 0) return Polylines();

// Perform offset.
ExPolygons expp = offset_ex(surface.expolygon, -scale_(this->spacing)/2);

// Create the infills for each of the regions.
Polylines polylines_out;
for (size_t i = 0; i < expp.size(); ++i)
this->_fill_surface_single(
params,
surface.thickness_layers,
this->_infill_direction(surface),
expp[i],
Expand Down
62 changes: 29 additions & 33 deletions xs/src/libslic3r/Fill/Fill.hpp
Expand Up @@ -16,26 +16,7 @@ namespace Slic3r {

class Surface;

struct FillParams
{
public:
FillParams() : density(0), dont_connect(false), dont_adjust(false), complete(false) {};

// Fill density, fraction in <0, 1>
float density;

// Don't connect the fill lines around the inner perimeter.
bool dont_connect;

// Don't adjust spacing to fill the space evenly.
bool dont_adjust;

// For Honeycomb.
// we were requested to complete each loop;
// in this case we don't try to make more continuous paths
bool complete;
};

// Abstract base class for the infill generators.
class Fill
{
public:
Expand All @@ -60,45 +41,60 @@ class Fill
coord_t loop_clipping;

// In scaled coordinates. Bounding box of the 2D projection of the object.
// If not defined, the bounding box of each single expolygon is used.
BoundingBox bounding_box;

// Fill density, fraction in <0, 1>
float density;

public:
virtual ~Fill() {}
// Don't connect the fill lines around the inner perimeter.
bool dont_connect;

// Don't adjust spacing to fill the space evenly.
bool dont_adjust;

// For Honeycomb.
// we were requested to complete each loop;
// in this case we don't try to make more continuous paths
bool complete;

public:
static Fill* new_from_type(const InfillPattern type);
static Fill* new_from_type(const std::string &type);
static coord_t adjust_solid_spacing(const coord_t width, const coord_t distance);

void set_bounding_box(const BoundingBox &bb) { this->bounding_box = bb; }

// Implementations can override the following virtual methods:
// Use bridge flow for the fill?
virtual bool use_bridge_flow() const { return false; }

// Do not sort the fill lines to optimize the print head path?
virtual bool no_sort() const { return false; }

// Perform the fill.
virtual Polylines fill_surface(const Surface &surface, const FillParams &params);

static coord_t adjust_solid_spacing(const coord_t width, const coord_t distance);

virtual Polylines fill_surface(const Surface &surface);

protected:
Fill() :
layer_id(size_t(-1)),
z(0.f),
spacing(0.f),
angle(0),
link_max_length(0),
loop_clipping(0)
loop_clipping(0),
density(0),
dont_connect(false),
dont_adjust(false),
complete(false)
{};

// The expolygon may be modified by the method to avoid a copy.
virtual void _fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Polylines* polylines_out) {};


// Implementations can override the following virtual method:
virtual float _layer_angle(size_t idx) const {
return (idx % 2) == 0 ? (M_PI/2.) : 0;
}
Expand Down
5 changes: 2 additions & 3 deletions xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp
Expand Up @@ -149,15 +149,14 @@ makeGrid(coord_t z, coord_t gridSize, size_t gridWidth, size_t gridHeight, size_

void
Fill3DHoneycomb::_fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Polylines* polylines_out)
{
// no rotation is supported for this infill pattern
BoundingBox bb = expolygon.contour.bounding_box();
const coord_t distance = coord_t(scale_(this->spacing) / params.density);
const coord_t distance = coord_t(scale_(this->spacing) / this->density);

// align bounding box to a multiple of our honeycomb grid module
// (a module is 2*$distance since one $distance half-module is
Expand All @@ -181,7 +180,7 @@ Fill3DHoneycomb::_fill_surface_single(
polylines = intersection_pl(polylines, (Polygons)expolygon);

// connect lines
if (!params.dont_connect && !polylines.empty()) { // prevent calling leftmost_point() on empty collections
if (!this->dont_connect && !polylines.empty()) { // prevent calling leftmost_point() on empty collections
ExPolygon expolygon_off;
{
ExPolygons expolygons_off = offset_ex(expolygon, SCALED_EPSILON);
Expand Down
1 change: 0 additions & 1 deletion xs/src/libslic3r/Fill/Fill3DHoneycomb.hpp
Expand Up @@ -19,7 +19,6 @@ class Fill3DHoneycomb : public Fill

protected:
virtual void _fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Expand Down
5 changes: 2 additions & 3 deletions xs/src/libslic3r/Fill/FillConcentric.cpp
Expand Up @@ -8,7 +8,6 @@ namespace Slic3r {

void
FillConcentric::_fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Expand All @@ -17,9 +16,9 @@ FillConcentric::_fill_surface_single(
// no rotation is supported for this infill pattern

const coord_t min_spacing = scale_(this->spacing);
coord_t distance = coord_t(min_spacing / params.density);
coord_t distance = coord_t(min_spacing / this->density);

if (params.density > 0.9999f && !params.dont_adjust) {
if (this->density > 0.9999f && !this->dont_adjust) {
BoundingBox bounding_box = expolygon.contour.bounding_box();
distance = this->adjust_solid_spacing(bounding_box.size().x, distance);
this->spacing = unscale(distance);
Expand Down
1 change: 0 additions & 1 deletion xs/src/libslic3r/Fill/FillConcentric.hpp
Expand Up @@ -12,7 +12,6 @@ class FillConcentric : public Fill

protected:
virtual void _fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Expand Down
7 changes: 3 additions & 4 deletions xs/src/libslic3r/Fill/FillHoneycomb.cpp
Expand Up @@ -8,20 +8,19 @@ namespace Slic3r {

void
FillHoneycomb::_fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Polylines* polylines_out)
{
// cache hexagons math
CacheID cache_id = std::make_pair(params.density, this->spacing);
CacheID cache_id = std::make_pair(this->density, this->spacing);
Cache::iterator it_m = this->cache.find(cache_id);
if (it_m == this->cache.end()) {
it_m = this->cache.insert(it_m, std::pair<CacheID,CacheData>(cache_id, CacheData()));
CacheData &m = it_m->second;
coord_t min_spacing = scale_(this->spacing);
m.distance = min_spacing / params.density;
m.distance = min_spacing / this->density;
m.hex_side = m.distance / (sqrt(3)/2);
m.hex_width = m.distance * 2; // $m->{hex_width} == $m->{hex_side} * sqrt(3);
coord_t hex_height = m.hex_side * 2;
Expand Down Expand Up @@ -73,7 +72,7 @@ FillHoneycomb::_fill_surface_single(
}
}

if (true || params.complete) {
if (true || this->complete) {
// we were requested to complete each loop;
// in this case we don't try to make more continuous paths
Polygons polygons_trimmed = intersection((Polygons)expolygon, polygons);
Expand Down
1 change: 0 additions & 1 deletion xs/src/libslic3r/Fill/FillHoneycomb.hpp
Expand Up @@ -16,7 +16,6 @@ class FillHoneycomb : public Fill

protected:
virtual void _fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Expand Down
11 changes: 6 additions & 5 deletions xs/src/libslic3r/Fill/FillPlanePath.cpp
Expand Up @@ -7,19 +7,20 @@
namespace Slic3r {

void FillPlanePath::_fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Polylines* polylines_out)
{
expolygon.rotate(-direction.first);

const coord_t distance_between_lines = scale_(this->spacing) / params.density;
const coord_t distance_between_lines = scale_(this->spacing) / this->density;

// align infill across layers using the object's bounding box
// Rotated bounding box of the whole object.
BoundingBox bounding_box = this->bounding_box.rotated(-direction.first);
// align infill across layers using the object's bounding box (if available)
BoundingBox bounding_box = this->bounding_box.defined
? this->bounding_box
: expolygon.contour.bounding_box();
bounding_box = bounding_box.rotated(-direction.first);

const Point shift = this->_centered()
? bounding_box.center()
Expand Down
1 change: 0 additions & 1 deletion xs/src/libslic3r/Fill/FillPlanePath.hpp
Expand Up @@ -20,7 +20,6 @@ class FillPlanePath : public Fill

protected:
virtual void _fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Expand Down
11 changes: 6 additions & 5 deletions xs/src/libslic3r/Fill/FillRectilinear.cpp
Expand Up @@ -8,25 +8,26 @@
namespace Slic3r {

void FillRectilinear::_fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Polylines* polylines_out)
{
assert(params.density > 0.0001f && params.density <= 1.f);
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) / params.density);
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

// We ignore this->bounding_box because it doesn't matter; we're doing align_to_grid below.
BoundingBox bounding_box = expolygon.contour.bounding_box();

// define flow spacing according to requested density
if (params.density > 0.9999f && !params.dont_adjust) {
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);
} else {
Expand Down Expand Up @@ -79,7 +80,7 @@ void FillRectilinear::_fill_surface_single(
size_t n_polylines_out_old = polylines_out->size();

// connect lines
if (!params.dont_connect && !polylines.empty()) { // prevent calling leftmost_point() on empty collections
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;
{
Expand Down
1 change: 0 additions & 1 deletion xs/src/libslic3r/Fill/FillRectilinear.hpp
Expand Up @@ -14,7 +14,6 @@ class FillRectilinear : public Fill

protected:
virtual void _fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Expand Down

0 comments on commit ea98d97

Please sign in to comment.