Incomplete work for porting translate()

xsdata-boost
Alessandro Ranellucci 2013-08-05 10:48:38 +02:00
parent 515d5707c9
commit 04d5d1bb9b
7 changed files with 36 additions and 10 deletions

View File

@ -107,4 +107,9 @@ void TriangleMesh::scale(float factor)
stl_scale(&(this->stl), factor);
}
void TriangleMesh::translate(float x, float y, float z)
{
stl_translate(&(this->stl), x, y, z);
}
}

View File

@ -16,6 +16,7 @@ class TriangleMesh
void Repair();
void WriteOBJFile(char* output_file);
void scale(float factor);
void translate(float x, float y, float z);
stl_file stl;
};

View File

@ -23,6 +23,14 @@
#include "stl.h"
void
stl_invalidate_shared_vertices(stl_file *stl)
{
if (stl->v_indices != NULL)
free(stl->v_indices);
if (stl->v_shared != NULL)
free(stl->v_shared);
}
void
stl_generate_shared_vertices(stl_file *stl)
@ -38,6 +46,9 @@ stl_generate_shared_vertices(stl_file *stl)
int next_facet;
int reversed;
// make sure this function is idempotent and does not leak memory
stl_invalidate_shared_vertices(stl);
stl->v_indices = (v_indices_struct*)
calloc(stl->stats.number_of_facets, sizeof(v_indices_struct));
if(stl->v_indices == NULL) perror("stl_generate_shared_vertices");

View File

@ -163,6 +163,7 @@ extern void stl_mirror_xy(stl_file *stl);
extern void stl_mirror_yz(stl_file *stl);
extern void stl_mirror_xz(stl_file *stl);
extern void stl_open_merge(stl_file *stl, char *file);
extern void stl_invalidate_shared_vertices(stl_file *stl);
extern void stl_generate_shared_vertices(stl_file *stl);
extern void stl_write_obj(stl_file *stl, char *file);
extern void stl_write_off(stl_file *stl, char *file);

View File

@ -87,17 +87,19 @@ stl_translate(stl_file *stl, float x, float y, float z)
{
for(j = 0; j < 3; j++)
{
stl->facet_start[i].vertex[j].x -= (stl->stats.min.x - x);
stl->facet_start[i].vertex[j].y -= (stl->stats.min.y - y);
stl->facet_start[i].vertex[j].z -= (stl->stats.min.z - z);
stl->facet_start[i].vertex[j].x += x;
stl->facet_start[i].vertex[j].y += y;
stl->facet_start[i].vertex[j].z += z;
}
}
stl->stats.max.x -= (stl->stats.min.x - x);
stl->stats.max.y -= (stl->stats.min.y - y);
stl->stats.max.z -= (stl->stats.min.z - z);
stl->stats.min.x = x;
stl->stats.min.y = y;
stl->stats.min.z = z;
stl->stats.min.x += x;
stl->stats.min.y += y;
stl->stats.min.z += z;
stl->stats.max.x += x;
stl->stats.max.y += y;
stl->stats.max.z += z;
stl_invalidate_shared_vertices(stl);
}
void
@ -128,6 +130,8 @@ stl_scale(stl_file *stl, float factor)
stl->facet_start[i].vertex[j].z *= factor;
}
}
stl_invalidate_shared_vertices(stl);
}
static void calculate_normals(stl_file *stl)

View File

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 6;
use Test::More tests => 7;
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
'hello world';
@ -31,6 +31,9 @@ my $cube = {
$m->scale(2);
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale';
$m->translate(5,10,0);
is_deeply $m->vertices->[0], [45,50,0], 'translate';
}
__END__

View File

@ -13,6 +13,7 @@
void Repair();
void WriteOBJFile(char* output_file);
void scale(float factor);
void translate(float x, float y, float z);
%{
SV*