Skip to content

Commit

Permalink
mv refineTriangles into .hpp file
Browse files Browse the repository at this point in the history
  • Loading branch information
Islam0mar authored and artem-ogre committed Sep 29, 2023
1 parent b5c4380 commit 61309ef
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 87 deletions.
87 changes: 0 additions & 87 deletions CDT/include/Triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,93 +802,6 @@ void Triangulation<T, TNearPointLocator>::conformToEdges(
}
eraseDummies();
}

template <typename T, typename TNearPointLocator>
void Triangulation<T, TNearPointLocator>::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<TriInd> 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<T> 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<T> 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<VertInd>(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
Expand Down
85 changes: 85 additions & 0 deletions CDT/include/Triangulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2330,4 +2330,89 @@ void Triangulation<T, TNearPointLocator>::tryInitNearestPointLocator()
}
}

template <typename T, typename TNearPointLocator>
void Triangulation<T, TNearPointLocator>::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<TriInd> 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<T> 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<T> 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<VertInd>(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

0 comments on commit 61309ef

Please sign in to comment.