Remove ->ToPerl and add ->vertices and ->facets

This commit is contained in:
Alessandro Ranellucci 2013-08-04 21:23:27 +02:00
parent 6f1a1b546f
commit a0bd152243
4 changed files with 46 additions and 40 deletions

View File

@ -102,41 +102,4 @@ TriangleMesh::WriteOBJFile(char* output_file) {
stl_write_obj(&stl, output_file);
}
AV*
TriangleMesh::ToPerl() {
int i;
stl_generate_shared_vertices(&stl);
// vertices
AV* vertices = newAV();
av_extend(vertices, stl.stats.shared_vertices);
for (i = 0; i < stl.stats.shared_vertices; i++) {
AV* vertex = newAV();
av_store(vertices, i, newRV_noinc((SV*)vertex));
av_extend(vertex, 2);
av_store(vertex, 0, newSVnv(stl.v_shared[i].x));
av_store(vertex, 1, newSVnv(stl.v_shared[i].y));
av_store(vertex, 2, newSVnv(stl.v_shared[i].z));
}
// facets
AV* facets = newAV();
av_extend(facets, stl.stats.number_of_facets);
for (i = 0; i < stl.stats.number_of_facets; i++) {
AV* facet = newAV();
av_store(facets, i, newRV_noinc((SV*)facet));
av_extend(facet, 2);
av_store(facet, 0, newSVnv(stl.v_indices[i].vertex[0]));
av_store(facet, 1, newSVnv(stl.v_indices[i].vertex[1]));
av_store(facet, 2, newSVnv(stl.v_indices[i].vertex[2]));
}
AV* result = newAV();
av_extend(result, 1);
av_store(result, 0, newRV_noinc((SV*)vertices));
av_store(result, 1, newRV_noinc((SV*)facets));
return result;
}
}

View File

@ -15,7 +15,6 @@ class TriangleMesh
void ReadFromPerl(SV* vertices, SV* facets);
void Repair();
void WriteOBJFile(char* output_file);
AV* ToPerl();
stl_file stl;
};

View File

@ -18,7 +18,8 @@ my $cube = {
my $m = Slic3r::TriangleMesh::XS->new;
$m->ReadFromPerl($cube->{vertices}, $cube->{facets});
$m->Repair;
my ($vertices, $facets) = @{$m->ToPerl};
my ($vertices, $facets) = ($m->vertices, $m->facets);
is_deeply $vertices, $cube->{vertices}, 'vertices arrayref roundtrip';
is_deeply $facets, $cube->{facets}, 'facets arrayref roundtrip';

View File

@ -12,7 +12,6 @@
void ReadFromPerl(SV* vertices, SV* facets);
void Repair();
void WriteOBJFile(char* output_file);
AV* ToPerl();
%{
SV*
@ -33,6 +32,50 @@ TriangleMesh::stats()
OUTPUT:
RETVAL
SV*
TriangleMesh::vertices()
CODE:
if (THIS->stl.stats.shared_vertices == 0)
stl_generate_shared_vertices(&(THIS->stl));
// vertices
AV* vertices = newAV();
av_extend(vertices, THIS->stl.stats.shared_vertices);
for (int i = 0; i < THIS->stl.stats.shared_vertices; i++) {
AV* vertex = newAV();
av_store(vertices, i, newRV_noinc((SV*)vertex));
av_extend(vertex, 2);
av_store(vertex, 0, newSVnv(THIS->stl.v_shared[i].x));
av_store(vertex, 1, newSVnv(THIS->stl.v_shared[i].y));
av_store(vertex, 2, newSVnv(THIS->stl.v_shared[i].z));
}
RETVAL = newRV_noinc((SV*)vertices);
OUTPUT:
RETVAL
SV*
TriangleMesh::facets()
CODE:
if (THIS->stl.stats.shared_vertices == 0)
stl_generate_shared_vertices(&(THIS->stl));
// facets
AV* facets = newAV();
av_extend(facets, THIS->stl.stats.number_of_facets);
for (int i = 0; i < THIS->stl.stats.number_of_facets; i++) {
AV* facet = newAV();
av_store(facets, i, newRV_noinc((SV*)facet));
av_extend(facet, 2);
av_store(facet, 0, newSVnv(THIS->stl.v_indices[i].vertex[0]));
av_store(facet, 1, newSVnv(THIS->stl.v_indices[i].vertex[1]));
av_store(facet, 2, newSVnv(THIS->stl.v_indices[i].vertex[2]));
}
RETVAL = newRV_noinc((SV*)facets);
OUTPUT:
RETVAL
%}
};