mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 06:05:53 +08:00
Untested implementation of split_mesh()
This commit is contained in:
parent
b6548137de
commit
93dddb7ee2
@ -1,4 +1,7 @@
|
|||||||
#include "TriangleMesh.hpp"
|
#include "TriangleMesh.hpp"
|
||||||
|
#include <queue>
|
||||||
|
#include <deque>
|
||||||
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -468,4 +471,50 @@ TriangleMesh::slice(const std::vector<double> &z)
|
|||||||
return layers;
|
return layers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<TriangleMesh>
|
||||||
|
TriangleMesh::split() const
|
||||||
|
{
|
||||||
|
std::vector<TriangleMesh> meshes;
|
||||||
|
std::set<int> seen_facets;
|
||||||
|
|
||||||
|
// loop while we have remaining facets
|
||||||
|
while (1) {
|
||||||
|
// get the first facet
|
||||||
|
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()) {
|
||||||
|
facet_queue.push(facet_idx);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (facet_queue.empty()) break;
|
||||||
|
|
||||||
|
while (!facet_queue.empty()) {
|
||||||
|
int facet_idx = facet_queue.front();
|
||||||
|
facet_queue.pop();
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
seen_facets.insert(facet_idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
meshes.resize(meshes.size()+1);
|
||||||
|
TriangleMesh* mesh = &(meshes.back());
|
||||||
|
stl_initialize(&mesh->stl);
|
||||||
|
mesh->stl.stats.type = inmemory;
|
||||||
|
mesh->stl.stats.number_of_facets = facets.size();
|
||||||
|
mesh->stl.stats.original_num_facets = mesh->stl.stats.number_of_facets;
|
||||||
|
stl_allocate(&mesh->stl);
|
||||||
|
|
||||||
|
for (std::deque<int>::const_iterator facet = facets.begin(); facet != facets.end(); facet++) {
|
||||||
|
mesh->stl.facet_start[facet - facets.begin()] = this->stl.facet_start[*facet];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshes;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ class TriangleMesh
|
|||||||
void align_to_origin();
|
void align_to_origin();
|
||||||
void rotate(double angle, Point* center);
|
void rotate(double angle, Point* center);
|
||||||
std::vector<Polygons>* slice(const std::vector<double> &z);
|
std::vector<Polygons>* slice(const std::vector<double> &z);
|
||||||
|
std::vector<TriangleMesh> split() const;
|
||||||
stl_file stl;
|
stl_file stl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user