Replaced Moose with Moo => big performance boost and easier packaging
This commit is contained in:
parent
bf5824781d
commit
26b05ab155
@ -20,9 +20,6 @@ algorithms in the future.
|
|||||||
I also aim at implementing better support for hollow objects, as Skeinforge
|
I also aim at implementing better support for hollow objects, as Skeinforge
|
||||||
isn't smart enough to generate internal support structures for horizontal
|
isn't smart enough to generate internal support structures for horizontal
|
||||||
facets.
|
facets.
|
||||||
Of course, Perl's not that fast as C and usage of modules like Moose make
|
|
||||||
everything quite memory-hungry, but I'm happy with it. I want to build a "rapid
|
|
||||||
prototyping" architecture for a slicer.
|
|
||||||
|
|
||||||
Also, http://xkcd.com/224/
|
Also, http://xkcd.com/224/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package Slic3r::ExtrusionPath;
|
package Slic3r::ExtrusionPath;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
extends 'Slic3r::Polyline';
|
extends 'Slic3r::Polyline';
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package Slic3r::Fill;
|
package Slic3r::Fill;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
use Slic3r::Fill::Rectilinear;
|
use Slic3r::Fill::Rectilinear;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package Slic3r::Fill::Rectilinear;
|
package Slic3r::Fill::Rectilinear;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
use constant epsilon => 1E-10;
|
use constant epsilon => 1E-10;
|
||||||
use constant PI => 4 * atan2(1, 1);
|
use constant PI => 4 * atan2(1, 1);
|
||||||
@ -45,10 +45,10 @@ sub make_fill {
|
|||||||
|
|
||||||
# find out the coordinates
|
# find out the coordinates
|
||||||
my @coordinates = map @$_, @$line;
|
my @coordinates = map @$_, @$line;
|
||||||
Slic3r::debugf "Segment %d,%d - %d,%d\n", @coordinates;
|
|
||||||
|
|
||||||
# get the extents of the segment along the primary axis
|
# get the extents of the segment along the primary axis
|
||||||
my @line_c = sort ($coordinates[X1], $coordinates[X2]);
|
my @line_c = sort { $a <=> $b } @coordinates[X1, X2];
|
||||||
|
Slic3r::debugf "Segment %d,%d - %d,%d (extents: %f, %f)\n", @coordinates, @line_c;
|
||||||
|
|
||||||
for (my $c = $line_c[0]; $c <= $line_c[1]; $c += $distance_between_lines) {
|
for (my $c = $line_c[0]; $c <= $line_c[1]; $c += $distance_between_lines) {
|
||||||
my $i = sprintf('%.0f', $c / $distance_between_lines) - 1;
|
my $i = sprintf('%.0f', $c / $distance_between_lines) - 1;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package Slic3r::Layer;
|
package Slic3r::Layer;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
use XXX;
|
use XXX;
|
||||||
|
|
||||||
# a sequential number of layer, starting at 0
|
# a sequential number of layer, starting at 0
|
||||||
has 'id' => (
|
has 'id' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Int',
|
#isa => 'Int',
|
||||||
required => 1,
|
required => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -16,18 +16,15 @@ has 'id' => (
|
|||||||
has 'pointmap' => (
|
has 'pointmap' => (
|
||||||
traits => ['Hash'],
|
traits => ['Hash'],
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'HashRef[Slic3r::Point]',
|
#isa => 'HashRef[Slic3r::Point]',
|
||||||
default => sub { {} },
|
default => sub { {} },
|
||||||
handles => {
|
|
||||||
points => 'values',
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
# collection of segments generated by slicing the original geometry
|
# collection of segments generated by slicing the original geometry
|
||||||
# each segment is part of a closed polyline
|
# each segment is part of a closed polyline
|
||||||
has 'lines' => (
|
has 'lines' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::Line]',
|
#isa => 'ArrayRef[Slic3r::Line]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -35,21 +32,21 @@ has 'lines' => (
|
|||||||
has 'surfaces' => (
|
has 'surfaces' => (
|
||||||
traits => ['Array'],
|
traits => ['Array'],
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::Surface]',
|
#isa => 'ArrayRef[Slic3r::Surface]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
);
|
);
|
||||||
|
|
||||||
# ordered collection of extrusion paths to build all perimeters
|
# ordered collection of extrusion paths to build all perimeters
|
||||||
has 'perimeters' => (
|
has 'perimeters' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::ExtrusionPath]',
|
#isa => 'ArrayRef[Slic3r::ExtrusionPath]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
);
|
);
|
||||||
|
|
||||||
# ordered collection of extrusion paths to build skirt loops
|
# ordered collection of extrusion paths to build skirt loops
|
||||||
has 'skirts' => (
|
has 'skirts' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::ExtrusionPath]',
|
#isa => 'ArrayRef[Slic3r::ExtrusionPath]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -58,14 +55,14 @@ has 'skirts' => (
|
|||||||
has 'fill_surfaces' => (
|
has 'fill_surfaces' => (
|
||||||
traits => ['Array'],
|
traits => ['Array'],
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::Surface]',
|
#isa => 'ArrayRef[Slic3r::Surface]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
);
|
);
|
||||||
|
|
||||||
# ordered collection of extrusion paths to fill surfaces
|
# ordered collection of extrusion paths to fill surfaces
|
||||||
has 'fills' => (
|
has 'fills' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::ExtrusionPath]',
|
#isa => 'ArrayRef[Slic3r::ExtrusionPath]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -74,6 +71,11 @@ sub z {
|
|||||||
return $self->id * $Slic3r::layer_height / $Slic3r::resolution;
|
return $self->id * $Slic3r::layer_height / $Slic3r::resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub points {
|
||||||
|
my $self = shift;
|
||||||
|
return values %{ $self->pointmap };
|
||||||
|
}
|
||||||
|
|
||||||
sub add_surface {
|
sub add_surface {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my (@vertices) = @_;
|
my (@vertices) = @_;
|
||||||
|
@ -1,32 +1,28 @@
|
|||||||
package Slic3r::Line;
|
package Slic3r::Line;
|
||||||
use Moose;
|
use Moo;
|
||||||
use Moose::Util::TypeConstraints;
|
|
||||||
use Scalar::Util qw(weaken);
|
use Scalar::Util qw(weaken);
|
||||||
|
|
||||||
subtype 'Slic3r::Line::Length', as 'Int';
|
|
||||||
coerce 'Slic3r::Line::Length', from 'Num', via { sprintf '%.0f', $_ };
|
|
||||||
|
|
||||||
has 'a' => (
|
has 'a' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Slic3r::Point',
|
#isa => 'Slic3r::Point',
|
||||||
required => 1,
|
required => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'b' => (
|
has 'b' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Slic3r::Point',
|
#isa => 'Slic3r::Point',
|
||||||
required => 1,
|
required => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'polyline' => (
|
has 'polyline' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'Slic3r::Polyline',
|
#isa => 'Slic3r::Polyline',
|
||||||
weak_ref => 1,
|
weak_ref => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'solid_side' => (
|
has 'solid_side' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => enum([qw(left right)]), # going from a to b
|
#isa => enum([qw(left right)]), # going from a to b
|
||||||
);
|
);
|
||||||
|
|
||||||
sub BUILD {
|
sub BUILD {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package Slic3r::Perimeter;
|
package Slic3r::Perimeter;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
use Math::Geometry::Planar;
|
use Math::Geometry::Planar;
|
||||||
*Math::Geometry::Planar::OffsetPolygon = *Math::Geometry::Planar::Offset::OffsetPolygon;
|
*Math::Geometry::Planar::OffsetPolygon = *Math::Geometry::Planar::Offset::OffsetPolygon;
|
||||||
|
@ -1,28 +1,24 @@
|
|||||||
package Slic3r::Point;
|
package Slic3r::Point;
|
||||||
use Moose;
|
use Moo;
|
||||||
use Moose::Util::TypeConstraints;
|
|
||||||
|
|
||||||
subtype 'Slic3r::Point::Coordinate', as 'Int';
|
|
||||||
coerce 'Slic3r::Point::Coordinate', from 'Num', via { sprintf '%.0f', $_ };
|
|
||||||
|
|
||||||
has 'x' => (
|
has 'x' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Slic3r::Point::Coordinate',
|
#isa => 'Slic3r::Point::Coordinate',
|
||||||
required => 1,
|
required => 1,
|
||||||
coerce => 1,
|
coerce => sub { sprintf '%.0f', $_[0] },
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'y' => (
|
has 'y' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Slic3r::Point::Coordinate',
|
#isa => 'Slic3r::Point::Coordinate',
|
||||||
required => 1,
|
required => 1,
|
||||||
coerce => 1,
|
coerce => sub { sprintf '%.0f', $_[0] },
|
||||||
);
|
);
|
||||||
|
|
||||||
# this array contains weak references, so it can contain undef's as well
|
# this array contains weak references, so it can contain undef's as well
|
||||||
has 'lines' => (
|
has 'lines' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::Line]',
|
#isa => 'ArrayRef[Slic3r::Line]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
package Slic3r::Polyline;
|
package Slic3r::Polyline;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
has 'lines' => (
|
has 'lines' => (
|
||||||
traits => ['Array'],
|
traits => ['Array'],
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::Line]',
|
#isa => 'ArrayRef[Slic3r::Line]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
handles => {
|
|
||||||
add_line => 'push',
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
after 'add_line' => sub {
|
sub add_line {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my ($line) = @_;
|
||||||
|
|
||||||
|
push @{ $self->lines }, $line;
|
||||||
|
|
||||||
# add a weak reference to this polyline in line objects
|
# add a weak reference to this polyline in line objects
|
||||||
# (avoid circular refs)
|
# (avoid circular refs)
|
||||||
$self->lines->[-1]->polyline($self);
|
$self->lines->[-1]->polyline($self);
|
||||||
};
|
}
|
||||||
|
|
||||||
sub BUILD {
|
sub BUILD {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
package Slic3r::Polyline::Closed;
|
package Slic3r::Polyline::Closed;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
extends 'Slic3r::Polyline';
|
extends 'Slic3r::Polyline';
|
||||||
|
|
||||||
has 'contour_of' => (
|
has 'contour_of' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'Slic3r::Surface',
|
#isa => 'Slic3r::Surface',
|
||||||
weak_ref => 1,
|
weak_ref => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'hole_of' => (
|
has 'hole_of' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'Slic3r::Surface',
|
#isa => 'Slic3r::Surface',
|
||||||
weak_ref => 1,
|
weak_ref => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
override 'new_from_points' => sub {
|
sub new_from_points {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $polyline = super();
|
my $polyline = $class->SUPER::new_from_points(@_);
|
||||||
|
|
||||||
# polylines must be always closed, otherwise it means that our object is not manifold!
|
# polylines must be always closed, otherwise it means that our object is not manifold!
|
||||||
die "Polylines must be closed! Object not manifold?\n"
|
die "Polylines must be closed! Object not manifold?\n"
|
||||||
if ($polyline->lines->[0]->a != $polyline->lines->[-1]->b);
|
if ($polyline->lines->[0]->a != $polyline->lines->[-1]->b);
|
||||||
|
|
||||||
return $polyline;
|
return $polyline;
|
||||||
};
|
}
|
||||||
|
|
||||||
sub encloses_point {
|
sub encloses_point {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package Slic3r::Print;
|
package Slic3r::Print;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
use constant PI => 4 * atan2(1, 1);
|
use constant PI => 4 * atan2(1, 1);
|
||||||
use constant X => 0;
|
use constant X => 0;
|
||||||
@ -7,37 +7,39 @@ use constant Y => 1;
|
|||||||
|
|
||||||
has 'x_length' => (
|
has 'x_length' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Slic3r::Line::Length',
|
#isa => 'Slic3r::Line::Length',
|
||||||
required => 1,
|
required => 1,
|
||||||
coerce => 1,
|
coerce => sub { sprintf '%.0f', $_[0] },
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'y_length' => (
|
has 'y_length' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Slic3r::Line::Length',
|
#isa => 'Slic3r::Line::Length',
|
||||||
required => 1,
|
required => 1,
|
||||||
coerce => 1,
|
coerce => sub { sprintf '%.0f', $_[0] },
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'layers' => (
|
has 'layers' => (
|
||||||
traits => ['Array'],
|
traits => ['Array'],
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::Layer]',
|
#isa => 'ArrayRef[Slic3r::Layer]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
handles => {
|
|
||||||
layer_count => 'count',
|
|
||||||
add_layer => 'push',
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sub layer_count {
|
||||||
|
my $self = shift;
|
||||||
|
return scalar @{ $self->layers };
|
||||||
|
}
|
||||||
|
|
||||||
sub layer {
|
sub layer {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($layer_id) = @_;
|
my ($layer_id) = @_;
|
||||||
|
|
||||||
# extend our print by creating all necessary layers
|
# extend our print by creating all necessary layers
|
||||||
|
|
||||||
if ($self->layer_count < $layer_id + 1) {
|
if ($self->layer_count < $layer_id + 1) {
|
||||||
for (my $i = $self->layer_count; $i <= $layer_id; $i++) {
|
for (my $i = $self->layer_count; $i <= $layer_id; $i++) {
|
||||||
$self->add_layer(Slic3r::Layer->new(id => $i));
|
push @{ $self->layers }, Slic3r::Layer->new(id => $i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package Slic3r::STL;
|
package Slic3r::STL;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
use CAD::Format::STL;
|
use CAD::Format::STL;
|
||||||
use XXX;
|
use XXX;
|
||||||
|
@ -1,39 +1,38 @@
|
|||||||
package Slic3r::Surface;
|
package Slic3r::Surface;
|
||||||
use Moose;
|
use Moo;
|
||||||
|
|
||||||
use Math::Geometry::Planar;
|
use Math::Geometry::Planar;
|
||||||
use Moose::Util::TypeConstraints;
|
|
||||||
|
|
||||||
has 'contour' => (
|
has 'contour' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Slic3r::Polyline::Closed',
|
#isa => 'Slic3r::Polyline::Closed',
|
||||||
required => 1,
|
required => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'holes' => (
|
has 'holes' => (
|
||||||
traits => ['Array'],
|
traits => ['Array'],
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef[Slic3r::Polyline::Closed]',
|
#isa => 'ArrayRef[Slic3r::Polyline::Closed]',
|
||||||
default => sub { [] },
|
default => sub { [] },
|
||||||
handles => {
|
|
||||||
'add_hole' => 'push',
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
# TODO: to allow for multiple solid skins to be filled near external
|
# TODO: to allow for multiple solid skins to be filled near external
|
||||||
# surfaces, a new type should be defined: internal-solid
|
# surfaces, a new type should be defined: internal-solid
|
||||||
has 'surface_type' => (
|
has 'surface_type' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => enum([qw(internal bottom top)]),
|
#isa => enum([qw(internal bottom top)]),
|
||||||
);
|
);
|
||||||
|
|
||||||
after 'add_hole' => sub {
|
sub add_hole {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my ($hole) = @_;
|
||||||
|
|
||||||
|
push @{ $self->holes }, $hole;
|
||||||
|
|
||||||
# add a weak reference to this surface in polyline objects
|
# add a weak reference to this surface in polyline objects
|
||||||
# (avoid circular refs)
|
# (avoid circular refs)
|
||||||
$self->holes->[-1]->hole_of($self);
|
$self->holes->[-1]->hole_of($self);
|
||||||
};
|
}
|
||||||
|
|
||||||
sub BUILD {
|
sub BUILD {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
Loading…
Reference in New Issue
Block a user