mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-12 02:48:59 +08:00
Refactoring: moved Fill::adjust_solid_spacing() to Flow::solid_spacing().
This commit is contained in:
parent
678ae9de72
commit
3f0fea7585
@ -804,6 +804,8 @@ sub generate_toolpaths {
|
|||||||
$to_infill,
|
$to_infill,
|
||||||
offset($object->get_layer(0)->slices->polygons, $d),
|
offset($object->get_layer(0)->slices->polygons, $d),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$to_infill = union_ex($to_infill);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# draw a perimeter all around support infill
|
# draw a perimeter all around support infill
|
||||||
|
2
t/fill.t
2
t/fill.t
@ -22,7 +22,7 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
|
|||||||
{
|
{
|
||||||
my $print = Slic3r::Print->new;
|
my $print = Slic3r::Print->new;
|
||||||
my $surface_width = 250;
|
my $surface_width = 250;
|
||||||
my $distance = Slic3r::Filler::adjust_solid_spacing($surface_width, 47);
|
my $distance = Slic3r::Flow::solid_spacing($surface_width, 47);
|
||||||
is $distance, 50, 'adjusted solid distance';
|
is $distance, 50, 'adjusted solid distance';
|
||||||
is $surface_width % $distance, 0, 'adjusted solid distance';
|
is $surface_width % $distance, 0, 'adjusted solid distance';
|
||||||
}
|
}
|
||||||
|
@ -72,36 +72,6 @@ Fill::fill_surface(const Surface &surface)
|
|||||||
return polylines_out;
|
return polylines_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate a new spacing to fill width with possibly integer number of lines,
|
|
||||||
// the first and last line being centered at the interval ends.
|
|
||||||
// This function possibly increases the spacing, never decreases,
|
|
||||||
// and for a narrow width the increase in spacing may become severe,
|
|
||||||
// therefore the adjustment is limited to 20% increase.
|
|
||||||
coord_t
|
|
||||||
Fill::adjust_solid_spacing(const coord_t width, const coord_t distance)
|
|
||||||
{
|
|
||||||
assert(width >= 0);
|
|
||||||
assert(distance > 0);
|
|
||||||
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);
|
|
||||||
|
|
||||||
// How much could the extrusion width be increased? By 20%.
|
|
||||||
// Because of this limit, this method is not idempotent: each run
|
|
||||||
// will increment distance by 20%.
|
|
||||||
const coordf_t factor_max = 1.2;
|
|
||||||
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.
|
// 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.
|
// For a normal print, the reference point is the center of a bounding box of the STL.
|
||||||
Fill::direction_t
|
Fill::direction_t
|
||||||
|
@ -64,7 +64,6 @@ public:
|
|||||||
public:
|
public:
|
||||||
static Fill* new_from_type(const InfillPattern type);
|
static Fill* new_from_type(const InfillPattern type);
|
||||||
static Fill* new_from_type(const std::string &type);
|
static Fill* new_from_type(const std::string &type);
|
||||||
static coord_t adjust_solid_spacing(const coord_t width, const coord_t distance);
|
|
||||||
virtual Fill* clone() const = 0;
|
virtual Fill* clone() const = 0;
|
||||||
virtual ~Fill() {};
|
virtual ~Fill() {};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "../ClipperUtils.hpp"
|
#include "../ClipperUtils.hpp"
|
||||||
#include "../ExPolygon.hpp"
|
#include "../ExPolygon.hpp"
|
||||||
|
#include "../Flow.hpp"
|
||||||
#include "../Surface.hpp"
|
#include "../Surface.hpp"
|
||||||
|
|
||||||
#include "FillConcentric.hpp"
|
#include "FillConcentric.hpp"
|
||||||
@ -20,7 +21,7 @@ FillConcentric::_fill_surface_single(
|
|||||||
|
|
||||||
if (this->density > 0.9999f && !this->dont_adjust) {
|
if (this->density > 0.9999f && !this->dont_adjust) {
|
||||||
BoundingBox bounding_box = expolygon.contour.bounding_box();
|
BoundingBox bounding_box = expolygon.contour.bounding_box();
|
||||||
distance = this->adjust_solid_spacing(bounding_box.size().x, distance);
|
distance = Flow::solid_spacing(bounding_box.size().x, distance);
|
||||||
this->_spacing = unscale(distance);
|
this->_spacing = unscale(distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "../ClipperUtils.hpp"
|
#include "../ClipperUtils.hpp"
|
||||||
#include "../ExPolygon.hpp"
|
#include "../ExPolygon.hpp"
|
||||||
|
#include "../Flow.hpp"
|
||||||
#include "../PolylineCollection.hpp"
|
#include "../PolylineCollection.hpp"
|
||||||
#include "../Surface.hpp"
|
#include "../Surface.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -48,7 +49,7 @@ FillRectilinear::_fill_single_direction(ExPolygon expolygon,
|
|||||||
|
|
||||||
// define flow spacing according to requested density
|
// define flow spacing according to requested density
|
||||||
if (this->density > 0.9999f && !this->dont_adjust) {
|
if (this->density > 0.9999f && !this->dont_adjust) {
|
||||||
line_spacing = this->adjust_solid_spacing(bounding_box.size().x, line_spacing);
|
line_spacing = Flow::solid_spacing(bounding_box.size().x, line_spacing);
|
||||||
this->_spacing = unscale(line_spacing);
|
this->_spacing = unscale(line_spacing);
|
||||||
} else {
|
} else {
|
||||||
// extend bounding box so that our pattern will be aligned with other layers
|
// extend bounding box so that our pattern will be aligned with other layers
|
||||||
|
@ -120,4 +120,37 @@ Flow::_width_from_spacing(float spacing, float nozzle_diameter, float height, bo
|
|||||||
return spacing + OVERLAP_FACTOR * height * (1 - PI/4.0);
|
return spacing + OVERLAP_FACTOR * height * (1 - PI/4.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate a new spacing to fill width with possibly integer number of lines,
|
||||||
|
// the first and last line being centered at the interval ends.
|
||||||
|
// This function possibly increases the spacing, never decreases,
|
||||||
|
// and for a narrow width the increase in spacing may become severe,
|
||||||
|
// therefore the adjustment is limited to 20% increase.
|
||||||
|
template <class T>
|
||||||
|
T
|
||||||
|
Flow::solid_spacing(const T total_width, const T spacing)
|
||||||
|
{
|
||||||
|
assert(total_width >= 0);
|
||||||
|
assert(spacing > 0);
|
||||||
|
const int number_of_intervals = floor(total_width / spacing);
|
||||||
|
if (number_of_intervals == 0) return spacing;
|
||||||
|
|
||||||
|
T spacing_new = (total_width / number_of_intervals);
|
||||||
|
|
||||||
|
const double factor = (double)spacing_new / (double)spacing;
|
||||||
|
assert(factor > 1. - 1e-5);
|
||||||
|
|
||||||
|
// How much could the extrusion width be increased? By 20%.
|
||||||
|
// Because of this limit, this method is not idempotent: each run
|
||||||
|
// will increment spacing by 20%.
|
||||||
|
const double factor_max = 1.2;
|
||||||
|
if (factor > factor_max)
|
||||||
|
spacing_new = floor((double)spacing * factor_max + 0.5);
|
||||||
|
|
||||||
|
assert((spacing_new * number_of_intervals) <= total_width);
|
||||||
|
|
||||||
|
return spacing_new;
|
||||||
|
}
|
||||||
|
template coord_t Flow::solid_spacing<coord_t>(const coord_t total_width, const coord_t spacing);
|
||||||
|
template coordf_t Flow::solid_spacing<coordf_t>(const coordf_t total_width, const coordf_t spacing);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,12 @@ class Flow
|
|||||||
float spacing() const;
|
float spacing() const;
|
||||||
float spacing(const Flow &other) const;
|
float spacing(const Flow &other) const;
|
||||||
void set_spacing(float spacing);
|
void set_spacing(float spacing);
|
||||||
|
void set_solid_spacing(const coord_t total_width) {
|
||||||
|
this->set_spacing(Flow::solid_spacing(total_width, this->scaled_spacing()));
|
||||||
|
};
|
||||||
|
void set_solid_spacing(const coordf_t total_width) {
|
||||||
|
this->set_spacing(Flow::solid_spacing(total_width, (coordf_t)this->spacing()));
|
||||||
|
};
|
||||||
double mm3_per_mm() const;
|
double mm3_per_mm() const;
|
||||||
coord_t scaled_width() const {
|
coord_t scaled_width() const {
|
||||||
return scale_(this->width);
|
return scale_(this->width);
|
||||||
@ -44,6 +50,7 @@ class Flow
|
|||||||
|
|
||||||
static Flow new_from_config_width(FlowRole role, const ConfigOptionFloatOrPercent &width, float nozzle_diameter, float height, float bridge_flow_ratio);
|
static Flow new_from_config_width(FlowRole role, const ConfigOptionFloatOrPercent &width, float nozzle_diameter, float height, float bridge_flow_ratio);
|
||||||
static Flow new_from_spacing(float spacing, float nozzle_diameter, float height, bool bridge);
|
static Flow new_from_spacing(float spacing, float nozzle_diameter, float height, bool bridge);
|
||||||
|
template <class T> static T solid_spacing(const T total_width, const T spacing);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static float _bridge_width(float nozzle_diameter, float bridge_flow_ratio);
|
static float _bridge_width(float nozzle_diameter, float bridge_flow_ratio);
|
||||||
|
@ -771,7 +771,8 @@ Print::brim_flow() const
|
|||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
flow.set_spacing(unscale(Fill::adjust_solid_spacing(scale_(this->config.brim_width.value), scale_(flow.spacing()))));
|
// Adjust extrusion width in order to fill the total brim width with an integer number of lines.
|
||||||
|
flow.set_solid_spacing(this->config.brim_width.value);
|
||||||
|
|
||||||
return flow;
|
return flow;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,3 @@ new_from_type(CLASS, type)
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
%package{Slic3r::Filler};
|
|
||||||
|
|
||||||
coord_t adjust_solid_spacing(coord_t width, coord_t distance)
|
|
||||||
%code{% RETVAL = Fill::adjust_solid_spacing(width, distance); %};
|
|
||||||
|
@ -81,3 +81,6 @@ _constant()
|
|||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
coord_t solid_spacing(coord_t width, coord_t distance)
|
||||||
|
%code{% RETVAL = Flow::solid_spacing(width, distance); %};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user