Beispiel #1
0
        public int SS(DataProcess BB, DataStucture.Triangle[] Tri, int K, int k, ref int L, double[,] Value1, DataStucture.Line[] Line, ref int o)
        {
            int temp, jud = 0, re = 0, k1 = 0, k2 = 0, c = 0, d = 0;

            DataStucture.Line[] Linetemp = new DataStucture.Line[2];
            Linetemp[0] = new DataStucture.Line();
            Linetemp[1] = new DataStucture.Line();
            temp        = BB.Search(Tri, K, 2, k, Value1);
            if (temp != -1)
            {
                Linetemp[0].Point[0] = Tri[K].Peak[0];
                Linetemp[0].Point[1] = temp;
                Linetemp[1].Point[0] = temp;
                Linetemp[1].Point[1] = Tri[K].Peak[1];
                jud = BB.Judge(Tri, L, Linetemp[0], Linetemp[1], Tri[K].Line[0]);
                if (jud == 1)
                {
                    Line[o]        = new DataStucture.Line();
                    Tri[L]         = new DataStucture.Triangle();
                    Tri[L].Line[0] = new DataStucture.Line();
                    Tri[L].Line[1] = new DataStucture.Line();
                    Tri[L].Line[2] = new DataStucture.Line();
                    Line[Tri[K].Line[0].ID - 1].Bor[1] = L + 1;
                    Tri[L].ID      = L + 1;
                    Tri[L].Peak[0] = Tri[K].Peak[1];
                    Tri[L].Peak[1] = Tri[K].Peak[0];
                    Tri[L].Peak[2] = temp;

                    k1               = Judge2(Tri, L, Linetemp[1], ref c, ref d);
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Linetemp[1].Point[0];
                    Line[o].Point[1] = Linetemp[1].Point[1];
                    Line[o].Bor[0]   = L + 1;
                    Tri[L].Line[2]   = Line[o];

                    if (k1 != -1)
                    {
                        Line[k1].Bor[1] = L + 1;
                        Line[o].Bor[1]  = c + 1;
                        Tri[c].Bor[d]   = L + 1;
                        Tri[L].Bor[2]   = c + 1;
                    }
                    o++;

                    k2               = Judge2(Tri, L, Linetemp[0], ref c, ref d);
                    Line[o]          = new DataStucture.Line();
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Linetemp[0].Point[0];
                    Line[o].Point[1] = Linetemp[0].Point[1];
                    Line[o].Bor[0]   = L + 1;
                    Tri[L].Line[1]   = Line[o];

                    if (k2 != -1)
                    {
                        Line[k2].Bor[1] = L + 1;
                        Line[o].Bor[1]  = c + 1;
                        Tri[c].Bor[d]   = L + 1;
                        Tri[L].Bor[1]   = c + 1;
                    }
                    o++;

                    Line[o]          = new DataStucture.Line();
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Tri[L].Peak[0];
                    Line[o].Point[1] = Tri[L].Peak[1];
                    Line[o].Bor[0]   = L + 1;
                    Line[o].Bor[1]   = K + 1;
                    Tri[L].Line[0]   = Line[o];
                    o++;

                    Tri[K].Bor[0] = L + 1;
                    Tri[L].Bor[0] = K + 1;
                    L++;
                    re++;
                }
                else
                {
                    //if (K+1 == Line[Tri[K].Line[0].ID-1].Bor[0] && Line[Tri[K].Line[0].ID-1].Bor[1] != 0)
                    //    Tri[K].Bor[0] = Line[Tri[K].Line[0].ID-1].Bor[1];
                    //else if (K+1 == Line[Tri[K].Line[0].ID-1].Bor[0] && Line[Tri[K].Line[0].ID-1].Bor[1] == 0)
                    //    Tri[K].Bor[0] = -1;
                    //else if (K+1 != Line[Tri[K].Line[0].ID-1].Bor[0] && Line[Tri[K].Line[0].ID-1].Bor[0] == 0)
                    //    Tri[K].Bor[0] = -1;
                    //else if (K+1 != Line[Tri[K].Line[0].ID-1].Bor[0] && Line[Tri[K].Line[0].ID-1].Bor[0] != 0)
                    //    Tri[K].Bor[0] = Line[Tri[K].Line[0].ID-1].Bor[0];
                }
            }
            else
            {
                Tri[K].Bor[0]         = -1;
                Tri[K].Line[0].Bor[1] = -1;
            }


            temp = BB.Search(Tri, K, 1, k, Value1);
            if (temp != -1)
            {
                Linetemp[0].Point[0] = temp;
                Linetemp[0].Point[1] = Tri[K].Peak[0];
                Linetemp[1].Point[0] = Tri[K].Peak[2];
                Linetemp[1].Point[1] = temp;
                jud = BB.Judge(Tri, L, Linetemp[0], Linetemp[1], Tri[K].Line[2]);
                if (jud == 1)
                {
                    Tri[L]         = new DataStucture.Triangle();
                    Line[o]        = new DataStucture.Line();
                    Tri[L].Line[0] = new DataStucture.Line();
                    Tri[L].Line[1] = new DataStucture.Line();
                    Tri[L].Line[2] = new DataStucture.Line();
                    Line[Tri[K].Line[2].ID - 1].Bor[1] = L + 1;
                    Tri[L].ID      = L + 1;
                    Tri[L].Peak[0] = Tri[K].Peak[0];
                    Tri[L].Peak[1] = Tri[K].Peak[2];
                    Tri[L].Peak[2] = temp;

                    k1               = Judge2(Tri, L, Linetemp[0], ref c, ref d);
                    Line[o]          = new DataStucture.Line();
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Linetemp[0].Point[0];
                    Line[o].Point[1] = Linetemp[0].Point[1];
                    Line[o].Bor[0]   = L + 1;
                    Tri[L].Line[2]   = Line[o];

                    if (k1 != -1)
                    {
                        Line[k1].Bor[1] = L + 1;
                        Line[o].Bor[1]  = c + 1;
                        Tri[c].Bor[d]   = L + 1;
                        Tri[L].Bor[2]   = c + 1;
                    }
                    o++;

                    k2               = Judge2(Tri, L, Linetemp[1], ref c, ref d);
                    Line[o]          = new DataStucture.Line();
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Linetemp[1].Point[0];
                    Line[o].Point[1] = Linetemp[1].Point[1];
                    Line[o].Bor[0]   = L + 1;
                    Tri[L].Line[1]   = Line[o];

                    if (k2 != -1)
                    {
                        Line[k2].Bor[1] = L + 1;
                        Line[o].Bor[1]  = c + 1;
                        Tri[c].Bor[d]   = L + 1;
                        Tri[L].Bor[1]   = c + 1;
                    }
                    o++;

                    Line[o]          = new DataStucture.Line();
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Tri[L].Peak[0];
                    Line[o].Point[1] = Tri[L].Peak[1];
                    Line[o].Bor[0]   = L + 1;
                    Line[o].Bor[1]   = K + 1;
                    Tri[L].Line[0]   = Line[o];
                    o++;

                    Tri[K].Bor[2] = L + 1;
                    Tri[L].Bor[0] = K + 1;
                    L++;
                    re++;
                }
                else
                {
                    //if (K == Line[Tri[K].Line[2].ID].Bor[0] &&  Line[Tri[K].Line[2].ID].Bor[1]!=0)
                    //    Tri[K].Bor[2] = Line[Tri[K].Line[2].ID].Bor[1];
                    //else if (K == Line[Tri[K].Line[2].ID].Bor[0] && Line[Tri[K].Line[2].ID].Bor[1] == 0)
                    //    Tri[K].Bor[2] = -1;
                    //else if(K != Line[Tri[K].Line[2].ID].Bor[0] &&  Line[Tri[K].Line[2].ID].Bor[0]==0)
                    //    Tri[K].Bor[2] = -1;
                    //else if(K != Line[Tri[K].Line[2].ID].Bor[0] &&  Line[Tri[K].Line[2].ID].Bor[0]!=0)
                    //    Tri[K].Bor[2] = Line[Tri[K].Line[2].ID].Bor[0];
                }
            }
            else
            {
                Tri[K].Line[2].Bor[1] = -1;
                Tri[K].Bor[2]         = -1;
            }

            temp = BB.Search(Tri, K, 0, k, Value1);
            if (temp != -1)
            {
                Linetemp[0].Point[0] = temp;
                Linetemp[0].Point[1] = Tri[K].Peak[2];
                Linetemp[1].Point[0] = Tri[K].Peak[1];
                Linetemp[1].Point[1] = temp;
                jud = BB.Judge(Tri, L, Linetemp[0], Linetemp[1], Tri[K].Line[1]);
                if (jud == 1)
                {
                    Tri[L]         = new DataStucture.Triangle();
                    Line[o]        = new DataStucture.Line();
                    Tri[L].Line[0] = new DataStucture.Line();
                    Tri[L].Line[1] = new DataStucture.Line();
                    Tri[L].Line[2] = new DataStucture.Line();
                    Line[Tri[K].Line[1].ID - 1].Bor[1] = L + 1;
                    Tri[L].ID      = L + 1;
                    Tri[L].Peak[0] = Tri[K].Peak[2];
                    Tri[L].Peak[1] = Tri[K].Peak[1];
                    Tri[L].Peak[2] = temp;

                    k1               = Judge2(Tri, L, Linetemp[0], ref c, ref d);
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Linetemp[0].Point[0];
                    Line[o].Point[1] = Linetemp[0].Point[1];
                    Line[o].Bor[0]   = L + 1;
                    Tri[L].Line[2]   = Line[o];
                    if (k1 != -1)
                    {
                        Line[k1].Bor[1] = L + 1;
                        Line[o].Bor[1]  = c + 1;
                        Tri[c].Bor[d]   = L + 1;
                        Tri[L].Bor[2]   = c + 1;
                    }
                    o++;

                    k2               = Judge2(Tri, L, Linetemp[1], ref c, ref d);
                    Line[o]          = new DataStucture.Line();
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Linetemp[1].Point[0];
                    Line[o].Point[1] = Linetemp[1].Point[1];
                    Line[o].Bor[0]   = L + 1;
                    Tri[L].Line[1]   = Line[o];

                    if (k2 != -1)
                    {
                        Line[k2].Bor[1] = L + 1;
                        Line[o].Bor[1]  = c + 1;
                        Tri[c].Bor[d]   = L + 1;
                        Tri[L].Bor[1]   = c + 1;
                    }
                    o++;

                    Line[o]          = new DataStucture.Line();
                    Line[o].ID       = o + 1;
                    Line[o].Point[0] = Tri[L].Peak[0];
                    Line[o].Point[1] = Tri[L].Peak[1];
                    Line[o].Bor[0]   = L + 1;
                    Line[o].Bor[1]   = K + 1;
                    Tri[L].Line[0]   = Line[o];
                    o++;

                    Tri[K].Bor[1] = L + 1;
                    Tri[L].Bor[0] = K + 1;
                    L++;
                    re++;
                }
                else
                {
                    //if (K == Line[Tri[K].Line[1].ID].Bor[0] && Line[Tri[K].Line[1].ID].Bor[1] != 0)
                    //    Tri[K].Bor[1] = Line[Tri[K].Line[1].ID].Bor[1];
                    //else if (K == Line[Tri[K].Line[1].ID].Bor[0] && Line[Tri[K].Line[1].ID].Bor[1] == 0)
                    //    Tri[K].Bor[1] = -1;
                    //else if (K != Line[Tri[K].Line[1].ID].Bor[0] && Line[Tri[K].Line[1].ID].Bor[0] == 0)
                    //    Tri[K].Bor[1] = -1;
                    //else if (K != Line[Tri[K].Line[1].ID].Bor[0] && Line[Tri[K].Line[1].ID].Bor[0] != 0)
                    //    Tri[K].Bor[1] = Line[Tri[K].Line[1].ID].Bor[0];
                }
            }
            else
            {
                Tri[K].Line[1].Bor[1] = -1;
                Tri[K].Bor[1]         = -1;
            }
            return(re);
        }
