Ejemplo n.º 1
0
        /// <summary>
        /// Rotates a triangle pair one vertex CW
        ///       n2                    n2
        ///  P +-----+             P +-----+
        ///    | t  /|               |\  t |
        ///    |   / |               | \   |
        ///  n1|  /  |n3           n1|  \  |n3
        ///    | /   |    after CW   |   \ |
        ///    |/ oT |               | oT \|
        ///    +-----+ oP            +-----+
        ///       n4                    n4
        /// </summary>
        private static void RotateTrianglePair(DelaunayTriangle t, TriangulationPoint p, DelaunayTriangle ot, TriangulationPoint op)
        {
            DelaunayTriangle n1 = t.NeighborCCW(p);
            DelaunayTriangle n2 = t.NeighborCW(p);
            DelaunayTriangle n3 = ot.NeighborCCW(op);
            DelaunayTriangle n4 = ot.NeighborCW(op);

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

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

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

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

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

            // Remap neighbors
            // XXX: might optimize the markNeighbor by keeping track of
            //      what side should be assigned to what neighbor after the
            //      rotation. Now mark neighbor does lots of testing to find
            //      the right side.
            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);
        }
Ejemplo n.º 2
0
        private static void FinalizationPolygon(DTSweepContext tcx)
        {
            DelaunayTriangle   delaunayTriangle = tcx.aFront.Head.Next.Triangle;
            TriangulationPoint point            = tcx.aFront.Head.Next.Point;

            while (!delaunayTriangle.GetConstrainedEdgeCW(point))
            {
                delaunayTriangle = delaunayTriangle.NeighborCCW(point);
            }
            tcx.MeshClean(delaunayTriangle);
        }
Ejemplo n.º 3
0
        private static void RotateTrianglePair(DelaunayTriangle t, TriangulationPoint p, DelaunayTriangle ot, TriangulationPoint op)
        {
            DelaunayTriangle delaunayTriangle    = t.NeighborCCW(p);
            DelaunayTriangle delaunayTriangle2   = t.NeighborCW(p);
            DelaunayTriangle delaunayTriangle3   = ot.NeighborCCW(op);
            DelaunayTriangle delaunayTriangle4   = ot.NeighborCW(op);
            bool             constrainedEdgeCCW  = t.GetConstrainedEdgeCCW(p);
            bool             constrainedEdgeCW   = t.GetConstrainedEdgeCW(p);
            bool             constrainedEdgeCCW2 = ot.GetConstrainedEdgeCCW(op);
            bool             constrainedEdgeCW2  = ot.GetConstrainedEdgeCW(op);
            bool             delaunayEdgeCCW     = t.GetDelaunayEdgeCCW(p);
            bool             delaunayEdgeCW      = t.GetDelaunayEdgeCW(p);
            bool             delaunayEdgeCCW2    = ot.GetDelaunayEdgeCCW(op);
            bool             delaunayEdgeCW2     = ot.GetDelaunayEdgeCW(op);

            t.Legalize(p, op);
            ot.Legalize(op, p);
            ot.SetDelaunayEdgeCCW(p, delaunayEdgeCCW);
            t.SetDelaunayEdgeCW(p, delaunayEdgeCW);
            t.SetDelaunayEdgeCCW(op, delaunayEdgeCCW2);
            ot.SetDelaunayEdgeCW(op, delaunayEdgeCW2);
            ot.SetConstrainedEdgeCCW(p, constrainedEdgeCCW);
            t.SetConstrainedEdgeCW(p, constrainedEdgeCW);
            t.SetConstrainedEdgeCCW(op, constrainedEdgeCCW2);
            ot.SetConstrainedEdgeCW(op, constrainedEdgeCW2);
            t.Neighbors.Clear();
            ot.Neighbors.Clear();
            bool flag = delaunayTriangle != null;

            if (flag)
            {
                ot.MarkNeighbor(delaunayTriangle);
            }
            bool flag2 = delaunayTriangle2 != null;

            if (flag2)
            {
                t.MarkNeighbor(delaunayTriangle2);
            }
            bool flag3 = delaunayTriangle3 != null;

            if (flag3)
            {
                t.MarkNeighbor(delaunayTriangle3);
            }
            bool flag4 = delaunayTriangle4 != null;

            if (flag4)
            {
                ot.MarkNeighbor(delaunayTriangle4);
            }
            t.MarkNeighbor(ot);
        }
Ejemplo n.º 4
0
        private static void FinalizationPolygon(DTSweepContext tcx)
        {
            // Get an Internal triangle to start with
            DelaunayTriangle   t = tcx.aFront.Head.Next.Triangle;
            TriangulationPoint p = tcx.aFront.Head.Next.Point;

            while (!t.GetConstrainedEdgeCW(p))
            {
                t = t.NeighborCCW(p);
            }

            // Collect interior triangles constrained by edges
            tcx.MeshClean(t);
        }
