Example #1
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);
                }
            }
        }