Exemple #1
0
 public bool Contains(TriangulationPoint p)
 {
     return(Points.Contains(p));
 }
Exemple #2
0
        private static void FlipScanEdgeEvent(DTSweepContext tcx, TriangulationPoint ep, TriangulationPoint eq, DelaunayTriangle flipTriangle, DelaunayTriangle t, TriangulationPoint p)
        {
            DelaunayTriangle   ot;
            TriangulationPoint op, newP;
            bool inScanArea;

            ot = t.NeighborAcrossFrom(p);
            op = ot.OppositePoint(t, p);

            if (ot == null)
            {
                throw new Exception("FLIP failed due to missing triangle");
            }

            if (tcx.IsDebugEnabled)
            {
                Console.WriteLine("scan next point");
                tcx.DTDebugContext.PrimaryTriangle   = t;
                tcx.DTDebugContext.SecondaryTriangle = ot;
            }

            inScanArea = TriangulationUtil.InScanArea(eq, flipTriangle.PointCCWFrom(eq), flipTriangle.PointCWFrom(eq), op);
            if (inScanArea)
            {
                FlipEdgeEvent(tcx, eq, op, ot, op);
            }
            else
            {
                if (NextFlipPoint(ep, eq, ot, op, out newP))
                {
                    FlipScanEdgeEvent(tcx, ep, eq, flipTriangle, ot, newP);
                }
            }
        }
Exemple #3
0
 public DelaunayTriangle NeighborCCWFrom(TriangulationPoint point)
 {
     return(Neighbors[(Points.IndexOf(point) + 2) % 3]);
 }
Exemple #4
0
        private static void EdgeEvent(DTSweepContext tcx, TriangulationPoint ep, TriangulationPoint eq, DelaunayTriangle triangle, TriangulationPoint point)
        {
            TriangulationPoint p1, p2;

            if (tcx.IsDebugEnabled)
            {
                tcx.DTDebugContext.PrimaryTriangle = triangle;
            }

            if (IsEdgeSideOfTriangle(triangle, ep, eq))
            {
                return;
            }

            p1 = triangle.PointCCWFrom(point);
            Orientation o1 = TriangulationUtil.Orient2d(eq, p1, ep);

            if (o1 == Orientation.Collinear)
            {
                if (triangle.Contains(eq) && triangle.Contains(p1))
                {
                    triangle.MarkConstrainedEdge(eq, p1);

                    tcx.EdgeEvent.ConstrainedEdge.Q = p1;
                    triangle = triangle.NeighborAcrossFrom(point);
                    EdgeEvent(tcx, ep, p1, triangle, p1);
                }
                else
                {
                    throw new PointOnEdgeException("EdgeEvent - Point on constrained edge not supported yet", ep, eq, p1);
                }
                if (tcx.IsDebugEnabled)
                {
                    Console.WriteLine("EdgeEvent - Point on constrained edge");
                }

                return;
            }

            p2 = triangle.PointCWFrom(point);
            Orientation o2 = TriangulationUtil.Orient2d(eq, p2, ep);

            if (o2 == Orientation.Collinear)
            {
                if (triangle.Contains(eq) && triangle.Contains(p2))
                {
                    triangle.MarkConstrainedEdge(eq, p2);

                    tcx.EdgeEvent.ConstrainedEdge.Q = p2;
                    triangle = triangle.NeighborAcrossFrom(point);
                    EdgeEvent(tcx, ep, p2, triangle, p2);
                }
                else
                {
                    throw new PointOnEdgeException("EdgeEvent - Point on constrained edge not supported yet", ep, eq, p2);
                }
                if (tcx.IsDebugEnabled)
                {
                    Console.WriteLine("EdgeEvent - Point on constrained edge");
                }

                return;
            }

            if (o1 == o2)
            {
                if (o1 == Orientation.CW)
                {
                    triangle = triangle.NeighborCCWFrom(point);
                }
                else
                {
                    triangle = triangle.NeighborCWFrom(point);
                }
                EdgeEvent(tcx, ep, eq, triangle, point);
            }
            else
            {
                FlipEdgeEvent(tcx, ep, eq, triangle, point);
            }
        }
Exemple #5
0
        private static bool NextFlipPoint(TriangulationPoint ep, TriangulationPoint eq, DelaunayTriangle ot, TriangulationPoint op, out TriangulationPoint newP)
        {
            newP = null;
            Orientation o2d = TriangulationUtil.Orient2d(eq, op, ep);

            switch (o2d)
            {
            case Orientation.CW:
                newP = ot.PointCCWFrom(op);
                return(true);

            case Orientation.CCW:
                newP = ot.PointCWFrom(op);
                return(true);

            case Orientation.Collinear:
                return(false);

            default:
                throw new NotImplementedException("Orientation not handled");
            }
        }
