当前位置: 首页>>代码示例>>C#>>正文


C# Sweep.DTSweepContext类代码示例

本文整理汇总了C#中Poly2Tri.Triangulation.Delaunay.Sweep.DTSweepContext的典型用法代码示例。如果您正苦于以下问题:C# DTSweepContext类的具体用法?C# DTSweepContext怎么用?C# DTSweepContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DTSweepContext类属于Poly2Tri.Triangulation.Delaunay.Sweep命名空间,在下文中一共展示了DTSweepContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Triangulate

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

            Sweep(tcx);

            // Finalize triangulation
            if (tcx.TriangulationMode == TriangulationMode.Polygon)
            {
                FinalizationPolygon(tcx);
            }
            else
            {
                FinalizationConvexHull(tcx);
            }

            tcx.Done();
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:21,代码来源:DTSweep.cs

示例2: Triangulate

    public int[] Triangulate(UnityEngine.Vector2[] verts)
    {
        PolygonPoint[] points = new PolygonPoint[verts.Length];
        for (int i = 0; i < verts.Length; i++)
            points[i] = new PolygonPoint(verts[i].x, verts[i].y);
        Polygon polygon = new Polygon(points);
        DTSweepContext tcx = new DTSweepContext();
        tcx.PrepareTriangulation(polygon);
        DTSweep.Triangulate(tcx);
        int[] resultPoints = new int[polygon.Triangles.Count * 3];
        int idx = 0;

        foreach (DelaunayTriangle triangle in polygon.Triangles) {
            resultPoints[idx++] = FindIndex(points, triangle.Points._0);
            resultPoints[idx++] = FindIndex(points, triangle.Points._1);
            resultPoints[idx++] = FindIndex(points, triangle.Points._2);
        }
        return resultPoints;
    }
开发者ID:AtrapadosGame,项目名称:Atrapados-Viejo,代码行数:19,代码来源:FarseerTriangulator.cs

示例3: Sweep

        /// <summary>
        /// Start sweeping the Y-sorted point set from bottom to top
        /// </summary>
        private static void Sweep(DTSweepContext tcx)
        {
            List<TriangulationPoint> points = tcx.Points;
            TriangulationPoint point;
            AdvancingFrontNode node;

            for (int i = 1; i < points.Count; i++)
            {
                point = points[i];

                node = PointEvent(tcx, point);

                if (point.HasEdges)
                {
                    foreach (DTSweepConstraint e in point.Edges)
                    {
                        EdgeEvent(tcx, e, node);
                    }
                }
                tcx.Update(null);
            }
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:25,代码来源:DTSweep.cs

示例4: EdgeEvent

        private static void EdgeEvent(DTSweepContext tcx, TriangulationPoint ep, TriangulationPoint eq,
                                      DelaunayTriangle triangle, TriangulationPoint point)
        {
            TriangulationPoint p1, p2;

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

            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;
            }

            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);
            }
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:78,代码来源:DTSweep.cs

