Merge branch 'master' into xsdata

Conflicts:
	lib/Slic3r/GCode.pm
	xs/src/Point.hpp
This commit is contained in:
Alessandro Ranellucci 2013-07-13 21:00:19 +02:00
commit 31809d473f
14 changed files with 127 additions and 16 deletions

View file

@ -10,6 +10,8 @@ extern "C" {
#include "Point.hpp"
namespace Slic3r {
typedef std::vector<Point> Polygon;
typedef std::vector<Polygon> Polygons;
@ -98,4 +100,6 @@ polygon2perl(Polygon& poly) {
return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::Polygon", GV_ADD));
}
}
#endif

View file

@ -10,6 +10,8 @@ extern "C" {
#include <math.h>
namespace Slic3r {
class Point
{
public:
@ -36,4 +38,6 @@ point2perl(Point& point) {
return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::Point", GV_ADD));
}
}
#endif

View file

@ -1,5 +1,7 @@
#include "TriangleMesh.hpp"
namespace Slic3r {
TriangleMesh::TriangleMesh() {}
TriangleMesh::~TriangleMesh() {
stl_close(&stl);
@ -86,6 +88,12 @@ TriangleMesh::Repair() {
// normal_values
stl_fix_normal_values(&stl);
// always calculate the volume and reverse all normals if volume is negative
stl_calculate_volume(&stl);
// neighbors
stl_verify_neighbors(&stl);
}
void
@ -130,3 +138,5 @@ TriangleMesh::ToPerl() {
av_store(result, 1, newRV_noinc((SV*)facets));
return result;
}
}

View file

@ -10,6 +10,8 @@ extern "C" {
#include "ppport.h"
}
namespace Slic3r {
class TriangleMesh
{
public:
@ -20,8 +22,9 @@ class TriangleMesh
void Repair();
void WriteOBJFile(char* output_file);
AV* ToPerl();
private:
stl_file stl;
};
}
#endif

View file

@ -8,6 +8,8 @@ extern "C" {
#include "ppport.h"
}
namespace Slic3r {
class ZTable
{
public:
@ -21,4 +23,6 @@ ZTable::ZTable(std::vector<unsigned int>* ztable) :
{
}
}
#endif

View file

@ -3,6 +3,9 @@
#include <vector>
namespace Slic3r {}
using namespace Slic3r;
#define av_store_point_xy(AV, X, Y) \
av_store(AV, 0, newSViv(X)); \
av_store(AV, 1, newSViv(Y))

View file

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 3;
use Test::More tests => 5;
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
'hello world';
@ -21,6 +21,10 @@ my $cube = {
my ($vertices, $facets) = @{$m->ToPerl};
is_deeply $vertices, $cube->{vertices}, 'vertices arrayref roundtrip';
is_deeply $facets, $cube->{facets}, 'facets arrayref roundtrip';
my $stats = $m->stats;
is $stats->{number_of_facets}, scalar(@{ $cube->{facets} }), 'stats.number_of_facets';
ok abs($stats->{volume} - 20*20*20) < 1E-3, 'stats.volume';
}
__END__

View file

@ -13,6 +13,27 @@
void Repair();
void WriteOBJFile(char* output_file);
AV* ToPerl();
%{
SV*
TriangleMesh::stats()
CODE:
HV* hv = newHV();
(void)hv_stores( hv, "number_of_facets", newSViv(THIS->stl.stats.number_of_facets) );
(void)hv_stores( hv, "number_of_parts", newSViv(THIS->stl.stats.number_of_parts) );
(void)hv_stores( hv, "volume", newSVnv(THIS->stl.stats.volume) );
(void)hv_stores( hv, "degenerate_facets", newSViv(THIS->stl.stats.degenerate_facets) );
(void)hv_stores( hv, "edges_fixed", newSViv(THIS->stl.stats.edges_fixed) );
(void)hv_stores( hv, "facets_removed", newSViv(THIS->stl.stats.facets_removed) );
(void)hv_stores( hv, "facets_added", newSViv(THIS->stl.stats.facets_added) );
(void)hv_stores( hv, "facets_reversed", newSViv(THIS->stl.stats.facets_reversed) );
(void)hv_stores( hv, "backwards_edges", newSViv(THIS->stl.stats.backwards_edges) );
(void)hv_stores( hv, "normals_fixed", newSViv(THIS->stl.stats.normals_fixed) );
RETVAL = (SV*)newRV_noinc((SV*)hv);
OUTPUT:
RETVAL
%}
};
%package{Slic3r::TriangleMesh::XS};