Integration of spline based layer height postprocessing

This commit is contained in:
Florens Wasserfall 2017-01-26 09:22:04 +01:00
parent 7293f56f9b
commit a3867b0be8
6 changed files with 143 additions and 112 deletions

View File

@ -149,9 +149,9 @@ sub new {
$self->{htoolbar}->AddTool(TB_SCALE, "Scale…", Wx::Bitmap->new($Slic3r::var->("arrow_out.png"), wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_SPLIT, "Split", Wx::Bitmap->new($Slic3r::var->("shape_ungroup.png"), wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_CUT, "Cut…", Wx::Bitmap->new($Slic3r::var->("package.png"), wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_LAYERS, "Layers…", Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddSeparator;
$self->{htoolbar}->AddTool(TB_SETTINGS, "Settings…", Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_LAYERS, "Layers…", Wx::Bitmap->new($Slic3r::var->("layers.png"), wxBITMAP_TYPE_PNG), '');
} else {
my %tbar_buttons = (
add => "Add…",

View File

@ -4,6 +4,7 @@ use warnings;
use utf8;
use Slic3r::Geometry qw(PI X scale unscale);
use Slic3r::Print::State ':steps';
use List::Util qw(min max sum first);
use Wx qw(wxTheApp :dialog :id :misc :sizer wxTAB_TRAVERSAL);
use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
@ -14,11 +15,10 @@ sub new {
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, -1, $params{object}->name, wxDefaultPosition, [500,500], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
$self->{model_object} = $params{model_object};
my $model_object = $self->{model_object} = $params{model_object};
my $obj_idx = $self->{obj_idx} = $params{obj_idx};
my $plater = $self->{plater} = $parent;
my $object = $self->{object} = $self->{plater}->{print}->get_object($self->{obj_idx});
# Initialize 3D toolpaths preview
if ($Slic3r::GUI::have_OpenGL) {
@ -33,7 +33,7 @@ sub new {
$self->{preview3D}->canvas->zoom_to_volumes;
}
$self->{splineControl} = Slic3r::GUI::Plater::SplineControl->new($self, Wx::Size->new(100, 200));
$self->{splineControl} = Slic3r::GUI::Plater::SplineControl->new($self, Wx::Size->new(200, 200), $object);
my $right_sizer = Wx::BoxSizer->new(wxVERTICAL);
$right_sizer->Add($self->{splineControl}, 1, wxEXPAND | wxALL, 0);
@ -47,8 +47,6 @@ sub new {
$self->SetMinSize($self->GetSize);
# init spline control values
my $object = $self->{plater}->{print}->get_object($self->{obj_idx});
# determine min and max layer height from perimeter extruder capabilities.
my %extruders;
for my $region_id (0 .. ($object->region_count - 1)) {
@ -62,10 +60,12 @@ sub new {
$self->{splineControl}->set_size_parameters($min_height, $max_height, unscale($object->size->z));
# get array of current Z coordinates for selected object
my @layer_heights = map $_->print_z, @{$object->layers};
$self->{splineControl}->set_layer_points(@layer_heights);
$self->{splineControl}->on_layer_update(sub {
# trigger re-slicing
$self->{object}->invalidate_step(STEP_SLICE);
$self->{plater}->start_background_process;
});
return $self;
}

View File

@ -89,7 +89,11 @@ sub slice {
my $slice_z = 0;
my $height = 0;
my $cusp_height = 0;
my @layers = ();
if(!$self->layer_height_spline->updateRequired) { # layer heights are already generated, just update layers from spline
@layers = @{$self->layer_height_spline->getInterpolatedLayers};
}else{ # create new set of layers
# create stateful objects and variables for the adaptive slicing process
my @adaptive_slicing;
my $min_height = 0;
@ -128,7 +132,7 @@ sub slice {
# loop until we have at least one layer and the max slice_z reaches the object height
my $max_z = unscale($self->size->z);
while (($slice_z - $height) <= $max_z) {
while (($slice_z) < $max_z) {
if ($self->config->adaptive_slicing) {
$height = 999;
@ -183,15 +187,37 @@ sub slice {
}
}
if ($first_object_layer_height != -1 && !@{$self->layers}) {
# set first layer height if raft is active
if ($first_object_layer_height != -1 && !@layers) {
$height = $first_object_layer_height;
$print_z += ($first_object_layer_distance - $height);
#$print_z += ($first_object_layer_distance - $height);
}
$slice_z += $height;
$id++;
# collect layers for spline smoothing
push (@layers, $slice_z);
}
$self->layer_height_spline->setLayers(\@layers);
if ($self->config->adaptive_slicing) { # smoothing after adaptive algorithm
$self->layer_height_spline->setLayers($self->layer_height_spline->getInterpolatedLayers);
}
}
$id = 0;
if ($self->config->raft_layers > 0) {
$id = $self->config->raft_layers;
}
# generate layer objects
$slice_z = 0;
foreach my $z (@layers) {
$height = $z - $slice_z;
$print_z += $height;
$slice_z += $height/2;
### Slic3r::debugf "Layer %d: height = %s; slice_z = %s; print_z = %s\n", $id, $height, $slice_z, $print_z;
Slic3r::debugf "Layer %d: height = %s; slice_z = %s; print_z = %s\n", $id, $height, $slice_z, $print_z;
$self->add_layer($id, $height, $print_z, $slice_z);
if ($self->layer_count >= 2) {
@ -199,8 +225,8 @@ sub slice {
$self->get_layer($lc - 2)->set_upper_layer($self->get_layer($lc - 1));
$self->get_layer($lc - 1)->set_lower_layer($self->get_layer($lc - 2));
}
$id++;
$id++;
$slice_z += $height/2; # add the other half layer
}
}

View File

@ -12,7 +12,7 @@
#include "Layer.hpp"
#include "Model.hpp"
#include "PlaceholderParser.hpp"
#include "LayerHeightSpline.hpp"
namespace Slic3r {
@ -83,6 +83,8 @@ class PrintObject
PrintObjectConfig config;
t_layer_height_ranges layer_height_ranges;
LayerHeightSpline layer_height_spline;
// this is set to true when LayerRegion->slices is split in top/internal/bottom
// so that next call to make_perimeters() performs a union() before computing loops
bool typed_slices;

View File

@ -8,7 +8,8 @@ namespace Slic3r {
PrintObject::PrintObject(Print* print, ModelObject* model_object, const BoundingBoxf3 &modobj_bbox)
: typed_slices(false),
_print(print),
_model_object(model_object)
_model_object(model_object),
layer_height_spline(modobj_bbox.size().z)
{
// Compute the translation to be applied to our meshes so that we work with smaller coordinates
{

View File

@ -58,6 +58,8 @@ _constant()
Points copies();
t_layer_height_ranges layer_height_ranges()
%code%{ RETVAL = THIS->layer_height_ranges; %};
Ref<LayerHeightSpline> layer_height_spline()
%code%{ RETVAL = &THIS->layer_height_spline; %};
Ref<Point3> size()
%code%{ RETVAL = &THIS->size; %};
Clone<BoundingBox> bounding_box();