示例5: CreateMesh

    public void CreateMesh(Vector2[] vertsToCopy, Transform transform)
    {
        List<Vector3> resultsLocal = new List<Vector3>();
        List<int> resultsTriIndexesLocal = new List<int>();
        List<int> resultsTriIndexesReversedLocal = new List<int>();
        List<Vector2> uvsLocal = new List<Vector2>();
        List<Vector3> normalsLocal = new List<Vector3>();

        Sprite spr = transform.GetComponent<SpriteRenderer>().sprite;
        Rect rec = spr.rect;
        Vector3 bound = transform.GetComponent<Renderer>().bounds.max- transform.GetComponent<Renderer>().bounds.min ;

        TextureImporter textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(spr)) as TextureImporter;

        int i =  0;

        Polygon poly =  new Polygon();

        for (i=0; i <vertsToCopy.Length;i++)
        {
            poly.Points.Add(new TriangulationPoint(vertsToCopy[i].x, vertsToCopy[i].y));

        }

        DTSweepContext tcx = new DTSweepContext();
        tcx.PrepareTriangulation(poly);
        DTSweep.Triangulate(tcx);

        int indexNumber = 0;
        bool multiSprites = false;
        foreach (DelaunayTriangle triangle in poly.Triangles)
        {
            Vector3 v = new Vector3();
            foreach (TriangulationPoint p in triangle.Points)
            {
                v = new Vector3((float)p.X, (float)p.Y,0);
                if(!resultsLocal.Contains(v))
                {
                    resultsLocal.Add(v);
                    resultsTriIndexesLocal.Add(indexNumber);
                    Vector2 newUv = new Vector2((v.x /bound.x) + 0.5f,  (v.y /bound.y)  + 0.5f);

                    newUv.x *= rec.width/ spr.texture.width;
                    newUv.y *= rec.height/ spr.texture.height;
                    //Debug.Log(spr.textureRectOffset);
                    newUv.x += (rec.x)/ spr.texture.width;
                    newUv.y += (rec.y) / spr.texture.height;

                    //Debug.Log(Application.unityVersion);

                    SpriteMetaData[] smdArray = textureImporter.spritesheet;
                    Vector2 pivot = new Vector2(.0f,.0f);;

                    for (int j = 0; j < smdArray.Length; j++)
                    {
                        if (smdArray[j].name == spr.name)
                        {
                            switch(smdArray[j].alignment)
                            {
                                case(0):
                                smdArray[j].pivot = Vector2.zero;
                                break;
                                case(1):
                                smdArray[j].pivot = new Vector2(0f,1f) -new Vector2(.5f,.5f);
                                break;
                                case(2):
                                smdArray[j].pivot = new Vector2(0.5f,1f) -new Vector2(.5f,.5f);
                                break;
                                case(3):
                                smdArray[j].pivot = new Vector2(1f,1f) -new Vector2(.5f,.5f);
                                break;
                                case(4):
                                smdArray[j].pivot = new Vector2(0f,.5f) -new Vector2(.5f,.5f);
                                break;
                                case(5):
                                smdArray[j].pivot = new Vector2(1f,.5f) -new Vector2(.5f,.5f);
                                break;
                                case(6):
                                smdArray[j].pivot = new Vector2(0f,0f) -new Vector2(.5f,.5f);
                                break;
                                case(7):
                                smdArray[j].pivot = new Vector2(0.5f,0f) -new Vector2(.5f,.5f);
                                break;
                                case(8):
                                smdArray[j].pivot = new Vector2(1f,0f) -new Vector2(.5f,.5f);
                                break;
                                case(9):
                                smdArray[j].pivot -= new Vector2(.5f,.5f);
                                break;
                            }
                            pivot = smdArray[j].pivot ;
                        }
                    }
                    if(textureImporter.spriteImportMode == SpriteImportMode.Single)
                        pivot = textureImporter.spritePivot-new Vector2(.5f,.5f);
                    newUv.x += ((pivot.x)*rec.width)/ spr.texture.width;
                    newUv.y += ((pivot.y)*rec.height)/ spr.texture.height;
                    /*
                    if(Application.unityVersion != "4.3.0f4")
                    {
//.........这里部分代码省略.........
开发者ID:quanganh94,项目名称:Swing,代码行数:101,代码来源:Puppet2D_CreatePolygonFromSprite.cs

示例6: Legalize

        /// <summary>
        /// Returns true if triangle was legalized
        /// </summary>
        private static bool Legalize(DTSweepContext tcx, DelaunayTriangle t)
        {
            int oi;
            bool inside;
            TriangulationPoint p, op;
            DelaunayTriangle ot;

            // To legalize a triangle we start by finding if any of the three edges
            // violate the Delaunay condition
            for (int i = 0; i < 3; i++)
            {
                // TODO: fix so that cEdge is always valid when creating new triangles then we can check it here
                //       instead of below with ot
                if (t.EdgeIsDelaunay[i])
                {
                    continue;
                }

                ot = t.Neighbors[i];
                if (ot != null)
                {
                    p = t.Points[i];
                    op = ot.OppositePoint(t, p);
                    oi = ot.IndexOf(op);
                    // If this is a Constrained Edge or a Delaunay Edge(only during recursive legalization)
                    // then we should not try to legalize
                    if (ot.EdgeIsConstrained[oi] || ot.EdgeIsDelaunay[oi])
                    {
                        t.EdgeIsConstrained[i] = ot.EdgeIsConstrained[oi];
                            // XXX: have no good way of setting this property when creating new triangles so lets set it here
                        continue;
                    }

                    inside = TriangulationUtil.SmartIncircle(p,
                                                             t.PointCCW(p),
                                                             t.PointCW(p),
                                                             op);

                    if (inside)
                    {
                        bool notLegalized;

                        // Lets mark this shared edge as Delaunay 
                        t.EdgeIsDelaunay[i] = true;
                        ot.EdgeIsDelaunay[oi] = true;

                        // Lets rotate shared edge one vertex CW to legalize it
                        RotateTrianglePair(t, p, ot, op);

                        // We now got one valid Delaunay Edge shared by two triangles
                        // This gives us 4 new edges to check for Delaunay

                        // Make sure that triangle to node mapping is done only one time for a specific triangle
                        notLegalized = !Legalize(tcx, t);

                        if (notLegalized)
                        {
                            tcx.MapTriangleToNodes(t);
                        }
                        notLegalized = !Legalize(tcx, ot);
                        if (notLegalized)
                        {
                            tcx.MapTriangleToNodes(ot);
                        }

                        // Reset the Delaunay edges, since they only are valid Delaunay edges
                        // until we add a new triangle or point.
                        // XXX: need to think about this. Can these edges be tried after we 
                        //      return to previous recursive level?
                        t.EdgeIsDelaunay[i] = false;
                        ot.EdgeIsDelaunay[oi] = false;

                        // If triangle have been legalized no need to check the other edges since
                        // the recursive legalization will handles those so we can end here.
                        return true;
                    }
                }
            }
            return false;
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:83,代码来源:DTSweep.cs

示例7: IsShallow

        private static bool IsShallow(DTSweepContext tcx, AdvancingFrontNode node)
        {
            double height;

            if (tcx.Basin.leftHighest)
            {
                height = tcx.Basin.leftNode.Point.Y - node.Point.Y;
            }
            else
            {
                height = tcx.Basin.rightNode.Point.Y - node.Point.Y;
            }
            if (tcx.Basin.width > height)
            {
                return true;
            }
            return false;
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:18,代码来源:DTSweep.cs

示例8: FillAdvancingFront

        /// <summary>
        /// Fills holes in the Advancing Front
        /// </summary>
        private static void FillAdvancingFront(DTSweepContext tcx, AdvancingFrontNode n)
        {
            AdvancingFrontNode node;
            double angle;

            // Fill right holes
            node = n.Next;
            while (node.HasNext)
            {
                angle = HoleAngle(node);
                if (angle > PI_div2 || angle < -PI_div2)
                {
                    break;
                }
                Fill(tcx, node);
                node = node.Next;
            }

            // Fill left holes
            node = n.Prev;
            while (node.HasPrev)
            {
                angle = HoleAngle(node);
                if (angle > PI_div2 || angle < -PI_div2)
                {
                    break;
                }
                Fill(tcx, node);
                node = node.Prev;
            }

            // Fill right basins
            if (n.HasNext && n.Next.HasNext)
            {
                angle = BasinAngle(n);
                if (angle < PI_3div4)
                {
                    FillBasin(tcx, n);
                }
            }
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:44,代码来源:DTSweep.cs

示例9: NextFlipTriangle

 /// <summary>
 /// After a flip we have two triangles and know that only one will still be
 /// intersecting the edge. So decide which to contiune with and legalize the other
 /// </summary>
 /// <param name="tcx"></param>
 /// <param name="o">should be the result of an TriangulationUtil.orient2d( eq, op, ep )</param>
 /// <param name="t">triangle 1</param>
 /// <param name="ot">triangle 2</param>
 /// <param name="p">a point shared by both triangles</param>
 /// <param name="op">another point shared by both triangles</param>
 /// <returns>returns the triangle still intersecting the edge</returns>
 private static DelaunayTriangle NextFlipTriangle(DTSweepContext tcx, Orientation o, DelaunayTriangle t,
                                                  DelaunayTriangle ot, TriangulationPoint p,
                                                  TriangulationPoint op)
 {
     int edgeIndex;
     if (o == Orientation.CCW)
     {
         // ot is not crossing edge after flip
         edgeIndex = ot.EdgeIndex(p, op);
         ot.EdgeIsDelaunay[edgeIndex] = true;
         Legalize(tcx, ot);
         ot.EdgeIsDelaunay.Clear();
         return t;
     }
     // t is not crossing edge after flip
     edgeIndex = t.EdgeIndex(p, op);
     t.EdgeIsDelaunay[edgeIndex] = true;
     Legalize(tcx, t);
     t.EdgeIsDelaunay.Clear();
     return ot;
 }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:32,代码来源:DTSweep.cs

示例10: NewFrontTriangle

        /// <summary>
        /// Creates a new front triangle and legalize it
        /// </summary>
        private static AdvancingFrontNode NewFrontTriangle(DTSweepContext tcx, TriangulationPoint point,
                                                           AdvancingFrontNode node)
        {
            AdvancingFrontNode newNode;
            DelaunayTriangle triangle;

            triangle = new DelaunayTriangle(point, node.Point, node.Next.Point);
            triangle.MarkNeighbor(node.Triangle);
            tcx.Triangles.Add(triangle);

            newNode = new AdvancingFrontNode(point);
            newNode.Next = node.Next;
            newNode.Prev = node;
            node.Next.Prev = newNode;
            node.Next = newNode;

            tcx.AddNode(newNode); // XXX: BST

            if (!Legalize(tcx, triangle))
            {
                tcx.MapTriangleToNodes(triangle);
            }

            return newNode;
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:28,代码来源:DTSweep.cs

示例11: PointEvent

        /// <summary>
        /// Find closes node to the left of the new point and
        /// create a new triangle. If needed new holes and basins
        /// will be filled to.
        /// </summary>
        private static AdvancingFrontNode PointEvent(DTSweepContext tcx, TriangulationPoint point)
        {
            AdvancingFrontNode node, newNode;

            node = tcx.LocateNode(point);
            newNode = NewFrontTriangle(tcx, point, node);

            // Only need to check +epsilon since point never have smaller 
            // x value than node due to how we fetch nodes from the front
            if (point.X <= node.Point.X + TriangulationUtil.EPSILON)
            {
                Fill(tcx, node);
            }

            tcx.AddNode(newNode);

            FillAdvancingFront(tcx, newNode);
            return newNode;
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:24,代码来源:DTSweep.cs

示例12: FinalizationPolygon

        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);
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:13,代码来源:DTSweep.cs

示例13: TurnAdvancingFrontConvex

 /// <summary>
 /// We will traverse the entire advancing front and fill it to form a convex hull.
 /// </summary>
 private static void TurnAdvancingFrontConvex(DTSweepContext tcx, AdvancingFrontNode b, AdvancingFrontNode c)
 {
     AdvancingFrontNode first = b;
     while (c != tcx.aFront.Tail)
     {
         if (TriangulationUtil.Orient2d(b.Point, c.Point, c.Next.Point) == Orientation.CCW)
         {
             // [b,c,d] Concave - fill around c
             Fill(tcx, c);
             c = c.Next;
         }
         else
         {
             // [b,c,d] Convex
             if (b != first && TriangulationUtil.Orient2d(b.Prev.Point, b.Point, c.Point) == Orientation.CCW)
             {
                 // [a,b,c] Concave - fill around b
                 Fill(tcx, b);
                 b = b.Prev;
             }
             else
             {
                 // [a,b,c] Convex - nothing to fill
                 b = c;
                 c = c.Next;
             }
         }
     }
 }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:32,代码来源:DTSweep.cs

示例14: FinalizationConvexHull

        /// <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;
            DelaunayTriangle t1, t2;
            TriangulationPoint first, p1;

            n1 = tcx.aFront.Head.Next;
            n2 = n1.Next;
            first = n1.Point;

            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 
            first = tcx.aFront.Head.Point;
            n2 = tcx.aFront.Tail.Prev;
            t1 = n2.Triangle;
            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();
        }
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:81,代码来源:DTSweep.cs

示例15: FillRightBelowEdgeEvent

 private static void FillRightBelowEdgeEvent(DTSweepContext tcx, DTSweepConstraint edge, AdvancingFrontNode node)
 {
     if (node.Point.x < edge.P.x) // needed?
     {
         if (TriangulationUtil.Orient2d(node.Point, node.Next.Point, node.Next.Next.Point) == Orientation.CCW)
         {
             // Concave
             FillRightConcaveEdgeEvent(tcx, edge, node);
         }
         else
         {
             // Convex
             FillRightConvexEdgeEvent(tcx, edge, node);
             // Retry this one
             FillRightBelowEdgeEvent(tcx, edge, node);
         }
     }
 }
开发者ID:kyallbarrows,项目名称:Cinch_4-3,代码行数:18,代码来源:DTSweep.cs


注:本文中的Poly2Tri.Triangulation.Delaunay.Sweep.DTSweepContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。