From 98e40d3fe462e7cf29d0bf61129bc283cd98833b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 29 Apr 2014 23:15:36 +0200 Subject: [PATCH] Store width and height in ExtrusionEntity objects for debugging purposes --- lib/Slic3r/ExtrusionLoop.pm | 2 ++ lib/Slic3r/Fill.pm | 4 +++- lib/Slic3r/Layer/Region.pm | 6 +++++ lib/Slic3r/Print.pm | 4 ++++ lib/Slic3r/Print/SupportMaterial.pm | 8 +++++++ lib/Slic3r/Test/SectionCut.pm | 35 ++++++++++++++++++++--------- xs/lib/Slic3r/XS.pm | 12 ++++++++-- xs/src/ExtrusionEntity.cpp | 2 ++ xs/src/ExtrusionEntity.hpp | 3 +++ xs/xsp/ExtrusionLoop.xsp | 26 ++++++++++++++++++++- xs/xsp/ExtrusionPath.xsp | 26 ++++++++++++++++++++- 11 files changed, 113 insertions(+), 15 deletions(-) diff --git a/lib/Slic3r/ExtrusionLoop.pm b/lib/Slic3r/ExtrusionLoop.pm index 7123b3a77..0ec9f829b 100644 --- a/lib/Slic3r/ExtrusionLoop.pm +++ b/lib/Slic3r/ExtrusionLoop.pm @@ -9,6 +9,8 @@ sub split_at { polyline => $self->polygon->split_at(@_), role => $self->role, mm3_per_mm => $self->mm3_per_mm, + width => $self->width, + height => $self->height, ); } diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index da82ec6d1..678e71f9a 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -237,7 +237,9 @@ sub make_fill { : $is_solid ? (($surface->surface_type == S_TYPE_TOP) ? EXTR_ROLE_TOPSOLIDFILL : EXTR_ROLE_SOLIDFILL) : EXTR_ROLE_FILL), - mm3_per_mm => $mm3_per_mm, + mm3_per_mm => $mm3_per_mm, + width => $flow->width, + height => $h, ), @polylines, ); push @fills_ordering_points, $polylines[0]->first_point; diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index ba93efa2a..14d6aa6b9 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -264,6 +264,8 @@ sub make_perimeters { polygon => $polygon, role => $role, mm3_per_mm => $mm3_per_mm, + width => $perimeter_flow->width, + height => $self->height, )); # save the children @@ -278,6 +280,8 @@ sub make_perimeters { polyline => $polyline, role => EXTR_ROLE_EXTERNAL_PERIMETER, mm3_per_mm => $mm3_per_mm, + width => $perimeter_flow->width, + height => $self->height, )); } } @@ -355,6 +359,8 @@ sub _fill_gaps { my %path_args = ( role => EXTR_ROLE_GAPFILL, mm3_per_mm => $flow->mm3_per_mm($self->height), + width => $flow->width, + height => $self->height, ); my @polylines = map @{$_->medial_axis($max, $min/2)}, @$this; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 18678e391..44618b083 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -709,6 +709,8 @@ sub make_skirt { polygon => Slic3r::Polygon->new(@$loop), role => EXTR_ROLE_SKIRT, mm3_per_mm => $mm3_per_mm, + width => $flow->width, + height => $first_layer_height, )); if ($self->config->min_skirt_length > 0) { @@ -790,6 +792,8 @@ sub make_brim { polygon => Slic3r::Polygon->new(@$_), role => EXTR_ROLE_SKIRT, mm3_per_mm => $mm3_per_mm, + width => $flow->width, + height => $first_layer_height, ), reverse @{union_pt_chained(\@loops)}); } diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index 5df48b030..7eb17607e 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -544,6 +544,8 @@ sub generate_toolpaths { polyline => $_, role => EXTR_ROLE_SUPPORTMATERIAL, mm3_per_mm => $mm3_per_mm, + width => $interface_flow->width, + height => $layer->height, ), @loops; $layer->support_interface_fills->append(@loops); @@ -587,6 +589,8 @@ sub generate_toolpaths { polyline => Slic3r::Polyline->new(@$_), role => EXTR_ROLE_SUPPORTMATERIAL, mm3_per_mm => $mm3_per_mm, + width => $params->{flow}->width, + height => $layer->height, ), @p; } @@ -618,6 +622,8 @@ sub generate_toolpaths { polyline => $_->split_at_first_point, role => EXTR_ROLE_SUPPORTMATERIAL, mm3_per_mm => $mm3_per_mm, + width => $flow->width, + height => $layer->height, ), map @$_, @$to_infill; # TODO: use offset2_ex() @@ -638,6 +644,8 @@ sub generate_toolpaths { polyline => Slic3r::Polyline->new(@$_), role => EXTR_ROLE_SUPPORTMATERIAL, mm3_per_mm => $mm3_per_mm, + width => $params->{flow}->width, + height => $layer->height, ), @p; } diff --git a/lib/Slic3r/Test/SectionCut.pm b/lib/Slic3r/Test/SectionCut.pm index dc67e839c..51bda6b7f 100644 --- a/lib/Slic3r/Test/SectionCut.pm +++ b/lib/Slic3r/Test/SectionCut.pm @@ -5,19 +5,21 @@ use List::Util qw(first max); use Slic3r::Geometry qw(X Y A B X1 Y1 X2 Y2 unscale); use Slic3r::Geometry::Clipper qw(union_ex intersection_pl); use SVG; + use Slic3r::SVG; has 'scale' => (is => 'ro', default => sub {30}); has 'print' => (is => 'ro', required => 1); has 'y_percent' => (is => 'ro', default => sub {0.5}); -has 'line' => (is => 'lazy'); +has 'line' => (is => 'rw'); has 'height' => (is => 'rw'); -sub _build_line { +sub BUILD { my $self = shift; my $bb = $self->print->bounding_box; - my $y = $bb->size->[Y] * $self->y_percent; - return Slic3r::Line->new([ $bb->x_min, $y ], [ $bb->x_max, $y ]); + my $y = ($bb->y_min + $bb->y_max) * $self->y_percent; + my $line = Slic3r::Line->new([ $bb->x_min, $y ], [ $bb->x_max, $y ]); + $self->line($line); } sub export_svg { @@ -79,27 +81,40 @@ sub _plot { my (@rectangles, @circles) = (); foreach my $object (@{$self->print->objects}) { - foreach my $copy (@{$object->shifted_copies}) { + foreach my $copy (@{$object->_shifted_copies}) { foreach my $layer (@{$object->layers}, @{$object->support_layers}) { # get all ExtrusionPath objects my @paths = - map { $_->polyline->translate(@$copy); $_ } - map { $_->isa('Slic3r::ExtrusionLoop') ? $_->split_at_first_point : $_ } + map { $_->isa('Slic3r::ExtrusionLoop') ? $_->split_at_first_point : $_->clone } map { $_->isa('Slic3r::ExtrusionPath::Collection') ? @$_ : $_ } grep defined $_, $filter->($layer); + $_->polyline->translate(@$copy) for @paths; + + require "Slic3r/SVG.pm"; + Slic3r::SVG::output( + "line.svg", + no_arrows => 1, + #polygon => $line->grow(Slic3r::Geometry::scale $path->width/2), + polygons => [ $object->bounding_box->polygon ], + lines => [ $self->line ], + red_polylines => [ map $_->polyline, @paths ], + ); + exit; + foreach my $path (@paths) { foreach my $line (@{$path->lines}) { my @intersections = @{intersection_pl( [ $self->line->as_polyline ], - $line->grow(Slic3r::Geometry::scale $path->flow_spacing/2), + $line->grow(Slic3r::Geometry::scale $path->width/2), )}; + die "Intersection has more than two points!\n" if first { @$_ > 2 } @intersections; if ($path->is_bridge) { foreach my $line (@intersections) { - my $radius = $path->flow_spacing / 2; + my $radius = $path->width / 2; my $width = unscale abs($line->[B][X] - $line->[A][X]); if ((10 * Slic3r::Geometry::scale $radius) < $width) { # we're cutting the path in the longitudinal direction, so we've got a rectangle @@ -148,7 +163,7 @@ sub _plot { sub _y { my $self = shift; my ($y) = @_; - + return $y; return $self->height - $y; } diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm index 42821b816..5529d24ba 100644 --- a/xs/lib/Slic3r/XS.pm +++ b/xs/lib/Slic3r/XS.pm @@ -112,7 +112,9 @@ sub new { return $class->_new( $args{polygon}, # required $args{role}, # required - $args{mm3_per_mm} // -1, + $args{mm3_per_mm} // die("Missing required mm3_per_mm in ExtrusionLoop constructor"), + $args{width} // -1, + $args{height} // -1, ); } @@ -123,6 +125,8 @@ sub clone { $args{polygon} // $self->polygon, $args{role} // $self->role, $args{mm3_per_mm} // $self->mm3_per_mm, + $args{width} // $self->width, + $args{height} // $self->height, ); } @@ -142,7 +146,9 @@ sub new { return $class->_new( $args{polyline}, # required $args{role}, # required - $args{mm3_per_mm} // -1, + $args{mm3_per_mm} // die("Missing required mm3_per_mm in ExtrusionPath constructor"), + $args{width} // -1, + $args{height} // -1, ); } @@ -153,6 +159,8 @@ sub clone { $args{polyline} // $self->polyline, $args{role} // $self->role, $args{mm3_per_mm} // $self->mm3_per_mm, + $args{width} // $self->width, + $args{height} // $self->height, ); } diff --git a/xs/src/ExtrusionEntity.cpp b/xs/src/ExtrusionEntity.cpp index 0e023577e..060c914bb 100644 --- a/xs/src/ExtrusionEntity.cpp +++ b/xs/src/ExtrusionEntity.cpp @@ -172,6 +172,8 @@ ExtrusionLoop::split_at_index(int index) const path->polyline = *poly; path->role = this->role; path->mm3_per_mm = this->mm3_per_mm; + path->width = this->width; + path->height = this->height; delete poly; return path; diff --git a/xs/src/ExtrusionEntity.hpp b/xs/src/ExtrusionEntity.hpp index 0e3c71ea7..347a7ce23 100644 --- a/xs/src/ExtrusionEntity.hpp +++ b/xs/src/ExtrusionEntity.hpp @@ -29,10 +29,13 @@ enum ExtrusionRole { class ExtrusionEntity { public: + ExtrusionEntity() : mm3_per_mm(-1), width(-1), height(-1) {}; virtual ExtrusionEntity* clone() const = 0; virtual ~ExtrusionEntity() {}; ExtrusionRole role; double mm3_per_mm; // mm^3 of plastic per mm of linear head motion + float width; + float height; virtual void reverse() = 0; virtual Point first_point() const = 0; virtual Point last_point() const = 0; diff --git a/xs/xsp/ExtrusionLoop.xsp b/xs/xsp/ExtrusionLoop.xsp index 9a4629156..c1c6e4a97 100644 --- a/xs/xsp/ExtrusionLoop.xsp +++ b/xs/xsp/ExtrusionLoop.xsp @@ -25,16 +25,20 @@ %{ ExtrusionLoop* -_new(CLASS, polygon_sv, role, mm3_per_mm) +_new(CLASS, polygon_sv, role, mm3_per_mm, width, height) char* CLASS; SV* polygon_sv; ExtrusionRole role; double mm3_per_mm; + float width; + float height; CODE: RETVAL = new ExtrusionLoop (); RETVAL->polygon.from_SV_check(polygon_sv); RETVAL->role = role; RETVAL->mm3_per_mm = mm3_per_mm; + RETVAL->width = width; + RETVAL->height = height; OUTPUT: RETVAL @@ -68,5 +72,25 @@ ExtrusionLoop::mm3_per_mm(...) OUTPUT: RETVAL +float +ExtrusionLoop::width(...) + CODE: + if (items > 1) { + THIS->width = (float)SvNV(ST(1)); + } + RETVAL = THIS->width; + OUTPUT: + RETVAL + +float +ExtrusionLoop::height(...) + CODE: + if (items > 1) { + THIS->height = (float)SvNV(ST(1)); + } + RETVAL = THIS->height; + OUTPUT: + RETVAL + %} }; diff --git a/xs/xsp/ExtrusionPath.xsp b/xs/xsp/ExtrusionPath.xsp index 2926f2eda..55ec7ddbb 100644 --- a/xs/xsp/ExtrusionPath.xsp +++ b/xs/xsp/ExtrusionPath.xsp @@ -31,16 +31,20 @@ %{ ExtrusionPath* -_new(CLASS, polyline_sv, role, mm3_per_mm) +_new(CLASS, polyline_sv, role, mm3_per_mm, width, height) char* CLASS; SV* polyline_sv; ExtrusionRole role; double mm3_per_mm; + float width; + float height; CODE: RETVAL = new ExtrusionPath (); RETVAL->polyline.from_SV_check(polyline_sv); RETVAL->role = role; RETVAL->mm3_per_mm = mm3_per_mm; + RETVAL->width = width; + RETVAL->height = height; OUTPUT: RETVAL @@ -74,6 +78,26 @@ ExtrusionPath::mm3_per_mm(...) OUTPUT: RETVAL +float +ExtrusionPath::width(...) + CODE: + if (items > 1) { + THIS->width = (float)SvNV(ST(1)); + } + RETVAL = THIS->width; + OUTPUT: + RETVAL + +float +ExtrusionPath::height(...) + CODE: + if (items > 1) { + THIS->height = (float)SvNV(ST(1)); + } + RETVAL = THIS->height; + OUTPUT: + RETVAL + void ExtrusionPath::append(...) CODE: