From 6ac79e3ed6bf903edf45b52ee6fd68c1b0b54a9d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 23 Jul 2015 16:27:21 +0200 Subject: [PATCH] Ported make_perimeters() to C++ --- lib/Slic3r/Layer/Region.pm | 30 ----------------- t/perimeters.t | 2 +- .../libslic3r/ExtrusionEntityCollection.hpp | 3 ++ xs/src/libslic3r/Layer.hpp | 1 + xs/src/libslic3r/LayerRegion.cpp | 33 +++++++++++++++++++ xs/src/libslic3r/PerimeterGenerator.hpp | 6 ++-- xs/xsp/Layer.xsp | 2 ++ 7 files changed, 43 insertions(+), 34 deletions(-) diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index 51648c3ed..09e4a9fc8 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -25,36 +25,6 @@ sub print { return $_[0]->layer->print; } sub config { return $_[0]->region->config; } -sub make_perimeters { - my ($self, $slices, $fill_surfaces) = @_; - - $self->perimeters->clear; - $self->thin_fills->clear; - - my $generator = Slic3r::Layer::PerimeterGenerator->new( - # input: - $slices, - $self->height, - $self->flow(FLOW_ROLE_PERIMETER), - $self->config, - $self->layer->object->config, - $self->layer->print->config, - - # output: - $self->perimeters, - $self->thin_fills, - $fill_surfaces, - ); - $generator->set_lower_slices($self->layer->lower_layer->slices) - if defined($self->layer->lower_layer); - $generator->set_layer_id($self->id); - $generator->set_ext_perimeter_flow($self->flow(FLOW_ROLE_EXTERNAL_PERIMETER)); - $generator->set_overhang_flow($self->region->flow(FLOW_ROLE_PERIMETER, -1, 1, 0, -1, $self->layer->object)); - $generator->set_solid_infill_flow($self->flow(FLOW_ROLE_SOLID_INFILL)); - - $generator->process; -} - sub process_external_surfaces { my ($self, $lower_layer) = @_; diff --git a/t/perimeters.t b/t/perimeters.t index 1e47b51f0..134c23536 100644 --- a/t/perimeters.t +++ b/t/perimeters.t @@ -310,7 +310,7 @@ use Slic3r::Test; [ map @$_, (@$covered_by_perimeters, @$covered_by_infill) ], ); - if (1) { + if (0) { printf "max non covered = %f\n", List::Util::max(map unscale unscale $_->area, @$non_covered); require "Slic3r/SVG.pm"; Slic3r::SVG::output( diff --git a/xs/src/libslic3r/ExtrusionEntityCollection.hpp b/xs/src/libslic3r/ExtrusionEntityCollection.hpp index 504c82ae1..62909c55c 100644 --- a/xs/src/libslic3r/ExtrusionEntityCollection.hpp +++ b/xs/src/libslic3r/ExtrusionEntityCollection.hpp @@ -29,6 +29,9 @@ class ExtrusionEntityCollection : public ExtrusionEntity bool empty() const { return this->entities.empty(); }; + void clear() { + this->entities.clear(); + }; void swap (ExtrusionEntityCollection &c); void append(const ExtrusionEntity &entity); void append(const ExtrusionEntitiesPtr &entities); diff --git a/xs/src/libslic3r/Layer.hpp b/xs/src/libslic3r/Layer.hpp index 85f4844cb..1c09b5f0f 100644 --- a/xs/src/libslic3r/Layer.hpp +++ b/xs/src/libslic3r/Layer.hpp @@ -57,6 +57,7 @@ class LayerRegion Flow flow(FlowRole role, bool bridge = false, double width = -1) const; void merge_slices(); void prepare_fill_surfaces(); + void make_perimeters(const SurfaceCollection &slices, SurfaceCollection* fill_surfaces); private: Layer *_layer; diff --git a/xs/src/libslic3r/LayerRegion.cpp b/xs/src/libslic3r/LayerRegion.cpp index d09ea19c7..ef6150015 100644 --- a/xs/src/libslic3r/LayerRegion.cpp +++ b/xs/src/libslic3r/LayerRegion.cpp @@ -1,5 +1,6 @@ #include "Layer.hpp" #include "ClipperUtils.hpp" +#include "PerimeterGenerator.hpp" #include "Print.hpp" #include "Surface.hpp" @@ -53,6 +54,38 @@ LayerRegion::merge_slices() this->slices.surfaces.push_back(Surface(stInternal, *expoly)); } +void +LayerRegion::make_perimeters(const SurfaceCollection &slices, SurfaceCollection* fill_surfaces) +{ + this->perimeters.clear(); + this->thin_fills.clear(); + + PerimeterGenerator g( + // input: + &slices, + this->layer()->height, + this->flow(frPerimeter), + &this->region()->config, + &this->layer()->object()->config, + &this->layer()->object()->print()->config, + + // output: + &this->perimeters, + &this->thin_fills, + fill_surfaces + ); + + if (this->layer()->lower_layer != NULL) + g.lower_slices = &this->layer()->lower_layer->slices; + + g.layer_id = this->layer()->id(); + g.ext_perimeter_flow = this->flow(frExternalPerimeter); + g.overhang_flow = this->region()->flow(frPerimeter, -1, true, false, -1, *this->layer()->object()); + g.solid_infill_flow = this->flow(frSolidInfill); + + g.process(); +} + void LayerRegion::prepare_fill_surfaces() { diff --git a/xs/src/libslic3r/PerimeterGenerator.hpp b/xs/src/libslic3r/PerimeterGenerator.hpp index 6465d63f9..8ce5f87d9 100644 --- a/xs/src/libslic3r/PerimeterGenerator.hpp +++ b/xs/src/libslic3r/PerimeterGenerator.hpp @@ -30,8 +30,8 @@ class PerimeterGeneratorLoop { class PerimeterGenerator { public: - SurfaceCollection* slices; - ExPolygonCollection* lower_slices; + const SurfaceCollection* slices; + const ExPolygonCollection* lower_slices; double layer_height; int layer_id; Flow perimeter_flow; @@ -45,7 +45,7 @@ class PerimeterGenerator { ExtrusionEntityCollection* gap_fill; SurfaceCollection* fill_surfaces; - PerimeterGenerator(SurfaceCollection* slices, double layer_height, Flow flow, + PerimeterGenerator(const SurfaceCollection* slices, double layer_height, Flow flow, PrintRegionConfig* config, PrintObjectConfig* object_config, PrintConfig* print_config, ExtrusionEntityCollection* loops, ExtrusionEntityCollection* gap_fill, SurfaceCollection* fill_surfaces) diff --git a/xs/xsp/Layer.xsp b/xs/xsp/Layer.xsp index d8444f092..00913e615 100644 --- a/xs/xsp/Layer.xsp +++ b/xs/xsp/Layer.xsp @@ -30,6 +30,8 @@ %code%{ RETVAL = THIS->flow(role, bridge, width); %}; void merge_slices(); void prepare_fill_surfaces(); + void make_perimeters(SurfaceCollection* slices, SurfaceCollection* fill_surfaces) + %code%{ THIS->make_perimeters(*slices, fill_surfaces); %}; }; %name{Slic3r::Layer} class Layer {