Exemple #1
0
        /// <summary>
        /// Рисует сшитые сканы на одном холсте.
        /// </summary>
        /// <param name="X1_rl"></param>
        /// <param name="Y1_rl"></param>
        private void drawCrosslinkedScans(int X1_rl, int Y1_rl)
        {
            int X0 = crosslinker.getXY0()[0];
            int Y0 = crosslinker.getXY0()[1];
            //
            //    int X2 = crosslinker.getXY2()[0];
            //    int Y2 = crosslinker.getXY2()[1];
            //
            PixelMap scan01 = new PixelMap(Parameters.getD_scan1() + Parameters.getR_scan(), Parameters.getD_scan1() + Parameters.getR_scan(), 0, 0, 0);
            int      C      = (Parameters.getD_scan() + Parameters.getR_scan()) / 2;

            for (int i = 0; i < crosslinker.scan0.xyScan.Count; i++)
            {
                scan01[crosslinker.scan0.xyScan[i][0] + C, crosslinker.scan0.xyScan[i][1] + C] = new Pixel(Parameters.startColor);
            }
            for (int i = 0; i < crosslinker.scan1.xyScan.Count; i++)
            {
                scan01[crosslinker.scan1.xyScan[i][0] + X1_rl - X0 + C, crosslinker.scan1.xyScan[i][1] + Y1_rl - Y0 + C] = new Pixel(Parameters.finishColor);
            }
            MainForm.drawBitmapOnPictureBox(pictureBox4, scan01.GetBitmap());
        }
Exemple #2
0
 /// <summary>
 /// отрисовать все три центра
 /// отрисовать радиусы для scan0 и scan1
 /// </summary>
 /// <param name="preciseMapBmp"></param>
 /// <param name="graphics"></param>
 private void interfaceDrawing(Bitmap preciseMapBmp, Graphics graphics)
 {
     try
     {
         Pen pen;
         int X0 = crosslinker.getXY0()[0];
         int Y0 = crosslinker.getXY0()[1];
         int X1 = crosslinker.getXY1()[0];
         int Y1 = crosslinker.getXY1()[1];
         int X2 = crosslinker.getXY2()[0];
         int Y2 = crosslinker.getXY2()[1];
         if ((X0 >= 0) && (Y0 >= 0))
         {
             preciseMapBmp.SetPixel(X0, Y0, Parameters.startColor);
             pen = new Pen(Parameters.startColor);
             graphics.DrawEllipse(pen, X0 - Parameters.getR_scan(), Y0 - Parameters.getR_scan(), Parameters.getD_scan(), Parameters.getD_scan());
             graphics.DrawEllipse(pen, X0 - Parameters.getR_robot(), Y0 - Parameters.getR_robot(), Parameters.getD_robot(), Parameters.getD_robot());
         }
         if ((X1 >= 0) && (Y1 >= 0))
         {
             preciseMapBmp.SetPixel(X1, Y1, Parameters.finishColor);
             pen = new Pen(Parameters.finishColor);
             graphics.DrawEllipse(pen, X1 - Parameters.getR_scan(), Y1 - Parameters.getR_scan(), Parameters.getD_scan(), Parameters.getD_scan());
             graphics.DrawEllipse(pen, X1 - Parameters.getR_robot(), Y1 - Parameters.getR_robot(), Parameters.getD_robot(), Parameters.getD_robot());
         }
         if ((X2 >= 0) && (Y2 >= 0))
         {
             preciseMapBmp.SetPixel(X2, Y2, Parameters.routeColor);
         }
     }
     catch (Exception ex) { }
     mouseMoveMap = new PixelMap(preciseMapBmp);
     mainForm.drawBitmapOnPictureBox1(preciseMapBmp);
 }
