Exemplo n.º 1
0
        private static bool isEdgeSideOfTriangle(DelaunayTriangle triangle,
                                                 TriangulationPoint ep,
                                                 TriangulationPoint eq)
        {
            int index;

            index = triangle.edgeIndex(ep, eq);
            if (index != -1)
            {
                triangle.markConstrainedEdge(index);
                triangle = triangle.neighbors[index];
                if (triangle != null)
                {
                    triangle.markConstrainedEdge(ep, eq);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public void markEdge(DelaunayTriangle triangle)
        {
            for (int i = 0; i < 3; i++)
            {
                if (cEdge[i])
                {
                    switch (i)
                    {
                    case 0:
                        triangle.markConstrainedEdge(points[1], points[2]);
                        break;

                    case 1:
                        triangle.markConstrainedEdge(points[0], points[2]);
                        break;

                    case 2:
                        triangle.markConstrainedEdge(points[0], points[1]);
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static void flipEdgeEvent(DTSweepContext tcx,
                                          TriangulationPoint ep,
                                          TriangulationPoint eq,
                                          DelaunayTriangle t,
                                          TriangulationPoint p)
        {
            TriangulationPoint op, newP;
            DelaunayTriangle   ot;
            bool _inScanArea;

            ot = t.neighborAcross(p);
            op = ot.oppositePoint(t, p);

            if (ot == null)
            {
                // If we want to integrate the fillEdgeEvent do it here
                // With current implementation we should never get here
                throw new Exception("[BUG:FIXME] FLIP failed due to missing triangle");
            }

            if (t.getConstrainedEdgeAcross(p))
            {
                throw new Exception("Intersecting Constraints");
            }

            if (tcx.isDebugEnabled())
            {
                tcx.getDebugContext().setPrimaryTriangle(t);
                tcx.getDebugContext().setSecondaryTriangle(ot);
            } // TODO: remove

            _inScanArea = inScanArea(p,
                                     t.pointCCW(p),
                                     t.pointCW(p),
                                     op);
            if (_inScanArea)
            {
                // Lets rotate shared edge one vertex CW
                rotateTrianglePair(t, p, ot, op);
                tcx.mapTriangleToNodes(t);
                tcx.mapTriangleToNodes(ot);

                if (p == eq && op == ep)
                {
                    if (eq == tcx.edgeEvent.constrainedEdge.getQ() &&
                        ep == tcx.edgeEvent.constrainedEdge.getP())
                    {
                        if (tcx.isDebugEnabled())
                        {
                            Console.Out.WriteLine("[FLIP] - constrained edge done");
                        } // TODO: remove
                        t.markConstrainedEdge(ep, eq);
                        ot.markConstrainedEdge(ep, eq);
                        legalize(tcx, t);
                        legalize(tcx, ot);
                    }
                    else
                    {
                        if (tcx.isDebugEnabled())
                        {
                            Console.Out.WriteLine("[FLIP] - subedge done");
                        } // TODO: remove
                          // XXX: I think one of the triangles should be legalized here?
                    }
                }
                else
                {
                    if (tcx.isDebugEnabled())
                    {
                        Console.Out.WriteLine("[FLIP] - flipping and continuing with triangle still crossing edge");
                    } // TODO: remove
                    Orientation o = orient2d(eq, op, ep);
                    t = nextFlipTriangle(tcx, o, t, ot, p, op);
                    flipEdgeEvent(tcx, ep, eq, t, p);
                }
            }
            else
            {
                newP = nextFlipPoint(ep, eq, ot, op);
                flipScanEdgeEvent(tcx, ep, eq, t, ot, newP);
                edgeEvent(tcx, ep, eq, t, p);
            }
        }
Exemplo n.º 4
0
        private static void edgeEvent(DTSweepContext tcx,
                                      TriangulationPoint ep,
                                      TriangulationPoint eq,
                                      DelaunayTriangle triangle,
                                      TriangulationPoint point)
        {
            TriangulationPoint p1, p2;

            if (tcx.isDebugEnabled())
            {
                tcx.getDebugContext().setPrimaryTriangle(triangle);
            }

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

            p1 = triangle.pointCCW(point);
            Orientation o1 = 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.setQ(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())
                {
                    logger.Info("EdgeEvent - Point on constrained edge");
                }
                return;
            }

            p2 = triangle.pointCW(point);
            Orientation o2 = 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.setQ(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())
                {
                    logger.Info("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);
            }
        }