예제 #1
0
        private void btn_randomOptions_Click(object sender, EventArgs e)
        {
            FormRandomOptions randomOptions = new FormRandomOptions();

            randomOptions.StartPosition = FormStartPosition.CenterScreen;
            randomOptions.ShowDialog();
        }
예제 #2
0
        private void runTestTimerAlgorithm()
        {
            btn_Clear.Enabled         = false;
            btn_draw.Enabled          = false;
            btn_inputLine.Enabled     = false;
            btn_randomOptions.Enabled = false;
            btn_statistics.Enabled    = false;

            btn_inputCircle.Enabled    = false;
            btn_inputEllipse.Enabled   = false;
            btn_inputParabol.Enabled   = false;
            btn_intputHyperbol.Enabled = false;

            listBox1.Enabled = false;

            int shapeType    = FormRandomOptions.getType();
            int numberObject = FormRandomOptions.getObjectNumer();

            Init();
            int[] x0, y0;

            switch (shapeType)
            {
            case FormRandomOptions.Line:
                x0 = new int[numberObject];
                y0 = new int[numberObject];
                int[] x1 = new int[numberObject];
                int[] y1 = new int[numberObject];
                //Random range 0..numberObject-1
                Random rd = new Random();
                for (int i = 0; i < numberObject; i++)
                {
                    x0[i] = rd.Next(0, max_X);
                    y0[i] = rd.Next(0, max_Y);
                    x1[i] = rd.Next(0, max_X);
                    y1[i] = rd.Next(0, max_Y);
                }

                //timer DDA
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Line(x0[i], y0[i], x1[i], y1[i]);
                    time.Reset();
                    time.Start();
                    myObject.draw_DDA(drawOnePixel);
                    time.Stop();
                    time_DDA   += time.ElapsedMilliseconds;
                    numObj.Text = (i + 1).ToString();
                }


                //timer Bresenham

                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Line(x0[i], y0[i], x1[i], y1[i]);
                    time.Reset();
                    time.Start();
                    myObject.draw_Bresenham(drawOnePixel);
                    time.Stop();
                    time_Bresenham += time.ElapsedMilliseconds;
                    numObj.Text     = (i + 1).ToString();
                }


                //timer midpoint

                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Line(x0[i], y0[i], x1[i], y1[i]);
                    time.Reset();
                    time.Start();
                    myObject.draw_MidPoint(drawOnePixel);
                    time.Stop();
                    time_MidPoint += time.ElapsedMilliseconds;
                    numObj.Text    = (i + 1).ToString();
                }


                //timer xiaolin wu

                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Line(x0[i], y0[i], x1[i], y1[i]);
                    time.Reset();
                    time.Start();
                    myObject.draw_XiaolinWu(drawOnePixelWithBrightness);
                    time.Stop();
                    time_XiaolinWu += time.ElapsedMilliseconds;
                    numObj.Text     = (i + 1).ToString();
                }
                break;

            case FormRandomOptions.Circle:
                time_Bresenham = 0;
                time_DDA       = 0;
                time_XiaolinWu = 0;

                x0 = new int[numberObject];
                y0 = new int[numberObject];
                int[] radius = new int[numberObject];

                //Random range 0..numberObject-1
                rd = new Random();
                for (int i = 0; i < numberObject; i++)
                {
                    radius[i] = rd.Next(0, max_Y / 4);
                    x0[i]     = rd.Next(max_X / 3, 2 * max_X / 3);
                    y0[i]     = rd.Next(max_Y / 3, 2 * max_Y / 3);
                }

                //timer midpoint
                time.Reset();
                time.Start();
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Circle(x0[i], y0[i], radius[i]);
                    myObject.draw_MidPoint(drawOnePixel);
                    numObj.Text = (i + 1).ToString();
                }
                time.Stop();
                time_MidPoint = time.ElapsedMilliseconds;

                //timer dda
                time.Reset();
                time.Start();
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Circle(x0[i], y0[i], radius[i]);
                    myObject.draw_DDA(drawOnePixel);
                    numObj.Text = (i + 1).ToString();
                }
                time.Stop();
                time_DDA = time.ElapsedMilliseconds;
                break;

            case FormRandomOptions.Ellipse:
                time_Bresenham = 0;
                time_DDA       = 0;
                time_XiaolinWu = 0;

                x0 = new int[numberObject];
                y0 = new int[numberObject];
                int[] halBigAxis    = new int[numberObject];
                int[] halfSmallAxis = new int[numberObject];

                //Random range 0..numberObject-1
                rd = new Random();
                for (int i = 0; i < numberObject; i++)
                {
                    halBigAxis[i]    = rd.Next(0, max_Y / 4);
                    halfSmallAxis[i] = rd.Next(0, max_Y / 4);
                    x0[i]            = rd.Next(max_X / 3, 2 * max_X / 3);
                    y0[i]            = rd.Next(max_Y / 3, 2 * max_Y / 3);
                }

                //timer midpoint
                time.Reset();
                time.Start();
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Ellipse(x0[i], y0[i], halBigAxis[i], halfSmallAxis[i]);
                    myObject.draw_MidPoint(drawOnePixel);
                    numObj.Text = (i + 1).ToString();
                }
                time.Stop();
                time_MidPoint = time.ElapsedMilliseconds;

                //timer dda
                time.Reset();
                time.Start();
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Ellipse(x0[i], y0[i], halBigAxis[i], halfSmallAxis[i]);
                    myObject.draw_DDA(drawOnePixel);
                    numObj.Text = (i + 1).ToString();
                }
                time.Stop();
                time_DDA = time.ElapsedMilliseconds;
                break;

            case FormRandomOptions.Parabol:
                time_Bresenham = 0;
                time_DDA       = 0;
                time_XiaolinWu = 0;

                x0 = new int[numberObject];
                y0 = new int[numberObject];
                double[] a = new double[numberObject];

                //Random range 0..numberObject-1
                rd = new Random();
                for (int i = 0; i < numberObject; i++)
                {
                    a[i]  = rd.NextDouble();
                    x0[i] = rd.Next(300, 400);
                    y0[i] = rd.Next(100, 200);
                }

                //timer midpoint
                time.Reset();
                time.Start();
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Parabol(x0[i], y0[i], a[i]);
                    myObject.draw_MidPoint(drawOnePixel);
                    numObj.Text = (i + 1).ToString();
                }
                time.Stop();
                time_MidPoint = time.ElapsedMilliseconds;

                //timer dda
                time.Reset();
                time.Start();
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Parabol(x0[i], y0[i], a[i]);
                    myObject.draw_DDA(drawOnePixel);
                    numObj.Text = (i + 1).ToString();
                }
                time.Stop();
                time_DDA = time.ElapsedMilliseconds;
                break;

            case FormRandomOptions.Hyperbol:
                time_Bresenham = 0;
                time_DDA       = 0;
                time_XiaolinWu = 0;

                x0 = new int[numberObject];
                y0 = new int[numberObject];
                int[] realAxis    = new int[numberObject];
                int[] virtualAxis = new int[numberObject];

                //Random range 0..numberObject-1
                rd = new Random();
                for (int i = 0; i < numberObject; i++)
                {
                    realAxis[i]    = rd.Next(0, max_Y / 4);
                    virtualAxis[i] = rd.Next(0, max_Y / 4);
                    x0[i]          = rd.Next(max_X / 3, 2 * max_X / 3);
                    y0[i]          = rd.Next(max_Y / 3, 2 * max_Y / 3);
                }

                //timer midpoint
                time.Reset();
                time.Start();
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Hyperbol(x0[i], y0[i], realAxis[i], virtualAxis[i]);
                    myObject.draw_MidPoint(drawOnePixel);
                    numObj.Text = (i + 1).ToString();
                }
                time.Stop();
                time_MidPoint = time.ElapsedMilliseconds;

                //timer dda
                time.Reset();
                time.Start();
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    DrawingObject myObject = new Hyperbol(x0[i], y0[i], realAxis[i], virtualAxis[i]);
                    myObject.draw_DDA(drawOnePixel);
                    numObj.Text = (i + 1).ToString();
                }
                time.Stop();
                time_DDA = time.ElapsedMilliseconds;
                break;
            }



            if (shapeType != FormRandomOptions.Acc_line)
            {
                //display result
                FormStatistic formStat = new FormStatistic();
                formStat.StartPosition = FormStartPosition.CenterScreen;
                formStat.setTimeForStat(time_DDA, time_Bresenham, time_MidPoint, time_XiaolinWu);
                formStat.ShowDialog();
            }
            else
            {
                double var_DDA = 0, var_Bresenham = 0, var_Midpoint = 0, var_xiaolin = 0;

                x0 = new int[numberObject];
                y0 = new int[numberObject];
                int[] x1 = new int[numberObject];
                int[] y1 = new int[numberObject];
                //Random range 0..numberObject-1
                Random rd = new Random();
                for (int i = 0; i < numberObject; i++)
                {
                    x0[i] = rd.Next(0, max_X);
                    y0[i] = rd.Next(0, max_Y);
                    x1[i] = rd.Next(0, max_X);
                    y1[i] = rd.Next(0, max_Y);
                }
                Line.var = 0;
                var_DDA  = 0;
                //accuracy DDA with sum of sub all pixel with real point on the line
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    Line myObject = new Line(x0[i], y0[i], x1[i], y1[i]);

                    myObject.draw_DDA(myObject.calculateAcc);

                    var_DDA    += Line.var;
                    numObj.Text = (i + 1).ToString();
                }

                Line.var      = 0;
                var_Bresenham = 0;
                //accuracy Bresenham with sum of sub all pixel with real point on the line
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    Line myObject = new Line(x0[i], y0[i], x1[i], y1[i]);

                    myObject.draw_Bresenham(myObject.calculateAcc);

                    var_Bresenham += Line.var;
                    numObj.Text    = (i + 1).ToString();
                }

                Line.var     = 0;
                var_Midpoint = 0;
                //accuracy Midpoint with sum of sub all pixel with real point on the line
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    Line myObject = new Line(x0[i], y0[i], x1[i], y1[i]);

                    myObject.draw_MidPoint(myObject.calculateAcc);

                    var_Midpoint += Line.var;
                    numObj.Text   = (i + 1).ToString();
                }

                Line.var    = 0;
                var_xiaolin = 0;
                //accuracy Xiaolin with sum of sub all pixel with real point on the line
                for (int i = 0; i < numberObject; i++)
                {
                    Init();
                    Line myObject = new Line(x0[i], y0[i], x1[i], y1[i]);

                    myObject.draw_XiaolinWu(myObject.calculateAcc_Xiaolin);

                    var_xiaolin += Line.var;
                    numObj.Text  = (i + 1).ToString();
                }

                //display result
                FormAccuracy formAcc = new FormAccuracy();
                formAcc.StartPosition = FormStartPosition.CenterScreen;
                formAcc.setVarForAcc(var_DDA, var_Bresenham, var_Midpoint, var_xiaolin);
                formAcc.ShowDialog();
            }



            btn_Clear.Enabled         = true;
            btn_draw.Enabled          = true;
            btn_inputLine.Enabled     = true;
            btn_randomOptions.Enabled = true;
            btn_statistics.Enabled    = true;

            btn_inputCircle.Enabled    = true;
            btn_inputEllipse.Enabled   = true;
            btn_inputParabol.Enabled   = true;
            btn_intputHyperbol.Enabled = true;
            listBox1.Enabled           = true;

            numObj.Text = "";
        }