Add unit test for split()
This commit is contained in:
parent
3919ba83d8
commit
28b043e9a9
@ -4,6 +4,7 @@ use strict;
|
|||||||
|
|
||||||
our $VERSION = '0.01';
|
our $VERSION = '0.01';
|
||||||
|
|
||||||
|
use Carp qw();
|
||||||
use XSLoader;
|
use XSLoader;
|
||||||
XSLoader::load(__PACKAGE__, $VERSION);
|
XSLoader::load(__PACKAGE__, $VERSION);
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
TriangleMesh::TriangleMesh() {}
|
|
||||||
TriangleMesh::~TriangleMesh() {
|
TriangleMesh::~TriangleMesh() {
|
||||||
stl_close(&stl);
|
stl_close(&stl);
|
||||||
}
|
}
|
||||||
@ -112,6 +111,8 @@ TriangleMesh::Repair() {
|
|||||||
|
|
||||||
// neighbors
|
// neighbors
|
||||||
stl_verify_neighbors(&stl);
|
stl_verify_neighbors(&stl);
|
||||||
|
|
||||||
|
this->repaired = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -484,6 +485,9 @@ TriangleMesh::split() const
|
|||||||
TriangleMeshPtrs meshes;
|
TriangleMeshPtrs meshes;
|
||||||
std::set<int> seen_facets;
|
std::set<int> seen_facets;
|
||||||
|
|
||||||
|
// we need neighbors
|
||||||
|
if (!this->repaired) CONFESS("split() requires Repair()");
|
||||||
|
|
||||||
// loop while we have remaining facets
|
// loop while we have remaining facets
|
||||||
while (1) {
|
while (1) {
|
||||||
// get the first facet
|
// get the first facet
|
||||||
@ -530,8 +534,8 @@ TriangleMesh::merge(const TriangleMesh* mesh)
|
|||||||
{
|
{
|
||||||
// reset stats and metadata
|
// reset stats and metadata
|
||||||
int number_of_facets = this->stl.stats.number_of_facets;
|
int number_of_facets = this->stl.stats.number_of_facets;
|
||||||
stl_initialize(&this->stl);
|
|
||||||
stl_invalidate_shared_vertices(&this->stl);
|
stl_invalidate_shared_vertices(&this->stl);
|
||||||
|
this->repaired = false;
|
||||||
|
|
||||||
// update facet count and allocate more memory
|
// update facet count and allocate more memory
|
||||||
this->stl.stats.number_of_facets = number_of_facets + mesh->stl.stats.number_of_facets;
|
this->stl.stats.number_of_facets = number_of_facets + mesh->stl.stats.number_of_facets;
|
||||||
@ -542,6 +546,9 @@ TriangleMesh::merge(const TriangleMesh* mesh)
|
|||||||
for (int i = 0; i < mesh->stl.stats.number_of_facets; i++) {
|
for (int i = 0; i < mesh->stl.stats.number_of_facets; i++) {
|
||||||
this->stl.facet_start[number_of_facets + i] = mesh->stl.facet_start[i];
|
this->stl.facet_start[number_of_facets + i] = mesh->stl.facet_start[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update size
|
||||||
|
stl_get_size(&this->stl);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ typedef std::vector<TriangleMesh*> TriangleMeshPtrs;
|
|||||||
class TriangleMesh
|
class TriangleMesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TriangleMesh();
|
TriangleMesh() : repaired(false) {};
|
||||||
~TriangleMesh();
|
~TriangleMesh();
|
||||||
SV* to_SV();
|
SV* to_SV();
|
||||||
void ReadSTLFile(char* input_file);
|
void ReadSTLFile(char* input_file);
|
||||||
@ -30,6 +30,7 @@ class TriangleMesh
|
|||||||
TriangleMeshPtrs split() const;
|
TriangleMeshPtrs split() const;
|
||||||
void merge(const TriangleMesh* mesh);
|
void merge(const TriangleMesh* mesh);
|
||||||
stl_file stl;
|
stl_file stl;
|
||||||
|
bool repaired;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum FacetEdgeType { feNone, feTop, feBottom };
|
enum FacetEdgeType { feNone, feTop, feBottom };
|
||||||
|
@ -4,7 +4,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 46;
|
use Test::More tests => 47;
|
||||||
|
|
||||||
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
|
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
|
||||||
'hello world';
|
'hello world';
|
||||||
@ -43,14 +43,23 @@ my $cube = {
|
|||||||
$m->rotate(45, Slic3r::Point->new(20,20));
|
$m->rotate(45, Slic3r::Point->new(20,20));
|
||||||
ok abs($m->size->[0] - sqrt(2)*40) < 1E-4, 'rotate';
|
ok abs($m->size->[0] - sqrt(2)*40) < 1E-4, 'rotate';
|
||||||
|
|
||||||
my $result = $m->split;
|
{
|
||||||
is scalar(@$result), 1, 'split';
|
my $meshes = $m->split;
|
||||||
isa_ok $result->[0], 'Slic3r::TriangleMesh::XS', 'split';
|
is scalar(@$meshes), 1, 'split';
|
||||||
|
isa_ok $meshes->[0], 'Slic3r::TriangleMesh::XS', 'split';
|
||||||
|
}
|
||||||
|
|
||||||
my $m2 = Slic3r::TriangleMesh::XS->new;
|
my $m2 = Slic3r::TriangleMesh::XS->new;
|
||||||
$m2->ReadFromPerl($cube->{vertices}, $cube->{facets});
|
$m2->ReadFromPerl($cube->{vertices}, $cube->{facets});
|
||||||
|
$m2->Repair;
|
||||||
$m->merge($m2);
|
$m->merge($m2);
|
||||||
|
$m->Repair;
|
||||||
is $m->stats->{number_of_facets}, 2 * $m2->stats->{number_of_facets}, 'merge';
|
is $m->stats->{number_of_facets}, 2 * $m2->stats->{number_of_facets}, 'merge';
|
||||||
|
|
||||||
|
{
|
||||||
|
my $meshes = $m->split;
|
||||||
|
is scalar(@$meshes), 2, 'split';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -41,6 +41,8 @@ TriangleMesh::stats()
|
|||||||
SV*
|
SV*
|
||||||
TriangleMesh::vertices()
|
TriangleMesh::vertices()
|
||||||
CODE:
|
CODE:
|
||||||
|
if (!THIS->repaired) CONFESS("vertices() requires Repair()");
|
||||||
|
|
||||||
if (THIS->stl.v_shared == NULL)
|
if (THIS->stl.v_shared == NULL)
|
||||||
stl_generate_shared_vertices(&(THIS->stl));
|
stl_generate_shared_vertices(&(THIS->stl));
|
||||||
|
|
||||||
@ -63,6 +65,8 @@ TriangleMesh::vertices()
|
|||||||
SV*
|
SV*
|
||||||
TriangleMesh::facets()
|
TriangleMesh::facets()
|
||||||
CODE:
|
CODE:
|
||||||
|
if (!THIS->repaired) CONFESS("facets() requires Repair()");
|
||||||
|
|
||||||
if (THIS->stl.v_shared == NULL)
|
if (THIS->stl.v_shared == NULL)
|
||||||
stl_generate_shared_vertices(&(THIS->stl));
|
stl_generate_shared_vertices(&(THIS->stl));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user