2013-06-23 13:33:07 +00:00
|
|
|
%module{Slic3r::XS};
|
2013-06-24 17:35:49 +00:00
|
|
|
|
|
|
|
%{
|
2015-12-07 23:39:54 +00:00
|
|
|
#include <xsinit.h>
|
2014-08-03 17:42:29 +00:00
|
|
|
#include "libslic3r/TriangleMesh.hpp"
|
2021-05-17 18:25:59 +00:00
|
|
|
#include "libslic3r/TriangleMeshSlicer.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-09-11 07:49:28 +00:00
|
|
|
void write_ascii(char* output_file);
|
|
|
|
void write_binary(char* output_file);
|
2013-08-04 19:34:26 +00:00
|
|
|
void scale(float factor);
|
2018-08-21 15:43:05 +00:00
|
|
|
void scale_xyz(Vec3d* versor)
|
2021-09-20 15:12:22 +00:00
|
|
|
%code{% THIS->scale(versor->cast<float>()); %};
|
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);
|
2015-11-04 22:11:30 +00:00
|
|
|
void mirror_x();
|
|
|
|
void mirror_y();
|
|
|
|
void mirror_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);
|
2014-08-03 18:33:16 +00:00
|
|
|
void merge(TriangleMesh* mesh)
|
|
|
|
%code{% THIS->merge(*mesh); %};
|
2015-01-19 17:53:04 +00:00
|
|
|
Clone<Polygon> convex_hull();
|
|
|
|
Clone<BoundingBoxf3> bounding_box();
|
2018-08-21 15:43:05 +00:00
|
|
|
Clone<Vec3d> center()
|
2015-01-19 17:53:04 +00:00
|
|
|
%code{% RETVAL = THIS->bounding_box().center(); %};
|
2014-09-21 08:51:36 +00:00
|
|
|
int facets_count();
|
2016-11-28 08:46:43 +00:00
|
|
|
|
2013-07-13 16:51:49 +00:00
|
|
|
%{
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
void
|
|
|
|
TriangleMesh::ReadFromPerl(vertices, facets)
|
|
|
|
SV* vertices
|
|
|
|
SV* facets
|
|
|
|
CODE:
|
2021-09-20 15:12:22 +00:00
|
|
|
std::vector<Slic3r::Vec3f> out_vertices;
|
|
|
|
{
|
|
|
|
AV* vertices_av = (AV*)SvRV(vertices);
|
|
|
|
int number_of_vertices = av_len(vertices_av) + 1;
|
|
|
|
out_vertices.reserve(number_of_vertices);
|
|
|
|
for (int i = 0; i < number_of_vertices; ++ i) {
|
|
|
|
AV* vertex_av = (AV*)SvRV(*av_fetch(vertices_av, i, 0));
|
|
|
|
out_vertices.push_back(Slic3r::Vec3f(SvNV(*av_fetch(vertex_av, 0, 0)), SvNV(*av_fetch(vertex_av, 1, 0)), SvNV(*av_fetch(vertex_av, 2, 0))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::vector<Slic3r::Vec3i> out_indices;
|
|
|
|
{
|
|
|
|
AV* facets_av = (AV*)SvRV(facets);
|
|
|
|
int number_of_facets = av_len(facets_av) + 1;
|
|
|
|
out_indices.reserve(number_of_facets);
|
|
|
|
for (int i = 0; i < number_of_facets; ++ i) {
|
|
|
|
AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0));
|
|
|
|
out_indices.push_back(Slic3r::Vec3i(SvIV(*av_fetch(facet_av, 0, 0)), SvIV(*av_fetch(facet_av, 1, 0)), SvIV(*av_fetch(facet_av, 2, 0))));
|
2015-12-07 23:39:54 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-20 15:12:22 +00:00
|
|
|
*THIS = TriangleMesh(std::move(out_vertices), std::move(out_indices));
|
2015-12-07 23:39:54 +00:00
|
|
|
|
2013-07-13 16:51:49 +00:00
|
|
|
SV*
|
|
|
|
TriangleMesh::stats()
|
|
|
|
CODE:
|
|
|
|
HV* hv = newHV();
|
2021-09-20 15:12:22 +00:00
|
|
|
(void)hv_stores( hv, "number_of_facets", newSViv(THIS->facets_count()) );
|
|
|
|
(void)hv_stores( hv, "number_of_parts", newSViv(THIS->stats().number_of_parts) );
|
|
|
|
(void)hv_stores( hv, "volume", newSVnv(THIS->stats().volume) );
|
2021-10-06 11:49:03 +00:00
|
|
|
(void)hv_stores( hv, "degenerate_facets", newSViv(THIS->stats().repaired_errors.degenerate_facets) );
|
|
|
|
(void)hv_stores( hv, "edges_fixed", newSViv(THIS->stats().repaired_errors.edges_fixed) );
|
|
|
|
(void)hv_stores( hv, "facets_removed", newSViv(THIS->stats().repaired_errors.facets_removed) );
|
|
|
|
(void)hv_stores( hv, "facets_reversed", newSViv(THIS->stats().repaired_errors.facets_reversed) );
|
|
|
|
(void)hv_stores( hv, "backwards_edges", newSViv(THIS->stats().repaired_errors.backwards_edges) );
|
2013-07-13 16:51:49 +00:00
|
|
|
RETVAL = (SV*)newRV_noinc((SV*)hv);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2013-08-04 19:23:27 +00:00
|
|
|
SV*
|
|
|
|
TriangleMesh::vertices()
|
|
|
|
CODE:
|
|
|
|
// vertices
|
|
|
|
AV* vertices = newAV();
|
2019-06-10 16:30:54 +00:00
|
|
|
av_extend(vertices, THIS->its.vertices.size());
|
|
|
|
for (size_t i = 0; i < THIS->its.vertices.size(); i++) {
|
2013-08-04 19:23:27 +00:00
|
|
|
AV* vertex = newAV();
|
|
|
|
av_store(vertices, i, newRV_noinc((SV*)vertex));
|
|
|
|
av_extend(vertex, 2);
|
2019-06-10 16:30:54 +00:00
|
|
|
av_store(vertex, 0, newSVnv(THIS->its.vertices[i](0)));
|
|
|
|
av_store(vertex, 1, newSVnv(THIS->its.vertices[i](1)));
|
|
|
|
av_store(vertex, 2, newSVnv(THIS->its.vertices[i](2)));
|
2013-08-04 19:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL = newRV_noinc((SV*)vertices);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
|
|
|
SV*
|
|
|
|
TriangleMesh::facets()
|
|
|
|
CODE:
|
|
|
|
// facets
|
|
|
|
AV* facets = newAV();
|
2021-09-20 15:12:22 +00:00
|
|
|
av_extend(facets, THIS->facets_count());
|
|
|
|
for (int i = 0; i < THIS->facets_count(); i++) {
|
2013-08-04 19:23:27 +00:00
|
|
|
AV* facet = newAV();
|
|
|
|
av_store(facets, i, newRV_noinc((SV*)facet));
|
|
|
|
av_extend(facet, 2);
|
2019-06-10 19:14:58 +00:00
|
|
|
av_store(facet, 0, newSVnv(THIS->its.indices[i][0]));
|
|
|
|
av_store(facet, 1, newSVnv(THIS->its.indices[i][1]));
|
|
|
|
av_store(facet, 2, newSVnv(THIS->its.indices[i][2]));
|
2013-08-04 19:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL = newRV_noinc((SV*)facets);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2013-08-05 17:39:10 +00:00
|
|
|
SV*
|
|
|
|
TriangleMesh::size()
|
|
|
|
CODE:
|
|
|
|
AV* size = newAV();
|
|
|
|
av_extend(size, 2);
|
2021-09-20 15:12:22 +00:00
|
|
|
av_store(size, 0, newSVnv(THIS->stats().size(0)));
|
|
|
|
av_store(size, 1, newSVnv(THIS->stats().size(1)));
|
|
|
|
av_store(size, 2, newSVnv(THIS->stats().size(2)));
|
2013-08-05 17:39:10 +00:00
|
|
|
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
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
std::vector<float> z_f = cast<float>(z);
|
2014-01-12 22:56:07 +00:00
|
|
|
|
2021-05-18 13:05:23 +00:00
|
|
|
std::vector<ExPolygons> layers = slice_mesh_ex(THIS->its, z_f, 0.049f);
|
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
|
2021-05-18 13:05:23 +00:00
|
|
|
TriangleMesh::cut(z, upper_mesh, lower_mesh)
|
2014-01-16 10:25:26 +00:00
|
|
|
float z;
|
2021-05-18 13:05:23 +00:00
|
|
|
TriangleMesh* upper_mesh;
|
|
|
|
TriangleMesh* lower_mesh;
|
2014-01-16 10:25:26 +00:00
|
|
|
CODE:
|
2021-05-18 13:05:23 +00:00
|
|
|
indexed_triangle_set upper, lower;
|
|
|
|
cut_mesh(THIS->its, z, upper_mesh ? &upper : nullptr, lower_mesh ? &lower : nullptr);
|
|
|
|
if (upper_mesh)
|
|
|
|
*upper_mesh = TriangleMesh(upper);
|
|
|
|
if (lower_mesh)
|
|
|
|
*lower_mesh = TriangleMesh(lower);
|
2014-01-16 10:25:26 +00:00
|
|
|
|
2013-09-11 09:55:08 +00:00
|
|
|
std::vector<double>
|
|
|
|
TriangleMesh::bb3()
|
|
|
|
CODE:
|
2021-09-20 15:12:22 +00:00
|
|
|
RETVAL.push_back(THIS->stats().min(0));
|
|
|
|
RETVAL.push_back(THIS->stats().min(1));
|
|
|
|
RETVAL.push_back(THIS->stats().max(0));
|
|
|
|
RETVAL.push_back(THIS->stats().max(1));
|
|
|
|
RETVAL.push_back(THIS->stats().min(2));
|
|
|
|
RETVAL.push_back(THIS->stats().max(2));
|
2013-09-11 09:55:08 +00:00
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2016-11-28 08:46:43 +00:00
|
|
|
|
|
|
|
Clone<TriangleMesh>
|
|
|
|
cube(double x, double y, double z)
|
|
|
|
CODE:
|
|
|
|
RETVAL = make_cube(x,y,z);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
|
|
|
Clone<TriangleMesh>
|
|
|
|
cylinder(double r, double h)
|
|
|
|
CODE:
|
|
|
|
RETVAL = make_cylinder(r, h);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2016-12-05 22:43:55 +00:00
|
|
|
Clone<TriangleMesh>
|
|
|
|
sphere(double rho)
|
|
|
|
CODE:
|
|
|
|
RETVAL = make_sphere(rho);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
2013-07-13 16:51:49 +00:00
|
|
|
%}
|
2013-06-24 17:35:49 +00:00
|
|
|
};
|