Ejemplo n.º 5
0
        private static void EdgeEvent(DTSweepContext tcx, TriangulationPoint ep, TriangulationPoint eq, DelaunayTriangle triangle, TriangulationPoint point)
        {
            if (IsEdgeSideOfTriangle(triangle, ep, eq))
            {
                return;
            }

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

            if (o1 == Orientation.Collinear)
            {
                if (triangle.Contains(eq, p1))
                {
                    triangle.MarkConstrainedEdge(eq, p1);
                    // We are modifying the constraint maybe it would be better to
                    // not change the given constraint and just keep a variable for the new constraint
                    tcx.EdgeEvent.ConstrainedEdge.Q = p1;
                    triangle = triangle.NeighborAcross(point);
                    EdgeEvent(tcx, ep, p1, triangle, p1);
                }
                else
                {
                    throw new PointOnEdgeException("EdgeEvent - Point on constrained edge not supported yet");
                }
                if (tcx.IsDebugEnabled)
                {
                    Debug.WriteLine("EdgeEvent - Point on constrained edge");
                }
                return;
            }

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

            if (o2 == Orientation.Collinear)
            {
                if (triangle.Contains(eq, p2))
                {
                    triangle.MarkConstrainedEdge(eq, p2);
                    // We are modifying the constraint maybe it would be better to
                    // not change the given constraint and just keep a variable for the new constraint
                    tcx.EdgeEvent.ConstrainedEdge.Q = p2;
                    triangle = triangle.NeighborAcross(point);
                    EdgeEvent(tcx, ep, p2, triangle, p2);
                }
                else
                {
                    throw new PointOnEdgeException("EdgeEvent - Point on constrained edge not supported yet");
                }
                if (tcx.IsDebugEnabled)
                {
                    Debug.WriteLine("EdgeEvent - Point on constrained edge");
                }
                return;
            }

            if (o1 == o2)
            {
                // Need to decide if we are rotating CW or CCW to get to a triangle
                // that will cross edge
                if (o1 == Orientation.CW)
                {
                    triangle = triangle.NeighborCCW(point);
                }
                else
                {
                    triangle = triangle.NeighborCW(point);
                }
                EdgeEvent(tcx, ep, eq, triangle, point);
            }
            else
            {
                // This triangle crosses constraint so lets flippin start!
                FlipEdgeEvent(tcx, ep, eq, triangle, point);
            }
        }
Ejemplo n.º 6
0
        private static void EdgeEvent(DTSweepContext tcx, TriangulationPoint ep, TriangulationPoint eq, DelaunayTriangle triangle, TriangulationPoint point)
        {
            bool flag = DTSweep.IsEdgeSideOfTriangle(triangle, ep, eq);

            if (!flag)
            {
                TriangulationPoint triangulationPoint = triangle.PointCCW(point);
                Orientation        orientation        = TriangulationUtil.Orient2d(eq, triangulationPoint, ep);
                bool flag2 = orientation == Orientation.Collinear;
                if (flag2)
                {
                    bool flag3 = triangle.Contains(eq, triangulationPoint);
                    if (!flag3)
                    {
                        throw new PointOnEdgeException("EdgeEvent - Point on constrained edge not supported yet");
                    }
                    triangle.MarkConstrainedEdge(eq, triangulationPoint);
                    tcx.EdgeEvent.ConstrainedEdge.Q = triangulationPoint;
                    triangle = triangle.NeighborAcross(point);
                    DTSweep.EdgeEvent(tcx, ep, triangulationPoint, triangle, triangulationPoint);
                    bool isDebugEnabled = tcx.IsDebugEnabled;
                    if (isDebugEnabled)
                    {
                        Debug.WriteLine("EdgeEvent - Point on constrained edge");
                    }
                }
                else
                {
                    TriangulationPoint triangulationPoint2 = triangle.PointCW(point);
                    Orientation        orientation2        = TriangulationUtil.Orient2d(eq, triangulationPoint2, ep);
                    bool flag4 = orientation2 == Orientation.Collinear;
                    if (flag4)
                    {
                        bool flag5 = triangle.Contains(eq, triangulationPoint2);
                        if (!flag5)
                        {
                            throw new PointOnEdgeException("EdgeEvent - Point on constrained edge not supported yet");
                        }
                        triangle.MarkConstrainedEdge(eq, triangulationPoint2);
                        tcx.EdgeEvent.ConstrainedEdge.Q = triangulationPoint2;
                        triangle = triangle.NeighborAcross(point);
                        DTSweep.EdgeEvent(tcx, ep, triangulationPoint2, triangle, triangulationPoint2);
                        bool isDebugEnabled2 = tcx.IsDebugEnabled;
                        if (isDebugEnabled2)
                        {
                            Debug.WriteLine("EdgeEvent - Point on constrained edge");
                        }
                    }
                    else
                    {
                        bool flag6 = orientation == orientation2;
                        if (flag6)
                        {
                            bool flag7 = orientation == Orientation.CW;
                            if (flag7)
                            {
                                triangle = triangle.NeighborCCW(point);
                            }
                            else
                            {
                                triangle = triangle.NeighborCW(point);
                            }
                            DTSweep.EdgeEvent(tcx, ep, eq, triangle, point);
                        }
                        else
                        {
                            DTSweep.FlipEdgeEvent(tcx, ep, eq, triangle, point);
                        }
                    }
                }
            }
        }