コード例 #1
0
        private void HeapInsert(SweepLine.SweepEvent[] heap, int heapsize, SweepLine.SweepEvent newevent)
        {
            double num  = newevent.xkey;
            double num1 = newevent.ykey;
            int    num2 = heapsize;
            bool   flag = num2 > 0;

            while (flag)
            {
                int num3 = num2 - 1 >> 1;
                if (heap[num3].ykey < num1 || heap[num3].ykey == num1 && heap[num3].xkey <= num)
                {
                    flag = false;
                }
                else
                {
                    heap[num2] = heap[num3];
                    heap[num2].heapposition = num2;
                    num2 = num3;
                    flag = num2 > 0;
                }
            }
            heap[num2]            = newevent;
            newevent.heapposition = num2;
        }
コード例 #2
0
        private void Heapify(SweepLine.SweepEvent[] heap, int heapsize, int eventnum)
        {
            int num;

            SweepLine.SweepEvent sweepEvent = heap[eventnum];
            double num1 = sweepEvent.xkey;
            double num2 = sweepEvent.ykey;
            int    num3 = 2 * eventnum + 1;
            bool   flag = num3 < heapsize;

            while (flag)
            {
                num = (heap[num3].ykey < num2 || heap[num3].ykey == num2 && heap[num3].xkey < num1 ? num3 : eventnum);
                int num4 = num3 + 1;
                if (num4 < heapsize && (heap[num4].ykey < heap[num].ykey || heap[num4].ykey == heap[num].ykey && heap[num4].xkey < heap[num].xkey))
                {
                    num = num4;
                }
                if (num != eventnum)
                {
                    heap[eventnum] = heap[num];
                    heap[eventnum].heapposition = eventnum;
                    heap[num] = sweepEvent;
                    sweepEvent.heapposition = num;
                    eventnum = num;
                    num3     = 2 * eventnum + 1;
                    flag     = num3 < heapsize;
                }
                else
                {
                    flag = false;
                }
            }
        }
コード例 #3
0
        private void HeapDelete(SweepLine.SweepEvent[] heap, int heapsize, int eventnum)
        {
            bool flag;

            SweepLine.SweepEvent sweepEvent = heap[heapsize - 1];
            if (eventnum > 0)
            {
                double num  = sweepEvent.xkey;
                double num1 = sweepEvent.ykey;
                do
                {
                    int num2 = eventnum - 1 >> 1;
                    if (heap[num2].ykey < num1 || heap[num2].ykey == num1 && heap[num2].xkey <= num)
                    {
                        flag = false;
                    }
                    else
                    {
                        heap[eventnum] = heap[num2];
                        heap[eventnum].heapposition = eventnum;
                        eventnum = num2;
                        flag     = eventnum > 0;
                    }
                }while (flag);
            }
            heap[eventnum]          = sweepEvent;
            sweepEvent.heapposition = eventnum;
            this.Heapify(heap, heapsize - 1, eventnum);
        }
コード例 #4
0
        private void CreateHeap(out SweepLine.SweepEvent[] eventheap)
        {
            int num = 3 * this.mesh.invertices / 2;

            eventheap = new SweepLine.SweepEvent[num];
            int num1 = 0;

            foreach (Vertex value in this.mesh.vertices.Values)
            {
                SweepLine.SweepEvent sweepEvent = new SweepLine.SweepEvent()
                {
                    vertexEvent = value,
                    xkey        = value.x,
                    ykey        = value.y
                };
                int num2 = num1;
                num1 = num2 + 1;
                this.HeapInsert(eventheap, num2, sweepEvent);
            }
        }
コード例 #5
0
 public SweepEventVertex(SweepLine.SweepEvent e)
 {
     this.evt = e;
 }
