From cdd7469c583dcbf62ad13ac7b92a892f01865e05 Mon Sep 17 00:00:00 2001 From: florens Date: Wed, 13 Aug 2014 19:09:58 +0200 Subject: [PATCH] created stump of the AdaptiveSlicing class that will provide the cusp computations --- lib/Slic3r/AdaptiveSlicing.pm | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/Slic3r/AdaptiveSlicing.pm diff --git a/lib/Slic3r/AdaptiveSlicing.pm b/lib/Slic3r/AdaptiveSlicing.pm new file mode 100644 index 000000000..037754777 --- /dev/null +++ b/lib/Slic3r/AdaptiveSlicing.pm @@ -0,0 +1,53 @@ +package Slic3r::AdaptiveSlicing; +use Moo; + +use List::Util qw(min max); +use Slic3r::Geometry qw(X Y Z triangle_normal scale unscale); + +#private +has 'normal' => (is => 'ro', default => sub { [] }); # facet_id => [normal]; +has 'ordered_facets' => (is => 'ro', default => sub { [] }); # id => [facet_id, min_z, max_z]; +has 'current_facet' => (is => 'rw'); + +sub BUILD { + my $self = shift; + + my $facet_id = 0; + my $facets = $self->mesh->facets; + my $vertices = $self->mesh->vertices; + + # generate facet normals + foreach my $facet (@{$facets}) { + my $normal = triangle_normal(map $vertices->[$_], @$facet[-3..-1]); + # normalize length + my $normal_length = sqrt($normal->[0]**2 + $normal->[1]**2 + $normal->[2]**2); + + if($normal_length > 0) { + $self->normal->[$facet_id] = [ map $normal->[$_]/$normal_length, (X,Y,Z) ]; + }else{ # facet with area = 0 + $self->normal->[$facet_id] = [0 ,0 ,0]; + } + $facet_id++; + } + + # generate a list of facet_ids, containing maximum and minimum Z-Value of the facet, ordered by minimum Z + my @sort_facets; + + for ($facet_id = 0; $facet_id <= $#{$facets}; $facet_id++) { + my $a = $vertices->[$facets->[$facet_id]->[0]]->[Z]; + my $b = $vertices->[$facets->[$facet_id]->[1]]->[Z]; + my $c = $vertices->[$facets->[$facet_id]->[2]]->[Z]; + my $min_z = min($a, $b, $c); + my $max_z = max($a, $b, $c); + push @sort_facets, [$facet_id, $min_z, $max_z]; + } + @sort_facets = sort {$a->[1] <=> $b->[1]} @sort_facets; + for (my $i = 0; $i <= $#sort_facets; $i++) { + $self->ordered_facets->[$i] = $sort_facets[$i]; + } + # initialize pointer for cusp_height run + $self->current_facet(0); +} + + +1; \ No newline at end of file