Skip to content

Commit

Permalink
refactor: bw add tid min visited
Browse files Browse the repository at this point in the history
Adds `tIdMinVisited` in Bower-Watson algorithm, which allows for removal BadTriangles sorting instruction.
  • Loading branch information
andywiecko committed Nov 17, 2024
1 parent 638c4a7 commit 986db2b
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions Runtime/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,8 @@ public struct UnsafeBowerWatson
public NativeList<int> PathHalfedges;
public NativeList<bool> VisitedTriangles;

private int tIdMinVisited;

private int UnsafeInsertPointCommon(T2 p, int initTriangle)
{
var pId = Output.Positions.Length;
Expand All @@ -3170,14 +3172,10 @@ private int UnsafeInsertPointCommon(T2 p, int initTriangle)
TrianglesQueue.Clear();
PathPoints.Clear();
PathHalfedges.Clear();

VisitedTriangles.Clear();
VisitedTriangles.Length = Output.Triangles.Length / 3;

TrianglesQueue.Enqueue(initTriangle);
BadTriangles.Add(initTriangle);
VisitedTriangles[initTriangle] = true;
RecalculateBadTriangles(p);
RecalculateBadTriangles(p, initTriangle);

return pId;
}
Expand All @@ -3201,10 +3199,15 @@ public int UnsafeInsertPointBoundary(T2 p, int initHe, NativeList<int> heQueue =
return PathPoints.Length;
}

private void RecalculateBadTriangles(T2 p)
private void RecalculateBadTriangles(T2 p, int initTriangle)
{
var triangles = Output.Triangles;

TrianglesQueue.Enqueue(initTriangle);
BadTriangles.Add(initTriangle);
VisitedTriangles[initTriangle] = true;
tIdMinVisited = initTriangle;

while (TrianglesQueue.TryDequeue(out var tId))
{
for (int i = 0; i < 3; i++)
Expand All @@ -3222,6 +3225,7 @@ private void RecalculateBadTriangles(T2 p)
BadTriangles.Add(otherId);
TrianglesQueue.Enqueue(otherId);
VisitedTriangles[otherId] = true;
tIdMinVisited = math.min(tIdMinVisited, otherId);
}
}
}
Expand Down Expand Up @@ -3303,11 +3307,6 @@ static void AdaptHe(NativeList<int> halfedges, int he, int rId, int wId)
}
}

if (BadTriangles.IsEmpty)
{
return;
}

var triangles = Output.Triangles;
var halfedges = Output.Halfedges;
var constrainedHalfedges = Output.ConstrainedHalfedges;
Expand All @@ -3316,14 +3315,8 @@ static void AdaptHe(NativeList<int> halfedges, int he, int rId, int wId)
var constrainedHalfedges3 = constrainedHalfedges.AsArray().Reinterpret<bool3>(1);
var triangles3 = triangles.AsArray().Reinterpret<int3>(4);

// TODO:
// This is required for proper adapt heQueue, tQueue.
// This instruction, as well as, `BadTriangles` buffer
// will be eliminated in the future entirely.
BadTriangles.Sort();

var wId = BadTriangles[0];
for (int rId = BadTriangles[0]; rId < triangles3.Length; rId++)
var wId = tIdMinVisited;
for (int rId = tIdMinVisited; rId < triangles3.Length; rId++)
{
if (!VisitedTriangles[rId])
{
Expand Down

0 comments on commit 986db2b

Please sign in to comment.