mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Incomplete work for porting simplify() to XS
This commit is contained in:
		
							parent
							
								
									7475762a27
								
							
						
					
					
						commit
						518798beb3
					
				
					 24 changed files with 121 additions and 41 deletions
				
			
		| 
						 | 
				
			
			@ -10,9 +10,4 @@ our @EXPORT_OK = qw(EXTR_ROLE_PERIMETER EXTR_ROLE_EXTERNAL_PERIMETER
 | 
			
		|||
    EXTR_ROLE_INTERNALBRIDGE EXTR_ROLE_SKIRT EXTR_ROLE_SUPPORTMATERIAL EXTR_ROLE_GAPFILL);
 | 
			
		||||
our %EXPORT_TAGS = (roles => \@EXPORT_OK);
 | 
			
		||||
 | 
			
		||||
sub simplify {
 | 
			
		||||
    my $self = shift;
 | 
			
		||||
    $self->polyline($self->polyline->simplify(@_));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
1;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,7 +38,7 @@ sub BUILD {
 | 
			
		|||
    my $crossing_edges = $self->_crossing_edges;
 | 
			
		||||
    
 | 
			
		||||
    # simplify islands
 | 
			
		||||
    @{$self->islands} = map $_->simplify($self->_inner_margin), @{$self->islands};
 | 
			
		||||
    $_->simplify($self->_inner_margin) for @{$self->islands};
 | 
			
		||||
    
 | 
			
		||||
    # process individual islands
 | 
			
		||||
    for my $i (0 .. $#{$self->islands}) {        
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1360,10 +1360,10 @@ sub make_thumbnail {
 | 
			
		|||
        # remove polygons with area <= 1mm
 | 
			
		||||
        my $area_threshold = Slic3r::Geometry::scale 1;
 | 
			
		||||
        $self->thumbnail->append(
 | 
			
		||||
            map $_->simplify(0.5),
 | 
			
		||||
            grep $_->area >= $area_threshold,
 | 
			
		||||
            @{ $mesh->horizontal_projection },
 | 
			
		||||
        );
 | 
			
		||||
        $self->thumbnail->simplify(0.5);
 | 
			
		||||
    } else {
 | 
			
		||||
        my $convex_hull = Slic3r::ExPolygon->new($self->convex_hull)->clone;
 | 
			
		||||
        $convex_hull->scale(1/&Slic3r::SCALING_FACTOR);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,13 +32,6 @@ sub grow {
 | 
			
		|||
    return $self->split_at_first_point->grow(@_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# NOTE that this will turn the polygon to ccw regardless of its 
 | 
			
		||||
# original orientation
 | 
			
		||||
sub simplify {
 | 
			
		||||
    my $self = shift;
 | 
			
		||||
    return @{Slic3r::Geometry::Clipper::simplify_polygons([ $self->SUPER::simplify(@_) ])};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# this method subdivides the polygon segments to that no one of them
 | 
			
		||||
# is longer than the length provided
 | 
			
		||||
sub subdivide {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,14 +27,6 @@ sub remove_acute_vertices {
 | 
			
		|||
    polyline_remove_acute_vertices($self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub simplify {
 | 
			
		||||
    my $self = shift;
 | 
			
		||||
    my $tolerance = shift || 10;
 | 
			
		||||
    
 | 
			
		||||
    my $simplified = Boost::Geometry::Utils::linestring_simplify($self->pp, $tolerance);
 | 
			
		||||
    return __PACKAGE__->new(@$simplified);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub bounding_box {
 | 
			
		||||
    my $self = shift;
 | 
			
		||||
    return Slic3r::Geometry::BoundingBox->new_from_points($self);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -317,14 +317,8 @@ sub _simplify_slices {
 | 
			
		|||
    my ($distance) = @_;
 | 
			
		||||
    
 | 
			
		||||
    foreach my $layer (map @{$_->layers}, @{$self->objects}) {
 | 
			
		||||
        my @new = map $_->simplify($distance), map $_->clone, @{$layer->slices};
 | 
			
		||||
        $layer->slices->clear;
 | 
			
		||||
        $layer->slices->append(@new);
 | 
			
		||||
        foreach my $layerm (@{$layer->regions}) {
 | 
			
		||||
            my @new = map $_->simplify($distance), map $_->clone, @{$layerm->slices};
 | 
			
		||||
            $layerm->slices->clear;
 | 
			
		||||
            $layerm->slices->append(@new);
 | 
			
		||||
        }
 | 
			
		||||
        $layer->slices->simplify($distance);
 | 
			
		||||
        $_->slices->simplify($distance) for @{$layer->regions};
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,11 +38,6 @@ sub offset {
 | 
			
		|||
    return [ map $self->clone(expolygon => $_), @{$self->expolygon->offset_ex(@_)} ];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub simplify {
 | 
			
		||||
    my $self = shift;
 | 
			
		||||
    return map $self->clone(expolygon => $_), $self->expolygon->simplify(@_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub p {
 | 
			
		||||
    my $self = shift;
 | 
			
		||||
    return @{$self->polygons};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue