Ejemplo n.º 1
0
        static void DoTimeTest()
        {
            int    size = 100000, size2 = size;
            double delta = 1000, delta2 = delta / 2;

            double[]   xx  = new double[size], yy = new double[size];
            Point_dt[] ps  = new Point_dt[size];
            double[]   xx2 = new double[size2], yy2 = new double[size2];

            DateTime start            = DateTime.Now;
            Delaunay_Triangulation ad = new Delaunay_Triangulation();

            Random r = new Random();

            for (int i = 0; i < size; i++)
            {
                xx[i] = (r.NextDouble() * delta - (delta * 0.1));
                yy[i] = (r.NextDouble() * delta - (delta * 0.1));

                ps[i] = new Point_dt(xx[i], yy[i]);
                ad.insertPoint(ps[i]);
            }
            DateTime mid = DateTime.Now;

            for (int i = 0; i < size2; i++)
            {
                xx2[i] = (r.NextDouble() * delta2);
                yy2[i] = (r.NextDouble() * delta2);
            }
            DateTime m1 = DateTime.Now;

            for (int i = 0; i < size2; i++)
            {
                Point_dt    p  = new Point_dt(xx2[i], yy2[i]);
                Triangle_dt t1 = ad.find(p);
                if (!t1.contains(p))
                {
                    Console.WriteLine(i + ") **ERR: find *** T: " + t1);
                }
            }
            DateTime e1 = DateTime.Now;

            Console.WriteLine("delaunay_triangulation " + ad.size() + " points, "
                              + ad.trianglesSize() + " triangles,  Triangles_td: "
                              + Triangle_dt._counter + "  ,c2: " + Triangle_dt._c2);
            Console.WriteLine("Constructing time: " + (mid - start).TotalSeconds);
            Console.WriteLine("*** E3 find:  time: " + (e1 - m1).TotalSeconds);
            Console.WriteLine("delaunay_triangulation " + ad.size() + " points, "
                              + ad.trianglesSize() + " triangles,  Triangles_td: "
                              + Triangle_dt._counter + "  ,c2: " + Triangle_dt._c2);
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            // _ajd.initTriangle();
            // ajTriangle[] tt = _ajd._triangles;
            if (_ajd == null || _ajd.size() == 0)
            {
                return;
            }
            _dx_f = new Point_dt(5, this.Width - 5);
            _dy_f = new Point_dt(5, this.Height - 5);

            List <Triangle_dt> it = _ajd.trianglesIterator();

            foreach (Triangle_dt curr in it)
            {
                if (!curr.isHalfplane())
                {
                    drawTriangle(g, curr, Color.Empty);
                }
            }
            it = _ajd.trianglesIterator();
            foreach (Triangle_dt curr in it)
            {
                if (curr.isHalfplane())
                {
                    drawTriangle(g, curr, Color.Empty);
                }
            }
            if (_t2 != null)
            {
                drawTriangle(g, _t2, Color.Red);
            }
            if (_t1 != null && _stage == FIND)
            {
                drawTriangle(g, _t1, Color.YellowGreen);
            }
            if (this._view_flag == VIEW3)
            {
                drawTopo(g);
            }

            // debug
            if (_mc < _ajd.getModeCounter())
            {
                _mc = _ajd.getModeCounter();

                List <Triangle_dt> it2 = _ajd.getLastUpdatedTriangles();
                for (int i = 0; i < it2.Count; i++)
                {
                    drawTriangle(g, it2[i], Color.Cyan);
                }

                Console.WriteLine("   MC: " + _mc + "  number of triangles updated: " + it2.Count);
            }

            if (_los != null && (_stage == SECTION1 || _stage == SECTION2))
            {
                if (_los != null && _los._tr != null)
                {
                    foreach (Triangle_dt curr in _los._tr)
                    {
                        if (!curr.isHalfplane())
                        {
                            drawTriangle(g, curr, Color.Red);
                        }
                    }
                }

                for (int i = 0; i < _los._section.Count; i++)
                {
                    Point_dt curr_p = _los._section[i];

                    if (curr_p != null)
                    {
                        drawPoint(g, curr_p, Color.Blue);
                        Console.WriteLine(i + ") " + curr_p + "  dist _p1: " + _p1.distance(curr_p));
                    }
                }

                drawLine(g, _p1, _p2, Color.Blue);
            }

            /*
             * if(_stage == GUARD | _stage == CLIENT) { if(_p1!=null)
             * drawPoint(g,_p1,6,Color.ORANGE); if(_p2!=null) { if(_visible)
             * drawPoint(g,_p2,6,Color.BLUE); else drawPoint(g,_p2,6, Color.RED); }
             * }
             */
            if (_los == null)
            {
                _los = new Visibility(_ajd);
            }
            if (_stage == GUARD || _stage == CLIENT)
            {
                int[] ccc = new int[0];
                if (_clients != null)
                {
                    ccc = new int[_clients.Count];
                }
                for (int gr = 0; _guards != null && gr < _guards.Count; gr++)
                {
                    Point_dt gg = _guards.ElementAt(gr);
                    drawPoint(g, gg, 8, Color.Orange);

                    for (int c = 0; _clients != null && c < _clients.Count; c++)
                    {
                        Point_dt cc = _clients.ElementAt(c);
                        drawPoint(g, cc, 6, Color.White);
                        // Color cl = Color.RED;
                        if (_los.los(gg, cc))
                        {
                            this.drawLine(g, gg, cc, Color.Red);
                            ccc[c]++;
                        }
                    }
                }

                int c1 = 0, c2 = 0, c3 = 0;
                for (int i = 0; i < ccc.Length; i++)
                {
                    if (ccc[i] > 0)
                    {
                        c1++;
                        c2 += ccc[i];
                    }
                }
                if (c1 > 0)
                {
                    Console.WriteLine("clients:" + ccc.Length + "  visible c:" + c1 + "   ave:" + c2 / c1);
                }
            }
        }