Exemple #6
0
 public PointOnEdgeException(string message, TriangulationPoint a, TriangulationPoint b, TriangulationPoint c) : base(message)
 {
     A = a;
     B = b;
     C = c;
 }
Exemple #7
0
 public override TriangulationConstraint NewConstraint(TriangulationPoint a, TriangulationPoint b)
 {
     return(new DTSweepConstraint(a, b));
 }
Exemple #8
0
 public bool GetConstrainedEdgeAcross(TriangulationPoint p)
 {
     return(EdgeIsConstrained[IndexOf(p)]);
 }
Exemple #9
0
        public void SetConstrainedEdgeCW(TriangulationPoint p, bool ce)
        {
            int idx = (IndexOf(p) + 1) % 3;

            SetConstrainedEdge(idx, ce);
        }
Exemple #10
0
 public DelaunayTriangle(TriangulationPoint p1, TriangulationPoint p2, TriangulationPoint p3)
 {
     Points[0] = p1;
     Points[1] = p2;
     Points[2] = p3;
 }
Exemple #11
0
 public bool GetConstrainedEdgeCW(TriangulationPoint p)
 {
     return(EdgeIsConstrained[(IndexOf(p) + 1) % 3]);
 }
Exemple #12
0
 public void Legalize(TriangulationPoint oPoint, TriangulationPoint nPoint)
 {
     RotateCW();
     Points[IndexCCWFrom(oPoint)] = nPoint;
 }
Exemple #13
0
 public TriangulationPoint PointCWFrom(TriangulationPoint point)
 {
     return(Points[(IndexOf(point) + 2) % 3]);
 }
Exemple #14
0
 public DelaunayTriangle NeighborAcrossFrom(TriangulationPoint point)
 {
     return(Neighbors[Points.IndexOf(point)]);
 }
Exemple #15
0
 public AdvancingFrontNode(TriangulationPoint point)
 {
     this.Point = point;
     Value      = point.X;
 }
Exemple #16
0
        public void SetConstrainedEdgeAcross(TriangulationPoint p, bool ce)
        {
            int idx = IndexOf(p);

            SetConstrainedEdge(idx, ce);
        }
Exemple #17
0
 public DTSweepConstraint(TriangulationPoint p1, TriangulationPoint p2) : base(p1, p2)
 {
     Q.AddEdge(this);
 }
Exemple #18
0
 public bool GetDelaunayEdgeCW(TriangulationPoint p)
 {
     return(EdgeIsDelaunay[(IndexOf(p) + 1) % 3]);
 }
Exemple #19
0
 public AdvancingFrontNode LocateNode(TriangulationPoint point)
 {
     return(Front.LocateNode(point));
 }
Exemple #20
0
 public bool GetDelaunayEdgeAcross(TriangulationPoint p)
 {
     return(EdgeIsDelaunay[IndexOf(p)]);
 }
Exemple #21
0
        private static bool IsEdgeSideOfTriangle(DelaunayTriangle triangle, TriangulationPoint ep, TriangulationPoint eq)
        {
            int index = triangle.EdgeIndex(ep, eq);

            if (index == -1)
            {
                return(false);
            }
            triangle.MarkConstrainedEdge(index);
            triangle = triangle.Neighbors[index];
            if (triangle != null)
            {
                triangle.MarkConstrainedEdge(ep, eq);
            }
            return(true);
        }
Exemple #22
0
 public void SetDelaunayEdgeCW(TriangulationPoint p, bool ce)
 {
     EdgeIsDelaunay[(IndexOf(p) + 1) % 3] = ce;
 }
