From 2d5e98d955f8642a56787db5854b15c464007b53 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Mon, 14 Nov 2022 21:53:03 +1100 Subject: [PATCH] Remove unused triangle source node resolver --- application/application.pro | 2 - dust3d/mesh/mesh_generator.cc | 1 - dust3d/mesh/resolve_triangle_source_node.cc | 211 -------------------- dust3d/mesh/resolve_triangle_source_node.h | 38 ---- 4 files changed, 252 deletions(-) delete mode 100644 dust3d/mesh/resolve_triangle_source_node.cc delete mode 100644 dust3d/mesh/resolve_triangle_source_node.h diff --git a/application/application.pro b/application/application.pro index d335d860..7dbcdf7d 100644 --- a/application/application.pro +++ b/application/application.pro @@ -285,8 +285,6 @@ HEADERS += ../dust3d/mesh/mesh_state.h SOURCES += ../dust3d/mesh/mesh_state.cc HEADERS += ../dust3d/mesh/re_triangulator.h SOURCES += ../dust3d/mesh/re_triangulator.cc -HEADERS += ../dust3d/mesh/resolve_triangle_source_node.h -SOURCES += ../dust3d/mesh/resolve_triangle_source_node.cc HEADERS += ../dust3d/mesh/resolve_triangle_tangent.h SOURCES += ../dust3d/mesh/resolve_triangle_tangent.cc HEADERS += ../dust3d/mesh/rope_mesh.h diff --git a/dust3d/mesh/mesh_generator.cc b/dust3d/mesh/mesh_generator.cc index 847e7fd2..78b2ef56 100644 --- a/dust3d/mesh/mesh_generator.cc +++ b/dust3d/mesh/mesh_generator.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/dust3d/mesh/resolve_triangle_source_node.cc b/dust3d/mesh/resolve_triangle_source_node.cc deleted file mode 100644 index 03683e31..00000000 --- a/dust3d/mesh/resolve_triangle_source_node.cc +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2016-2021 Jeremy HU . All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include - -namespace dust3d { - -struct HalfColorEdge { - int cornVertexIndex; - std::pair source; -}; - -struct CandidateEdge { - std::pair source; - int fromVertexIndex; - int toVertexIndex; - float dot; - float length; -}; - -static void fixRemainVertexSourceNodes(const Object& object, std::vector>& triangleSourceNodes, - std::vector>* vertexSourceNodes) -{ - if (nullptr != vertexSourceNodes) { - std::map, size_t>> remainVertexSourcesMap; - for (size_t faceIndex = 0; faceIndex < object.triangles.size(); ++faceIndex) { - for (const auto& vertexIndex : object.triangles[faceIndex]) { - if (!(*vertexSourceNodes)[vertexIndex].second.isNull()) - continue; - remainVertexSourcesMap[vertexIndex][triangleSourceNodes[faceIndex]]++; - } - } - for (const auto& it : remainVertexSourcesMap) { - (*vertexSourceNodes)[it.first] = std::max_element(it.second.begin(), it.second.end(), [](const std::map, size_t>::value_type& first, const std::map, size_t>::value_type& second) { - return first.second < second.second; - })->first; - } - } -} - -void resolveTriangleSourceNode(const Object& object, - const std::vector>>& nodeVertices, - std::vector>& triangleSourceNodes, - std::vector>* vertexSourceNodes) -{ - std::map> vertexSourceMap; - std::map> positionMap; - std::map, HalfColorEdge> halfColorEdgeMap; - std::set brokenTriangleSet; - for (const auto& it : nodeVertices) { - positionMap.insert({ PositionKey(it.first), it.second }); - } - if (nullptr != vertexSourceNodes) - vertexSourceNodes->resize(object.vertices.size()); - for (auto x = 0u; x < object.vertices.size(); x++) { - const Vector3* resultVertex = &object.vertices[x]; - std::pair source; - auto findPosition = positionMap.find(PositionKey(*resultVertex)); - if (findPosition != positionMap.end()) { - (*vertexSourceNodes)[x] = findPosition->second; - vertexSourceMap[x] = findPosition->second; - } - } - for (auto x = 0u; x < object.triangles.size(); x++) { - const auto triangle = object.triangles[x]; - std::vector, int>> colorTypes; - for (int i = 0; i < 3; i++) { - int index = triangle[i]; - const auto& findResult = vertexSourceMap.find(index); - if (findResult != vertexSourceMap.end()) { - std::pair source = findResult->second; - bool colorExisted = false; - for (auto j = 0u; j < colorTypes.size(); j++) { - if (colorTypes[j].first == source) { - colorTypes[j].second++; - colorExisted = true; - break; - } - } - if (!colorExisted) { - colorTypes.push_back(std::make_pair(source, 1)); - } - } - } - if (colorTypes.empty()) { - triangleSourceNodes.push_back(std::make_pair(Uuid(), Uuid())); - brokenTriangleSet.insert(x); - continue; - } - if (colorTypes.size() != 1 || 3 == colorTypes[0].second) { - std::sort(colorTypes.begin(), colorTypes.end(), [](const std::pair, int>& a, const std::pair, int>& b) -> bool { - return a.second > b.second; - }); - } - std::pair choosenColor = colorTypes[0].first; - triangleSourceNodes.push_back(choosenColor); - for (int i = 0; i < 3; i++) { - int oppositeStartIndex = triangle[(i + 1) % 3]; - int oppositeStopIndex = triangle[i]; - auto oppositePair = std::make_pair(oppositeStartIndex, oppositeStopIndex); - if (halfColorEdgeMap.find(oppositePair) != halfColorEdgeMap.end()) { - halfColorEdgeMap.erase(oppositePair); - continue; - } - auto selfPair = std::make_pair(oppositeStopIndex, oppositeStartIndex); - HalfColorEdge edge; - edge.cornVertexIndex = triangle[(i + 2) % 3]; - edge.source = choosenColor; - halfColorEdgeMap[selfPair] = edge; - } - } - std::map, int> brokenTriangleMapByEdge; - std::vector candidateEdges; - for (const auto& x : brokenTriangleSet) { - const auto triangle = object.triangles[x]; - for (int i = 0; i < 3; i++) { - int oppositeStartIndex = triangle[(i + 1) % 3]; - int oppositeStopIndex = triangle[i]; - auto selfPair = std::make_pair(oppositeStopIndex, oppositeStartIndex); - brokenTriangleMapByEdge[selfPair] = x; - auto oppositePair = std::make_pair(oppositeStartIndex, oppositeStopIndex); - const auto& findOpposite = halfColorEdgeMap.find(oppositePair); - if (findOpposite == halfColorEdgeMap.end()) - continue; - Vector3 selfPositions[3] = { - object.vertices[triangle[i]], // A - object.vertices[triangle[(i + 1) % 3]], // B - object.vertices[triangle[(i + 2) % 3]] // C - }; - Vector3 oppositeCornPosition = object.vertices[findOpposite->second.cornVertexIndex]; // D - Vector3 AB = selfPositions[1] - selfPositions[0]; - float length = AB.length(); - Vector3 AC = selfPositions[2] - selfPositions[0]; - Vector3 AD = oppositeCornPosition - selfPositions[0]; - AB.normalize(); - AC.normalize(); - AD.normalize(); - Vector3 ABxAC = Vector3::crossProduct(AB, AC); - Vector3 ADxAB = Vector3::crossProduct(AD, AB); - ABxAC.normalize(); - ADxAB.normalize(); - float dot = Vector3::dotProduct(ABxAC, ADxAB); - CandidateEdge candidate; - candidate.dot = dot; - candidate.length = length; - candidate.fromVertexIndex = triangle[i]; - candidate.toVertexIndex = triangle[(i + 1) % 3]; - candidate.source = findOpposite->second.source; - candidateEdges.push_back(candidate); - } - } - if (candidateEdges.empty()) { - fixRemainVertexSourceNodes(object, triangleSourceNodes, vertexSourceNodes); - return; - } - std::sort(candidateEdges.begin(), candidateEdges.end(), [](const CandidateEdge& a, const CandidateEdge& b) -> bool { - if (a.dot > b.dot) - return true; - else if (a.dot < b.dot) - return false; - return a.length > b.length; - }); - for (auto cand = 0u; cand < candidateEdges.size(); cand++) { - const auto& candidate = candidateEdges[cand]; - if (brokenTriangleSet.empty()) - break; - std::vector> toResolvePairs; - toResolvePairs.push_back(std::make_pair(candidate.fromVertexIndex, candidate.toVertexIndex)); - for (auto order = 0u; order < toResolvePairs.size(); order++) { - const auto& findTriangle = brokenTriangleMapByEdge.find(toResolvePairs[order]); - if (findTriangle == brokenTriangleMapByEdge.end()) - continue; - int x = findTriangle->second; - if (brokenTriangleSet.find(x) == brokenTriangleSet.end()) - continue; - brokenTriangleSet.erase(x); - triangleSourceNodes[x] = candidate.source; - const auto triangle = object.triangles[x]; - for (int i = 0; i < 3; i++) { - int oppositeStartIndex = triangle[(i + 1) % 3]; - int oppositeStopIndex = triangle[i]; - auto oppositePair = std::make_pair(oppositeStartIndex, oppositeStopIndex); - toResolvePairs.push_back(oppositePair); - } - } - } - fixRemainVertexSourceNodes(object, triangleSourceNodes, vertexSourceNodes); -} - -} diff --git a/dust3d/mesh/resolve_triangle_source_node.h b/dust3d/mesh/resolve_triangle_source_node.h deleted file mode 100644 index 0d1737c5..00000000 --- a/dust3d/mesh/resolve_triangle_source_node.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2016-2021 Jeremy HU . All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef DUST3D_MESH_RESOLVE_TRIANGLE_SOURCE_NODE_H_ -#define DUST3D_MESH_RESOLVE_TRIANGLE_SOURCE_NODE_H_ - -#include -#include - -namespace dust3d { - -void resolveTriangleSourceNode(const Object& object, - const std::vector>>& nodeVertices, - std::vector>& triangleSourceNodes, - std::vector>* vertexSourceNodes = nullptr); - -} - -#endif