예제 #1
0
        private void initSegmento()
        {
            modoseg           = "er";
            mstatus           = false;
            aux               = new Bitmap(795, 462);
            b                 = new Bitmap(795, 462);
            pbsegmentos.Image = new Bitmap(795, 462);
            ctrlz             = new List <Bitmap>();
            ctrlz.Add(new Bitmap(795, 462));
            poligonos = new List <Poligono>();
            polatual  = null;

            dtpontos = new DataTable();
            dtpontos.Columns.Add("X");
            dtpontos.Columns.Add("Y");

            dgvpontos.DataSource = dtpontos;

            dtma = new DataTable();
            dtma.Columns.Add("a");
            dtma.Columns.Add("c");
            dtma.Columns.Add("d");

            dgvma.DataSource         = dtma;
            dgvma.RowTemplate.Height = 46;
        }
예제 #2
0
 private void pbsegmentos_Click(object sender, EventArgs e)
 {
     if (modoseg.Equals("po"))
     {
         if (x1 == 0 && y1 == 0)
         {
             polatual = new Poligono(idpol++);
             x1       = (e as MouseEventArgs).X;
             y1       = (e as MouseEventArgs).Y;
             polatual.addAtuais(new Ponto(x1, y1));
             polatual.addOriginais(new Ponto(x2, y2));
             x1pol = x1;
             y1pol = y1;
         }
         else
         {
             x1 = x2;
             y1 = y2;
             if (Math.Abs(x2 - x1pol) < 10 && Math.Abs(y2 - y1pol) < 10)
             {
                 x1 = 0;
                 y1 = 0;
                 poligonos.Add(polatual);
                 lvPoligonos.Items.Add(polatual.getId().ToString());
                 ctrlZ(b);
             }
             else
             {
                 polatual.addAtuais(new Ponto(x2, y2));
                 polatual.addOriginais(new Ponto(x2, y2));
             }
         }
         aux = b;
     }
     else if (modoseg.Equals("fo"))
     {
         pbsegmentos.Cursor = Cursors.Cross;
         FiltroM.floodFill((e as MouseEventArgs).X, (e as MouseEventArgs).Y, corpintura, b);
         pbsegmentos.Image = b;
         modoseg           = "";
     }
 }
예제 #3
0
        public static void scanLine(Poligono p, Color cor, Bitmap b)
        {
            List <Ponto> lp = p.getAtuais();
            int          y = 0, ymin = lp[0].getY(), ymax = lp[0].getY(), xmin = 0, primy;
            double       incx = 0;
            Ponto        p1, p2;
            Color        color = Color.FromArgb(cor.ToArgb());

            for (int i = 1; i < lp.Count; i++)
            {
                if (ymin > lp[i].getY())
                {
                    ymin = lp[i].getY();
                }
                if (ymax < lp[i].getY())
                {
                    ymax = lp[i].getY();
                }
            }
            primy = ymin;

            List <NoScan>[] et = new List <NoScan> [ymax - ymin + 1];

            for (int i = 0; i < ymax - ymin + 1; i++)
            {
                et[i] = new List <NoScan>();
            }
            for (int i = 1; i < lp.Count; i++)
            {
                p1 = lp[i - 1];
                p2 = lp[i];
                if (p1.getY() != p2.getY())
                {
                    if (p1.getY() < p2.getY())
                    {
                        ymin = p1.getY();
                        ymax = p2.getY();
                        xmin = p1.getX();
                    }
                    else if (p1.getY() > p2.getY())
                    {
                        ymin = p2.getY();
                        ymax = p1.getY();
                        xmin = p2.getX();
                    }
                    incx = (double)(p2.getX() - p1.getX()) / (p2.getY() - p1.getY());
                    et[ymin - primy].Add(new NoScan(ymax, xmin, incx));
                }
            }
            p1 = lp[0];
            p2 = lp[lp.Count - 1];
            if (p1.getY() != p2.getY())
            {
                if (p1.getY() < p2.getY())
                {
                    ymin = p1.getY();
                    ymax = p2.getY();
                    xmin = p1.getX();
                }
                else if (p1.getY() > p2.getY())
                {
                    ymin = p2.getY();
                    ymax = p1.getY();
                    xmin = p2.getX();
                }
                incx = (double)(p2.getX() - p1.getX()) / (p2.getY() - p1.getY());
                et[ymin - primy].Add(new NoScan(ymax, xmin, incx));
            }

            List <NoScan> aet = et[y];

            while (y < et.Length)
            {
                for (int i = 0; i < aet.Count; i++)
                {
                    if (y + primy == aet[i].Ymax)
                    {
                        aet.RemoveAt(i);
                    }
                }
                aet.Sort((o1, o2) => o1.Xmin.CompareTo(o2.Xmin));
                for (int i = 1; i < aet.Count; i += 2)
                {
                    retaDda(b, (int)aet[i - 1].Xmin, (int)aet[i].Xmin, y + primy, y + primy, color);
                }
                for (int i = 0; i < aet.Count; i++)
                {
                    aet[i].Xmin += aet[i].Incx;
                }
                y++;
                if (y < et.Length)
                {
                    for (int pos2 = 0; pos2 < et[y].Count; pos2++)
                    {
                        aet.Add(et[y][pos2]);
                    }
                }
            }
        }