Ported TriangleMesh->size

This commit is contained in:
Alessandro Ranellucci 2013-08-05 19:39:10 +02:00
parent 9d50616c7d
commit 9402898c58
5 changed files with 32 additions and 3 deletions

View File

@ -42,6 +42,8 @@ void TriangleMesh::ReadFromPerl(SV* vertices, SV* facets)
stl.facet_start[i] = facet;
}
stl_get_size(&(this->stl));
}
void

View File

@ -181,3 +181,4 @@ static void stl_facet_stats(stl_file *stl, stl_facet facet, int first);
static 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

@ -26,7 +26,6 @@
#include "stl.h"
static void stl_rotate(float *x, float *y, float angle);
static void stl_get_size(stl_file *stl);
static float get_area(stl_facet *facet);
static float get_volume(stl_file *stl);
@ -116,6 +115,11 @@ stl_scale(stl_file *stl, float factor)
stl->stats.max.y *= factor;
stl->stats.max.z *= factor;
// scale size
stl->stats.size.x *= factor;
stl->stats.size.y *= factor;
stl->stats.size.z *= factor;
// scale volume
if (stl->stats.volume > 0.0) {
stl->stats.volume *= (factor * factor * factor);
@ -219,7 +223,7 @@ stl_rotate(float *x, float *y, float angle)
*y = r * sin(theta + radian_angle);
}
static void
extern void
stl_get_size(stl_file *stl)
{
int i;
@ -250,6 +254,14 @@ stl_get_size(stl_file *stl)
stl->facet_start[i].vertex[j].z);
}
}
stl->stats.size.x = stl->stats.max.x - stl->stats.min.x;
stl->stats.size.y = stl->stats.max.y - stl->stats.min.y;
stl->stats.size.z = stl->stats.max.z - stl->stats.min.z;
stl->stats.bounding_diameter = sqrt(
stl->stats.size.x * stl->stats.size.x +
stl->stats.size.y * stl->stats.size.y +
stl->stats.size.z * stl->stats.size.z
);
}
void

View File

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 8;
use Test::More tests => 9;
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
'hello world';
@ -37,6 +37,8 @@ my $cube = {
$m->align_to_origin;
is_deeply $m->vertices->[2], [0,0,0], 'align_to_origin';
is_deeply $m->size, [40,40,40], 'size';
}
__END__

View File

@ -79,6 +79,18 @@ TriangleMesh::facets()
OUTPUT:
RETVAL
SV*
TriangleMesh::size()
CODE:
AV* size = newAV();
av_extend(size, 2);
av_store(size, 0, newSVnv(THIS->stl.stats.size.x));
av_store(size, 1, newSVnv(THIS->stl.stats.size.y));
av_store(size, 2, newSVnv(THIS->stl.stats.size.z));
RETVAL = newRV_noinc((SV*)size);
OUTPUT:
RETVAL
%}
};