Exemple #23
0
        private static void FlipEdgeEvent(DTSweepContext tcx, TriangulationPoint ep, TriangulationPoint eq, DelaunayTriangle t, TriangulationPoint p)
        {
            DelaunayTriangle   ot = t.NeighborAcrossFrom(p);
            TriangulationPoint op = ot.OppositePoint(t, p);

            if (ot == null)
            {
                throw new InvalidOperationException("[BUG:FIXME] FLIP failed due to missing triangle");
            }

            if (tcx.IsDebugEnabled)
            {
                tcx.DTDebugContext.PrimaryTriangle   = t;
                tcx.DTDebugContext.SecondaryTriangle = ot;
            }

            bool inScanArea = TriangulationUtil.InScanArea(p, t.PointCCWFrom(p), t.PointCWFrom(p), op);

            if (inScanArea)
            {
                RotateTrianglePair(t, p, ot, op);
                tcx.MapTriangleToNodes(t);
                tcx.MapTriangleToNodes(ot);

                if (p == eq && op == ep)
                {
                    if (eq == tcx.EdgeEvent.ConstrainedEdge.Q && ep == tcx.EdgeEvent.ConstrainedEdge.P)
                    {
                        if (tcx.IsDebugEnabled)
                        {
                            Console.WriteLine("[FLIP] - constrained edge done");
                        }
                        t.MarkConstrainedEdge(ep, eq);
                        ot.MarkConstrainedEdge(ep, eq);
                        Legalize(tcx, t);
                        Legalize(tcx, ot);
                    }
                    else
                    {
                        if (tcx.IsDebugEnabled)
                        {
                            Console.WriteLine("[FLIP] - subedge done");
                        }
                    }
                }
                else
                {
                    Orientation o = TriangulationUtil.Orient2d(eq, op, ep);
                    t = NextFlipTriangle(tcx, o, t, ot, p, op);
                    FlipEdgeEvent(tcx, ep, eq, t, p);
                }
            }
            else
            {
                TriangulationPoint newP = null;
                if (NextFlipPoint(ep, eq, ot, op, out newP))
                {
                    FlipScanEdgeEvent(tcx, ep, eq, t, ot, newP);
                    EdgeEvent(tcx, ep, eq, t, p);
                }
            }
        }
Exemple #24
0
 public void SetDelaunayEdgeAcross(TriangulationPoint p, bool ce)
 {
     EdgeIsDelaunay[IndexOf(p)] = ce;
 }
Exemple #25
0
        private static DelaunayTriangle NextFlipTriangle(DTSweepContext tcx, Orientation o, DelaunayTriangle t, DelaunayTriangle ot, TriangulationPoint p, TriangulationPoint op)
        {
            int edgeIndex;

            if (o == Orientation.CCW)
            {
                edgeIndex = ot.EdgeIndex(p, op);
                ot.EdgeIsDelaunay[edgeIndex] = true;
                Legalize(tcx, ot);
                ot.EdgeIsDelaunay.Clear();
                return(t);
            }
            edgeIndex = t.EdgeIndex(p, op);
            t.EdgeIsDelaunay[edgeIndex] = true;
            Legalize(tcx, t);
            t.EdgeIsDelaunay.Clear();
            return(ot);
        }
Exemple #26
0
 public int IndexCCWFrom(TriangulationPoint p)
 {
     return((IndexOf(p) + 1) % 3);
 }
Exemple #27
0
        private static void RotateTrianglePair(DelaunayTriangle t, TriangulationPoint p, DelaunayTriangle ot, TriangulationPoint op)
        {
            DelaunayTriangle n1, n2, n3, n4;

            n1 = t.NeighborCCWFrom(p);
            n2 = t.NeighborCWFrom(p);
            n3 = ot.NeighborCCWFrom(op);
            n4 = ot.NeighborCWFrom(op);

            bool ce1, ce2, ce3, ce4;

            ce1 = t.GetConstrainedEdgeCCW(p);
            ce2 = t.GetConstrainedEdgeCW(p);
            ce3 = ot.GetConstrainedEdgeCCW(op);
            ce4 = ot.GetConstrainedEdgeCW(op);

            bool de1, de2, de3, de4;

            de1 = t.GetDelaunayEdgeCCW(p);
            de2 = t.GetDelaunayEdgeCW(p);
            de3 = ot.GetDelaunayEdgeCCW(op);
            de4 = ot.GetDelaunayEdgeCW(op);

            t.Legalize(p, op);
            ot.Legalize(op, p);

            ot.SetDelaunayEdgeCCW(p, de1);
            t.SetDelaunayEdgeCW(p, de2);
            t.SetDelaunayEdgeCCW(op, de3);
            ot.SetDelaunayEdgeCW(op, de4);

            ot.SetConstrainedEdgeCCW(p, ce1);
            t.SetConstrainedEdgeCW(p, ce2);
            t.SetConstrainedEdgeCCW(op, ce3);
            ot.SetConstrainedEdgeCW(op, ce4);

            t.Neighbors.Clear();
            ot.Neighbors.Clear();
            if (n1 != null)
            {
                ot.MarkNeighbor(n1);
            }
            if (n2 != null)
            {
                t.MarkNeighbor(n2);
            }
            if (n3 != null)
            {
                t.MarkNeighbor(n3);
            }
            if (n4 != null)
            {
                ot.MarkNeighbor(n4);
            }
            t.MarkNeighbor(ot);
        }
Exemple #28
0
 public TriangulationPoint OppositePoint(DelaunayTriangle t, TriangulationPoint p)
 {
     Debug.Assert(t != this, "self-pointer error");
     return(PointCWFrom(t.PointCWFrom(p)));
 }