Added measuring sandbox for neighbors index creation

This commit is contained in:
tamasmeszaros 2021-06-01 15:49:19 +02:00
parent c542e6e14b
commit c8be2cdceb
11 changed files with 988 additions and 266 deletions

View file

@ -139,70 +139,11 @@ int its_compactify_vertices(indexed_triangle_set &its, bool shrink_to_fit = true
using FaceNeighborIndex = std::vector< std::array<size_t, 3> >;
// Create index that gives neighbor faces for each face. Ignores face orientations.
FaceNeighborIndex its_create_neighbors_index(const indexed_triangle_set &its);
std::vector<Vec3i> its_create_neighbors_index(const indexed_triangle_set &its);
// Visit all unvisited neighboring facets that are reachable from the first unvisited facet,
// and return them.
std::vector<size_t> its_find_unvisited_neighbors(
const indexed_triangle_set &its,
const FaceNeighborIndex & neighbor_index,
std::vector<bool> & visited);
std::vector<indexed_triangle_set> its_split(const indexed_triangle_set &its);
// Splits a mesh into multiple meshes when possible.
template<class OutputIt>
void its_split(const indexed_triangle_set & its,
OutputIt out_it,
const FaceNeighborIndex &neighbor_index_ = {})
{
const auto &neighbor_index = neighbor_index_.empty() ?
its_create_neighbors_index(its) :
neighbor_index_;
std::vector<bool> visited(its.indices.size(), false);
const size_t UNASSIGNED = its.vertices.size();
std::vector<size_t> vidx_conv(its.vertices.size());
for (;;) {
std::vector<size_t> facets =
its_find_unvisited_neighbors(its, neighbor_index, visited);
if (facets.empty())
break;
std::fill(vidx_conv.begin(), vidx_conv.end(), UNASSIGNED);
// Create a new mesh for the part that was just split off.
indexed_triangle_set mesh;
// Assign the facets to the new mesh.
for (size_t face_id : facets) {
const auto &face = its.indices[face_id];
Vec3i new_face;
for (size_t v = 0; v < 3; ++v) {
auto vi = face(v);
if (vidx_conv[vi] == UNASSIGNED) {
vidx_conv[vi] = mesh.vertices.size();
mesh.vertices.emplace_back(its.vertices[size_t(vi)]);
}
new_face(v) = vidx_conv[vi];
}
mesh.indices.emplace_back(new_face);
}
out_it = std::move(mesh);
}
}
std::vector<indexed_triangle_set> its_split(
const indexed_triangle_set &its,
const FaceNeighborIndex & neighbor_index = {});
bool its_is_splittable(const indexed_triangle_set &its,
const FaceNeighborIndex & neighbor_index = {});
bool its_is_splittable(const indexed_triangle_set &its);
// Shrink the vectors of its.vertices and its.faces to a minimum size by reallocating the two vectors.
void its_shrink_to_fit(indexed_triangle_set &its);