Finished implementation of TriangleMesh->split

This commit is contained in:
Alessandro Ranellucci 2013-09-09 22:27:58 +02:00
parent 2d4aa439ae
commit 27e7c6b9f7
18 changed files with 59 additions and 23 deletions

View file

@ -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

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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();

View file

@ -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;
};