Change method signature for slice()

This commit is contained in:
Alessandro Ranellucci 2013-11-23 00:15:42 +01:00
parent 878d587196
commit 67a7e4f769
3 changed files with 11 additions and 13 deletions

View file

@ -161,8 +161,8 @@ void TriangleMesh::rotate(double angle, Point* center)
this->translate(+center->x, +center->y, 0);
}
std::vector<Polygons>*
TriangleMesh::slice(const std::vector<double> &z)
void
TriangleMesh::slice(const std::vector<double> &z, std::vector<Polygons> &layers)
{
/*
This method gets called with a list of Z coordinates and outputs
@ -368,7 +368,7 @@ TriangleMesh::slice(const std::vector<double> &z)
}
// build loops
std::vector<Polygons>* layers = new std::vector<Polygons>(z.size());
layers.resize(z.size());
for (std::vector<IntersectionLines>::iterator it = lines.begin(); it != lines.end(); ++it) {
int layer_idx = it - lines.begin();
#ifdef SLIC3R_DEBUG
@ -461,7 +461,7 @@ TriangleMesh::slice(const std::vector<double> &z)
for (IntersectionLinePtrs::iterator lineptr = loop.begin(); lineptr != loop.end(); ++lineptr) {
p.points.push_back((*lineptr)->a);
}
(*layers)[layer_idx].push_back(p);
layers[layer_idx].push_back(p);
#ifdef SLIC3R_DEBUG
printf(" Discovered %s polygon of %d points\n", (p.is_counter_clockwise() ? "ccw" : "cw"), (int)p.points.size());
@ -487,8 +487,6 @@ TriangleMesh::slice(const std::vector<double> &z)
}
}
}
return layers;
}
TriangleMeshPtrs

View file

@ -28,7 +28,7 @@ class TriangleMesh
void translate(float x, float y, float z);
void align_to_origin();
void rotate(double angle, Point* center);
std::vector<Polygons>* slice(const std::vector<double> &z);
void slice(const std::vector<double> &z, std::vector<Polygons> &layers);
TriangleMeshPtrs split() const;
void merge(const TriangleMesh* mesh);
stl_file stl;

View file

@ -129,20 +129,20 @@ SV*
TriangleMesh::slice(z)
std::vector<double>* z
CODE:
std::vector<Polygons>* layers = THIS->slice(*z);
std::vector<Polygons> layers;
THIS->slice(*z, layers);
AV* layers_av = newAV();
av_extend(layers_av, layers->size()-1);
for (unsigned int i = 0; i < layers->size(); i++) {
av_extend(layers_av, layers.size()-1);
for (unsigned int i = 0; i < layers.size(); i++) {
AV* polygons_av = newAV();
av_extend(polygons_av, (*layers)[i].size()-1);
av_extend(polygons_av, layers[i].size()-1);
unsigned int j = 0;
for (Polygons::iterator it = (*layers)[i].begin(); it != (*layers)[i].end(); ++it) {
for (Polygons::iterator it = layers[i].begin(); it != layers[i].end(); ++it) {
av_store(polygons_av, j++, (*it).to_SV_clone_ref());
}
av_store(layers_av, i, newRV_noinc((SV*)polygons_av));
}
delete layers;
RETVAL = (SV*)newRV_noinc((SV*)layers_av);
OUTPUT:
RETVAL