2014-08-03 17:28:40 +00:00
|
|
|
#include "Layer.hpp"
|
2015-10-26 22:23:03 +00:00
|
|
|
#include "BridgeDetector.hpp"
|
2014-11-09 15:23:50 +00:00
|
|
|
#include "ClipperUtils.hpp"
|
2017-07-31 14:23:52 +00:00
|
|
|
#include "Geometry.hpp"
|
2015-07-23 14:27:21 +00:00
|
|
|
#include "PerimeterGenerator.hpp"
|
2014-08-03 17:28:40 +00:00
|
|
|
#include "Print.hpp"
|
2014-11-09 15:23:50 +00:00
|
|
|
#include "Surface.hpp"
|
2016-09-30 13:23:18 +00:00
|
|
|
#include "BoundingBox.hpp"
|
2016-09-26 11:44:23 +00:00
|
|
|
#include "SVG.hpp"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2014-08-03 17:28:40 +00:00
|
|
|
|
2017-03-02 15:41:16 +00:00
|
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
|
2014-08-03 17:28:40 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
2021-03-08 12:44:00 +00:00
|
|
|
Flow LayerRegion::flow(FlowRole role) const
|
2014-08-03 17:28:40 +00:00
|
|
|
{
|
2021-03-08 12:44:00 +00:00
|
|
|
return m_region->flow(*m_layer->object(), role, m_layer->height, m_layer->id() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Flow LayerRegion::bridging_flow(FlowRole role) const
|
|
|
|
{
|
|
|
|
return this->layer()->object()->config().thick_bridges ? m_region->bridging_flow(role) : this->flow(role);
|
2014-08-03 17:28:40 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 18:23:01 +00:00
|
|
|
// Fill in layerm->fill_surfaces by trimming the layerm->slices by the cummulative layerm->fill_surfaces.
|
|
|
|
void LayerRegion::slices_to_fill_surfaces_clipped()
|
|
|
|
{
|
|
|
|
// Note: this method should be idempotent, but fill_surfaces gets modified
|
|
|
|
// in place. However we're now only using its boundaries (which are invariant)
|
|
|
|
// so we're safe. This guarantees idempotence of prepare_infill() also in case
|
|
|
|
// that combine_infill() turns some fill_surface into VOID surfaces.
|
2018-11-02 19:45:23 +00:00
|
|
|
// Polygons fill_boundaries = to_polygons(std::move(this->fill_surfaces));
|
2016-11-17 22:22:59 +00:00
|
|
|
Polygons fill_boundaries = to_polygons(this->fill_expolygons);
|
2017-03-02 15:41:16 +00:00
|
|
|
// Collect polygons per surface type.
|
|
|
|
std::vector<Polygons> polygons_by_surface;
|
|
|
|
polygons_by_surface.assign(size_t(stCount), Polygons());
|
|
|
|
for (Surface &surface : this->slices.surfaces)
|
|
|
|
polygons_append(polygons_by_surface[(size_t)surface.surface_type], surface.expolygon);
|
|
|
|
// Trim surfaces by the fill_boundaries.
|
2016-11-10 18:23:01 +00:00
|
|
|
this->fill_surfaces.surfaces.clear();
|
2017-03-02 15:41:16 +00:00
|
|
|
for (size_t surface_type = 0; surface_type < size_t(stCount); ++ surface_type) {
|
|
|
|
const Polygons &polygons = polygons_by_surface[surface_type];
|
|
|
|
if (! polygons.empty())
|
|
|
|
this->fill_surfaces.append(intersection_ex(polygons, fill_boundaries), SurfaceType(surface_type));
|
|
|
|
}
|
2014-11-09 15:23:50 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 15:05:31 +00:00
|
|
|
void LayerRegion::make_perimeters(const SurfaceCollection &slices, SurfaceCollection* fill_surfaces)
|
2015-07-23 14:27:21 +00:00
|
|
|
{
|
|
|
|
this->perimeters.clear();
|
|
|
|
this->thin_fills.clear();
|
2020-12-09 13:07:22 +00:00
|
|
|
|
|
|
|
const PrintConfig &print_config = this->layer()->object()->print()->config();
|
|
|
|
const PrintRegionConfig ®ion_config = this->region()->config();
|
|
|
|
// This needs to be in sync with PrintObject::_slice() slicing_mode_normal_below_layer!
|
|
|
|
bool spiral_vase = print_config.spiral_vase &&
|
2021-01-11 09:23:56 +00:00
|
|
|
(this->layer()->id() >= size_t(region_config.bottom_solid_layers.value) &&
|
2020-12-09 13:07:22 +00:00
|
|
|
this->layer()->print_z >= region_config.bottom_solid_min_thickness - EPSILON);
|
|
|
|
|
2015-07-23 14:27:21 +00:00
|
|
|
PerimeterGenerator g(
|
|
|
|
// input:
|
|
|
|
&slices,
|
|
|
|
this->layer()->height,
|
|
|
|
this->flow(frPerimeter),
|
2020-12-09 13:07:22 +00:00
|
|
|
®ion_config,
|
2018-09-11 12:04:47 +00:00
|
|
|
&this->layer()->object()->config(),
|
2020-12-09 13:07:22 +00:00
|
|
|
&print_config,
|
|
|
|
spiral_vase,
|
2015-07-23 14:27:21 +00:00
|
|
|
|
|
|
|
// output:
|
|
|
|
&this->perimeters,
|
|
|
|
&this->thin_fills,
|
|
|
|
fill_surfaces
|
|
|
|
);
|
|
|
|
|
2019-10-17 15:09:15 +00:00
|
|
|
if (this->layer()->lower_layer != nullptr)
|
2016-09-13 11:30:00 +00:00
|
|
|
// Cummulative sum of polygons over all the regions.
|
2020-01-03 13:05:56 +00:00
|
|
|
g.lower_slices = &this->layer()->lower_layer->lslices;
|
2015-07-23 14:27:21 +00:00
|
|
|
|
2019-03-05 10:54:04 +00:00
|
|
|
g.layer_id = (int)this->layer()->id();
|
2015-07-23 14:27:21 +00:00
|
|
|
g.ext_perimeter_flow = this->flow(frExternalPerimeter);
|
2021-03-08 12:44:00 +00:00
|
|
|
g.overhang_flow = this->bridging_flow(frPerimeter);
|
2015-07-23 14:27:21 +00:00
|
|
|
g.solid_infill_flow = this->flow(frSolidInfill);
|
|
|
|
|
|
|
|
g.process();
|
|
|
|
}
|
|
|
|
|
2016-11-28 16:33:17 +00:00
|
|
|
//#define EXTERNAL_SURFACES_OFFSET_PARAMETERS ClipperLib::jtMiter, 3.
|
|
|
|
//#define EXTERNAL_SURFACES_OFFSET_PARAMETERS ClipperLib::jtMiter, 1.5
|
|
|
|
#define EXTERNAL_SURFACES_OFFSET_PARAMETERS ClipperLib::jtSquare, 0.
|
2016-11-08 14:35:08 +00:00
|
|
|
|
2019-09-06 13:03:49 +00:00
|
|
|
void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Polygons *lower_layer_covered)
|
2015-10-26 22:23:03 +00:00
|
|
|
{
|
2019-09-06 13:03:49 +00:00
|
|
|
const bool has_infill = this->region()->config().fill_density.value > 0.;
|
|
|
|
const float margin = float(scale_(EXTERNAL_INFILL_MARGIN));
|
|
|
|
|
2016-09-26 11:44:23 +00:00
|
|
|
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
|
|
|
|
export_region_fill_surfaces_to_svg_debug("3_process_external_surfaces-initial");
|
|
|
|
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
|
|
|
|
|
2016-09-30 13:23:18 +00:00
|
|
|
// 1) Collect bottom and bridge surfaces, each of them grown by a fixed 3mm offset
|
|
|
|
// for better anchoring.
|
2016-11-08 08:59:25 +00:00
|
|
|
// Bottom surfaces, grown.
|
|
|
|
Surfaces bottom;
|
|
|
|
// Bridge surfaces, initialy not grown.
|
|
|
|
Surfaces bridges;
|
2016-11-10 18:23:01 +00:00
|
|
|
// Top surfaces, grown.
|
|
|
|
Surfaces top;
|
|
|
|
// Internal surfaces, not grown.
|
|
|
|
Surfaces internal;
|
|
|
|
// Areas, where an infill of various types (top, bottom, bottom bride, sparse, void) could be placed.
|
2019-09-06 13:03:49 +00:00
|
|
|
Polygons fill_boundaries = to_polygons(this->fill_expolygons);
|
|
|
|
Polygons lower_layer_covered_tmp;
|
2016-11-10 18:23:01 +00:00
|
|
|
|
|
|
|
// Collect top surfaces and internal surfaces.
|
|
|
|
// Collect fill_boundaries: If we're slicing with no infill, we can't extend external surfaces over non-existent infill.
|
|
|
|
// This loop destroys the surfaces (aliasing this->fill_surfaces.surfaces) by moving into top/internal/fill_boundaries!
|
2019-09-06 13:03:49 +00:00
|
|
|
|
2016-11-10 18:23:01 +00:00
|
|
|
{
|
2019-09-06 13:03:49 +00:00
|
|
|
// Voids are sparse infills if infill rate is zero.
|
|
|
|
Polygons voids;
|
2017-03-07 16:43:43 +00:00
|
|
|
for (const Surface &surface : this->fill_surfaces.surfaces) {
|
2020-03-14 10:59:50 +00:00
|
|
|
if (surface.is_top()) {
|
2016-11-10 18:23:01 +00:00
|
|
|
// Collect the top surfaces, inflate them and trim them by the bottom surfaces.
|
|
|
|
// This gives the priority to bottom surfaces.
|
2019-09-06 13:03:49 +00:00
|
|
|
surfaces_append(top, offset_ex(surface.expolygon, margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS), surface);
|
|
|
|
} else if (surface.surface_type == stBottom || (surface.surface_type == stBottomBridge && lower_layer == nullptr)) {
|
2016-11-10 18:23:01 +00:00
|
|
|
// Grown by 3mm.
|
2019-09-06 13:03:49 +00:00
|
|
|
surfaces_append(bottom, offset_ex(surface.expolygon, margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS), surface);
|
2017-03-07 16:43:43 +00:00
|
|
|
} else if (surface.surface_type == stBottomBridge) {
|
|
|
|
if (! surface.empty())
|
2019-09-06 13:03:49 +00:00
|
|
|
bridges.emplace_back(surface);
|
|
|
|
}
|
|
|
|
if (surface.is_internal()) {
|
2019-10-17 15:09:15 +00:00
|
|
|
assert(surface.surface_type == stInternal || surface.surface_type == stInternalSolid);
|
2019-09-06 13:03:49 +00:00
|
|
|
if (! has_infill && lower_layer != nullptr)
|
|
|
|
polygons_append(voids, surface.expolygon);
|
|
|
|
internal.emplace_back(std::move(surface));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! has_infill && lower_layer != nullptr && ! voids.empty()) {
|
|
|
|
// Remove voids from fill_boundaries, that are not supported by the layer below.
|
|
|
|
if (lower_layer_covered == nullptr) {
|
|
|
|
lower_layer_covered = &lower_layer_covered_tmp;
|
2020-01-03 13:05:56 +00:00
|
|
|
lower_layer_covered_tmp = to_polygons(lower_layer->lslices);
|
2016-11-10 18:23:01 +00:00
|
|
|
}
|
2019-09-06 13:03:49 +00:00
|
|
|
if (! lower_layer_covered->empty())
|
|
|
|
voids = diff(voids, *lower_layer_covered);
|
2019-09-24 14:01:01 +00:00
|
|
|
fill_boundaries = diff(fill_boundaries, voids);
|
2016-09-30 13:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
static int iRun = 0;
|
2016-10-21 08:18:01 +00:00
|
|
|
bridges.export_to_svg(debug_out_path("bridges-before-grouping-%d.svg", iRun ++), true);
|
2016-09-30 13:23:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-10 18:23:01 +00:00
|
|
|
if (bridges.empty())
|
|
|
|
{
|
|
|
|
fill_boundaries = union_(fill_boundaries, true);
|
|
|
|
} else
|
2016-11-08 08:59:25 +00:00
|
|
|
{
|
2016-11-10 18:23:01 +00:00
|
|
|
// 1) Calculate the inflated bridge regions, each constrained to its island.
|
|
|
|
ExPolygons fill_boundaries_ex = union_ex(fill_boundaries, true);
|
|
|
|
std::vector<Polygons> bridges_grown;
|
|
|
|
std::vector<BoundingBox> bridge_bboxes;
|
|
|
|
|
|
|
|
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
|
|
|
|
{
|
|
|
|
static int iRun = 0;
|
|
|
|
SVG svg(debug_out_path("3_process_external_surfaces-fill_regions-%d.svg", iRun ++).c_str(), get_extents(fill_boundaries_ex));
|
|
|
|
svg.draw(fill_boundaries_ex);
|
|
|
|
svg.draw_outline(fill_boundaries_ex, "black", "blue", scale_(0.05));
|
|
|
|
svg.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// export_region_fill_surfaces_to_svg_debug("3_process_external_surfaces-initial");
|
|
|
|
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
|
|
|
|
|
|
|
|
{
|
|
|
|
// Bridge expolygons, grown, to be tested for intersection with other bridge regions.
|
|
|
|
std::vector<BoundingBox> fill_boundaries_ex_bboxes = get_extents_vector(fill_boundaries_ex);
|
|
|
|
bridges_grown.reserve(bridges.size());
|
|
|
|
bridge_bboxes.reserve(bridges.size());
|
|
|
|
for (size_t i = 0; i < bridges.size(); ++ i) {
|
|
|
|
// Find the island of this bridge.
|
|
|
|
const Point pt = bridges[i].expolygon.contour.points.front();
|
|
|
|
int idx_island = -1;
|
|
|
|
for (int j = 0; j < int(fill_boundaries_ex.size()); ++ j)
|
|
|
|
if (fill_boundaries_ex_bboxes[j].contains(pt) &&
|
|
|
|
fill_boundaries_ex[j].contains(pt)) {
|
|
|
|
idx_island = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Grown by 3mm.
|
2019-09-06 13:03:49 +00:00
|
|
|
Polygons polys = offset(to_polygons(bridges[i].expolygon), margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS);
|
2016-11-10 18:23:01 +00:00
|
|
|
if (idx_island == -1) {
|
2019-09-06 13:03:49 +00:00
|
|
|
BOOST_LOG_TRIVIAL(trace) << "Bridge did not fall into the source region!";
|
2016-11-10 18:23:01 +00:00
|
|
|
} else {
|
|
|
|
// Found an island, to which this bridge region belongs. Trim it,
|
|
|
|
polys = intersection(polys, to_polygons(fill_boundaries_ex[idx_island]));
|
|
|
|
}
|
|
|
|
bridge_bboxes.push_back(get_extents(polys));
|
2018-11-02 19:45:23 +00:00
|
|
|
bridges_grown.push_back(std::move(polys));
|
2016-11-10 18:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 08:59:25 +00:00
|
|
|
// 2) Group the bridge surfaces by overlaps.
|
|
|
|
std::vector<size_t> bridge_group(bridges.size(), (size_t)-1);
|
|
|
|
size_t n_groups = 0;
|
|
|
|
for (size_t i = 0; i < bridges.size(); ++ i) {
|
|
|
|
// A grup id for this bridge.
|
2019-06-25 11:06:04 +00:00
|
|
|
size_t group_id = (bridge_group[i] == size_t(-1)) ? (n_groups ++) : bridge_group[i];
|
2016-11-08 08:59:25 +00:00
|
|
|
bridge_group[i] = group_id;
|
|
|
|
// For all possibly overlaping bridges:
|
|
|
|
for (size_t j = i + 1; j < bridges.size(); ++ j) {
|
|
|
|
if (! bridge_bboxes[i].overlap(bridge_bboxes[j]))
|
|
|
|
continue;
|
|
|
|
if (intersection(bridges_grown[i], bridges_grown[j], false).empty())
|
|
|
|
continue;
|
|
|
|
// The two bridge regions intersect. Give them the same group id.
|
2019-06-25 11:06:04 +00:00
|
|
|
if (bridge_group[j] != size_t(-1)) {
|
2016-11-08 08:59:25 +00:00
|
|
|
// The j'th bridge has been merged with some other bridge before.
|
|
|
|
size_t group_id_new = bridge_group[j];
|
2016-11-10 18:23:01 +00:00
|
|
|
for (size_t k = 0; k < j; ++ k)
|
2016-11-08 08:59:25 +00:00
|
|
|
if (bridge_group[k] == group_id)
|
|
|
|
bridge_group[k] = group_id_new;
|
|
|
|
group_id = group_id_new;
|
|
|
|
}
|
|
|
|
bridge_group[j] = group_id;
|
2016-09-30 13:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 08:59:25 +00:00
|
|
|
// 3) Merge the groups with the same group id, detect bridges.
|
|
|
|
{
|
2017-03-02 15:41:16 +00:00
|
|
|
BOOST_LOG_TRIVIAL(trace) << "Processing external surface, detecting bridges. layer" << this->layer()->print_z << ", bridge groups: " << n_groups;
|
2016-11-08 08:59:25 +00:00
|
|
|
for (size_t group_id = 0; group_id < n_groups; ++ group_id) {
|
|
|
|
size_t n_bridges_merged = 0;
|
|
|
|
size_t idx_last = (size_t)-1;
|
|
|
|
for (size_t i = 0; i < bridges.size(); ++ i) {
|
|
|
|
if (bridge_group[i] == group_id) {
|
|
|
|
++ n_bridges_merged;
|
|
|
|
idx_last = i;
|
|
|
|
}
|
2016-09-30 13:23:18 +00:00
|
|
|
}
|
2016-11-08 08:59:25 +00:00
|
|
|
if (n_bridges_merged == 0)
|
|
|
|
// This group has no regions assigned as these were moved into another group.
|
|
|
|
continue;
|
|
|
|
// Collect the initial ungrown regions and the grown polygons.
|
|
|
|
ExPolygons initial;
|
|
|
|
Polygons grown;
|
|
|
|
for (size_t i = 0; i < bridges.size(); ++ i) {
|
2016-09-30 13:23:18 +00:00
|
|
|
if (bridge_group[i] != group_id)
|
|
|
|
continue;
|
2018-11-02 19:45:23 +00:00
|
|
|
initial.push_back(std::move(bridges[i].expolygon));
|
2016-11-08 08:59:25 +00:00
|
|
|
polygons_append(grown, bridges_grown[i]);
|
2016-09-30 13:23:18 +00:00
|
|
|
}
|
2016-11-08 08:59:25 +00:00
|
|
|
// detect bridge direction before merging grown surfaces otherwise adjacent bridges
|
|
|
|
// would get merged into a single one while they need different directions
|
|
|
|
// also, supply the original expolygon instead of the grown one, because in case
|
|
|
|
// of very thin (but still working) anchors, the grown expolygon would go beyond them
|
2021-03-08 12:44:00 +00:00
|
|
|
BridgeDetector bd(initial, lower_layer->lslices, this->bridging_flow(frInfill).scaled_width());
|
2016-11-08 08:59:25 +00:00
|
|
|
#ifdef SLIC3R_DEBUG
|
2020-06-16 11:13:51 +00:00
|
|
|
printf("Processing bridge at layer %zu:\n", this->layer()->id());
|
2016-11-08 08:59:25 +00:00
|
|
|
#endif
|
2019-04-01 15:12:39 +00:00
|
|
|
double custom_angle = Geometry::deg2rad(this->region()->config().bridge_angle.value);
|
|
|
|
if (bd.detect_angle(custom_angle)) {
|
2016-11-08 08:59:25 +00:00
|
|
|
bridges[idx_last].bridge_angle = bd.angle;
|
2021-02-23 14:31:08 +00:00
|
|
|
if (this->layer()->object()->has_support()) {
|
2021-02-09 17:36:28 +00:00
|
|
|
// polygons_append(this->bridged, bd.coverage());
|
2019-09-27 16:17:21 +00:00
|
|
|
append(this->unsupported_bridge_edges, bd.unsupported_edges());
|
2016-11-08 08:59:25 +00:00
|
|
|
}
|
2019-04-01 15:12:39 +00:00
|
|
|
} else if (custom_angle > 0) {
|
|
|
|
// Bridge was not detected (likely it is only supported at one side). Still it is a surface filled in
|
|
|
|
// using a bridging flow, therefore it makes sense to respect the custom bridging direction.
|
|
|
|
bridges[idx_last].bridge_angle = custom_angle;
|
|
|
|
}
|
2016-11-08 08:59:25 +00:00
|
|
|
// without safety offset, artifacts are generated (GH #2494)
|
|
|
|
surfaces_append(bottom, union_ex(grown, true), bridges[idx_last]);
|
2016-09-30 13:23:18 +00:00
|
|
|
}
|
2016-11-10 18:23:01 +00:00
|
|
|
|
2021-01-29 15:16:23 +00:00
|
|
|
fill_boundaries = to_polygons(fill_boundaries_ex);
|
2017-03-02 15:41:16 +00:00
|
|
|
BOOST_LOG_TRIVIAL(trace) << "Processing external surface, detecting bridges - done";
|
|
|
|
}
|
2016-09-30 13:23:18 +00:00
|
|
|
|
2016-11-08 08:59:25 +00:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
static int iRun = 0;
|
|
|
|
bridges.export_to_svg(debug_out_path("bridges-after-grouping-%d.svg", iRun ++), true);
|
2016-09-30 13:23:18 +00:00
|
|
|
}
|
2016-11-08 08:59:25 +00:00
|
|
|
#endif
|
2016-09-30 13:23:18 +00:00
|
|
|
}
|
2016-11-08 08:59:25 +00:00
|
|
|
|
|
|
|
Surfaces new_surfaces;
|
2016-11-10 18:23:01 +00:00
|
|
|
{
|
|
|
|
// Merge top and bottom in a single collection.
|
2018-11-02 19:45:23 +00:00
|
|
|
surfaces_append(top, std::move(bottom));
|
2016-11-10 18:23:01 +00:00
|
|
|
// Intersect the grown surfaces with the actual fill boundaries.
|
|
|
|
Polygons bottom_polygons = to_polygons(bottom);
|
|
|
|
for (size_t i = 0; i < top.size(); ++ i) {
|
|
|
|
Surface &s1 = top[i];
|
|
|
|
if (s1.empty())
|
|
|
|
continue;
|
|
|
|
Polygons polys;
|
2018-11-02 19:45:23 +00:00
|
|
|
polygons_append(polys, std::move(s1));
|
2016-11-10 18:23:01 +00:00
|
|
|
for (size_t j = i + 1; j < top.size(); ++ j) {
|
|
|
|
Surface &s2 = top[j];
|
2017-01-02 15:51:43 +00:00
|
|
|
if (! s2.empty() && surfaces_could_merge(s1, s2)) {
|
2018-11-02 19:45:23 +00:00
|
|
|
polygons_append(polys, std::move(s2));
|
2017-01-02 15:51:43 +00:00
|
|
|
s2.clear();
|
|
|
|
}
|
2016-11-10 18:23:01 +00:00
|
|
|
}
|
2020-03-14 10:59:50 +00:00
|
|
|
if (s1.is_top())
|
2016-11-10 18:23:01 +00:00
|
|
|
// Trim the top surfaces by the bottom surfaces. This gives the priority to the bottom surfaces.
|
|
|
|
polys = diff(polys, bottom_polygons);
|
|
|
|
surfaces_append(
|
|
|
|
new_surfaces,
|
|
|
|
// Don't use a safety offset as fill_boundaries were already united using the safety offset.
|
2021-01-29 15:16:23 +00:00
|
|
|
intersection_ex(polys, fill_boundaries, false),
|
2016-11-10 18:23:01 +00:00
|
|
|
s1);
|
2015-10-26 22:23:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 08:59:25 +00:00
|
|
|
// Subtract the new top surfaces from the other non-top surfaces and re-add them.
|
|
|
|
Polygons new_polygons = to_polygons(new_surfaces);
|
|
|
|
for (size_t i = 0; i < internal.size(); ++ i) {
|
|
|
|
Surface &s1 = internal[i];
|
|
|
|
if (s1.empty())
|
|
|
|
continue;
|
|
|
|
Polygons polys;
|
2018-11-02 19:45:23 +00:00
|
|
|
polygons_append(polys, std::move(s1));
|
2016-11-08 08:59:25 +00:00
|
|
|
for (size_t j = i + 1; j < internal.size(); ++ j) {
|
|
|
|
Surface &s2 = internal[j];
|
2017-01-02 15:51:43 +00:00
|
|
|
if (! s2.empty() && surfaces_could_merge(s1, s2)) {
|
2018-11-02 19:45:23 +00:00
|
|
|
polygons_append(polys, std::move(s2));
|
2017-01-02 15:51:43 +00:00
|
|
|
s2.clear();
|
|
|
|
}
|
2015-10-26 22:23:03 +00:00
|
|
|
}
|
2016-11-08 08:59:25 +00:00
|
|
|
ExPolygons new_expolys = diff_ex(polys, new_polygons);
|
|
|
|
polygons_append(new_polygons, to_polygons(new_expolys));
|
2018-11-02 19:45:23 +00:00
|
|
|
surfaces_append(new_surfaces, std::move(new_expolys), s1);
|
2015-10-26 22:23:03 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 19:45:23 +00:00
|
|
|
this->fill_surfaces.surfaces = std::move(new_surfaces);
|
2016-09-26 11:44:23 +00:00
|
|
|
|
|
|
|
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
|
|
|
|
export_region_fill_surfaces_to_svg_debug("3_process_external_surfaces-final");
|
|
|
|
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
|
2015-10-26 22:23:03 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 15:05:31 +00:00
|
|
|
void LayerRegion::prepare_fill_surfaces()
|
2015-02-01 11:43:58 +00:00
|
|
|
{
|
2016-11-10 18:23:01 +00:00
|
|
|
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
|
|
|
|
export_region_slices_to_svg_debug("2_prepare_fill_surfaces-initial");
|
|
|
|
export_region_fill_surfaces_to_svg_debug("2_prepare_fill_surfaces-initial");
|
|
|
|
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
|
|
|
|
|
2015-02-01 11:43:58 +00:00
|
|
|
/* Note: in order to make the psPrepareInfill step idempotent, we should never
|
|
|
|
alter fill_surfaces boundaries on which our idempotency relies since that's
|
|
|
|
the only meaningful information returned by psPerimeters. */
|
|
|
|
|
2020-02-08 20:36:29 +00:00
|
|
|
bool spiral_vase = this->layer()->object()->print()->config().spiral_vase;
|
|
|
|
|
2015-02-01 11:43:58 +00:00
|
|
|
// if no solid layers are requested, turn top/bottom surfaces to internal
|
2020-02-08 20:36:29 +00:00
|
|
|
if (! spiral_vase && this->region()->config().top_solid_layers == 0) {
|
2019-09-10 17:09:37 +00:00
|
|
|
for (Surface &surface : this->fill_surfaces.surfaces)
|
|
|
|
if (surface.is_top())
|
|
|
|
surface.surface_type = this->layer()->object()->config().infill_only_where_needed ? stInternalVoid : stInternal;
|
2015-02-01 11:43:58 +00:00
|
|
|
}
|
2018-09-11 12:04:47 +00:00
|
|
|
if (this->region()->config().bottom_solid_layers == 0) {
|
2019-09-10 17:09:37 +00:00
|
|
|
for (Surface &surface : this->fill_surfaces.surfaces)
|
|
|
|
if (surface.is_bottom()) // (surface.surface_type == stBottom)
|
|
|
|
surface.surface_type = stInternal;
|
2015-02-01 11:43:58 +00:00
|
|
|
}
|
2019-09-10 17:09:37 +00:00
|
|
|
|
2015-02-01 11:43:58 +00:00
|
|
|
// turn too small internal regions into solid regions according to the user setting
|
2020-02-08 20:36:29 +00:00
|
|
|
if (! spiral_vase && this->region()->config().fill_density.value > 0) {
|
2015-02-01 11:43:58 +00:00
|
|
|
// scaling an area requires two calls!
|
2018-09-11 12:04:47 +00:00
|
|
|
double min_area = scale_(scale_(this->region()->config().solid_infill_below_area.value));
|
2019-09-10 17:09:37 +00:00
|
|
|
for (Surface &surface : this->fill_surfaces.surfaces)
|
|
|
|
if (surface.surface_type == stInternal && surface.area() <= min_area)
|
|
|
|
surface.surface_type = stInternalSolid;
|
2015-02-01 11:43:58 +00:00
|
|
|
}
|
2016-09-26 11:44:23 +00:00
|
|
|
|
|
|
|
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
|
2016-11-10 18:23:01 +00:00
|
|
|
export_region_slices_to_svg_debug("2_prepare_fill_surfaces-final");
|
|
|
|
export_region_fill_surfaces_to_svg_debug("2_prepare_fill_surfaces-final");
|
2016-09-26 11:44:23 +00:00
|
|
|
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
|
2015-02-01 11:43:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 15:05:31 +00:00
|
|
|
double LayerRegion::infill_area_threshold() const
|
2015-10-26 22:23:03 +00:00
|
|
|
{
|
|
|
|
double ss = this->flow(frSolidInfill).scaled_spacing();
|
|
|
|
return ss*ss;
|
|
|
|
}
|
|
|
|
|
2019-03-05 10:54:04 +00:00
|
|
|
void LayerRegion::trim_surfaces(const Polygons &trimming_polygons)
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
for (const Surface &surface : this->slices.surfaces)
|
|
|
|
assert(surface.surface_type == stInternal);
|
|
|
|
#endif /* NDEBUG */
|
|
|
|
this->slices.set(intersection_ex(to_polygons(std::move(this->slices.surfaces)), trimming_polygons, false), stInternal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerRegion::elephant_foot_compensation_step(const float elephant_foot_compensation_perimeter_step, const Polygons &trimming_polygons)
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
for (const Surface &surface : this->slices.surfaces)
|
|
|
|
assert(surface.surface_type == stInternal);
|
|
|
|
#endif /* NDEBUG */
|
|
|
|
ExPolygons slices_expolygons = to_expolygons(std::move(this->slices.surfaces));
|
|
|
|
Polygons slices_polygons = to_polygons(slices_expolygons);
|
|
|
|
Polygons tmp = intersection(slices_polygons, trimming_polygons, false);
|
|
|
|
append(tmp, diff(slices_polygons, offset(offset_ex(slices_expolygons, -elephant_foot_compensation_perimeter_step), elephant_foot_compensation_perimeter_step)));
|
2021-01-29 15:16:23 +00:00
|
|
|
this->slices.set(union_ex(tmp), stInternal);
|
2019-03-05 10:54:04 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 11:15:32 +00:00
|
|
|
void LayerRegion::export_region_slices_to_svg(const char *path) const
|
2016-09-26 11:44:23 +00:00
|
|
|
{
|
|
|
|
BoundingBox bbox;
|
|
|
|
for (Surfaces::const_iterator surface = this->slices.surfaces.begin(); surface != this->slices.surfaces.end(); ++surface)
|
|
|
|
bbox.merge(get_extents(surface->expolygon));
|
|
|
|
Point legend_size = export_surface_type_legend_to_svg_box_size();
|
2018-08-17 13:53:43 +00:00
|
|
|
Point legend_pos(bbox.min(0), bbox.max(1));
|
|
|
|
bbox.merge(Point(std::max(bbox.min(0) + legend_size(0), bbox.max(0)), bbox.max(1) + legend_size(1)));
|
2016-09-26 11:44:23 +00:00
|
|
|
|
|
|
|
SVG svg(path, bbox);
|
|
|
|
const float transparency = 0.5f;
|
|
|
|
for (Surfaces::const_iterator surface = this->slices.surfaces.begin(); surface != this->slices.surfaces.end(); ++surface)
|
|
|
|
svg.draw(surface->expolygon, surface_type_to_color_name(surface->surface_type), transparency);
|
|
|
|
for (Surfaces::const_iterator surface = this->fill_surfaces.surfaces.begin(); surface != this->fill_surfaces.surfaces.end(); ++surface)
|
|
|
|
svg.draw(surface->expolygon.lines(), surface_type_to_color_name(surface->surface_type));
|
|
|
|
export_surface_type_legend_to_svg(svg, legend_pos);
|
|
|
|
svg.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export to "out/LayerRegion-name-%d.svg" with an increasing index with every export.
|
2017-09-14 11:15:32 +00:00
|
|
|
void LayerRegion::export_region_slices_to_svg_debug(const char *name) const
|
2016-09-26 11:44:23 +00:00
|
|
|
{
|
|
|
|
static std::map<std::string, size_t> idx_map;
|
|
|
|
size_t &idx = idx_map[name];
|
2016-10-21 08:18:01 +00:00
|
|
|
this->export_region_slices_to_svg(debug_out_path("LayerRegion-slices-%s-%d.svg", name, idx ++).c_str());
|
2016-09-26 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 11:15:32 +00:00
|
|
|
void LayerRegion::export_region_fill_surfaces_to_svg(const char *path) const
|
2016-09-26 11:44:23 +00:00
|
|
|
{
|
|
|
|
BoundingBox bbox;
|
|
|
|
for (Surfaces::const_iterator surface = this->fill_surfaces.surfaces.begin(); surface != this->fill_surfaces.surfaces.end(); ++surface)
|
|
|
|
bbox.merge(get_extents(surface->expolygon));
|
|
|
|
Point legend_size = export_surface_type_legend_to_svg_box_size();
|
2018-08-17 13:53:43 +00:00
|
|
|
Point legend_pos(bbox.min(0), bbox.max(1));
|
|
|
|
bbox.merge(Point(std::max(bbox.min(0) + legend_size(0), bbox.max(0)), bbox.max(1) + legend_size(1)));
|
2016-09-26 11:44:23 +00:00
|
|
|
|
|
|
|
SVG svg(path, bbox);
|
|
|
|
const float transparency = 0.5f;
|
2017-09-14 11:15:32 +00:00
|
|
|
for (const Surface &surface : this->fill_surfaces.surfaces) {
|
|
|
|
svg.draw(surface.expolygon, surface_type_to_color_name(surface.surface_type), transparency);
|
|
|
|
svg.draw_outline(surface.expolygon, "black", "blue", scale_(0.05));
|
2016-11-09 09:24:45 +00:00
|
|
|
}
|
2016-09-26 11:44:23 +00:00
|
|
|
export_surface_type_legend_to_svg(svg, legend_pos);
|
|
|
|
svg.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export to "out/LayerRegion-name-%d.svg" with an increasing index with every export.
|
2017-09-14 11:15:32 +00:00
|
|
|
void LayerRegion::export_region_fill_surfaces_to_svg_debug(const char *name) const
|
2016-09-26 11:44:23 +00:00
|
|
|
{
|
|
|
|
static std::map<std::string, size_t> idx_map;
|
|
|
|
size_t &idx = idx_map[name];
|
2016-10-21 08:18:01 +00:00
|
|
|
this->export_region_fill_surfaces_to_svg(debug_out_path("LayerRegion-fill_surfaces-%s-%d.svg", name, idx ++).c_str());
|
2016-09-26 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2014-08-03 17:28:40 +00:00
|
|
|
}
|
2019-09-24 14:01:01 +00:00
|
|
|
|