Merge branch 'master' into xsdata
Conflicts: lib/Slic3r.pm lib/Slic3r/ExPolygon.pm lib/Slic3r/Fill.pm lib/Slic3r/Fill/Rectilinear.pm lib/Slic3r/GCode.pm lib/Slic3r/GUI/Plater.pm lib/Slic3r/Geometry/Clipper.pm lib/Slic3r/Layer/Region.pm lib/Slic3r/Print.pm lib/Slic3r/Print/Object.pm lib/Slic3r/TriangleMesh.pm t/shells.t xs/MANIFEST
This commit is contained in:
commit
b38cc2c244
60 changed files with 1432 additions and 798 deletions
|
@ -25,7 +25,6 @@ use overload
|
|||
package Slic3r::Polyline;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1,
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Polygon;
|
||||
|
@ -128,7 +127,7 @@ sub clone {
|
|||
my ($self, %args) = @_;
|
||||
|
||||
return (ref $self)->_new(
|
||||
delete $args{expolygon} // $self->expolygon->clone,
|
||||
delete $args{expolygon} // $self->expolygon,
|
||||
delete $args{surface_type} // $self->surface_type,
|
||||
delete $args{thickness} // $self->thickness,
|
||||
delete $args{thickness_layers} // $self->thickness_layers,
|
||||
|
|
|
@ -277,4 +277,19 @@ void union_ex(Slic3r::Polygons &subject, Slic3r::ExPolygons &retval, bool safety
|
|||
_clipper(ClipperLib::ctUnion, subject, p, retval, safety_offset);
|
||||
}
|
||||
|
||||
void simplify_polygons(Slic3r::Polygons &subject, Slic3r::Polygons &retval)
|
||||
{
|
||||
// convert into Clipper polygons
|
||||
ClipperLib::Polygons* input_subject = new ClipperLib::Polygons();
|
||||
Slic3rPolygons_to_ClipperPolygons(subject, *input_subject);
|
||||
|
||||
ClipperLib::Polygons* output = new ClipperLib::Polygons();
|
||||
ClipperLib::SimplifyPolygons(*input_subject, *output, ClipperLib::pftNonZero);
|
||||
delete input_subject;
|
||||
|
||||
// convert into Slic3r polygons
|
||||
ClipperPolygons_to_Slic3rPolygons(*output, retval);
|
||||
delete output;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,6 +62,8 @@ void xor_ex(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::ExPolygon
|
|||
|
||||
void union_ex(Slic3r::Polygons &subject, Slic3r::ExPolygons &retval, bool safety_offset = false);
|
||||
|
||||
void simplify_polygons(Slic3r::Polygons &subject, Slic3r::Polygons &retval);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,6 @@ class ExPolygon
|
|||
public:
|
||||
Polygon contour;
|
||||
Polygons holes;
|
||||
bool in_collection;
|
||||
void from_SV(SV* poly_sv);
|
||||
void from_SV_check(SV* poly_sv);
|
||||
SV* to_SV();
|
||||
|
@ -23,7 +22,6 @@ class ExPolygon
|
|||
};
|
||||
|
||||
typedef std::vector<ExPolygon> ExPolygons;
|
||||
typedef std::vector<ExPolygon*> ExPolygonsPtr;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,24 +5,24 @@ namespace Slic3r {
|
|||
void
|
||||
ExPolygonCollection::scale(double factor)
|
||||
{
|
||||
for (ExPolygonsPtr::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
||||
(**it).scale(factor);
|
||||
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
||||
(*it).scale(factor);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygonCollection::translate(double x, double y)
|
||||
{
|
||||
for (ExPolygonsPtr::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
||||
(**it).translate(x, y);
|
||||
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
||||
(*it).translate(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygonCollection::rotate(double angle, Point* center)
|
||||
{
|
||||
for (ExPolygonsPtr::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
||||
(**it).rotate(angle, center);
|
||||
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
||||
(*it).rotate(angle, center);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Slic3r {
|
|||
class ExPolygonCollection
|
||||
{
|
||||
public:
|
||||
ExPolygonsPtr expolygons;
|
||||
ExPolygons expolygons;
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void rotate(double angle, Point* center);
|
||||
|
|
|
@ -16,11 +16,9 @@ class Surface
|
|||
unsigned short thickness_layers; // in layers
|
||||
double bridge_angle;
|
||||
unsigned short extra_perimeters;
|
||||
bool in_collection;
|
||||
};
|
||||
|
||||
typedef std::vector<Surface> Surfaces;
|
||||
typedef std::vector<Surface*> SurfacesPtr;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Slic3r {
|
|||
class SurfaceCollection
|
||||
{
|
||||
public:
|
||||
SurfacesPtr surfaces;
|
||||
Surfaces surfaces;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -28,17 +28,17 @@ void TriangleMesh::ReadFromPerl(SV* vertices, SV* facets)
|
|||
for (unsigned int i = 0; i < stl.stats.number_of_facets; i++) {
|
||||
AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0));
|
||||
stl_facet facet;
|
||||
facet.normal.x = NULL;
|
||||
facet.normal.y = NULL;
|
||||
facet.normal.z = NULL;
|
||||
facet.normal.x = 0;
|
||||
facet.normal.y = 0;
|
||||
facet.normal.z = 0;
|
||||
for (unsigned int v = 0; v <= 2; v++) {
|
||||
AV* vertex_av = (AV*)SvRV(*av_fetch(vertices_av, SvIV(*av_fetch(facet_av, v, 0)), 0));
|
||||
facet.vertex[v].x = SvNV(*av_fetch(vertex_av, 0, 0));
|
||||
facet.vertex[v].y = SvNV(*av_fetch(vertex_av, 1, 0));
|
||||
facet.vertex[v].z = SvNV(*av_fetch(vertex_av, 2, 0));
|
||||
}
|
||||
facet.extra[0] = NULL;
|
||||
facet.extra[1] = NULL;
|
||||
facet.extra[0] = 0;
|
||||
facet.extra[1] = 0;
|
||||
|
||||
stl.facet_start[i] = facet;
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ stl_check_facets_exact(stl_file *stl)
|
|||
{
|
||||
facet = stl->facet_start[i];
|
||||
|
||||
//If any two of the three vertices are found to be exactally the same, call them degenerate and remove the facet.
|
||||
if( !memcmp(&facet.vertex[0], &facet.vertex[1],
|
||||
sizeof(stl_vertex))
|
||||
|| !memcmp(&facet.vertex[1], &facet.vertex[2],
|
||||
|
|
|
@ -121,9 +121,13 @@ stl_fix_normal_directions(stl_file *stl)
|
|||
|
||||
|
||||
facet_num = 0;
|
||||
//If normal vector is not within tolerance and backwards:
|
||||
//Arbitrarily starts at face 0. If this one is wrong, we're screwed. Thankfully, the chances
|
||||
// of it being wrong randomly are low if most of the triangles are right:
|
||||
if(stl_check_normal_vector(stl, 0, 0) == 2)
|
||||
stl_reverse_facet(stl, 0);
|
||||
|
||||
|
||||
//Say that we've fixed this facet:
|
||||
norm_sw[facet_num] = 1;
|
||||
/* edge_num = 0;
|
||||
vnot = stl->neighbors_start[0].which_vertex_not[0];
|
||||
|
@ -133,19 +137,24 @@ stl_fix_normal_directions(stl_file *stl)
|
|||
for(;;)
|
||||
{
|
||||
/* Add neighbors_to_list. */
|
||||
//Add unconnected neighbors to the list:a
|
||||
for(j = 0; j < 3; j++)
|
||||
{
|
||||
/* Reverse the neighboring facets if necessary. */
|
||||
if(stl->neighbors_start[facet_num].which_vertex_not[j] > 2)
|
||||
{
|
||||
// If the facet has a neighbor that is -1, it means that edge isn't shared by another
|
||||
// facet.
|
||||
if(stl->neighbors_start[facet_num].neighbor[j] != -1)
|
||||
{
|
||||
stl_reverse_facet
|
||||
(stl, stl->neighbors_start[facet_num].neighbor[j]);
|
||||
}
|
||||
}
|
||||
//If this edge of the facet is connected:
|
||||
if(stl->neighbors_start[facet_num].neighbor[j] != -1)
|
||||
{
|
||||
//If we haven't fixed this facet yet, add it to the list:
|
||||
if(norm_sw[stl->neighbors_start[facet_num].neighbor[j]] != 1)
|
||||
{
|
||||
/* Add node to beginning of list. */
|
||||
|
@ -170,14 +179,14 @@ stl_fix_normal_directions(stl_file *stl)
|
|||
head->next = head->next->next;
|
||||
free(temp);
|
||||
}
|
||||
else
|
||||
else //if we ran out of facets to fix:
|
||||
{
|
||||
/* All of the facets in this part have been fixed. */
|
||||
stl->stats.number_of_parts += 1;
|
||||
/* There are (checked-checked_before) facets */
|
||||
/* in part stl->stats.number_of_parts */
|
||||
checked_before = checked;
|
||||
if(checked == stl->stats.number_of_facets)
|
||||
if(checked >= stl->stats.number_of_facets)
|
||||
{
|
||||
/* All of the facets have been checked. Bail out. */
|
||||
break;
|
||||
|
@ -350,7 +359,7 @@ void stl_normalize_vector(float v[])
|
|||
min_normal_length = 0.000000000001;
|
||||
if(length < min_normal_length)
|
||||
{
|
||||
v[0] = 1.0;
|
||||
v[0] = 0.0;
|
||||
v[1] = 0.0;
|
||||
v[2] = 0.0;
|
||||
return;
|
||||
|
|
|
@ -198,6 +198,7 @@ stl_print_neighbors(stl_file *stl, char *file)
|
|||
stl->neighbors_start[i].neighbor[2],
|
||||
(int)stl->neighbors_start[i].which_vertex_not[2]);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -4,9 +4,22 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 10;
|
||||
|
||||
my $table = Slic3r::Object::XS::ZTable->new([ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]);
|
||||
is_deeply $table->get_range(31, 61), [2, 6], 'get_layer_range';
|
||||
is_deeply $table->get_range(39, 69), [2, 6], 'get_layer_range';
|
||||
is_deeply $table->get_range(30, 60), [2, 5], 'get_layer_range';
|
||||
|
||||
# upper_bound points to the first element that is greater than argument
|
||||
is $table->upper_bound(30), 3, 'upper_bound';
|
||||
is $table->upper_bound(31), 3, 'upper_bound';
|
||||
is $table->upper_bound(39), 3, 'upper_bound';
|
||||
is $table->upper_bound(39, 4), 4, 'upper_bound with offset';
|
||||
|
||||
# lower_bound points to the first element that is not less than argument
|
||||
is $table->lower_bound(31), 3, 'lower_bound';
|
||||
is $table->lower_bound(39), 3, 'lower_bound';
|
||||
is $table->lower_bound(40), 3, 'lower_bound';
|
||||
|
||||
__END__
|
||||
|
|
|
@ -95,9 +95,7 @@ is_deeply $expolygon->clone->pp, [$square, $hole_in_square], 'clone';
|
|||
|
||||
my $exp = $collection->[0];
|
||||
$exp->scale(3);
|
||||
### we store a copy, not the original by reference
|
||||
###is_deeply $expolygon->pp, $exp->pp, 'input is stored by reference in collection';
|
||||
is_deeply $collection->[0]->pp, $exp->pp, 'collection items are returned by reference';
|
||||
isnt $collection->[0][0][0][0], $exp->[0][0][0], 'collection items are not returned by reference';
|
||||
|
||||
is_deeply $collection->[0]->clone->pp, $collection->[0]->pp, 'clone collection item';
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ is $surface->extra_perimeters, 2, 'extra_perimeters';
|
|||
|
||||
my $item = $collection->[0];
|
||||
$item->surface_type(Slic3r::Surface::S_TYPE_INTERNAL);
|
||||
is $item->surface_type, $collection->[0]->surface_type, 'changing item affects actual item';
|
||||
isnt $item->surface_type, $collection->[0]->surface_type, 'collection returns copies of items';
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
|
@ -119,4 +119,12 @@ union_ex(subject, safety_offset = false)
|
|||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
Polygons
|
||||
simplify_polygons(subject)
|
||||
Polygons subject
|
||||
CODE:
|
||||
simplify_polygons(subject, RETVAL);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
%}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
%}
|
||||
|
||||
%name{Slic3r::ExPolygon} class ExPolygon {
|
||||
~ExPolygon();
|
||||
ExPolygon* clone()
|
||||
%code{% const char* CLASS = "Slic3r::ExPolygon"; RETVAL = new ExPolygon(*THIS); RETVAL->in_collection = false; %};
|
||||
%code{% const char* CLASS = "Slic3r::ExPolygon"; RETVAL = new ExPolygon(*THIS); %};
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = THIS->to_SV(); %};
|
||||
SV* pp()
|
||||
|
@ -29,14 +30,6 @@ ExPolygon::new(...)
|
|||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
ExPolygon::DESTROY()
|
||||
CODE:
|
||||
if (!THIS->in_collection) {
|
||||
delete THIS;
|
||||
THIS = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygon::rotate(angle, center_sv)
|
||||
double angle;
|
||||
|
|
|
@ -24,9 +24,7 @@ ExPolygonCollection::new(...)
|
|||
RETVAL->expolygons.resize(items-1);
|
||||
for (unsigned int i = 1; i < items; i++) {
|
||||
// Note: a COPY of the input is stored
|
||||
RETVAL->expolygons[i-1] = new ExPolygon;
|
||||
RETVAL->expolygons[i-1]->from_SV_check(ST(i));
|
||||
RETVAL->expolygons[i-1]->in_collection = true;
|
||||
RETVAL->expolygons[i-1].from_SV_check(ST(i));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
@ -37,10 +35,8 @@ ExPolygonCollection::arrayref()
|
|||
AV* av = newAV();
|
||||
av_fill(av, THIS->expolygons.size()-1);
|
||||
int i = 0;
|
||||
for (ExPolygonsPtr::iterator it = THIS->expolygons.begin(); it != THIS->expolygons.end(); ++it) {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::ExPolygon", *it );
|
||||
av_store(av, i++, sv);
|
||||
for (ExPolygons::iterator it = THIS->expolygons.begin(); it != THIS->expolygons.end(); ++it) {
|
||||
av_store(av, i++, (*it).to_SV_ref());
|
||||
}
|
||||
RETVAL = newRV_noinc((SV*)av);
|
||||
OUTPUT:
|
||||
|
@ -52,8 +48,8 @@ ExPolygonCollection::pp()
|
|||
AV* av = newAV();
|
||||
av_fill(av, THIS->expolygons.size()-1);
|
||||
int i = 0;
|
||||
for (ExPolygonsPtr::iterator it = THIS->expolygons.begin(); it != THIS->expolygons.end(); ++it) {
|
||||
av_store(av, i++, (*it)->to_SV_pureperl());
|
||||
for (ExPolygons::iterator it = THIS->expolygons.begin(); it != THIS->expolygons.end(); ++it) {
|
||||
av_store(av, i++, (*it).to_SV_pureperl());
|
||||
}
|
||||
RETVAL = newRV_noinc((SV*)av);
|
||||
OUTPUT:
|
||||
|
@ -63,9 +59,8 @@ void
|
|||
ExPolygonCollection::append(...)
|
||||
CODE:
|
||||
for (unsigned int i = 1; i < items; i++) {
|
||||
ExPolygon* expolygon = new ExPolygon;
|
||||
expolygon->from_SV_check( ST(i) );
|
||||
expolygon->in_collection = true;
|
||||
ExPolygon expolygon;
|
||||
expolygon.from_SV_check( ST(i) );
|
||||
THIS->expolygons.push_back(expolygon);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
#include <myinit.h>
|
||||
#include "ZTable.hpp"
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
%}
|
||||
|
||||
%name{Slic3r::Object::XS::ZTable} class ZTable {
|
||||
ZTable(std::vector<unsigned int>* z_array);
|
||||
~ZTable();
|
||||
|
||||
%{
|
||||
std::vector<unsigned int>
|
||||
|
@ -47,6 +49,25 @@ get_range(THIS, min_z, max_z)
|
|||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
unsigned int
|
||||
ZTable::lower_bound(z, offset = 0)
|
||||
unsigned int z
|
||||
unsigned int offset
|
||||
CODE:
|
||||
RETVAL = std::lower_bound(THIS->z.begin() + offset, THIS->z.end(), z) - THIS->z.begin();
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
unsigned int
|
||||
ZTable::upper_bound(z, offset = 0)
|
||||
unsigned int z
|
||||
unsigned int offset
|
||||
CODE:
|
||||
RETVAL = std::upper_bound(THIS->z.begin() + offset, THIS->z.end(), z) - THIS->z.begin();
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
%}
|
||||
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
%}
|
||||
|
||||
%name{Slic3r::Surface} class Surface {
|
||||
~Surface();
|
||||
ExPolygon* expolygon()
|
||||
%code{% const char* CLASS = "Slic3r::ExPolygon"; RETVAL = new ExPolygon(THIS->expolygon); %};
|
||||
double thickness()
|
||||
|
@ -31,17 +32,11 @@ _new(CLASS, expolygon, surface_type, thickness, thickness_layers, bridge_angle,
|
|||
RETVAL->thickness_layers = thickness_layers;
|
||||
RETVAL->bridge_angle = bridge_angle;
|
||||
RETVAL->extra_perimeters = extra_perimeters;
|
||||
// we don't delete expolygon here because it's referenced by a Perl SV
|
||||
// whose DESTROY will take care of destruction
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
Surface::DESTROY()
|
||||
CODE:
|
||||
if (!THIS->in_collection) {
|
||||
delete THIS;
|
||||
THIS = NULL;
|
||||
}
|
||||
|
||||
SurfaceType
|
||||
Surface::surface_type(...)
|
||||
CODE:
|
||||
|
|
|
@ -14,13 +14,12 @@
|
|||
SurfaceCollection*
|
||||
SurfaceCollection::new(...)
|
||||
CODE:
|
||||
RETVAL = new SurfaceCollection ();
|
||||
RETVAL = new SurfaceCollection;
|
||||
// ST(0) is class name, others are surfaces
|
||||
RETVAL->surfaces.resize(items-1);
|
||||
for (unsigned int i = 1; i < items; i++) {
|
||||
// Note: a COPY of the input is stored
|
||||
RETVAL->surfaces[i-1] = (Surface *)SvIV((SV*)SvRV( ST(i) ));
|
||||
RETVAL->surfaces[i-1]->in_collection = true;
|
||||
RETVAL->surfaces[i-1] = *(Surface *)SvIV((SV*)SvRV( ST(i) ));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
@ -31,9 +30,9 @@ SurfaceCollection::arrayref()
|
|||
AV* av = newAV();
|
||||
av_fill(av, THIS->surfaces.size()-1);
|
||||
int i = 0;
|
||||
for (SurfacesPtr::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
|
||||
for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::Surface", *it );
|
||||
sv_setref_pv( sv, "Slic3r::Surface", new Surface(*it) );
|
||||
av_store(av, i++, sv);
|
||||
}
|
||||
RETVAL = newRV_noinc((SV*)av);
|
||||
|
@ -44,9 +43,22 @@ void
|
|||
SurfaceCollection::append(...)
|
||||
CODE:
|
||||
for (unsigned int i = 1; i < items; i++) {
|
||||
THIS->surfaces.push_back((Surface *)SvIV((SV*)SvRV( ST(i) )));
|
||||
THIS->surfaces.back()->in_collection = true;
|
||||
THIS->surfaces.push_back(*(Surface *)SvIV((SV*)SvRV( ST(i) )));
|
||||
}
|
||||
|
||||
void
|
||||
SurfaceCollection::replace(index, surface)
|
||||
int index
|
||||
Surface* surface
|
||||
CODE:
|
||||
THIS->surfaces[index] = *surface;
|
||||
|
||||
void
|
||||
SurfaceCollection::set_surface_type(index, surface_type)
|
||||
int index
|
||||
SurfaceType surface_type;
|
||||
CODE:
|
||||
THIS->surfaces[index].surface_type = surface_type;
|
||||
|
||||
%}
|
||||
};
|
||||
|
|
|
@ -44,8 +44,9 @@ OUTPUT
|
|||
T_ARRAYREF
|
||||
AV* av = newAV();
|
||||
$arg = newRV_noinc((SV*)av);
|
||||
const unsigned int len = $var.size();
|
||||
av_extend(av, len-1);
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
av_store(av, i, ${var}[i].to_SV_ref());
|
||||
}
|
||||
av_extend(av, $var.size()-1);
|
||||
int i = 0;
|
||||
for (${type}::iterator it = $var.begin(); it != $var.end(); ++it) {
|
||||
av_store(av, i++, (*it).to_SV_ref());
|
||||
}
|
||||
$var.clear();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue