mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Optimization in Polyline instantiation
This commit is contained in:
		
							parent
							
								
									27c421c27f
								
							
						
					
					
						commit
						8061cc6e30
					
				
					 14 changed files with 40 additions and 45 deletions
				
			
		|  | @ -17,11 +17,11 @@ sub new { | |||
|     my $self; | ||||
|     if (@_ == 1 && ref $_[0] eq 'HASH') { | ||||
|         $self = [ | ||||
|             Slic3r::Polygon->new($_[0]{outer}), | ||||
|             map Slic3r::Polygon->new($_), @{$_[0]{holes}}, | ||||
|             Slic3r::Polygon->new(@{$_[0]{outer}}), | ||||
|             map Slic3r::Polygon->new(@$_), @{$_[0]{holes}}, | ||||
|         ]; | ||||
|     } else { | ||||
|         $self = [ map Slic3r::Polygon->new($_), @_ ]; | ||||
|         $self = [ map Slic3r::Polygon->new(@$_), @_ ]; | ||||
|     } | ||||
|     bless $self, $class; | ||||
|     $self; | ||||
|  | @ -287,7 +287,7 @@ sub medial_axis { | |||
|             next if @$polyline == 2; | ||||
|             push @result, Slic3r::Polygon->new(@$polyline[0..$#$polyline-1]); | ||||
|         } else { | ||||
|             push @result, Slic3r::Polyline->new($polyline); | ||||
|             push @result, Slic3r::Polyline->new(@$polyline); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|  |  | |||
|  | @ -160,14 +160,14 @@ sub split_at_acute_angles { | |||
|             # if the angle between $p[-2], $p[-1], $p3 is too acute | ||||
|             # then consider $p3 only as a starting point of a new | ||||
|             # path and stop the current one as it is | ||||
|             push @paths, $self->clone(polyline => Slic3r::Polyline->new(\@p)); | ||||
|             push @paths, $self->clone(polyline => Slic3r::Polyline->new(@p)); | ||||
|             @p = ($p3); | ||||
|             push @p, grep $_, shift @points or last; | ||||
|         } else { | ||||
|             push @p, $p3; | ||||
|         } | ||||
|     } | ||||
|     push @paths, $self->clone(polyline => Slic3r::Polyline->new(\@p)) | ||||
|     push @paths, $self->clone(polyline => Slic3r::Polyline->new(@p)) | ||||
|         if @p > 1; | ||||
|      | ||||
|     return @paths; | ||||
|  | @ -254,7 +254,7 @@ sub detect_arcs { | |||
|             } | ||||
|              | ||||
|             my $arc = Slic3r::ExtrusionPath::Arc->new( | ||||
|                 polyline    => Slic3r::Polyline->new(\@arc_points), | ||||
|                 polyline    => Slic3r::Polyline->new(@arc_points), | ||||
|                 role        => $self->role, | ||||
|                 flow_spacing => $self->flow_spacing, | ||||
|                 orientation => $orientation, | ||||
|  | @ -279,7 +279,7 @@ sub detect_arcs { | |||
|     } | ||||
|      | ||||
|     # remaining points form a linear path | ||||
|     push @paths, $self->clone(polyline => Slic3r::Polyline->new(\@points)) | ||||
|     push @paths, $self->clone(polyline => Slic3r::Polyline->new(@points)) | ||||
|         if @points > 1; | ||||
|      | ||||
|     return @paths; | ||||
|  |  | |||
|  | @ -71,7 +71,7 @@ sub fill_surface { | |||
|                 $x += $m->{distance}; | ||||
|             } | ||||
|              | ||||
|             push @polygons, Slic3r::Polygon->new($p); | ||||
|             push @polygons, Slic3r::Polygon->new(@$p); | ||||
|         } | ||||
|          | ||||
|         $_->rotate(-$rotate_vector->[0][0], $m->{hex_center}) for @polygons; | ||||
|  | @ -88,7 +88,7 @@ sub fill_surface { | |||
|         # consider polygons as polylines without re-appending the initial point: | ||||
|         # this cuts the last segment on purpose, so that the jump to the next  | ||||
|         # path is more straight | ||||
|         @paths = map Slic3r::Polyline->new($_), | ||||
|         @paths = map Slic3r::Polyline->new(@$_), | ||||
|             @{ Boost::Geometry::Utils::polygon_multi_linestring_intersection( | ||||
|                 $surface->expolygon, | ||||
|                 \@polygons, | ||||
|  | @ -113,7 +113,7 @@ sub fill_surface { | |||
|         } | ||||
|          | ||||
|         # clip paths again to prevent connection segments from crossing the expolygon boundaries | ||||
|         @paths = map Slic3r::Polyline->new($_), | ||||
|         @paths = map Slic3r::Polyline->new(@$_), | ||||
|             @{ Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection( | ||||
|                 [ $surface->expolygon->offset_ex(scaled_epsilon) ], | ||||
|                 [ @paths ], | ||||
|  |  | |||
|  | @ -33,9 +33,9 @@ sub fill_surface { | |||
|     my $path = "Math::PlanePath::$1"->new; | ||||
|     my @n = $self->get_n($path, [ map +($_ / $distance_between_lines), @{$bounding_box->bb} ]); | ||||
|      | ||||
|     my $polyline = Slic3r::Polyline->new([ | ||||
|     my $polyline = Slic3r::Polyline->new( | ||||
|         map [ map {$_*$distance_between_lines} $path->n_to_xy($_) ], @n, | ||||
|     ]); | ||||
|     ); | ||||
|     return {} if !@$polyline; | ||||
|      | ||||
|     $self->process_polyline($polyline, $bounding_box); | ||||
|  |  | |||
|  | @ -295,7 +295,7 @@ sub extrude_path { | |||
|             $path_length += $line_length; | ||||
|             $gcode .= $self->G1($line->[B], undef, $e * $line_length, $description); | ||||
|         } | ||||
|         $self->wipe_path(Slic3r::Polyline->new([ reverse @{$path->points} ])) | ||||
|         $self->wipe_path(Slic3r::Polyline->new(reverse @{$path->points})) | ||||
|             if $self->extruder->wipe; | ||||
|     } | ||||
|      | ||||
|  | @ -409,7 +409,7 @@ sub retract { | |||
|     # wipe | ||||
|     my $wipe_path; | ||||
|     if ($self->extruder->wipe && $self->wipe_path) { | ||||
|         $wipe_path = Slic3r::Polyline->new([ $self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}] ]) | ||||
|         $wipe_path = Slic3r::Polyline->new($self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}]) | ||||
|             ->clip_start($self->extruder->scaled_wipe_distance); | ||||
|     } | ||||
|      | ||||
|  |  | |||
|  | @ -888,7 +888,7 @@ sub repaint { | |||
|              | ||||
|             # if sequential printing is enabled and we have more than one object | ||||
|             if ($parent->{config}->complete_objects && (map @{$_->instances}, @{$parent->{objects}}) > 1) { | ||||
|             	my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->contour}, @{$parent->{object_previews}->[-1][2]->expolygons} ])); | ||||
|             	my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @{$_->contour}, @{$parent->{object_previews}->[-1][2]->expolygons} ])}); | ||||
|                 my ($clearance) = @{offset([$convex_hull], $parent->{config}->extruder_clearance_radius / 2 * $parent->{scaling_factor}, 100, JT_ROUND)}; | ||||
|                 $dc->SetPen($parent->{clearance_pen}); | ||||
|                 $dc->SetBrush($parent->{transparent_brush}); | ||||
|  | @ -899,7 +899,7 @@ sub repaint { | |||
|      | ||||
|     # draw skirt | ||||
|     if (@{$parent->{object_previews}} && $parent->{config}->skirts) { | ||||
|         my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->contour}, map @{$_->[2]->expolygons}, @{$parent->{object_previews}} ])); | ||||
|         my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @{$_->contour}, map @{$_->[2]->expolygons}, @{$parent->{object_previews}} ])}); | ||||
|         ($convex_hull) = @{offset([$convex_hull], $parent->{config}->skirt_distance * $parent->{scaling_factor}, 100, JT_ROUND)}; | ||||
|         $dc->SetPen($parent->{skirt_pen}); | ||||
|         $dc->SetBrush($parent->{transparent_brush}); | ||||
|  | @ -1098,7 +1098,7 @@ sub _trigger_model_object { | |||
| 	    $self->bounding_box($self->model_object->bounding_box); | ||||
| 	     | ||||
|     	my $mesh = $self->model_object->mesh; | ||||
|         $self->convex_hull(Slic3r::Polygon->new(Math::ConvexHull::MonotoneChain::convex_hull($mesh->used_vertices))); | ||||
|         $self->convex_hull(Slic3r::Polygon->new(@{Math::ConvexHull::MonotoneChain::convex_hull($mesh->used_vertices)})); | ||||
| 	    $self->facets(scalar @{$mesh->facets}); | ||||
| 	    $self->vertices(scalar @{$mesh->vertices}); | ||||
| 	     | ||||
|  |  | |||
|  | @ -38,12 +38,12 @@ sub polygon { | |||
|     my $self = shift; | ||||
|      | ||||
|     my $e = $self->extents; | ||||
|     return Slic3r::Polygon->new([ | ||||
|     return Slic3r::Polygon->new( | ||||
|         [ $e->[X][MIN], $e->[Y][MIN] ], | ||||
|         [ $e->[X][MAX], $e->[Y][MIN] ], | ||||
|         [ $e->[X][MAX], $e->[Y][MAX] ], | ||||
|         [ $e->[X][MIN], $e->[Y][MAX] ], | ||||
|     ]); | ||||
|     ); | ||||
| } | ||||
| 
 | ||||
| # note to $self | ||||
|  |  | |||
|  | @ -83,7 +83,7 @@ sub diff { | |||
|     $clipper->add_subject_polygons($subject); | ||||
|     $clipper->add_clip_polygons($safety_offset ? safety_offset($clip) : $clip); | ||||
|     return [ | ||||
|         map Slic3r::Polygon->new($_), | ||||
|         map Slic3r::Polygon->new(@$_), | ||||
|             @{ $clipper->execute(CT_DIFFERENCE, PFT_NONZERO, PFT_NONZERO) }, | ||||
|     ]; | ||||
| } | ||||
|  | @ -126,7 +126,7 @@ sub intersection { | |||
|     $clipper->add_subject_polygons($subject); | ||||
|     $clipper->add_clip_polygons($safety_offset ? safety_offset($clip) : $clip); | ||||
|     return [ | ||||
|         map Slic3r::Polygon->new($_), | ||||
|         map Slic3r::Polygon->new(@$_), | ||||
|             @{ $clipper->execute(CT_INTERSECTION, $jointype, $jointype) }, | ||||
|     ]; | ||||
| } | ||||
|  |  | |||
|  | @ -247,7 +247,7 @@ sub make_perimeters { | |||
|             # return ccw contours and cw holes | ||||
|             # GCode.pm will convert all of them to ccw, but it needs to know | ||||
|             # what the holes are in order to compute the correct inwards move | ||||
|             my $polygon = Slic3r::Polygon->new($polynode->{outer} // [ reverse @{$polynode->{hole}} ]); | ||||
|             my $polygon = Slic3r::Polygon->new(defined $polynode->{outer} ? @{$polynode->{outer}} : reverse @{$polynode->{hole}}); | ||||
|             $polygon->reverse if !$is_contour; | ||||
|              | ||||
|             my $role = EXTR_ROLE_PERIMETER; | ||||
|  |  | |||
|  | @ -10,13 +10,8 @@ use Slic3r::Geometry::Clipper qw(JT_SQUARE); | |||
| # the constructor accepts an array(ref) of points | ||||
| sub new { | ||||
|     my $class = shift; | ||||
|     my $self; | ||||
|     if (@_ == 1) { | ||||
|         $self = [ @{$_[0]} ]; | ||||
|     } else { | ||||
|         $self = [ @_ ]; | ||||
|     } | ||||
|      | ||||
|     my $self = [ @_ ]; | ||||
|     bless $self, $class; | ||||
|     bless $_, 'Slic3r::Point' for @$self; | ||||
|     $self; | ||||
|  | @ -65,7 +60,7 @@ sub simplify { | |||
|     my $tolerance = shift || 10; | ||||
|      | ||||
|     my $simplified = Boost::Geometry::Utils::linestring_simplify($self, $tolerance); | ||||
|     return (ref $self)->new($simplified); | ||||
|     return (ref $self)->new(@$simplified); | ||||
| } | ||||
| 
 | ||||
| sub reverse { | ||||
|  | @ -83,9 +78,9 @@ sub grow { | |||
|     my ($distance, $scale, $joinType, $miterLimit) = @_; | ||||
|     $joinType //= JT_SQUARE; | ||||
|      | ||||
|     return map Slic3r::Polygon->new($_), | ||||
|     return map Slic3r::Polygon->new(@$_), | ||||
|         Slic3r::Geometry::Clipper::offset( | ||||
|             [ Slic3r::Polygon->new(@$self, CORE::reverse @$self[1..($#$self-1)]) ], | ||||
|             [ [ @$self, CORE::reverse @$self[1..($#$self-1)] ] ], | ||||
|             $distance, $scale, $joinType, $miterLimit, | ||||
|         ); | ||||
| } | ||||
|  |  | |||
|  | @ -170,8 +170,8 @@ sub validate { | |||
|                 my $clearance; | ||||
|                 { | ||||
|                     my @points = map [ @$_[X,Y] ], map @{$_->vertices}, @{$self->objects->[$obj_idx]->meshes}; | ||||
|                     my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points)); | ||||
|                     ($clearance) = map Slic3r::Polygon->new($_),  | ||||
|                     my $convex_hull = Slic3r::Polygon->new(@{convex_hull(\@points)}); | ||||
|                     ($clearance) = map Slic3r::Polygon->new(@$_),  | ||||
|                                         Slic3r::Geometry::Clipper::offset( | ||||
|                                             [$convex_hull], scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND); | ||||
|                 } | ||||
|  | @ -665,7 +665,7 @@ sub make_brim { | |||
|     } | ||||
|      | ||||
|     @{$self->brim} = map Slic3r::ExtrusionLoop->pack( | ||||
|         polygon         => Slic3r::Polygon->new($_), | ||||
|         polygon         => Slic3r::Polygon->new(@$_), | ||||
|         role            => EXTR_ROLE_SKIRT, | ||||
|         flow_spacing    => $flow->spacing, | ||||
|     ), reverse traverse_pt( union_pt(\@loops, PFT_EVENODD) ); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci