PrusaSlicer-NonPlainar/xs/xsp/TriangleMesh.xsp

116 lines
3.7 KiB
Plaintext
Raw Permalink Normal View History

2013-06-23 13:33:07 +00:00
%module{Slic3r::XS};
2013-06-24 17:35:49 +00:00
%{
#include <xsinit.h>
#include "libslic3r/TriangleMesh.hpp"
#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();
Clone<TriangleMesh> clone()
%code{% RETVAL = THIS; %};
void write_ascii(char* output_file);
void write_binary(char* output_file);
2013-08-04 19:34:26 +00:00
void scale(float factor);
void scale_xyz(Vec3d* versor)
%code{% THIS->scale(versor->cast<float>()); %};
void translate(float x, float y, float z);
void rotate_x(float angle);
void rotate_y(float angle);
void rotate_z(float angle);
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); %};
Clone<Polygon> convex_hull();
Clone<Vec3d> center()
%code{% RETVAL = THIS->bounding_box().center(); %};
2014-09-21 08:51:36 +00:00
int facets_count();
2013-07-13 16:51:49 +00:00
%{
void
TriangleMesh::ReadFromPerl(vertices, facets)
SV* vertices
SV* facets
CODE:
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))));
}
}
*THIS = TriangleMesh(std::move(out_vertices), std::move(out_indices));
SV*
TriangleMesh::vertices()
CODE:
// vertices
AV* vertices = newAV();
av_extend(vertices, THIS->its.vertices.size());
for (size_t i = 0; i < THIS->its.vertices.size(); i++) {
AV* vertex = newAV();
av_store(vertices, i, newRV_noinc((SV*)vertex));
av_extend(vertex, 2);
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)));
}
RETVAL = newRV_noinc((SV*)vertices);
OUTPUT:
RETVAL
SV*
TriangleMesh::facets()
CODE:
// facets
AV* facets = newAV();
av_extend(facets, THIS->facets_count());
for (int i = 0; i < THIS->facets_count(); i++) {
AV* facet = newAV();
av_store(facets, i, newRV_noinc((SV*)facet));
av_extend(facet, 2);
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]));
}
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);
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-07-13 16:51:49 +00:00
%}
2013-06-24 17:35:49 +00:00
};