Optimize hole fixer

If invalid neighbors are more than valid neighbors, the face will
be marked as invalid as well.
master
huxingyi 2020-04-15 08:33:23 +09:30
parent 09aebfb9f8
commit 244475e002
1 changed files with 27 additions and 0 deletions

View File

@ -39,6 +39,33 @@ void fixHoles(const std::vector<QVector3D> &verticies, std::vector<std::vector<s
} }
} }
std::unordered_set<size_t> 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<size_t, std::vector<size_t>> holeVertexLink; std::map<size_t, std::vector<size_t>> holeVertexLink;
std::vector<size_t> startVertices; std::vector<size_t> startVertices;
for (size_t index = 0; index < faces.size(); ++index) { for (size_t index = 0; index < faces.size(); ++index) {