From 00683195c85c1479d15c1792179eba1149dcc36d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 13 Jul 2013 19:00:38 +0200 Subject: Add two more repair actions and add volume to stats --- xs/src/TriangleMesh.cpp | 6 ++++++ xs/t/01_trianglemesh.t | 3 ++- xs/xsp/TriangleMesh.xsp | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'xs') diff --git a/xs/src/TriangleMesh.cpp b/xs/src/TriangleMesh.cpp index 546a2dfe5..901bdfa47 100644 --- a/xs/src/TriangleMesh.cpp +++ b/xs/src/TriangleMesh.cpp @@ -88,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 diff --git a/xs/t/01_trianglemesh.t b/xs/t/01_trianglemesh.t index 306617238..42ed11145 100644 --- a/xs/t/01_trianglemesh.t +++ b/xs/t/01_trianglemesh.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 4; +use Test::More tests => 5; is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!', 'hello world'; @@ -24,6 +24,7 @@ my $cube = { 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__ diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index a0e5d08f5..e053102c7 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -21,6 +21,7 @@ TriangleMesh::stats() 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) ); -- cgit v1.2.3