Make new split always default if feasible
This commit is contained in:
parent
97529ff6b7
commit
0ca17b0798
@ -451,27 +451,40 @@ std::deque<uint32_t> TriangleMesh::find_unvisited_neighbors(std::vector<unsigned
|
|||||||
*/
|
*/
|
||||||
TriangleMeshPtrs TriangleMesh::split() const
|
TriangleMeshPtrs TriangleMesh::split() const
|
||||||
{
|
{
|
||||||
// Loop while we have remaining facets.
|
struct MeshAdder {
|
||||||
std::vector<unsigned char> facet_visited;
|
TriangleMeshPtrs &meshes;
|
||||||
|
MeshAdder(TriangleMeshPtrs &ptrs): meshes{ptrs} {}
|
||||||
|
void operator=(const indexed_triangle_set &its)
|
||||||
|
{
|
||||||
|
meshes.emplace_back(new TriangleMesh(its));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TriangleMeshPtrs meshes;
|
TriangleMeshPtrs meshes;
|
||||||
for (;;) {
|
if (has_shared_vertices()) {
|
||||||
std::deque<uint32_t> facets = find_unvisited_neighbors(facet_visited);
|
its_split(its, MeshAdder{meshes});
|
||||||
if (facets.empty())
|
} else {
|
||||||
break;
|
// Loop while we have remaining facets.
|
||||||
|
std::vector<unsigned char> facet_visited;
|
||||||
|
for (;;) {
|
||||||
|
std::deque<uint32_t> facets = find_unvisited_neighbors(facet_visited);
|
||||||
|
if (facets.empty())
|
||||||
|
break;
|
||||||
|
|
||||||
// Create a new mesh for the part that was just split off.
|
// Create a new mesh for the part that was just split off.
|
||||||
TriangleMesh* mesh = new TriangleMesh;
|
TriangleMesh* mesh = new TriangleMesh;
|
||||||
meshes.emplace_back(mesh);
|
meshes.emplace_back(mesh);
|
||||||
mesh->stl.stats.type = inmemory;
|
mesh->stl.stats.type = inmemory;
|
||||||
mesh->stl.stats.number_of_facets = (uint32_t)facets.size();
|
mesh->stl.stats.number_of_facets = (uint32_t)facets.size();
|
||||||
mesh->stl.stats.original_num_facets = mesh->stl.stats.number_of_facets;
|
mesh->stl.stats.original_num_facets = mesh->stl.stats.number_of_facets;
|
||||||
stl_allocate(&mesh->stl);
|
stl_allocate(&mesh->stl);
|
||||||
|
|
||||||
// Assign the facets to the new mesh.
|
// Assign the facets to the new mesh.
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto facet = facets.begin(); facet != facets.end(); ++ facet) {
|
for (auto facet = facets.begin(); facet != facets.end(); ++ facet) {
|
||||||
mesh->stl.facet_start[facet - facets.begin()] = this->stl.facet_start[*facet];
|
mesh->stl.facet_start[facet - facets.begin()] = this->stl.facet_start[*facet];
|
||||||
stl_facet_stats(&mesh->stl, this->stl.facet_start[*facet], first);
|
stl_facet_stats(&mesh->stl, this->stl.facet_start[*facet], first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user