From 244475e002f4d16124a4e7693022afb65ce5c389 Mon Sep 17 00:00:00 2001 From: huxingyi Date: Wed, 15 Apr 2020 08:33:23 +0930 Subject: [PATCH] Optimize hole fixer If invalid neighbors are more than valid neighbors, the face will be marked as invalid as well. --- src/fixholes.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/fixholes.cpp b/src/fixholes.cpp index 9b2d882f..dff6e3d2 100644 --- a/src/fixholes.cpp +++ b/src/fixholes.cpp @@ -39,6 +39,33 @@ void fixHoles(const std::vector &verticies, std::vector newInvalidFaces; + for (size_t index = 0; index < faces.size(); ++index) { + if (invalidFaces.find(index) != invalidFaces.end()) + continue; + const auto &face = faces[index]; + size_t validNeighborNum = 0; + for (size_t i = 0; i < face.size(); i++) { + size_t j = (i + 1) % face.size(); + auto findOppositeFaceResult = edgeToFaceMap.find({face[j], face[i]}); + if (findOppositeFaceResult != edgeToFaceMap.end()) + ++validNeighborNum; + } + if (validNeighborNum < face.size() - validNeighborNum) { + invalidFaces.insert(index); + newInvalidFaces.insert(index); + continue; + } + } + + for (const auto &index: newInvalidFaces) { + const auto &face = faces[index]; + for (size_t i = 0; i < face.size(); i++) { + size_t j = (i + 1) % face.size(); + edgeToFaceMap.erase({face[i], face[j]}); + } + } + std::map> holeVertexLink; std::vector startVertices; for (size_t index = 0; index < faces.size(); ++index) {