Skip to content

Commit

Permalink
#7 Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-ogre committed Oct 6, 2023
1 parent 248ed51 commit c2e00df
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CDT/include/CDTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ inline Edge edge_make(VertInd iV1, VertInd iV2)
}

typedef std::vector<Edge> EdgeVec; ///< Vector of edges
typedef std::queue<Edge> EdgeQue; ///< Queue of edges
typedef std::queue<Edge> EdgeQueue; ///< Queue of edges
typedef unordered_set<Edge> EdgeUSet; ///< Hash table of edges
typedef unordered_set<TriInd> TriIndUSet; ///< Hash table of triangles
typedef unordered_map<TriInd, TriInd> TriIndUMap; ///< Triangle hash map
Expand Down
6 changes: 3 additions & 3 deletions CDT/include/Triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,15 @@ class CDT_EXPORT Triangulation
/// Search in all fixed edges to find encroached edges, each fixed edge is
/// checked against its opposite vertices
/// Returns queue of encroached edges
EdgeQue detectEncroachedEdges();
EdgeQueue detectEncroachedEdges();
/// Search in all fixed edges to find encroached edges, each fixed edge is
/// checked against its opposite vertices and vertex v
/// Returns queue of encroached edges
EdgeQue detectEncroachedEdges(const V2d<T>& v);
EdgeQueue detectEncroachedEdges(const V2d<T>& v);
/// Recursively split encroached edges
/// @return vector of badly shaped triangles
TriIndVec resolveEncroachedEdges(
EdgeQue encroachedEdges,
EdgeQueue encroachedEdges,
VertInd& newVertBudget,
VertInd steinerVerticesOffset,
const V2d<T>* circumcenterOrNull = NULL,
Expand Down
54 changes: 25 additions & 29 deletions CDT/include/Triangulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,24 +1250,21 @@ bool Triangulation<T, TNearPointLocator>::isRefinementNeeded(
}

template <typename T, typename TNearPointLocator>
EdgeQue Triangulation<T, TNearPointLocator>::detectEncroachedEdges()
EdgeQueue Triangulation<T, TNearPointLocator>::detectEncroachedEdges()
{
// Search in all fixed edges to find encroached edges, each fixed edge is
// checked against its opposite vertices
// Returns queue of encroached edges
EdgeQue encroachedEdges;
for(EdgeUSet::const_iterator cit = fixedEdges.begin();
cit != fixedEdges.end();
++cit)
EdgeQueue encroachedEdges;
typedef EdgeUSet::const_iterator Iter;
for(Iter it = fixedEdges.begin(); it != fixedEdges.end(); ++it)
{
const Edge edge = *cit;
const Edge edge = *it;
TriInd iT, iTopo;
std::tie(iT, iTopo) = edgeTriangles(edge.v1(), edge.v2());
assert(iT != invalidIndex && iTopo != invalidIndex);
const Triangle& t = triangles[iT];
const Triangle& tOpo = triangles[iTopo];
VertInd v1 = opposedVertex(t, iTopo);
VertInd v2 = opposedVertex(tOpo, iT);
const VertInd v1 = opposedVertex(triangles[iT], iTopo);
const VertInd v2 = opposedVertex(triangles[iTopo], iT);
const V2d<T>& edgeStart = vertices[edge.v1()];
const V2d<T>& edgeEnd = vertices[edge.v2()];
if(isEncroachingOnEdge(vertices[v1], edgeStart, edgeEnd) ||
Expand All @@ -1280,18 +1277,17 @@ EdgeQue Triangulation<T, TNearPointLocator>::detectEncroachedEdges()
}

template <typename T, typename TNearPointLocator>
EdgeQue
EdgeQueue
Triangulation<T, TNearPointLocator>::detectEncroachedEdges(const V2d<T>& v)
{
// Search in all fixed edges to find encroached edges, each fixed edge is
// checked against its opposite vertices and vertex v
// Returns queue of encroached edges
EdgeQue encroachedEdges;
for(EdgeUSet::const_iterator cit = fixedEdges.begin();
cit != fixedEdges.end();
++cit)
EdgeQueue encroachedEdges;
typedef EdgeUSet::const_iterator Iter;
for(Iter it = fixedEdges.begin(); it != fixedEdges.end(); ++it)
{
const Edge edge = *cit;
const Edge edge = *it;
if(isEncroachingOnEdge(v, vertices[edge.v1()], vertices[edge.v2()]))
{
encroachedEdges.push(edge);
Expand All @@ -1302,8 +1298,8 @@ Triangulation<T, TNearPointLocator>::detectEncroachedEdges(const V2d<T>& v)

template <typename T, typename TNearPointLocator>
TriIndVec Triangulation<T, TNearPointLocator>::resolveEncroachedEdges(
EdgeQue encroachedEdges,
VertInd& newVertBudget,
EdgeQueue encroachedEdges,
VertInd& remainingVertexBudget,
const VertInd steinerVerticesOffset,
const V2d<T>* const circumcenterOrNull,
const RefinementCriterion::Enum refinementCriterion,
Expand All @@ -1312,9 +1308,9 @@ TriIndVec Triangulation<T, TNearPointLocator>::resolveEncroachedEdges(
IndexSizeType numOfSplits = 0;
std::vector<TriInd> badTriangles;

while(!encroachedEdges.empty() && newVertBudget > 0)
while(!encroachedEdges.empty() && remainingVertexBudget > 0)
{
Edge edge = encroachedEdges.front();
const Edge edge = encroachedEdges.front();
encroachedEdges.pop();
if(!hasEdge(edge.v1(), edge.v2()))
{
Expand All @@ -1325,9 +1321,9 @@ TriIndVec Triangulation<T, TNearPointLocator>::resolveEncroachedEdges(
assert(iT != invalidIndex && iTopo != invalidIndex);
const VertInd i =
splitEncroachedEdge(edge, iT, iTopo, steinerVerticesOffset);
--newVertBudget;
--remainingVertexBudget;

TriInd start = m_vertTris[i];
const TriInd start = m_vertTris[i];
TriInd currTri = start;
do
{
Expand Down Expand Up @@ -1384,7 +1380,7 @@ VertInd Triangulation<T, TNearPointLocator>::splitEncroachedEdge(
// that introduces FP rounding erros, so it's avoided.
const T len = distance(start, end);
const T d = T(0.5) * len;
// Find the splitting distance.
// Find the splitting distance
T nearestPowerOfTwo = T(1);
while(d > nearestPowerOfTwo)
{
Expand All @@ -1399,7 +1395,7 @@ VertInd Triangulation<T, TNearPointLocator>::splitEncroachedEdge(
if(splitEdge.v1() >= steinerVerticesOffset)
split = T(1) - split;
}
V2d<T> mid = V2d<T>::make(
const V2d<T> mid = V2d<T>::make(
detail::lerp(start.x, end.x, split),
detail::lerp(start.y, end.y, split));

Expand Down Expand Up @@ -2246,10 +2242,10 @@ void Triangulation<T, TNearPointLocator>::refineTriangles(
}
tryInitNearestPointLocator();

VertInd newVertBudget = maxVerticesToInsert;
VertInd remainingVertexBudget = maxVerticesToInsert;
const VertInd steinerVerticesOffset = vertices.size();
resolveEncroachedEdges(
detectEncroachedEdges(), newVertBudget, steinerVerticesOffset);
detectEncroachedEdges(), remainingVertexBudget, steinerVerticesOffset);

std::queue<TriInd> badTriangles;
for(TriInd iT(0), n = triangles.size(); iT < n; ++iT)
Expand Down Expand Up @@ -2279,7 +2275,7 @@ void Triangulation<T, TNearPointLocator>::refineTriangles(
const Triangle& t = triangles[iT];
badTriangles.pop();
if(!isRefinementNeeded(t, refinementCriterion, refinementThreshold) ||
newVertBudget == 0)
remainingVertexBudget == 0)
{
continue;
}
Expand All @@ -2295,7 +2291,7 @@ void Triangulation<T, TNearPointLocator>::refineTriangles(

const TriIndVec badTris = resolveEncroachedEdges(
detectEncroachedEdges(vert),
newVertBudget,
remainingVertexBudget,
steinerVerticesOffset,
&vert,
refinementCriterion,
Expand All @@ -2305,7 +2301,7 @@ void Triangulation<T, TNearPointLocator>::refineTriangles(
badTriangles.push(badTris[i]);
}

if(badTris.empty() && newVertBudget > 0)
if(badTris.empty() && remainingVertexBudget > 0)
{
const VertInd iVert = static_cast<VertInd>(vertices.size());
addNewVertex(vert, noNeighbor);
Expand Down

0 comments on commit c2e00df

Please sign in to comment.