Skip to content

Commit

Permalink
Ported make_perimeters() to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Jul 23, 2015
1 parent 15d2522 commit 6ac79e3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 34 deletions.
30 changes: 0 additions & 30 deletions lib/Slic3r/Layer/Region.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) = @_;

Expand Down
2 changes: 1 addition & 1 deletion t/perimeters.t
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions xs/src/libslic3r/ExtrusionEntityCollection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions xs/src/libslic3r/Layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions xs/src/libslic3r/LayerRegion.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Layer.hpp"
#include "ClipperUtils.hpp"
#include "PerimeterGenerator.hpp"
#include "Print.hpp"
#include "Surface.hpp"

Expand Down Expand Up @@ -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()
{
Expand Down
6 changes: 3 additions & 3 deletions xs/src/libslic3r/PerimeterGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions xs/xsp/Layer.xsp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6ac79e3

Please sign in to comment.