Implemented TriangleMesh->merge

This commit is contained in:
Alessandro Ranellucci 2013-09-09 22:45:22 +02:00
parent 27e7c6b9f7
commit 3919ba83d8
6 changed files with 29 additions and 3 deletions

View file

@ -525,4 +525,23 @@ TriangleMesh::split() const
return meshes;
}
void
TriangleMesh::merge(const TriangleMesh* mesh)
{
// reset stats and metadata
int number_of_facets = this->stl.stats.number_of_facets;
stl_initialize(&this->stl);
stl_invalidate_shared_vertices(&this->stl);
// 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.original_num_facets = this->stl.stats.number_of_facets;
stl_reallocate(&this->stl);
// copy facets
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];
}
}
}

View file

@ -28,6 +28,7 @@ class TriangleMesh
void rotate(double angle, Point* center);
std::vector<Polygons>* slice(const std::vector<double> &z);
TriangleMeshPtrs split() const;
void merge(const TriangleMesh* mesh);
stl_file stl;
};

View file

@ -178,7 +178,7 @@ static void stl_count_facets(stl_file *stl, char *file);
extern void stl_allocate(stl_file *stl);
static void stl_read(stl_file *stl, int first_facet, int first);
static void stl_facet_stats(stl_file *stl, stl_facet facet, int first);
static void stl_reallocate(stl_file *stl);
extern void stl_reallocate(stl_file *stl);
static int stl_get_little_int(FILE *fp);
static float stl_get_little_float(FILE *fp);
extern void stl_get_size(stl_file *stl);

View file

@ -213,7 +213,7 @@ stl_open_merge(stl_file *stl, char *file)
stl_read(stl, first_facet, 0);
}
static void
extern void
stl_reallocate(stl_file *stl)
{
/* Reallocate more memory for the .STL file(s) */

View file

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 45;
use Test::More tests => 46;
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
'hello world';
@ -46,6 +46,11 @@ my $cube = {
my $result = $m->split;
is scalar(@$result), 1, 'split';
isa_ok $result->[0], 'Slic3r::TriangleMesh::XS', 'split';
my $m2 = Slic3r::TriangleMesh::XS->new;
$m2->ReadFromPerl($cube->{vertices}, $cube->{facets});
$m->merge($m2);
is $m->stats->{number_of_facets}, 2 * $m2->stats->{number_of_facets}, 'merge';
}
{

View file

@ -17,6 +17,7 @@
void align_to_origin();
void rotate(double angle, Point* center);
TriangleMeshPtrs split();
void merge(TriangleMesh* mesh);
%{
SV*