Exemplo n.º 1
0
        /// <summary>
        /// Triangulate simple polygon with holes
        /// </summary>
        public static void Triangulate(DTSweepContext tcx)
        {
            tcx.CreateAdvancingFront();

            Sweep(tcx);

            FixupConstrainedEdges(tcx);

            // Finalize triangulation
            if (tcx.TriangulationMode == TriangulationMode.Polygon)
            {
                FinalizationPolygon(tcx);
            }
            else
            {
                FinalizationConvexHull(tcx);
                if (tcx.TriangulationMode == TriangulationMode.Constrained)
                {
                    // work in progress.  When it's done, call FinalizationConstraints INSTEAD of tcx.FinalizeTriangulation
                    //FinalizationConstraints(tcx);

                    tcx.FinalizeTriangulation();
                }
                else
                {
                    tcx.FinalizeTriangulation();
                }
            }

            tcx.Done();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Triangulate simple polygon with holes
        /// </summary>
        public static void Triangulate(DTSweepContext tcx)
        {
            tcx.CreateAdvancingFront();

            Sweep(tcx);

            FixupConstrainedEdges(tcx);

            // Finalize triangulation
            if (tcx.TriangulationMode == TriangulationMode.Polygon)
            {
                FinalizationPolygon(tcx);
            }
            else 
            {
                FinalizationConvexHull(tcx);
                if (tcx.TriangulationMode == TriangulationMode.Constrained)
                {
                    // work in progress.  When it's done, call FinalizationConstraints INSTEAD of tcx.FinalizeTriangulation
                    //FinalizationConstraints(tcx);

                    tcx.FinalizeTriangulation();
                }
                else
                {
                    tcx.FinalizeTriangulation();
                }
            }

            tcx.Done();
        }
Exemplo n.º 3
0
        /// <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)
        {
            AdvancingFrontNode n1, n2, n3;
            DelaunayTriangle   t1;
            TriangulationPoint first, p1;

            n1    = tcx.Front.Head.Next;
            n2    = n1.Next;
            n3    = n2.Next;
            first = n1.Point;

            TurnAdvancingFrontConvex(tcx, n1, n2);

            n1 = tcx.Front.Tail.Prev;
            if (n1.Triangle.Contains(n1.Next.Point) && n1.Triangle.Contains(n1.Prev.Point))
            {
                t1 = n1.Triangle.NeighborAcrossFrom(n1.Point);
                RotateTrianglePair(n1.Triangle, n1.Point, t1, t1.OppositePoint(n1.Triangle, n1.Point));
                tcx.MapTriangleToNodes(n1.Triangle);
                tcx.MapTriangleToNodes(t1);
            }
            n1 = tcx.Front.Head.Next;
            if (n1.Triangle.Contains(n1.Prev.Point) && n1.Triangle.Contains(n1.Next.Point))
            {
                t1 = n1.Triangle.NeighborAcrossFrom(n1.Point);
                RotateTrianglePair(n1.Triangle, n1.Point, t1, t1.OppositePoint(n1.Triangle, n1.Point));
                tcx.MapTriangleToNodes(n1.Triangle);
                tcx.MapTriangleToNodes(t1);
            }

            // TODO: implement ConvexHull for lower right and left boundary
            // Lower right boundary
            first = tcx.Front.Head.Point;
            n2    = tcx.Front.Tail.Prev;
            t1    = n2.Triangle;
            p1    = n2.Point;
            do
            {
                tcx.RemoveFromList(t1);
                p1 = t1.PointCCWFrom(p1);
                if (p1 == first)
                {
                    break;
                }
                t1 = t1.NeighborCCWFrom(p1);
            } while (true);

            // Lower left boundary
            first = tcx.Front.Head.Next.Point;
            p1    = t1.PointCWFrom(tcx.Front.Head.Point);
            t1    = t1.NeighborCWFrom(tcx.Front.Head.Point);
            do
            {
                tcx.RemoveFromList(t1);
                p1 = t1.PointCCWFrom(p1);
                t1 = t1.NeighborCCWFrom(p1);
            } while (p1 != first);

            tcx.FinalizeTriangulation();
        }
Exemplo n.º 4
0
		/// <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)
		{
			AdvancingFrontNode n1, n2, n3;
			DelaunayTriangle t1;
			TriangulationPoint first, p1;

			n1 = tcx.Front.Head.Next;
			n2 = n1.Next;
			n3 = n2.Next;
			first = n1.Point;

			TurnAdvancingFrontConvex(tcx, n1, n2);

			n1 = tcx.Front.Tail.Prev;
			if (n1.Triangle.Contains(n1.Next.Point) && n1.Triangle.Contains(n1.Prev.Point))
			{
				t1 = n1.Triangle.NeighborAcrossFrom(n1.Point);
				RotateTrianglePair(n1.Triangle, n1.Point, t1, t1.OppositePoint(n1.Triangle, n1.Point));
				tcx.MapTriangleToNodes(n1.Triangle);
				tcx.MapTriangleToNodes(t1);
			}
			n1 = tcx.Front.Head.Next;
			if (n1.Triangle.Contains(n1.Prev.Point) && n1.Triangle.Contains(n1.Next.Point))
			{
				t1 = n1.Triangle.NeighborAcrossFrom(n1.Point);
				RotateTrianglePair(n1.Triangle, n1.Point, t1, t1.OppositePoint(n1.Triangle, n1.Point));
				tcx.MapTriangleToNodes(n1.Triangle);
				tcx.MapTriangleToNodes(t1);
			}

			// TODO: implement ConvexHull for lower right and left boundary
			// Lower right boundary
			first = tcx.Front.Head.Point;
			n2 = tcx.Front.Tail.Prev;
			t1 = n2.Triangle;
			p1 = n2.Point;
			do
			{
				tcx.RemoveFromList(t1);
				p1 = t1.PointCCWFrom(p1);
				if (p1 == first) break;
				t1 = t1.NeighborCCWFrom(p1);
			} while (true);

			// Lower left boundary
			first = tcx.Front.Head.Next.Point;
			p1 = t1.PointCWFrom(tcx.Front.Head.Point);
			t1 = t1.NeighborCWFrom(tcx.Front.Head.Point);
			do
			{
				tcx.RemoveFromList(t1);
				p1 = t1.PointCCWFrom(p1);
				t1 = t1.NeighborCCWFrom(p1);
			} while (p1 != first);

			tcx.FinalizeTriangulation();
		}