From 61309efd13cb3906ecc7fdbf65b79f2b7126b2a1 Mon Sep 17 00:00:00 2001 From: islam omar ahmed Date: Wed, 9 Aug 2023 08:16:12 +0300 Subject: [PATCH] mv refineTriangles into .hpp file --- CDT/include/Triangulation.h | 87 ----------------------------------- CDT/include/Triangulation.hpp | 85 ++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 87 deletions(-) diff --git a/CDT/include/Triangulation.h b/CDT/include/Triangulation.h index dfd2a89..9e96e67 100644 --- a/CDT/include/Triangulation.h +++ b/CDT/include/Triangulation.h @@ -802,93 +802,6 @@ void Triangulation::conformToEdges( } eraseDummies(); } - -template -void Triangulation::refineTriangles( - RefineTriangles::Enum refinementConstrain, - T threshold) -{ - if(isFinalized()) - { - throw std::runtime_error("Triangulation was finalized with 'erase...' " - "method. Refinement is not possible"); - } - tryInitNearestPointLocator(); - resolveEncroachedEdges(detectEncroachedEdges()); - - std::queue badTriangles; - for(TriInd iT(0), n = triangles.size(); iT < n; ++iT) - { - const Triangle& t = triangles[iT]; - if(t.vertices[0] < 3 || t.vertices[1] < 3 || t.vertices[2] < 3) - continue; - - if(isBadTriangle(t, refinementConstrain, threshold)) - { - const V2d vert = circumcenter(t); - if(locatePointTriangle( - vert, vertices[0], vertices[1], vertices[2]) != - PtTriLocation::Outside) - { - badTriangles.push(iT); - } - } - } - - while(!badTriangles.empty()) - { - TriInd iT = badTriangles.front(); - const Triangle& t = triangles[iT]; - badTriangles.pop(); - if(!isBadTriangle(t, refinementConstrain, threshold) || - numOfSteinerPoints >= maxSteinerPoints) - { - continue; - } - const V2d vert = circumcenter(t); - if(locatePointTriangle(vert, vertices[0], vertices[1], vertices[2]) == - PtTriLocation::Outside) - { - continue; - } - TriIndVec badTris = resolveEncroachedEdges( - detectEncroachedEdges(vert), - vert, - true, - true, - refinementConstrain, - threshold) - .first; - - for(IndexSizeType i(0); i < TriInd(badTris.size()); ++i) - { - badTriangles.push(badTris[i]); - } - - if(badTris.empty() && numOfSteinerPoints < maxSteinerPoints) - { - const VertInd iVert = static_cast(vertices.size()); - addNewVertex(vert, noNeighbor, true); - insertVertex(iVert); - TriInd start = m_vertTris[iVert]; - TriInd currTri = start; - do - { - const Triangle& t = triangles[currTri]; - if(isBadTriangle(t, refinementConstrain, threshold)) - { - badTriangles.push(currTri); - } - currTri = t.next(iVert).first; - } while(currTri != start); - } - else - { - badTriangles.push(iT); - } - } -} - } // namespace CDT #ifndef CDT_USE_AS_COMPILED_LIBRARY diff --git a/CDT/include/Triangulation.hpp b/CDT/include/Triangulation.hpp index 5b2075f..1c4a0b7 100644 --- a/CDT/include/Triangulation.hpp +++ b/CDT/include/Triangulation.hpp @@ -2330,4 +2330,89 @@ void Triangulation::tryInitNearestPointLocator() } } +template +void Triangulation::refineTriangles( + RefineTriangles::Enum refinementConstrain, + T threshold) +{ + if(isFinalized()) + { + throw std::runtime_error("Triangulation was finalized with 'erase...' " + "method. Refinement is not possible"); + } + tryInitNearestPointLocator(); + resolveEncroachedEdges(detectEncroachedEdges()); + + std::queue badTriangles; + for(TriInd iT(0), n = triangles.size(); iT < n; ++iT) + { + const Triangle& t = triangles[iT]; + if(t.vertices[0] < 3 || t.vertices[1] < 3 || t.vertices[2] < 3) + continue; + + if(isBadTriangle(t, refinementConstrain, threshold)) + { + const V2d vert = circumcenter(t); + if(locatePointTriangle( + vert, vertices[0], vertices[1], vertices[2]) != + PtTriLocation::Outside) + { + badTriangles.push(iT); + } + } + } + + while(!badTriangles.empty()) + { + TriInd iT = badTriangles.front(); + const Triangle& t = triangles[iT]; + badTriangles.pop(); + if(!isBadTriangle(t, refinementConstrain, threshold) || + numOfSteinerPoints >= maxSteinerPoints) + { + continue; + } + const V2d vert = circumcenter(t); + if(locatePointTriangle(vert, vertices[0], vertices[1], vertices[2]) == + PtTriLocation::Outside) + { + continue; + } + TriIndVec badTris = resolveEncroachedEdges( + detectEncroachedEdges(vert), + vert, + true, + true, + refinementConstrain, + threshold) + .first; + + for(IndexSizeType i(0); i < TriInd(badTris.size()); ++i) + { + badTriangles.push(badTris[i]); + } + + if(badTris.empty() && numOfSteinerPoints < maxSteinerPoints) + { + const VertInd iVert = static_cast(vertices.size()); + addNewVertex(vert, noNeighbor, true); + insertVertex(iVert); + TriInd start = m_vertTris[iVert]; + TriInd currTri = start; + do + { + const Triangle& t = triangles[currTri]; + if(isBadTriangle(t, refinementConstrain, threshold)) + { + badTriangles.push(currTri); + } + currTri = t.next(iVert).first; + } while(currTri != start); + } + else + { + badTriangles.push(iT); + } + } +} } // namespace CDT