Ported TriangleMesh::scale_xyz()
This commit is contained in:
parent
5e34a9cf21
commit
9b12d6037a
@ -126,6 +126,15 @@ void TriangleMesh::scale(float factor)
|
||||
stl_scale(&(this->stl), factor);
|
||||
}
|
||||
|
||||
void TriangleMesh::scale(std::vector<double> versor)
|
||||
{
|
||||
float fversor[3];
|
||||
fversor[0] = versor[0];
|
||||
fversor[1] = versor[1];
|
||||
fversor[2] = versor[2];
|
||||
stl_scale(&this->stl, fversor);
|
||||
}
|
||||
|
||||
void TriangleMesh::translate(float x, float y, float z)
|
||||
{
|
||||
stl_translate(&(this->stl), x, y, z);
|
||||
|
@ -23,6 +23,7 @@ class TriangleMesh
|
||||
void repair();
|
||||
void WriteOBJFile(char* output_file);
|
||||
void scale(float factor);
|
||||
void scale(std::vector<double> versor);
|
||||
void translate(float x, float y, float z);
|
||||
void align_to_origin();
|
||||
void rotate(double angle, Point* center);
|
||||
|
@ -155,6 +155,7 @@ extern void stl_fix_normal_directions(stl_file *stl);
|
||||
extern void stl_fix_normal_values(stl_file *stl);
|
||||
extern void stl_reverse_all_facets(stl_file *stl);
|
||||
extern void stl_translate(stl_file *stl, float x, float y, float z);
|
||||
extern void stl_scale(stl_file *stl, float versor[3]);
|
||||
extern void stl_scale(stl_file *stl, float factor);
|
||||
extern void stl_rotate_x(stl_file *stl, float angle);
|
||||
extern void stl_rotate_y(stl_file *stl, float angle);
|
||||
|
@ -102,42 +102,52 @@ stl_translate(stl_file *stl, float x, float y, float z)
|
||||
}
|
||||
|
||||
void
|
||||
stl_scale(stl_file *stl, float factor)
|
||||
stl_scale(stl_file *stl, float versor[3])
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
// scale extents
|
||||
stl->stats.min.x *= factor;
|
||||
stl->stats.min.y *= factor;
|
||||
stl->stats.min.z *= factor;
|
||||
stl->stats.max.x *= factor;
|
||||
stl->stats.max.y *= factor;
|
||||
stl->stats.max.z *= factor;
|
||||
stl->stats.min.x *= versor[0];
|
||||
stl->stats.min.y *= versor[1];
|
||||
stl->stats.min.z *= versor[2];
|
||||
stl->stats.max.x *= versor[0];
|
||||
stl->stats.max.y *= versor[1];
|
||||
stl->stats.max.z *= versor[2];
|
||||
|
||||
// scale size
|
||||
stl->stats.size.x *= factor;
|
||||
stl->stats.size.y *= factor;
|
||||
stl->stats.size.z *= factor;
|
||||
stl->stats.size.x *= versor[0];
|
||||
stl->stats.size.y *= versor[1];
|
||||
stl->stats.size.z *= versor[2];
|
||||
|
||||
// scale volume
|
||||
if (stl->stats.volume > 0.0) {
|
||||
stl->stats.volume *= (factor * factor * factor);
|
||||
stl->stats.volume *= (versor[0] * versor[1] * versor[2]);
|
||||
}
|
||||
|
||||
for(i = 0; i < stl->stats.number_of_facets; i++)
|
||||
{
|
||||
for(j = 0; j < 3; j++)
|
||||
{
|
||||
stl->facet_start[i].vertex[j].x *= factor;
|
||||
stl->facet_start[i].vertex[j].y *= factor;
|
||||
stl->facet_start[i].vertex[j].z *= factor;
|
||||
stl->facet_start[i].vertex[j].x *= versor[0];
|
||||
stl->facet_start[i].vertex[j].y *= versor[1];
|
||||
stl->facet_start[i].vertex[j].z *= versor[2];
|
||||
}
|
||||
}
|
||||
|
||||
stl_invalidate_shared_vertices(stl);
|
||||
}
|
||||
|
||||
void
|
||||
stl_scale(stl_file *stl, float factor)
|
||||
{
|
||||
float versor[3];
|
||||
versor[0] = factor;
|
||||
versor[1] = factor;
|
||||
versor[2] = factor;
|
||||
stl_scale(stl, versor);
|
||||
}
|
||||
|
||||
static void calculate_normals(stl_file *stl)
|
||||
{
|
||||
long i;
|
||||
|
@ -4,7 +4,7 @@ use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 47;
|
||||
use Test::More tests => 48;
|
||||
|
||||
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
|
||||
'hello world';
|
||||
@ -32,14 +32,18 @@ my $cube = {
|
||||
$m->scale(2);
|
||||
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale';
|
||||
|
||||
$m->scale_xyz([2,1,1]);
|
||||
ok abs($m->stats->{volume} - 2*40*40*40) < 1E-2, 'scale_xyz';
|
||||
|
||||
$m->translate(5,10,0);
|
||||
is_deeply $m->vertices->[0], [45,50,0], 'translate';
|
||||
is_deeply $m->vertices->[0], [85,50,0], 'translate';
|
||||
|
||||
$m->align_to_origin;
|
||||
is_deeply $m->vertices->[2], [0,0,0], 'align_to_origin';
|
||||
|
||||
is_deeply $m->size, [40,40,40], 'size';
|
||||
is_deeply $m->size, [80,40,40], 'size';
|
||||
|
||||
$m->scale_xyz([0.5,1,1]);
|
||||
$m->rotate(45, Slic3r::Point->new(20,20));
|
||||
ok abs($m->size->[0] - sqrt(2)*40) < 1E-4, 'rotate';
|
||||
|
||||
|
@ -13,6 +13,8 @@
|
||||
void repair();
|
||||
void WriteOBJFile(char* output_file);
|
||||
void scale(float factor);
|
||||
void scale_xyz(std::vector<double> versor)
|
||||
%code{% THIS->scale(versor); %};
|
||||
void translate(float x, float y, float z);
|
||||
void align_to_origin();
|
||||
void rotate(double angle, Point* center);
|
||||
|
@ -1,6 +1,7 @@
|
||||
%typemap{bool}{simple};
|
||||
%typemap{std::string};
|
||||
%typemap{std::vector<unsigned int>*};
|
||||
%typemap{std::vector<double>};
|
||||
%typemap{std::vector<double>*};
|
||||
%typemap{SV*};
|
||||
%typemap{AV*};
|
||||
|
Loading…
Reference in New Issue
Block a user