コード例 #6
0
        public int Triangulate(Mesh mesh)
        {
            SweepLine.SweepEvent[] sweepEventArray;
            SweepLine.SweepEvent   sweepEvent;
            Vertex vertex;
            Vertex vertex1;
            Vertex vertex2;
            Vertex vertex3;

            this.mesh        = mesh;
            this.xminextreme = 10 * mesh.bounds.Xmin - 9 * mesh.bounds.Xmax;
            Otri otri  = new Otri();
            Otri otri1 = new Otri();
            Otri otri2 = new Otri();
            Otri otri3 = new Otri();
            Otri otri4 = new Otri();
            Otri otri5 = new Otri();
            Otri otri6 = new Otri();
            bool i     = false;

            this.splaynodes = new List <SweepLine.SplayNode>();
            SweepLine.SplayNode splayNode = null;
            this.CreateHeap(out sweepEventArray);
            int num = mesh.invertices;

            mesh.MakeTriangle(ref otri2);
            mesh.MakeTriangle(ref otri3);
            otri2.Bond(ref otri3);
            otri2.LnextSelf();
            otri3.LprevSelf();
            otri2.Bond(ref otri3);
            otri2.LnextSelf();
            otri3.LprevSelf();
            otri2.Bond(ref otri3);
            Vertex vertex4 = sweepEventArray[0].vertexEvent;

            this.HeapDelete(sweepEventArray, num, 0);
            num--;
            do
            {
                if (num == 0)
                {
                    SimpleLog.Instance.Error("Input vertices are all identical.", "SweepLine.SweepLineDelaunay()");
                    throw new Exception("Input vertices are all identical.");
                }
                vertex = sweepEventArray[0].vertexEvent;
                this.HeapDelete(sweepEventArray, num, 0);
                num--;
                if (vertex4.x != vertex.x || vertex4.y != vertex.y)
                {
                    continue;
                }
                if (Behavior.Verbose)
                {
                    SimpleLog.Instance.Warning("A duplicate vertex appeared and was ignored.", "SweepLine.SweepLineDelaunay().1");
                }
                vertex.type = VertexType.UndeadVertex;
                Mesh mesh1 = mesh;
                mesh1.undeads = mesh1.undeads + 1;
            }while (vertex4.x == vertex.x && vertex4.y == vertex.y);
            otri2.SetOrg(vertex4);
            otri2.SetDest(vertex);
            otri3.SetOrg(vertex);
            otri3.SetDest(vertex4);
            otri2.Lprev(ref otri);
            Vertex vertex5 = vertex;

            while (num > 0)
            {
                SweepLine.SweepEvent sweepEvent1 = sweepEventArray[0];
                this.HeapDelete(sweepEventArray, num, 0);
                num--;
                bool flag = true;
                if (sweepEvent1.xkey >= mesh.bounds.Xmin)
                {
                    Vertex vertex6 = sweepEvent1.vertexEvent;
                    if (vertex6.x != vertex5.x || vertex6.y != vertex5.y)
                    {
                        vertex5   = vertex6;
                        splayNode = this.FrontLocate(splayNode, otri, vertex6, ref otri1, ref i);
                        otri.Copy(ref otri1);
                        for (i = false; !i && this.RightOfHyperbola(ref otri1, vertex6); i = otri1.Equal(otri))
                        {
                            otri1.OnextSelf();
                        }
                        this.Check4DeadEvent(ref otri1, sweepEventArray, ref num);
                        otri1.Copy(ref otri5);
                        otri1.Sym(ref otri4);
                        mesh.MakeTriangle(ref otri2);
                        mesh.MakeTriangle(ref otri3);
                        Vertex vertex7 = otri5.Dest();
                        otri2.SetOrg(vertex7);
                        otri2.SetDest(vertex6);
                        otri3.SetOrg(vertex6);
                        otri3.SetDest(vertex7);
                        otri2.Bond(ref otri3);
                        otri2.LnextSelf();
                        otri3.LprevSelf();
                        otri2.Bond(ref otri3);
                        otri2.LnextSelf();
                        otri3.LprevSelf();
                        otri2.Bond(ref otri4);
                        otri3.Bond(ref otri5);
                        if (!i && otri5.Equal(otri))
                        {
                            otri2.Copy(ref otri);
                        }
                        if (this.randomnation(SweepLine.SAMPLERATE) == 0)
                        {
                            splayNode = this.SplayInsert(splayNode, otri2, vertex6);
                        }
                        else if (this.randomnation(SweepLine.SAMPLERATE) == 0)
                        {
                            otri3.Lnext(ref otri6);
                            splayNode = this.SplayInsert(splayNode, otri6, vertex6);
                        }
                    }
                    else
                    {
                        if (Behavior.Verbose)
                        {
                            SimpleLog.Instance.Warning("A duplicate vertex appeared and was ignored.", "SweepLine.SweepLineDelaunay().2");
                        }
                        vertex6.type = VertexType.UndeadVertex;
                        Mesh mesh2 = mesh;
                        mesh2.undeads = mesh2.undeads + 1;
                        flag          = false;
                    }
                }
                else
                {
                    Otri otri7 = sweepEvent1.otriEvent;
                    otri7.Oprev(ref otri4);
                    this.Check4DeadEvent(ref otri4, sweepEventArray, ref num);
                    otri7.Onext(ref otri5);
                    this.Check4DeadEvent(ref otri5, sweepEventArray, ref num);
                    if (otri4.Equal(otri))
                    {
                        otri7.Lprev(ref otri);
                    }
                    mesh.Flip(ref otri7);
                    otri7.SetApex(null);
                    otri7.Lprev(ref otri2);
                    otri7.Lnext(ref otri3);
                    otri2.Sym(ref otri4);
                    if (this.randomnation(SweepLine.SAMPLERATE) == 0)
                    {
                        otri7.SymSelf();
                        vertex1   = otri7.Dest();
                        vertex2   = otri7.Apex();
                        vertex3   = otri7.Org();
                        splayNode = this.CircleTopInsert(splayNode, otri2, vertex1, vertex2, vertex3, sweepEvent1.ykey);
                    }
                }
                if (!flag)
                {
                    continue;
                }
                vertex1 = otri4.Apex();
                vertex2 = otri2.Dest();
                vertex3 = otri2.Apex();
                double num1 = Primitives.CounterClockwise(vertex1, vertex2, vertex3);
                if (num1 > 0)
                {
                    sweepEvent = new SweepLine.SweepEvent()
                    {
                        xkey      = this.xminextreme,
                        ykey      = this.CircleTop(vertex1, vertex2, vertex3, num1),
                        otriEvent = otri2
                    };
                    this.HeapInsert(sweepEventArray, num, sweepEvent);
                    num++;
                    otri2.SetOrg(new SweepLine.SweepEventVertex(sweepEvent));
                }
                vertex1 = otri3.Apex();
                vertex2 = otri3.Org();
                vertex3 = otri5.Apex();
                double num2 = Primitives.CounterClockwise(vertex1, vertex2, vertex3);
                if (num2 <= 0)
                {
                    continue;
                }
                sweepEvent = new SweepLine.SweepEvent()
                {
                    xkey      = this.xminextreme,
                    ykey      = this.CircleTop(vertex1, vertex2, vertex3, num2),
                    otriEvent = otri5
                };
                this.HeapInsert(sweepEventArray, num, sweepEvent);
                num++;
                otri5.SetOrg(new SweepLine.SweepEventVertex(sweepEvent));
            }
            this.splaynodes.Clear();
            otri.LprevSelf();
            return(this.RemoveGhosts(ref otri));
        }