Finished implementation of TriangleMesh->split
This commit is contained in:
parent
2d4aa439ae
commit
27e7c6b9f7
@ -51,7 +51,7 @@ ExPolygon::is_valid() const
|
||||
}
|
||||
|
||||
SV*
|
||||
ExPolygon::to_SV() {
|
||||
ExPolygon::to_AV() {
|
||||
const unsigned int num_holes = this->holes.size();
|
||||
AV* av = newAV();
|
||||
av_extend(av, num_holes); // -1 +1
|
||||
|
@ -13,7 +13,7 @@ class ExPolygon
|
||||
Polygons holes;
|
||||
void from_SV(SV* poly_sv);
|
||||
void from_SV_check(SV* poly_sv);
|
||||
SV* to_SV();
|
||||
SV* to_AV();
|
||||
SV* to_SV_ref();
|
||||
SV* to_SV_clone_ref() const;
|
||||
SV* to_SV_pureperl() const;
|
||||
|
@ -61,7 +61,7 @@ Line::from_SV_check(SV* line_sv)
|
||||
}
|
||||
|
||||
SV*
|
||||
Line::to_SV() {
|
||||
Line::to_AV() {
|
||||
AV* av = newAV();
|
||||
av_extend(av, 1);
|
||||
|
||||
|
@ -15,7 +15,7 @@ class Line
|
||||
explicit Line(Point _a, Point _b): a(_a), b(_b) {};
|
||||
void from_SV(SV* line_sv);
|
||||
void from_SV_check(SV* line_sv);
|
||||
SV* to_SV();
|
||||
SV* to_AV();
|
||||
SV* to_SV_ref();
|
||||
SV* to_SV_clone_ref() const;
|
||||
SV* to_SV_pureperl() const;
|
||||
|
@ -62,7 +62,7 @@ MultiPoint::from_SV_check(SV* poly_sv)
|
||||
}
|
||||
|
||||
SV*
|
||||
MultiPoint::to_SV() {
|
||||
MultiPoint::to_AV() {
|
||||
const unsigned int num_points = this->points.size();
|
||||
AV* av = newAV();
|
||||
av_extend(av, num_points-1);
|
||||
|
@ -13,7 +13,7 @@ class MultiPoint
|
||||
Points points;
|
||||
void from_SV(SV* poly_sv);
|
||||
void from_SV_check(SV* poly_sv);
|
||||
SV* to_SV();
|
||||
SV* to_AV();
|
||||
SV* to_SV_pureperl() const;
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
|
@ -16,6 +16,13 @@ TriangleMesh::~TriangleMesh() {
|
||||
stl_close(&stl);
|
||||
}
|
||||
|
||||
SV*
|
||||
TriangleMesh::to_SV() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::TriangleMesh::XS", (void*)this );
|
||||
return sv;
|
||||
}
|
||||
|
||||
void
|
||||
TriangleMesh::ReadSTLFile(char* input_file) {
|
||||
stl_open(&stl, input_file);
|
||||
@ -471,10 +478,10 @@ TriangleMesh::slice(const std::vector<double> &z)
|
||||
return layers;
|
||||
}
|
||||
|
||||
std::vector<TriangleMesh>
|
||||
TriangleMeshPtrs
|
||||
TriangleMesh::split() const
|
||||
{
|
||||
std::vector<TriangleMesh> meshes;
|
||||
TriangleMeshPtrs meshes;
|
||||
std::set<int> seen_facets;
|
||||
|
||||
// loop while we have remaining facets
|
||||
@ -483,7 +490,8 @@ TriangleMesh::split() const
|
||||
std::queue<int> facet_queue;
|
||||
std::deque<int> facets;
|
||||
for (int facet_idx = 0; facet_idx < this->stl.stats.number_of_facets; facet_idx++) {
|
||||
if (seen_facets.find(facet_idx) != seen_facets.end()) {
|
||||
if (seen_facets.find(facet_idx) == seen_facets.end()) {
|
||||
// if facet was not seen put it into queue and start searching
|
||||
facet_queue.push(facet_idx);
|
||||
break;
|
||||
}
|
||||
@ -493,7 +501,7 @@ TriangleMesh::split() const
|
||||
while (!facet_queue.empty()) {
|
||||
int facet_idx = facet_queue.front();
|
||||
facet_queue.pop();
|
||||
if (seen_facets.find(facet_idx) == seen_facets.end()) continue;
|
||||
if (seen_facets.find(facet_idx) != seen_facets.end()) continue;
|
||||
facets.push_back(facet_idx);
|
||||
for (int j = 0; j <= 2; j++) {
|
||||
facet_queue.push(this->stl.neighbors_start[facet_idx].neighbor[j]);
|
||||
@ -501,8 +509,8 @@ TriangleMesh::split() const
|
||||
seen_facets.insert(facet_idx);
|
||||
}
|
||||
|
||||
meshes.resize(meshes.size()+1);
|
||||
TriangleMesh* mesh = &(meshes.back());
|
||||
TriangleMesh* mesh = new TriangleMesh;
|
||||
meshes.push_back(mesh);
|
||||
stl_initialize(&mesh->stl);
|
||||
mesh->stl.stats.type = inmemory;
|
||||
mesh->stl.stats.number_of_facets = facets.size();
|
||||
|
@ -9,11 +9,15 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class TriangleMesh;
|
||||
typedef std::vector<TriangleMesh*> TriangleMeshPtrs;
|
||||
|
||||
class TriangleMesh
|
||||
{
|
||||
public:
|
||||
TriangleMesh();
|
||||
~TriangleMesh();
|
||||
SV* to_SV();
|
||||
void ReadSTLFile(char* input_file);
|
||||
void ReadFromPerl(SV* vertices, SV* facets);
|
||||
void Repair();
|
||||
@ -23,7 +27,7 @@ class TriangleMesh
|
||||
void align_to_origin();
|
||||
void rotate(double angle, Point* center);
|
||||
std::vector<Polygons>* slice(const std::vector<double> &z);
|
||||
std::vector<TriangleMesh> split() const;
|
||||
TriangleMeshPtrs split() const;
|
||||
stl_file stl;
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,7 @@ use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 43;
|
||||
use Test::More tests => 45;
|
||||
|
||||
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
|
||||
'hello world';
|
||||
@ -42,6 +42,10 @@ my $cube = {
|
||||
|
||||
$m->rotate(45, Slic3r::Point->new(20,20));
|
||||
ok abs($m->size->[0] - sqrt(2)*40) < 1E-4, 'rotate';
|
||||
|
||||
my $result = $m->split;
|
||||
is scalar(@$result), 1, 'split';
|
||||
isa_ok $result->[0], 'Slic3r::TriangleMesh::XS', 'split';
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
ExPolygon* clone()
|
||||
%code{% const char* CLASS = "Slic3r::ExPolygon"; RETVAL = new ExPolygon(*THIS); %};
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = THIS->to_SV(); %};
|
||||
%code{% RETVAL = THIS->to_AV(); %};
|
||||
SV* pp()
|
||||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||
Polygon* contour()
|
||||
|
@ -8,7 +8,7 @@
|
||||
%name{Slic3r::ExtrusionLoop} class ExtrusionLoop {
|
||||
~ExtrusionLoop();
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = THIS->polygon.to_SV(); %};
|
||||
%code{% RETVAL = THIS->polygon.to_AV(); %};
|
||||
SV* pp()
|
||||
%code{% RETVAL = THIS->polygon.to_SV_pureperl(); %};
|
||||
void reverse()
|
||||
|
@ -8,7 +8,7 @@
|
||||
%name{Slic3r::ExtrusionPath} class ExtrusionPath {
|
||||
~ExtrusionPath();
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = THIS->polyline.to_SV(); %};
|
||||
%code{% RETVAL = THIS->polyline.to_AV(); %};
|
||||
SV* pp()
|
||||
%code{% RETVAL = THIS->polyline.to_SV_pureperl(); %};
|
||||
void pop_back()
|
||||
|
@ -10,7 +10,7 @@
|
||||
Line* clone()
|
||||
%code{% const char* CLASS = "Slic3r::Line"; RETVAL = new Line(*THIS); %};
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = THIS->to_SV(); %};
|
||||
%code{% RETVAL = THIS->to_AV(); %};
|
||||
SV* pp()
|
||||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||
Point* a()
|
||||
|
@ -10,7 +10,7 @@
|
||||
Polygon* clone()
|
||||
%code{% const char* CLASS = "Slic3r::Polygon"; RETVAL = new Polygon(*THIS); %};
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = THIS->to_SV(); %};
|
||||
%code{% RETVAL = THIS->to_AV(); %};
|
||||
SV* pp()
|
||||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||
void scale(double factor);
|
||||
|
@ -10,7 +10,7 @@
|
||||
Polyline* clone()
|
||||
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = new Polyline(*THIS); %};
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = THIS->to_SV(); %};
|
||||
%code{% RETVAL = THIS->to_AV(); %};
|
||||
SV* pp()
|
||||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||
void scale(double factor);
|
||||
|
@ -16,6 +16,7 @@
|
||||
void translate(float x, float y, float z);
|
||||
void align_to_origin();
|
||||
void rotate(double angle, Point* center);
|
||||
TriangleMeshPtrs split();
|
||||
%{
|
||||
|
||||
SV*
|
||||
|
@ -18,13 +18,22 @@ SurfaceType T_UV
|
||||
ClipperLib::JoinType T_UV
|
||||
ClipperLib::PolyFillType T_UV
|
||||
|
||||
# we return these types whenever we want the items to be cloned
|
||||
Points T_ARRAYREF
|
||||
Lines T_ARRAYREF
|
||||
Polygons T_ARRAYREF
|
||||
ExPolygons T_ARRAYREF
|
||||
|
||||
# we return these types whenever we want the items to be returned
|
||||
# by reference and marked ::Ref because they're contained in another
|
||||
# Perl object
|
||||
Polygons* T_ARRAYREF_PTR
|
||||
|
||||
# we return these types whenever we want the items to be returned
|
||||
# by reference and not marked ::Ref because they're newly allocated
|
||||
# and not referenced by any Perl object
|
||||
TriangleMeshPtrs T_PTR_ARRAYREF
|
||||
|
||||
INPUT
|
||||
|
||||
T_ARRAYREF
|
||||
@ -52,7 +61,7 @@ T_ARRAYREF
|
||||
av_extend(av, $var.size()-1);
|
||||
int i = 0;
|
||||
for (${type}::const_iterator it = $var.begin(); it != $var.end(); ++it) {
|
||||
av_store(av, i++, (*it).to_SV_clone_ref());
|
||||
av_store(av, i++, it->to_SV_clone_ref());
|
||||
}
|
||||
$var.clear();
|
||||
|
||||
@ -63,5 +72,15 @@ T_ARRAYREF_PTR
|
||||
av_extend(av, $var->size()-1);
|
||||
int i = 0;
|
||||
for (${ my $t = $type; $t =~ s/\*$//; \$t }::iterator it = $var->begin(); it != $var->end(); ++it) {
|
||||
av_store(av, i++, (*it).to_SV_ref());
|
||||
av_store(av, i++, it->to_SV_ref());
|
||||
}
|
||||
|
||||
T_PTR_ARRAYREF
|
||||
AV* av = newAV();
|
||||
$arg = newRV_noinc((SV*)av);
|
||||
sv_2mortal($arg);
|
||||
av_extend(av, $var.size()-1);
|
||||
int i = 0;
|
||||
for (${type}::iterator it = $var.begin(); it != $var.end(); ++it) {
|
||||
av_store(av, i++, (*it)->to_SV());
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
%typemap{Polygons};
|
||||
%typemap{ExPolygons};
|
||||
%typemap{Polygons*};
|
||||
%typemap{Lines*};
|
||||
%typemap{TriangleMeshPtrs};
|
||||
|
||||
%typemap{SurfaceType}{parsed}{
|
||||
%cpp_type{SurfaceType};
|
||||
|
Loading…
Reference in New Issue
Block a user