Exemple #3
0
 public void initialize()
 {
     this.pictureBox2                = new System.Windows.Forms.PictureBox();
     this.pictureBox3                = new System.Windows.Forms.PictureBox();
     this.pictureBox4                = new System.Windows.Forms.PictureBox();
     this.button2Scan0Center         = new System.Windows.Forms.Button();
     this.button3Scan1Center         = new System.Windows.Forms.Button();
     this.button4SupposedScan1Center = new System.Windows.Forms.Button();
     this.label4                      = new System.Windows.Forms.Label();
     this.labelError                  = new System.Windows.Forms.Label();
     this.textBox1Scan0Center         = new System.Windows.Forms.TextBox();
     this.textBox2Scan1Center         = new System.Windows.Forms.TextBox();
     this.textBox3SupposedScan1Center = new System.Windows.Forms.TextBox();
     this.button1Crosslink            = new System.Windows.Forms.Button();
     ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit();
     mainForm.panel1SuspendLayout();
     mainForm.setPictureBox1MouseDownHandler(new MouseEventHandler(pictureBox1_MouseDown));
     mainForm.setPictureBox1MouseMoveHandler(new MouseEventHandler(pictureBox1_MouseMove));
     //
     // pictureBox2
     //
     this.pictureBox2.BackColor = System.Drawing.SystemColors.ControlDark;
     this.pictureBox2.Location  = new System.Drawing.Point(0, 32);
     this.pictureBox2.Name      = "pictureBox2";
     this.pictureBox2.Size      = new System.Drawing.Size(Parameters.getD_scan() + 1, Parameters.getD_scan() + 1);
     this.pictureBox2.SizeMode  = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
     this.pictureBox2.TabIndex  = 11;
     this.pictureBox2.TabStop   = false;
     //
     // pictureBox3
     //
     this.pictureBox3.BackColor = System.Drawing.SystemColors.ControlDark;
     this.pictureBox3.Location  = new System.Drawing.Point(0, Parameters.getD_scan() + 52 + 10);
     this.pictureBox3.Name      = "pictureBox3";
     this.pictureBox3.Size      = new System.Drawing.Size(Parameters.getD_scan() + 1, Parameters.getD_scan() + 1);
     this.pictureBox3.SizeMode  = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
     this.pictureBox3.TabIndex  = 12;
     this.pictureBox3.TabStop   = false;
     //
     // pictureBox4
     //
     this.pictureBox4.BackColor = System.Drawing.SystemColors.ControlDark;
     this.pictureBox4.Location  = new System.Drawing.Point(Parameters.getD_scan() + 1 + 5, 32);
     this.pictureBox4.Name      = "pictureBox4";
     this.pictureBox4.Size      = new System.Drawing.Size(Parameters.getD_scan() + Parameters.getR_scan() + 1, Parameters.getD_scan() + Parameters.getR_scan() + 1);
     this.pictureBox4.SizeMode  = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
     this.pictureBox4.TabIndex  = 13;
     this.pictureBox4.TabStop   = false;
     //
     // button2Scan0Center
     //
     this.button2Scan0Center.AutoSize  = true;
     this.button2Scan0Center.BackColor = System.Drawing.SystemColors.InactiveCaption;
     this.button2Scan0Center.Location  = new System.Drawing.Point(0, 6);
     this.button2Scan0Center.Name      = "button2";
     this.button2Scan0Center.Size      = new System.Drawing.Size(41, 13);
     this.button2Scan0Center.TabIndex  = 15;
     this.button2Scan0Center.Text      = "Scan 0";
     button2Scan0Center.MouseClick    += button2Scan0Center_Click;
     //
     // button3Scan1Center
     //
     this.button3Scan1Center.AutoSize  = true;
     this.button3Scan1Center.BackColor = System.Drawing.SystemColors.InactiveCaption;
     this.button3Scan1Center.Location  = new System.Drawing.Point(0, Parameters.getD_scan() + 36);
     this.button3Scan1Center.Name      = "button3";
     this.button3Scan1Center.Size      = new System.Drawing.Size(41, 13);
     this.button3Scan1Center.TabIndex  = 16;
     this.button3Scan1Center.Text      = "Scan 1";
     button3Scan1Center.MouseClick    += button3Scan1Center_Click;
     //
     // button4SupposedScan1Center
     //
     this.button4SupposedScan1Center.AutoSize  = true;
     this.button4SupposedScan1Center.BackColor = System.Drawing.SystemColors.InactiveCaption;
     this.button4SupposedScan1Center.Location  = new System.Drawing.Point(0, pictureBox3.Location.Y + pictureBox3.Height + 2);
     this.button4SupposedScan1Center.Name      = "button4";
     this.button4SupposedScan1Center.Size      = new System.Drawing.Size(41, 13);
     this.button4SupposedScan1Center.TabIndex  = 16;
     this.button4SupposedScan1Center.Text      = "Supposed";
     button4SupposedScan1Center.MouseClick    += button4SupposedScan1Center_Click;
     //
     // label4
     //
     this.label4.AutoSize  = true;
     this.label4.BackColor = System.Drawing.SystemColors.InactiveCaption;
     this.label4.Location  = new System.Drawing.Point(pictureBox4.Location.X, 10);
     this.label4.Name      = "label4";
     this.label4.Size      = new System.Drawing.Size(61, 13);
     this.label4.TabIndex  = 17;
     this.label4.Text      = "Crosslinked";
     //
     // label5
     //
     this.labelError.AutoSize  = true;
     this.labelError.BackColor = System.Drawing.SystemColors.InactiveCaption;
     this.labelError.Location  = new System.Drawing.Point(pictureBox4.Location.X, pictureBox4.Location.Y + pictureBox4.Height + 4);
     this.labelError.Name      = "label5";
     this.labelError.Size      = new System.Drawing.Size(61, 13);
     this.labelError.TabIndex  = 17;
     this.labelError.Text      = "error: ";
     //
     // textBox1
     //
     this.textBox1Scan0Center.Size     = new System.Drawing.Size(50, 13);
     this.textBox1Scan0Center.Location = new System.Drawing.Point(pictureBox2.Location.X + pictureBox2.Width - textBox1Scan0Center.Width, button2Scan0Center.Location.Y + 1);
     this.textBox1Scan0Center.Name     = "textBox1";
     this.textBox1Scan0Center.TabIndex = 17;
     this.textBox1Scan0Center.Text     = "x,y";
     //
     // textBox2
     //
     this.textBox2Scan1Center.Size     = new System.Drawing.Size(50, 13);
     this.textBox2Scan1Center.Location = new System.Drawing.Point(pictureBox2.Location.X + pictureBox2.Width - textBox2Scan1Center.Width, button3Scan1Center.Location.Y + 1);
     this.textBox2Scan1Center.Name     = "textBox2";
     this.textBox2Scan1Center.TabIndex = 17;
     this.textBox2Scan1Center.Text     = "x,y";
     //
     // textBox3
     //
     this.textBox3SupposedScan1Center.Size     = new System.Drawing.Size(50, 13);
     this.textBox3SupposedScan1Center.Location = new System.Drawing.Point(pictureBox2.Location.X + pictureBox2.Width - textBox3SupposedScan1Center.Width, pictureBox3.Location.Y + pictureBox3.Height + 3);
     this.textBox3SupposedScan1Center.Name     = "textBox2";
     this.textBox3SupposedScan1Center.TabIndex = 17;
     this.textBox3SupposedScan1Center.Text     = "x,y";
     //
     // button1
     //
     this.button1Crosslink.Location = new System.Drawing.Point(pictureBox4.Location.X + pictureBox4.Width - button1Crosslink.Size.Width, pictureBox4.Location.Y + pictureBox4.Height);
     this.button1Crosslink.Name     = "button1";
     this.button1Crosslink.Size     = new System.Drawing.Size(75, 23);
     this.button1Crosslink.TabIndex = 18;
     this.button1Crosslink.Text     = "Closslink";
     this.button1Crosslink.UseVisualStyleBackColor = true;
     this.button1Crosslink.Click += new System.EventHandler(this.button1Crosslink_Click);
     //
     // Form1
     //
     mainForm.BackColor  = System.Drawing.SystemColors.ActiveCaption;
     mainForm.ClientSize = new System.Drawing.Size(1454, 873);
     mainForm.addComponentToPanel1(button1Crosslink);
     mainForm.addComponentToPanel1(this.labelError);
     mainForm.addComponentToPanel1(this.label4);
     mainForm.addComponentToPanel1(this.button4SupposedScan1Center);
     mainForm.addComponentToPanel1(this.button3Scan1Center);
     mainForm.addComponentToPanel1(this.button2Scan0Center);
     mainForm.addComponentToPanel1(this.textBox3SupposedScan1Center);
     mainForm.addComponentToPanel1(this.textBox2Scan1Center);
     mainForm.addComponentToPanel1(this.textBox1Scan0Center);
     mainForm.addComponentToPanel1(this.pictureBox4);
     mainForm.addComponentToPanel1(this.pictureBox3);
     mainForm.addComponentToPanel1(this.pictureBox2);
     ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).EndInit();
     mainForm.panel1ReleaseLayout();
 }
