/// <summary> /// If this is a Delaunay Triangulation of a pointset we need to fill so the triangle mesh gets a ConvexHull /// </summary> private static void FinalizationConvexHull(DTSweepContext tcx) { DelaunayTriangle t1, t2; AdvancingFrontNode n1 = tcx.aFront.Head.Next; AdvancingFrontNode n2 = n1.Next; TurnAdvancingFrontConvex(tcx, n1, n2); // TODO: implement ConvexHull for lower right and left boundary // Lets remove triangles connected to the two "algorithm" points // XXX: When the first the nodes are points in a triangle we need to do a flip before // removing triangles or we will lose a valid triangle. // Same for last three nodes! // !!! If I implement ConvexHull for lower right and left boundary this fix should not be // needed and the removed triangles will be added again by default n1 = tcx.aFront.Tail.Prev; if (n1.Triangle.Contains(n1.Next.Point) && n1.Triangle.Contains(n1.Prev.Point)) { t1 = n1.Triangle.NeighborAcross(n1.Point); RotateTrianglePair(n1.Triangle, n1.Point, t1, t1.OppositePoint(n1.Triangle, n1.Point)); tcx.MapTriangleToNodes(n1.Triangle); tcx.MapTriangleToNodes(t1); } n1 = tcx.aFront.Head.Next; if (n1.Triangle.Contains(n1.Prev.Point) && n1.Triangle.Contains(n1.Next.Point)) { t1 = n1.Triangle.NeighborAcross(n1.Point); RotateTrianglePair(n1.Triangle, n1.Point, t1, t1.OppositePoint(n1.Triangle, n1.Point)); tcx.MapTriangleToNodes(n1.Triangle); tcx.MapTriangleToNodes(t1); } // Lower right boundary TriangulationPoint first = tcx.aFront.Head.Point; n2 = tcx.aFront.Tail.Prev; t1 = n2.Triangle; TriangulationPoint p1 = n2.Point; n2.Triangle = null; do { tcx.RemoveFromList(t1); p1 = t1.PointCCW(p1); if (p1 == first) break; t2 = t1.NeighborCCW(p1); t1.Clear(); t1 = t2; } while (true); // Lower left boundary first = tcx.aFront.Head.Next.Point; p1 = t1.PointCW(tcx.aFront.Head.Point); t2 = t1.NeighborCW(tcx.aFront.Head.Point); t1.Clear(); t1 = t2; while (p1 != first) //TODO: Port note. This was do while before. { tcx.RemoveFromList(t1); p1 = t1.PointCCW(p1); t2 = t1.NeighborCCW(p1); t1.Clear(); t1 = t2; } // Remove current head and tail node now that we have removed all triangles attached // to them. Then set new head and tail node points tcx.aFront.Head = tcx.aFront.Head.Next; tcx.aFront.Head.Prev = null; tcx.aFront.Tail = tcx.aFront.Tail.Prev; tcx.aFront.Tail.Next = null; tcx.FinalizeTriangulation(); }
/// <summary> /// If this is a Delaunay Triangulation of a pointset we need to fill so the triangle mesh gets a ConvexHull /// </summary> static void FinalizationConvexHull(DTSweepContext tcx) { DelaunayTriangle t1, t2; AdvancingFrontNode n1 = tcx.aFront.Head.Next; AdvancingFrontNode n2 = n1.Next; TurnAdvancingFrontConvex(tcx, n1, n2); // TODO: implement ConvexHull for lower right and left boundary // Lets remove triangles connected to the two "algorithm" points // XXX: When the first the nodes are points in a triangle we need to do a flip before // removing triangles or we will lose a valid triangle. // Same for last three nodes! // !!! If I implement ConvexHull for lower right and left boundary this fix should not be // needed and the removed triangles will be added again by default n1 = tcx.aFront.Tail.Prev; if (n1.Triangle.Contains(n1.Next.Point) && n1.Triangle.Contains(n1.Prev.Point)) { t1 = n1.Triangle.NeighborAcross(n1.Point); RotateTrianglePair(n1.Triangle, n1.Point, t1, t1.OppositePoint(n1.Triangle, n1.Point)); tcx.MapTriangleToNodes(n1.Triangle); tcx.MapTriangleToNodes(t1); } n1 = tcx.aFront.Head.Next; if (n1.Triangle.Contains(n1.Prev.Point) && n1.Triangle.Contains(n1.Next.Point)) { t1 = n1.Triangle.NeighborAcross(n1.Point); RotateTrianglePair(n1.Triangle, n1.Point, t1, t1.OppositePoint(n1.Triangle, n1.Point)); tcx.MapTriangleToNodes(n1.Triangle); tcx.MapTriangleToNodes(t1); } // Lower right boundary TriangulationPoint first = tcx.aFront.Head.Point; n2 = tcx.aFront.Tail.Prev; t1 = n2.Triangle; TriangulationPoint p1 = n2.Point; n2.Triangle = null; do { tcx.RemoveFromList(t1); p1 = t1.PointCCW(p1); if (p1 == first) { break; } t2 = t1.NeighborCCW(p1); t1.Clear(); t1 = t2; } while(true); // Lower left boundary first = tcx.aFront.Head.Next.Point; p1 = t1.PointCW(tcx.aFront.Head.Point); t2 = t1.NeighborCW(tcx.aFront.Head.Point); t1.Clear(); t1 = t2; while (p1 != first) //TODO: Port note. This was do while before. { tcx.RemoveFromList(t1); p1 = t1.PointCCW(p1); t2 = t1.NeighborCCW(p1); t1.Clear(); t1 = t2; } // Remove current head and tail node now that we have removed all triangles attached // to them. Then set new head and tail node points tcx.aFront.Head = tcx.aFront.Head.Next; tcx.aFront.Head.Prev = null; tcx.aFront.Tail = tcx.aFront.Tail.Prev; tcx.aFront.Tail.Next = null; tcx.FinalizeTriangulation(); }