Beispiel #2
0
        private void  角网生长算法ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.toolStripProgressBar1.Maximum = 20; //设置进度条的最大值
            this.toolStripProgressBar1.Value   = 4;  //设置进度条的值
            k      = TempStr2.Length / 3;            //点个数
            Value2 = new double[k, k];
            double Min = 0, min2 = 0, midx, midy;
            int    m = 0, n = 1, L = 0, g = 0, h = 1;

            K = 0;
            int[] AA = new int[k];
            for (int i = 0; i < k; i++)//计算两点间距离,找出距离最近的两个点
            {
                for (int j = i + 1; j < k; j++)
                {
                    Value2[i, j] = (Value1[i, 1] - Value1[j, 1]) * (Value1[i, 1] - Value1[j, 1]) +
                                   (Value1[i, 2] - Value1[j, 2]) * (Value1[i, 2] - Value1[j, 2]);
                    if (i == 0 && j == 1)
                    {
                        Min = Value2[0, 1];
                    }
                    else
                    {
                        if (Min > Value2[i, j])
                        {
                            m   = i; n = j;
                            Min = Value2[i, j];//求一个最小值
                        }
                    }
                }
            }

            this.toolStripProgressBar1.Value = 6;
            Tri            = new DataStucture.Triangle[k * (k - 1) / 2];
            Line           = new DataStucture.Line[k * (k - 1) / 2];
            Tri[0]         = new DataStucture.Triangle();
            Tri[0].Line[0] = new DataStucture.Line();
            Tri[0].Line[1] = new DataStucture.Line();
            Tri[0].Line[2] = new DataStucture.Line();

            Tri[0].ID      = 1;
            Tri[0].Peak[0] = m;
            Tri[0].Peak[1] = n;

            Tri[0].Line[0].ID       = 1;
            Tri[0].Line[0].Point[0] = m;
            Tri[0].Line[0].Point[1] = n;

            Line[0]          = new DataStucture.Line();
            Line[1]          = new DataStucture.Line();
            Line[2]          = new DataStucture.Line();
            Line[0].ID       = 1;
            Line[0].Point[0] = m;
            Line[0].Point[1] = n;
            o = 1;
            this.toolStripProgressBar1.Value = 8;
            int q = 0;

            midx = (Value1[m, 1] + Value1[n, 1]) / 2;
            midy = (Value1[m, 2] + Value1[n, 2]) / 2;

            for (int j = 0; j < k; j++)
            {
                if ((j != m) && (j != n))
                {
                    Min = (midx - Value1[j, 1]) * (midx - Value1[j, 1]) + (midy - Value1[j, 2]) * (midy - Value1[j, 2]);
                    q   = j;
                    break;
                }
            }
            for (int i = 0; i < k; i++)
            {
                if ((i != m) && (i != n) && ((midx - Value1[i, 1]) * (midx - Value1[i, 1]) + (midy - Value1[i, 2]) * (midy - Value1[i, 2]) < Min))
                {
                    Min = (midx - Value1[i, 1]) * (midx - Value1[i, 1]) + (midy - Value1[i, 2]) * (midy - Value1[i, 2]);
                    q   = i;
                }
            }
            Line[1].ID       = 2;
            Line[1].Point[0] = Tri[0].Line[0].Point[1];
            Line[1].Point[1] = q;
            Line[2].ID       = 3;
            Line[2].Point[0] = q;
            Line[2].Point[1] = Line[0].Point[0];
            Line[0].Bor[0]   = Tri[0].ID;
            Line[1].Bor[0]   = Tri[0].ID;
            Line[2].Bor[0]   = Tri[0].ID;

            Tri[0].Peak[2] = q;
            Tri[0].Line[1] = Line[1];
            Tri[0].Line[2] = Line[2];

            this.toolStripProgressBar1.Value = 12;

            o = 3;
            L = 1;
            K = 0;
            ArrayList List1 = new ArrayList();
            ArrayList List2 = new ArrayList();

            DataStucture.Line[] Linetemp = new DataStucture.Line[2];
            DataProcess         BB       = new DataProcess();
            DataProcess         CC       = new DataProcess();

            while (K < L)
            {
                int d;
                d = CC.SS(BB, Tri, K, k, ref L, Value1, Line, ref o);
                K++;
            }

            this.toolStripProgressBar1.Value = 16;
            DataTable dt = new DataTable();

            dt.Columns.Add("顶点1", typeof(String));
            dt.Columns.Add("顶点2", typeof(String));
            dt.Columns.Add("顶点3", typeof(String));
            this.dataGridView1.DataSource = dt;                 //将datatable绑定到datagridview上显示结果
            for (int i = 0; i < L; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = Tri[i].Peak[0];
                dr[1] = Tri[i].Peak[1];
                dr[2] = Tri[i].Peak[2];
                dt.Rows.Add(dr);
            }
            dataGridView1.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.AllowUserToAddRows             = false;
            groupBox1.Text = "TIN三角形点号";

            curBitmap = new Bitmap(wid, hig);
            //myGraphics.Clear(Color.White);
            for (int i = 0; i < K; i++)
            {
                Graphics myGraphics = Graphics.FromImage(curBitmap);    //创建Graphics对象
                myGraphics.DrawLine(new Pen(Color.Red, 1), new PointF((float)Value3[Tri[i].Peak[0], 2], (float)Value3[Tri[i].Peak[0], 1]), new PointF((float)Value3[Tri[i].Peak[1], 2], (float)Value3[Tri[i].Peak[1], 1]));
                myGraphics.DrawLine(new Pen(Color.Red, 1), new PointF((float)Value3[Tri[i].Peak[1], 2], (float)Value3[Tri[i].Peak[1], 1]), new PointF((float)Value3[Tri[i].Peak[2], 2], (float)Value3[Tri[i].Peak[2], 1]));
                myGraphics.DrawLine(new Pen(Color.Red, 1), new PointF((float)Value3[Tri[i].Peak[0], 2], (float)Value3[Tri[i].Peak[0], 1]), new PointF((float)Value3[Tri[i].Peak[2], 2], (float)Value3[Tri[i].Peak[2], 1]));
                myGraphics.Dispose();
                this.pictureBox1.Image = curBitmap;
            }
            this.toolStripProgressBar1.Value = 20;
            this.toolStripProgressBar1.Value = 0;
        }