Ejemplo n.º 1
0
 public voronoiboundary[] vetexboundary = new voronoiboundary[MaxVertices]; //节点的泰森多边形影响区域
 public DataStruct()
 {
     for (int i = 0; i < MaxVertices; i++)
     {
         vetexboundary[i] = new voronoiboundary();
     }
 }
Ejemplo n.º 2
0
        public voronoiboundary[] vetexboundary = new voronoiboundary[MaxVertices]; //节点的泰森多边形影响区域

        #endregion Fields

        #region Constructors

        public DataStruct()
        {
            for (int i = 0; i < MaxVertices; i++)
            {
                vetexboundary[i] = new voronoiboundary();
            }
        }
Ejemplo n.º 3
0
        //�����������
        /// <summary>
        ///�����������
        /// </summary>
        /// <param name="starti">��ʼ�����ڵ���</param>
        /// <param name="store">����˳��</param>
        /// <param name="Sosflag">�����������������</param>
        /// <param name="insectflag">�ཻ������� �ཻΪ1</param>
        ///  <param name="insectpoint">�ཻ�������¼����</param>
        ///  <param name="polyon">�������������</param>
        ///  <param name="vectcollect">�����ཻ��̩ɭ�����</param>
        public void Sospoloy(int starti, bool store, int[] Sosflag,int[] taisflag, int[,] insectflag, PointF[,] insectpoint, Polyon multrect, voronoiboundary tais)
        {
            int m = multrect.Vertices.Count; int n = tais.voronicollect.Count;
            if(store)
            {
                for(int j=starti;j<m;j++)
                {
                    if (Sosflag[j]==1)
                    {
                        return;
                    }
                    else
                    {
                        Sosflag[j] = 1;
                        if (PtInPolygon(multrect.Vertices[j], tais.voronicollect))
                        {
                            if (tais.Vimultptcompare(multrect.Vertices[j]))
                            {
                                tais.vimultcollect.Add(multrect.Vertices[j]);
                            }

                        }
                        for (int i = 0; i < n;i++ )
                        {
                            if (insectflag[i,j] == 1)
                            {
                                insectflag[i,j] = 0;
                                //�ж��ཻ�ĵ��Ƿ���Ƕ˵�
                                if (tais.Vimultptcompare(insectpoint[i, j]))
                                {
                                    tais.vimultcollect.Add(insectpoint[i, j]);
                                }

                                if (PtInPolygon(tais.voronicollect[i], multrect.Vertices))
                                {
                                    if (tais.Vimultptcompare(tais.voronicollect[i]))
                                    {
                                        tais.vimultcollect.Add(tais.voronicollect[i]);
                                    }

                                    //������һѭ���ĺ��� ����Ҫ�жϴ˶���ε�˳�������ʱ�����С�����������С�����˳�� ���������������ǴӴ�С��˳��
                                    if (i < (i + 1) % n)
                                   {
                                       if (!IsCCW(tais.voronicollect))
                                       {
                                           Sospoloy(i, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                       }
                                       else
                                           Sospoloy(i, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                   }
                                    else
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy(i, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy(i, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }

                                }
                                if (PtInPolygon(tais.voronicollect[(i + 1) % n], multrect.Vertices))
                                {
                                    if (tais.Vimultptcompare(tais.voronicollect[(i + 1) % n]))
                                    {
                                        tais.vimultcollect.Add(tais.voronicollect[(i + 1) % n]);
                                    }

                                    //������һѭ���ĺ���
                                    if (i < (i + 1) % n)
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy((i + 1) % n, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy((i + 1) % n, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }
                                    else
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy((i + 1) % n, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy((i + 1) % n,true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }

                                }
                            }
                        }
                    }

                }
            }
            else
            {
                for (int j = starti+m; j >0 ; j--)
                {
                    if (Sosflag[j%m] == 1)
                    {
                        return;
                    }
                    else
                    {
                        Sosflag[j % m] = 1;
                        if (PtInPolygon(multrect.Vertices[j % m], tais.voronicollect))
                        {
                            if (tais.Vimultptcompare(multrect.Vertices[j % m]))
                            {
                                tais.vimultcollect.Add(multrect.Vertices[j % m]);
                            }

                        }
                        for (int i = 0; i < n; i++)
                        {
                            if (insectflag[i,j % m] == 1)
                            {
                                insectflag[i,j % m] = 0;
                                if (tais.Vimultptcompare(insectpoint[i, j % m]))
                                {
                                    tais.vimultcollect.Add(insectpoint[i, j % m]);
                                }

                                if (PtInPolygon(tais.voronicollect[i], multrect.Vertices))
                                {
                                    if (tais.Vimultptcompare(tais.voronicollect[i]))
                                    {
                                        tais.vimultcollect.Add(tais.voronicollect[i]);
                                    }

                                    //������һѭ���ĺ���
                                    if (i < (i + 1) % n)
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy(i, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy(i, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }
                                   else
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy(i, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy(i, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }

                                }
                                if (PtInPolygon(tais.voronicollect[(i + 1) % n], multrect.Vertices))
                                {
                                    if (tais.Vimultptcompare(tais.voronicollect[(i + 1) % n]))
                                    {
                                        tais.vimultcollect.Add(tais.voronicollect[(i + 1) % n]);
                                    }

                                    //������һѭ���ĺ���
                                    if (i < (i + 1) % n)
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy((i + 1) % n, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy((i + 1) % n, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }
                                    else
                                    {
                                        if (!IsCCW(tais.voronicollect))
                                        {
                                            Sospoloy((i + 1) % n, false, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                        }
                                        else
                                            Sospoloy((i + 1) % n, true, Sosflag, taisflag, insectflag, insectpoint, tais, multrect);
                                    }

                                }
                            }
                        }
                    }

                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ��ö���κ�͹��̩ɭ����εĽ���
        /// </summary>
        /// <param name="multrect">��������</param>
        /// <param name="tais">͹�ǵ�̩ɭ�����</param>
        public void insectpoloy(Polyon multrect,voronoiboundary tais)
        {
            int m = multrect.Vertices.Count; int n = tais.voronicollect.Count;
               //Ϊ��������εĽ�����һ������һ������εı�� ��ʼΪ�� ������������ڲ���Ϊ1
               int[] rectpointflag=new int[m];
               int[] taispointflag=new int[n];
               for (int i=0;i<m;i++)
               {
               rectpointflag[i]=0;
               }
               for (int j=0;j<n;j++)
               {
               taispointflag[j]=0;
               }
               //����ཻ�����ཻ����·��ŵ�λ��Ϊ1 ������·�ĵ�һ���ڵ�ı��˳��
               int[,] insectflag=new int[n,m];
               PointF[,] insectpoint=new PointF[n,m];
               for (int i=0;i<n;i++)
               {
               for (int j=0;j<m;j++)
               {
                   insectflag[i,j]=0;
                   insectpoint[i,j] = new PointF();
               }

               }
               //�����ཻ���߶��ñ�Ǽ�¼
               for (int i = 0; i < n;i++ )
               {
               PointF p1 = tais.voronicollect[i];
               PointF p2 = tais.voronicollect[(i + 1) % n];
               for (int j = 0; j < m;j++ )
               {
                   PointF p=new PointF();
                   PointF p3 = multrect.Vertices[j];
                   PointF p4 = multrect.Vertices[(j + 1) % multrect.Vertices.Count];
                   if (GetIntersection(p1, p2, p3, p4, ref p) == 1)
                   {
                       insectflag[i,j] = 1;
                       insectpoint[i,j] = p;
                   }
               }
               }
               //���н����յ������
               int starti = 0;
              sosocontinue:
               Sospoloy(starti, true, rectpointflag, taispointflag, insectflag, insectpoint, tais, multrect);
               //�����ཻ�Ľڵ��Ƿ���ȫ����
               int resault = 0;
               for (int i = 0; i < n;i++ )
               {
               for (int j = 0; j < m;j++ )
               {
                   if (insectflag[i, j]==1)
                   {
                       starti=i;
                       goto sosocontinue;
                   }

               }
               }
              //������õĽ������� ̩ɭ����μ�����
               tais.voronicollect.Clear();
               for (int i = 0; i < tais.vimultcollect.Count;i++ )
               {
               tais.voronicollect.Add(tais.vimultcollect[i]);
               }

               //for (int i = 0; i < n;i++ )
               //{
               //    taispointflag[i] = 1;    //˵�������ڲ�
               //    if (PtInPolygon(tais.voronicollect[i],multrect.Vertices))
               //    {
               //         tais.insertboundarycollect.Add(tais.voronicollect[i]);

               //    }
               //    for (int j=0;j<m;j++)
               //    {
               //        if (insectflag[i,j]==1)
               //        {
               //            insectflag[i,j] = 0;
               //            tais.insertboundarycollect.Add(insectpoint[i,j]);
               //            if (PtInPolygon(multrect.Vertices[j],tais.voronicollect))
               //            {
               //                tais.insertboundarycollect.Add(multrect.Vertices[j]);

               //            }
               //            if (PtInPolygon(multrect.Vertices[(j + 1) % multrect.Vertices.Count], tais.voronicollect))
               //            {
               //                tais.insertboundarycollect.Add(multrect.Vertices[(j + 1) % multrect.Vertices.Count]);
               //            }
               //        }

               //    }

               //}
        }
Ejemplo n.º 5
0
        //���������ĵ���������
        /// <summary>
        ///���������ĵ��������У�����ʾ����
        /// </summary>
        private void DrawHullVorEdge(int i, voronoiboundary v1, voronoiboundary v2, Graphics g)
        {
            PointF pnt1 = new PointF(Convert.ToSingle(DS.Vertex[DS.TinEdges[i].Vertex1ID].x),
                 Convert.ToSingle(DS.Vertex[DS.TinEdges[i].Vertex1ID].y));
            PointF pnt2 = new PointF(Convert.ToSingle(DS.Vertex[DS.TinEdges[i].Vertex2ID].x),
                Convert.ToSingle(DS.Vertex[DS.TinEdges[i].Vertex2ID].y));
            PointF pnt3 = new PointF(Convert.ToSingle(DS.Vertex[DS.TinEdges[i].AdjacentT1V3].x),
                Convert.ToSingle(DS.Vertex[DS.TinEdges[i].AdjacentT1V3].y));    //�߶�Ӧ�ġ�����

            PointF MidPnt = new PointF((pnt1.X + pnt2.X) / 2, (pnt2.Y + pnt2.Y) / 2);  //TinEdge�е�
            PointF BaryCnt = new PointF(Convert.ToSingle(DS.Barycenters[DS.TinEdges[i].AdjTriangle1ID].X),
                Convert.ToSingle(DS.Barycenters[DS.TinEdges[i].AdjTriangle1ID].Y));  //���Բ��
            PointF EndPnt = new PointF();   //Բ�������ڴ˵㹹��VEdge

            //Բ����box����ֱ������
            if (!(BaryCnt.X >= DS.BBOX.XLeft && BaryCnt.X <= DS.BBOX.XRight &&
                BaryCnt.Y >= DS.BBOX.YTop && BaryCnt.Y <= DS.BBOX.YBottom))
                return;

            //���
            float k = 0;  //�
            bool KExist = true;
            if (Math.Abs(pnt1.Y - pnt2.Y) < 0.000001)
                KExist = false;     //k������
            else
                k = (pnt1.X - pnt2.X) / (pnt2.Y - pnt1.Y);

            //��͹�DZ��ǡ��Ķ۽DZ������Բ���ڡ���
            bool obtEdge = IsObtuseEdge(i);

            #region ���ݡ�Բ����͹���ڻ���������VEdge
            //Բ���ڱ������������죬����������

            if (!obtEdge)   //Բ����͹����(��߽���)/////////////////////////////////
            {
                if (!KExist)    //k������
                {
                    // MessageBox.Show("б�ʲ����ڵġ�-"+DS.TinEdges[i].AdjTriangle1ID.ToString());
                    if (BaryCnt.Y > MidPnt.Y || BaryCnt.Y < pnt3.Y)// BaryCnt<y3 ->Բ�����е��غ�
                        EndPnt.Y = DS.BBOX.YTop;
                    else if (BaryCnt.Y < MidPnt.Y || BaryCnt.Y > pnt3.Y)
                        EndPnt.Y = DS.BBOX.YBottom;

                    EndPnt.X = BaryCnt.X;
                }
                else      //K����
                {
                    if (BaryCnt.X > MidPnt.X || (BaryCnt.X == MidPnt.X && BaryCnt.X < pnt3.X))
                        EndPnt.X = DS.BBOX.XLeft;
                    else if (BaryCnt.X < MidPnt.X || (BaryCnt.X == MidPnt.X && BaryCnt.X > pnt3.X))
                        EndPnt.X = DS.BBOX.XRight;

                    EndPnt.Y = k * (EndPnt.X - BaryCnt.X) + BaryCnt.Y;
                }

            }
            else    //Բ����͹����/////////////////////////////////////////////
            {
                if (!KExist)    //k������
                {
                    if (BaryCnt.Y < MidPnt.Y || BaryCnt.Y < pnt3.Y)
                        EndPnt.Y = DS.BBOX.YTop;
                    else if (BaryCnt.Y > MidPnt.Y || BaryCnt.Y > pnt3.Y)
                        EndPnt.Y = DS.BBOX.YBottom;

                    EndPnt.X = BaryCnt.X;
                }
                else   //K����
                {
                    if (BaryCnt.X < MidPnt.X)
                        EndPnt.X = DS.BBOX.XLeft;
                    else if (BaryCnt.X > MidPnt.X)
                        EndPnt.X = DS.BBOX.XRight;

                    EndPnt.Y = k * (EndPnt.X - BaryCnt.X) + BaryCnt.Y;
                }

            }//else �ڡ���

            //����򽻵��ڱ߽���Ĵ���
            if (k != 0 && KExist)
            {
                if (EndPnt.Y < DS.BBOX.YTop)
                    EndPnt.Y = DS.BBOX.YTop;
                else if (EndPnt.Y > DS.BBOX.YBottom)
                    EndPnt.Y = DS.BBOX.YBottom;

                EndPnt.X = (EndPnt.Y - BaryCnt.Y) / k + BaryCnt.X;
            }

            #endregion
            v1.hullflag = true; v2.hullflag = true;
            if (v1.pointcompare(BaryCnt))
            {
                v1.voronicollect.Add(BaryCnt);
            }
            if (v2.pointcompare(BaryCnt))
            {
                v2.voronicollect.Add(BaryCnt);
            }
            v1.voronicollect.Add(EndPnt); v2.voronicollect.Add(EndPnt);
            v1.insertboundarycollect.Add(EndPnt); v2.insertboundarycollect.Add(EndPnt);
            g.DrawLine(new Pen(Color.Blue, 2), BaryCnt, EndPnt);
        }
Ejemplo n.º 6
0
        //����̩ɭ�����
        /// <summary>
        ///����̩ɭ�����
        /// </summary>
        /// <param name="starti">��ʼ�����ڵ���</param>
        /// <param name="store">����˳��</param>
        /// <param name="Sosflag">�����������������</param>
        /// <param name="insectflag">�ཻ������� �ཻΪ1</param>
        ///  <param name="insectpoint">�ཻ�������¼����</param>
        ///  <param name="polyon">�������������</param>
        ///  <param name="vectcollect">�����ཻ��̩ɭ�����</param>
        public void Sospoloy(int starti, bool store, int[] Sosflag, int[] taisflag,int[,] insectflag, PointF[,] insectpoint, voronoiboundary tais,Polyon multrect )
        {
            int m = multrect.Vertices.Count; int n = tais.voronicollect.Count;
            if (store)
            {
                for (int i = starti; i< n; i++)
                {
                    if (taisflag[i] == 1)
                    {
                        return;
                    }
                    else
                    {
                        taisflag[i] = 1;
                        if (PtInPolygon(tais.voronicollect[i], multrect.Vertices))
                        {
                            if (tais.Vimultptcompare(tais.voronicollect[i]))
                            {
                                tais.vimultcollect.Add(tais.voronicollect[i]);
                            }

                        }
                        for (int j = 0; j < m; j++)
                        {
                            if (insectflag[i,j] == 1)
                            {
                                insectflag[i,j] = 0;
                                if (tais.Vimultptcompare(insectpoint[i, j]))
                                {
                                    tais.vimultcollect.Add(insectpoint[i, j]);
                                }

                                if (PtInPolygon(multrect.Vertices[j], tais.voronicollect))
                                {
                                    if (tais.Vimultptcompare(multrect.Vertices[j]))
                                    {
                                        tais.vimultcollect.Add(multrect.Vertices[j]);
                                    }

                                    //������һ����ε�ѭ�� ����Ҫ�жϴ˶������ʲô˳��
                                    if (j < (j + 1) % m)
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy(j, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy(j, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                    else
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy(j, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy(j, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }

                                }
                                if (PtInPolygon(multrect.Vertices[(j + 1) % m], tais.voronicollect))
                                {
                                    if (tais.Vimultptcompare(multrect.Vertices[(j + 1) % m]))
                                    {
                                        tais.vimultcollect.Add(multrect.Vertices[(j + 1) % m]);
                                    }

                                    //������һ����ε�ѭ��
                                    if (j < (j + 1) % m)
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy((j + 1) % m, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy((j + 1) % m, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                    else
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy((j + 1) % m, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy((j + 1) % m, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }

                                }
                            }
                        }
                    }

                }
            }
            else
            {
                for (int i= starti + n; i > 0; i--)
                {
                    if (taisflag[i % n] == 1)
                    {
                        return;
                    }
                    else
                    {
                       taisflag[i% n] = 1;
                        if (PtInPolygon(tais.voronicollect[i % n], multrect.Vertices))
                        {
                            if (tais.Vimultptcompare(tais.voronicollect[i % n]))
                            {
                                tais.vimultcollect.Add(tais.voronicollect[i % n]);
                            }

                        }
                        for (int j = 0; j < m; j++)
                        {
                            if (insectflag[i%n,j] == 1)
                            {
                                insectflag[i % n,j] = 0;
                                if (tais.Vimultptcompare(insectpoint[i % n, j]))
                                {
                                    tais.vimultcollect.Add(insectpoint[i % n, j]);
                                }

                                if (PtInPolygon(multrect.Vertices[j], tais.voronicollect))
                                {
                                    if (tais.Vimultptcompare(multrect.Vertices[j]))
                                    {
                                        tais.vimultcollect.Add(multrect.Vertices[j]);
                                    }

                                    //������һ���ѭ��
                                    if (j < (j + 1) % m)
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy(j, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy(j, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }

                                    else
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy(j, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy(j,false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                }
                                if (PtInPolygon(multrect.Vertices[(j + 1) % m], tais.voronicollect))
                                {
                                    if (tais.Vimultptcompare(multrect.Vertices[(j + 1) % m]))
                                    {
                                        tais.vimultcollect.Add(multrect.Vertices[(j + 1) % m]);
                                    }

                                    //����Ҫѭ��������
                                    if (j < (j + 1) % m)
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy((j + 1) % m, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy((j + 1) % m, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                   else
                                    {
                                        if (!IsCCW(multrect.Vertices))
                                        {
                                            Sospoloy((j + 1) % m, false, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                        }
                                        else
                                            Sospoloy((j + 1) % m, true, Sosflag, taisflag, insectflag, insectpoint, multrect, tais);
                                    }
                                }
                            }
                        }
                    }

                }
            }
        }