Exemple #4
0
        /// <summary>
        /// Думаем, что центр scan1 - это X2,Y2. Нужно вернуть X1,Y1.
        /// </summary>
        /// <returns>Возвращает массив int[3]: X,Y,error: координаты настоящего центра scan1 и квадрат расстояния от него до реального симуляционного центра scan1</returns>
        public int[] getRealCoords4()
        {
            Console.WriteLine("crosslinkig " + X0 + "," + Y0 + ";"
                              + X1 + "," + Y1 + ";" + X2 + "," + Y2);
            double       minsum = 100000000;
            int          limXY  = 20;
            double       summ;
            double       min;
            int          optX = 0, optY = 0;
            int          C         = (Parameters.getD_scan() + Parameters.getR_scan()) / 2;
            List <int[]> errorZone = pieErrorZoneSearch(0, 0, X2 - X0, Y2 - Y0);
            //    Console.WriteLine("errorZone.Count "+ errorZone.Count);
            int numberOfMinPoints = 0; //количество точек с одинаковыми минимальными значениями функционала ошибки //TODO

            for (int k = 0; k < errorZone.Count; k++)
            {
                PixelMap     map01             = new PixelMap(Parameters.getD_scan1() + Parameters.getR_scan(), Parameters.getD_scan1() + Parameters.getR_scan(), 0, 0, 0);
                List <int[]> irrelevantPoints0 = new List <int[]>();
                List <int[]> irrelevantPoints1 = new List <int[]>();
                int          X = errorZone[k][0];
                int          Y = errorZone[k][1];
                for (int i = 0; i < scan0.xyScan.Count; i++)
                {
                    map01[scan0.xyScan[i][0] + C, scan0.xyScan[i][1] + C] = new Pixel(Parameters.wallColor);
                }
                for (int i = 0; i < scan1.xyScan.Count; i++)
                {
                    map01[scan1.xyScan[i][0] + X + C, scan1.xyScan[i][1] + Y + C] = new Pixel(Parameters.wallColor);
                }
                int  y1 = new int();
                int  x1 = new int();
                bool flagR;        //Будет true, если на текущем угле сканирования видно препятствие, иначе false и радиус от текущего угла будет равен нулю
                bool flagRepeated; //Будет true, если точка уже сохранена в списке скана
                int  rPhi = -1;

                for (int i = 0; i < Parameters.getN_phi(); i++)
                {
                    //---------------------------------------scan1
                    flagR = false;
                    for (ushort r = 1; r < Parameters.getR_scan() + 1; r++)
                    {
                        x1 = (int)Math.Round(r * Math.Cos(i * Parameters.getScan_step()));
                        y1 = (int)Math.Round(r * Math.Sin(i * Parameters.getScan_step()));
                        if (map01[x1 + X + C, y1 + Y + C].Color == Parameters.wallColor)
                        {
                            rPhi  = r;
                            flagR = true;
                            break;
                        }
                    }
                    if (!flagR)
                    {
                        rPhi = 0;
                    }
                    if (rPhi == -1)
                    {
                        Console.WriteLine("Scanning problems r == -1 on scan1, angle: " + i * Parameters.getScan_step() / Math.PI * 180);
                    }
                    if (scan1.rByPhi[i] != rPhi)
                    {
                        flagRepeated = false;
                        for (int j = 0; j < irrelevantPoints1.Count; j++)
                        {
                            if ((irrelevantPoints1[j][0] == x1) && (irrelevantPoints1[j][1] == y1))
                            {
                                flagRepeated = true;
                            }
                        }
                        if (!flagRepeated)
                        {
                            irrelevantPoints1.Add(new int[2] {
                                x1, y1
                            });
                        }
                    }
                    //---------------------------------------scan0
                    flagR = false;
                    for (ushort r = 1; r < Parameters.getR_scan() + 1; r++)
                    {
                        x1 = (int)Math.Round(r * Math.Cos(i * Parameters.getScan_step()));
                        y1 = (int)Math.Round(r * Math.Sin(i * Parameters.getScan_step()));
                        if (map01[x1 + C, y1 + C].Color == Parameters.wallColor)
                        {
                            rPhi  = r;
                            flagR = true;
                            break;
                        }
                    }
                    if (!flagR)
                    {
                        rPhi = 0;
                    }
                    if (rPhi == -1)
                    {
                        Console.WriteLine("Scanning problems r == -1 on scan0, angle: " + i * Parameters.getScan_step() / Math.PI * 180);
                    }
                    if (scan0.rByPhi[i] != rPhi)
                    {
                        flagRepeated = false;
                        for (int j = 0; j < irrelevantPoints0.Count; j++)
                        {
                            if ((irrelevantPoints0[j][0] == x1) && (irrelevantPoints0[j][1] == y1))
                            {
                                flagRepeated = true;
                            }
                        }
                        if (!flagRepeated)
                        {
                            irrelevantPoints0.Add(new int[2] {
                                x1, y1
                            });
                        }
                    }
                }

                summ = 0;
                for (int i = 0; i < irrelevantPoints1.Count; i++)
                {
                    min = 1000000;
                    for (int j = 0; j < scan1.xyScan.Count; j++)
                    {
                        if (min > Parameters.getSquaredDistance(irrelevantPoints1[i][0], irrelevantPoints1[i][1], scan1.xyScan[j][0], scan1.xyScan[j][1]))
                        {
                            min = Parameters.getSquaredDistance(irrelevantPoints1[i][0], irrelevantPoints1[i][1], scan1.xyScan[j][0], scan1.xyScan[j][1]);
                        }
                    }
                    summ += min;
                }
                for (int i = 0; i < irrelevantPoints0.Count; i++)
                {
                    min = 1000000;
                    for (int j = 0; j < scan0.xyScan.Count; j++)
                    {
                        if (min > Parameters.getSquaredDistance(irrelevantPoints0[i][0], irrelevantPoints0[i][1], scan0.xyScan[j][0], scan0.xyScan[j][1]))
                        {
                            min = Parameters.getSquaredDistance(irrelevantPoints0[i][0], irrelevantPoints0[i][1], scan0.xyScan[j][0], scan0.xyScan[j][1]);
                        }
                    }
                    summ += min;
                }
                if (minsum > summ)
                {
                    minsum            = summ;
                    optX              = X;
                    optY              = Y;
                    numberOfMinPoints = 0; //TODO
                }
                if (summ == minsum)        //TODO
                {
                    numberOfMinPoints++;
                }
            }
            int errorSquredDistance = Parameters.getSquaredDistance(X1, Y1, X0 + optX, Y0 + optY); //квадрат раастояния от реального положения до предсказанного

            //
            //    Console.WriteLine("opts "+optX+","+optY);
            if (errorSquredDistance != 0) //TODO
            {
                Console.WriteLine("Don't match--------------------------------------");
            }
            return(new int[5] {
                X0 + optX, Y0 + optY, errorSquredDistance, errorZone.Count(), numberOfMinPoints
            });                                                                                                    //TODO
        }