2013-06-23 13:33:07 +00:00
|
|
|
%module{Slic3r::XS};
|
2013-06-24 17:35:49 +00:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include <myinit.h>
|
2014-08-03 17:42:29 +00:00
|
|
|
#include "libslic3r/TriangleMesh.hpp"
|
2013-06-24 17:35:49 +00:00
|
|
|
%}
|
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
%name{Slic3r::TriangleMesh} class TriangleMesh {
|
2013-06-24 17:35:49 +00:00
|
|
|
TriangleMesh();
|
|
|
|
~TriangleMesh();
|
2014-04-27 17:18:53 +00:00
|
|
|
Clone<TriangleMesh> clone()
|
|
|
|
%code{% RETVAL = THIS; %};
|
2013-06-24 17:35:49 +00:00
|
|
|
void ReadSTLFile(char* input_file);
|
2013-09-11 07:49:28 +00:00
|
|
|
void write_ascii(char* output_file);
|
|
|
|
void write_binary(char* output_file);
|
2013-07-03 09:38:01 +00:00
|
|
|
void ReadFromPerl(SV* vertices, SV* facets);
|
2013-09-09 21:18:33 +00:00
|
|
|
void repair();
|
2013-06-24 17:35:49 +00:00
|
|
|
void WriteOBJFile(char* output_file);
|
2013-08-04 19:34:26 +00:00
|
|
|
void scale(float factor);
|
2014-09-21 08:51:36 +00:00
|
|
|
void scale_xyz(Pointf3* versor)
|
|
|
|
%code{% THIS->scale(*versor); %};
|
2013-08-05 08:48:38 +00:00
|
|
|
void translate(float x, float y, float z);
|
2014-04-25 15:50:03 +00:00
|
|
|
void rotate_x(float angle);
|
|
|
|
void rotate_y(float angle);
|
|
|
|
void rotate_z(float angle);
|
2014-06-14 19:14:33 +00:00
|
|
|
void flip_x();
|
|
|
|
void flip_y();
|
|
|
|
void flip_z();
|
2013-08-05 17:22:33 +00:00
|
|
|
void align_to_origin();
|
2013-08-05 17:52:37 +00:00
|
|
|
void rotate(double angle, Point* center);
|
2013-09-09 20:27:58 +00:00
|
|
|
TriangleMeshPtrs split();
|
2014-08-03 18:33:16 +00:00
|
|
|
void merge(TriangleMesh* mesh)
|
|
|
|
%code{% THIS->merge(*mesh); %};
|
2013-12-12 19:19:33 +00:00
|
|
|
ExPolygons horizontal_projection()
|
|
|
|
%code{% THIS->horizontal_projection(RETVAL); %};
|
2014-01-06 17:29:10 +00:00
|
|
|
BoundingBoxf3* bounding_box()
|
|
|
|
%code{%
|
|
|
|
RETVAL = new BoundingBoxf3();
|
|
|
|
THIS->bounding_box(RETVAL);
|
|
|
|
%};
|
2014-08-08 19:48:59 +00:00
|
|
|
Pointf3* center()
|
|
|
|
%code{%
|
|
|
|
BoundingBoxf3 bb;
|
|
|
|
THIS->bounding_box(&bb);
|
|
|
|
RETVAL = new Pointf3(bb.center());
|
|
|
|
%};
|
2014-09-21 08:51:36 +00:00
|
|
|
int facets_count();
|
2014-04-25 15:14:39 +00:00
|
|
|
void reset_repair_stats();
|
2013-07-13 16:51:49 +00:00
|
|
|
%{
|
|
|
|
|
|
|
|
SV*
|
|
|
|
TriangleMesh::stats()
|
|
|
|
CODE:
|
|
|
|
HV* hv = newHV();
|
|
|
|
(void)hv_stores( hv, "number_of_facets", newSViv(THIS->stl.stats.number_of_facets) );
|
|
|
|
(void)hv_stores( hv, "number_of_parts", newSViv(THIS->stl.stats.number_of_parts) );
|
2013-07-13 17:00:38 +00:00
|
|
|
(void)hv_stores( hv, "volume", newSVnv(THIS->stl.stats.volume) );
|
2013-07-13 16:51:49 +00:00
|
|
|
(void)hv_stores( hv, "degenerate_facets", newSViv(THIS->stl.stats.degenerate_facets) );
|
|
|
|
(void)hv_stores( hv, "edges_fixed", newSViv(THIS->stl.stats.edges_fixed) );
|
|
|
|
(void)hv_stores( hv, "facets_removed", newSViv(THIS->stl.stats.facets_removed) );
|
|
|
|
(void)hv_stores( hv, "facets_added", newSViv(THIS->stl.stats.facets_added) );
|
|
|
|
(void)hv_stores( hv, "facets_reversed", newSViv(THIS->stl.stats.facets_reversed) );
|
|
|
|
(void)hv_stores( hv, "backwards_edges", newSViv(THIS->stl.stats.backwards_edges) );
|
|
|
|
(void)hv_stores( hv, "normals_fixed", newSViv(THIS->stl.stats.normals_fixed) );
|
|
|
|
RETVAL = (SV*)newRV_noinc((SV*)hv);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2013-08-04 19:23:27 +00:00
|
|
|
SV*
|
|
|
|
TriangleMesh::vertices()
|
|
|
|
CODE:
|
2013-09-09 21:18:33 +00:00
|
|
|
if (!THIS->repaired) CONFESS("vertices() requires repair()");
|
2013-09-09 21:09:56 +00:00
|
|
|
|
2013-08-05 17:17:13 +00:00
|
|
|
if (THIS->stl.v_shared == NULL)
|
2013-08-04 19:23:27 +00:00
|
|
|
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:
|
2013-09-09 21:18:33 +00:00
|
|
|
if (!THIS->repaired) CONFESS("facets() requires repair()");
|
2013-09-09 21:09:56 +00:00
|
|
|
|
2013-08-05 17:17:13 +00:00
|
|
|
if (THIS->stl.v_shared == NULL)
|
2013-08-04 19:23:27 +00:00
|
|
|
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
|
|
|
|
|
2013-09-11 18:15:42 +00:00
|
|
|
SV*
|
|
|
|
TriangleMesh::normals()
|
|
|
|
CODE:
|
|
|
|
if (!THIS->repaired) CONFESS("normals() requires repair()");
|
|
|
|
|
|
|
|
// normals
|
|
|
|
AV* normals = newAV();
|
|
|
|
av_extend(normals, THIS->stl.stats.number_of_facets);
|
|
|
|
for (int i = 0; i < THIS->stl.stats.number_of_facets; i++) {
|
|
|
|
AV* facet = newAV();
|
|
|
|
av_store(normals, i, newRV_noinc((SV*)facet));
|
|
|
|
av_extend(facet, 2);
|
|
|
|
av_store(facet, 0, newSVnv(THIS->stl.facet_start[i].normal.x));
|
|
|
|
av_store(facet, 1, newSVnv(THIS->stl.facet_start[i].normal.y));
|
|
|
|
av_store(facet, 2, newSVnv(THIS->stl.facet_start[i].normal.z));
|
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL = newRV_noinc((SV*)normals);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2013-08-05 17:39:10 +00:00
|
|
|
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
|
|
|
|
|
2013-09-07 12:06:09 +00:00
|
|
|
SV*
|
|
|
|
TriangleMesh::slice(z)
|
2014-11-22 21:20:28 +00:00
|
|
|
std::vector<double> z
|
2013-09-07 12:06:09 +00:00
|
|
|
CODE:
|
2014-01-12 22:56:07 +00:00
|
|
|
// convert doubles to floats
|
2014-11-22 21:20:28 +00:00
|
|
|
std::vector<float> z_f(z.begin(), z.end());
|
2014-01-12 22:56:07 +00:00
|
|
|
|
2014-01-07 14:40:38 +00:00
|
|
|
std::vector<ExPolygons> layers;
|
2014-01-15 19:31:38 +00:00
|
|
|
TriangleMeshSlicer mslicer(THIS);
|
|
|
|
mslicer.slice(z_f, &layers);
|
2013-09-07 12:06:09 +00:00
|
|
|
|
|
|
|
AV* layers_av = newAV();
|
2014-06-25 12:57:06 +00:00
|
|
|
size_t len = layers.size();
|
|
|
|
if (len > 0) av_extend(layers_av, len-1);
|
2013-11-22 23:15:42 +00:00
|
|
|
for (unsigned int i = 0; i < layers.size(); i++) {
|
2014-01-07 14:40:38 +00:00
|
|
|
AV* expolygons_av = newAV();
|
2014-06-25 12:57:06 +00:00
|
|
|
len = layers[i].size();
|
|
|
|
if (len > 0) av_extend(expolygons_av, len-1);
|
2013-09-07 12:06:09 +00:00
|
|
|
unsigned int j = 0;
|
2014-01-07 14:40:38 +00:00
|
|
|
for (ExPolygons::iterator it = layers[i].begin(); it != layers[i].end(); ++it) {
|
2014-05-08 12:52:48 +00:00
|
|
|
av_store(expolygons_av, j++, perl_to_SV_clone_ref(*it));
|
2013-09-07 12:06:09 +00:00
|
|
|
}
|
2014-01-07 14:40:38 +00:00
|
|
|
av_store(layers_av, i, newRV_noinc((SV*)expolygons_av));
|
2013-09-07 12:06:09 +00:00
|
|
|
}
|
|
|
|
RETVAL = (SV*)newRV_noinc((SV*)layers_av);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2014-01-16 10:25:26 +00:00
|
|
|
void
|
|
|
|
TriangleMesh::cut(z, upper, lower)
|
|
|
|
float z;
|
|
|
|
TriangleMesh* upper;
|
|
|
|
TriangleMesh* lower;
|
|
|
|
CODE:
|
|
|
|
TriangleMeshSlicer mslicer(THIS);
|
|
|
|
mslicer.cut(z, upper, lower);
|
|
|
|
|
2013-09-11 09:55:08 +00:00
|
|
|
std::vector<double>
|
|
|
|
TriangleMesh::bb3()
|
|
|
|
CODE:
|
|
|
|
RETVAL.push_back(THIS->stl.stats.min.x);
|
|
|
|
RETVAL.push_back(THIS->stl.stats.min.y);
|
|
|
|
RETVAL.push_back(THIS->stl.stats.max.x);
|
|
|
|
RETVAL.push_back(THIS->stl.stats.max.y);
|
|
|
|
RETVAL.push_back(THIS->stl.stats.min.z);
|
|
|
|
RETVAL.push_back(THIS->stl.stats.max.z);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2013-12-12 19:19:33 +00:00
|
|
|
Polygon*
|
|
|
|
TriangleMesh::convex_hull()
|
|
|
|
CODE:
|
|
|
|
RETVAL = new Polygon ();
|
|
|
|
THIS->convex_hull(RETVAL);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2013-07-13 16:51:49 +00:00
|
|
|
%}
|
2013-06-24 17:35:49 +00:00
|
|
|
};
|
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
%package{Slic3r::TriangleMesh};
|
2013-06-22 15:16:45 +00:00
|
|
|
|
|
|
|
%{
|
|
|
|
PROTOTYPES: DISABLE
|
|
|
|
|
|
|
|
std::string
|
|
|
|
hello_world()
|
|
|
|
CODE:
|
|
|
|
RETVAL = "Hello world!";
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
%}
|