Пример #1
0
        // *** private methodes - random points obs ****

        // ********** Private methodes (open,save...) ********

        private void openTextFile()
        {
            _stage = 0;
            OpenFileDialog d  = new OpenFileDialog();
            DialogResult   dr = d.ShowDialog();

            if (dr != DialogResult.OK)
            {
                return;
            }

            string fi = d.FileName;

            _clients = null;
            _guards  = null;

            if (!string.IsNullOrEmpty(fi)) // the user actualy choose a file.
            {
                try
                {
                    _ajd    = new Delaunay_Triangulation(fi);
                    _dx_map = new Point_dt(_ajd.minBoundingBox().x, _ajd.maxBoundingBox().x);
                    _dy_map = new Point_dt(_ajd.minBoundingBox().y, _ajd.maxBoundingBox().y);

                    Refresh();
                }
                catch (Exception e)  // in case something went wrong.
                {
                    Console.WriteLine("** Error while reading text file **");
                    Console.WriteLine(e);
                }
            }
        }
Пример #2
0
 public MainForm(Delaunay_Triangulation aj)
 {
     this.Text = "ajDelaunay GUI tester";
     this.Size = new Size(550, 550);
     _stage    = 0;
     _ajd      = aj;
     _dx_f     = new Point_dt(5, this.Width - 5);
     _dy_f     = new Point_dt(5, this.Height - 5);
     _dx_map   = new Point_dt(aj.maxBoundingBox().x, aj.minBoundingBox().x);
     _dy_map   = new Point_dt(aj.maxBoundingBox().y, aj.minBoundingBox().y);
     _clients  = null;
     _guards   = null;
     //addWindowListener(new WindowAdapter() {
     //    public void windowClosing(WindowEvent e) {
     //        System.exit(0);
     //    }
     //});
 }
Пример #3
0
        public void drawTriangle(Graphics g, Triangle_dt t, Color cl)
        {
            if (_view_flag == VIEW1 || t.isHalfplane())
            {
                if (t.isHalfplane())
                {
                    if (cl == Color.Empty)
                    {
                        drawLine(g, t.p1(), t.p2(), Color.Blue);
                    }
                    else
                    {
                        drawLine(g, t.p1(), t.p2(), cl);
                    }
                }
                else
                {
                    if (cl == Color.Empty)
                    {
                        drawLine(g, t.p1(), t.p2(), Color.Black);
                        drawLine(g, t.p2(), t.p3(), Color.Black);
                        drawLine(g, t.p3(), t.p1(), Color.Black);
                    }

                    {
                        drawLine(g, t.p1(), t.p2(), cl);
                        drawLine(g, t.p2(), t.p3(), cl);
                        drawLine(g, t.p3(), t.p1(), cl);
                    }
                }
            }
            else
            {
                // //////////////////////////////////////////////////////////////////
                double maxZ = _ajd.maxBoundingBox().z;
                double minZ = _ajd.minBoundingBox().z;
                double z    = (t.p1().z + t.p2().z + t.p3().z) / 3.0;
                double dz   = maxZ - minZ;
                if (dz == 0)
                {
                    dz = 1;
                }
                int co = 30 + (int)(220 * ((z - minZ) / dz));
                if (cl == Color.Empty)
                {
                    cl = Color.FromArgb(co, co, co);
                }

                int[] xx = new int[3], yy = new int[3];
                // double f = 0;
                // double dx_map = _dx_map.y- _dx_map.x;
                // double dy_map = _dy_map.y- _dy_map.x;

                // f = (t.p1().x -_dx_map.x)/dx_map;
                Point_dt p1 = world2screen(t.p1());
                xx[0] = (int)p1.x;
                yy[0] = (int)p1.y;
                Point_dt p2 = world2screen(t.p2());
                xx[1] = (int)p2.x;
                yy[1] = (int)p2.y;
                Point_dt p3 = world2screen(t.p3());
                xx[2] = (int)p3.x;
                yy[2] = (int)p3.y;

                Brush b = new SolidBrush(cl);
                g.FillPolygon(b, ToPoints(xx, yy));
                // ////////////////////////////////////
            }
        }