private void button3_Click(object sender, EventArgs e) // Polygons { int nBits = CombIm.N_Bits; if (!EDGES) { MessageBox.Show("Click edge detection"); return; } if (!radioButton1.Checked && !radioButton2.Checked) { MessageBox.Show("Choose a radio button with 'Radii'"); return; } OrigIm.ImageToBitmapOld(BmpPictBox1, this); int maxL2 = 100000, maxV = 220000, maxArc = 40000; L = new CListLines(maxL2, maxV, maxArc); int marginX = (pictureBox2.Width - (int)(Scale1 * OrigIm.width)) / 2; int marginY = (pictureBox2.Height - (int)(Scale1 * OrigIm.height)) / 2; int PicBoxInd = 1; if (radioButton1.Checked) { Ins1 = new CInscript(PicBoxInd, 0.6, 0, 0, OrigIm.width, Color.Yellow, this); radio1_Checked = true; } else if (radioButton2.Checked) { Ins1 = new CInscript(PicBoxInd, 0.8, 0, 0, OrigIm.width, Color.Yellow, this); radio2_Checked = true; } PicBoxInd = 2; Ins2 = new CInscript(PicBoxInd, 0.5, 0, 0, OrigIm.width, Color.White, this); CombIm.nLoop = nLoop; CombIm.denomProg = denomProg; // 0 1 2 3 4 5 6 7 int[] minRad = { 10, 14, 23, 35, 53, 80, 120, 180 }; int[] maxRad = { 20, 30, 46, 70, 106, 160, 240, 360 }; double[] ProtEps = { 1.05, 1.15, 1.23, 1.35, 1.50, 1.67, 1.85, 2.0 }; double maxAngle1 = 0.0, maxAngle2 = 0.0; optVar1 = optVar2 = -1; optNcircle1 = optNcircle2 = 0; int nVar = 8; int maxCircle = 2000; nBest = 0; nCircle = new int[nVar]; Circle = new CCircle[nVar, maxCircle]; // declared in Form1 for (int iv = 0; iv < nVar; iv++) { for (int i = 0; i < maxCircle; i++) { Circle[iv, i] = new CCircle(); } } BestCircles1 = new CCircle[6000]; for (int i = 0; i < 600; i++) { BestCircles1[i] = new CCircle(); } BestCircles2 = new CCircle[600]; for (int i = 0; i < 600; i++) { BestCircles2[i] = new CCircle(); } int nArcs = 0, rv = 1; int iVarStart = 0, iVarEnd = 7; if (radioButton1.Checked) { iVarEnd = 4; } else if (radioButton2.Checked) { iVarStart = 3; } else { MessageBox.Show("Chose a radio button with 'Radii'"); } progressBar1.Value = 0; progressBar1.Visible = true; progressBar1.Step = 20; for (int iVar = iVarStart; iVar <= iVarEnd; iVar++) //=========================================== { progressBar1.PerformStep(); eps = ProtEps[iVar]; numericUpDown2.Value = (decimal)eps; rv = L.SearchPoly(ref CombIm, eps, this); if (rv < 0) { break; } double maxSinus = 0.7, maxProportion = 0.2; L.CheckSmooth(maxSinus, maxProportion); rv = L.DrawPolygons(pictureBox2, EdgeIm, this); EDGES = false; POLY = true; nArcs = L.MakeArcs3(pictureBox2, minRad[iVar], maxRad[iVar], eps, this); if (nArcs < 0) { break; } nBest = 0; nCircle[iVar] = 0; int[] iBestCircles1 = new int[100]; nCircle[iVar] = L.MakeCirclesEl(Circle, iVar, ref nCircle[iVar], minRad[iVar], maxRad[iVar], iBestCircles1, ref nBest); if (nCircle[iVar] < 0) { break; } double SumAngle; //if (nCircle[iVar] > 0) SumAngle = TestCircles(Circle, iVar, nCircle[iVar]); if (nCircle[iVar] > 0) { SumAngle = TestCircles(Circle, iVar, nCircle); } else { SumAngle = 0.0; } if (radioButton1.Checked) { int cnt = 0; if (SumAngle > maxAngle1) { cnt = 0; for (int iCircle = 0; iCircle < nCircle[iVar]; iCircle++) { if (Circle[iVar, iCircle].good) { BestCircles1[cnt] = Circle[iVar, iCircle]; cnt++; } } maxAngle1 = SumAngle; optVar1 = iVar; optNcircle1 = cnt; } } if (radioButton2.Checked) { int cnt = 0; if (SumAngle > maxAngle2) { cnt = 0; for (int iCircle = 0; iCircle < nCircle[iVar]; iCircle++) { if (Circle[iVar, iCircle].good) { BestCircles2[cnt] = Circle[iVar, iCircle]; cnt++; } } maxAngle2 = SumAngle; optVar2 = iVar; optNcircle2 = cnt; } } } //=========================== end for (int iVar... ================================== if (rv < 0) { return; } progressBar1.Visible = false; if (radioButton1.Checked) { nBest = L.ShowBestCircles3(BestCircles1, optNcircle1, 2.0, this); MessageBox.Show("Form1: Number of recognized circles is " + nBest); } if (radioButton2.Checked) { nBest = L.ShowBestCircles3(BestCircles2, optNcircle2, 1.0, this); MessageBox.Show("Form1: Number of recognized circles is " + nBest); } label5.Visible = true; label5.Text = "Recognized circles"; label6.Visible = true; label6.Text = "Polygons"; button4.Visible = true; button5.Visible = true; groupBox2.Visible = true; } //*************************** end Polygons *******************************
public void Write(string Str, int x0, int y0, CInscript Ins) { int i, len = Str.Length, rv = x0; for (i = 0; i < len; i++) //=============================================== { switch (Str[i]) { case '-': rv = Ins.Minus(rv, y0); break; case '+': rv = Ins.Plus(rv, y0); break; case '=': rv = Ins.Equal(rv, y0); break; case '.': rv = Ins.Stop(rv, y0); break; case '0': rv = Ins.Null(rv, y0); break; case '1': rv = Ins.F1(rv, y0); break; case '2': rv = Ins.F2(rv, y0); break; case '3': rv = Ins.F3(rv, y0); break; case '4': rv = Ins.F4(rv, y0); break; case '5': rv = Ins.F5(rv, y0); break; case '6': rv = Ins.F6(rv, y0); break; case '7': rv = Ins.F7(rv, y0); break; case '8': rv = Ins.F8(rv, y0); break; case '9': rv = Ins.F9(rv, y0); break; case 'a': case 'A': rv = Ins.A(rv, y0); break; case 'b': case 'B': rv = Ins.B(rv, y0); break; case 'c': case 'C': rv = Ins.C(rv, y0); break; case 'e': case 'E': rv = Ins.E(rv, y0); break; case 'i': case 'I': rv = Ins.I(rv, y0); break; case 'k': case 'K': rv = Ins.K(rv, y0); break; case 'l': case 'L': rv = Ins.L(rv, y0); break; case 'm': case 'M': rv = Ins.M(rv, y0); break; case 'n': case 'N': rv = Ins.N(rv, y0); break; case 'r': case 'R': rv = Ins.R(rv, y0); break; case 't': case 'T': rv = Ins.T(rv, y0); break; case 'u': case 'U': rv = Ins.U(rv, y0); break; case 'w': case 'W': rv = Ins.W(rv, y0); break; } //::::::::::::::::::::::: end switch ::::::::::::::::::::::::::::::::::: } //========================= end for (i ... ================================= } //*************************** end write ****************************************