Exemplo n.º 1
0
        void MainForm_Click(object sender, MouseEventArgs e)
        {
            int xx = e.X;
            int yy = e.Y;

            switch (_stage)
            {
                case 0:
                    {
                        Console.WriteLine("[" + xx + "," + yy + "]");
                        break;
                    }
                case POINT:
                    {
                        Point_dt q = new Point_dt(xx, yy);
                        Point_dt p = screen2world(q);
                        _ajd.insertPoint(p);
                        Refresh();
                        break;
                    }
                case FIND:
                    {
                        Point_dt q = new Point_dt(xx, yy);
                        Point_dt p = screen2world(q);
                        //_t1 = _ajd.find(p);
                        _t1 = _ajd.FastFind(p);
                        Refresh();
                        break;
                    }
                case SECTION1:
                    {
                        Point_dt q = new Point_dt(xx, yy);
                        _p1 = screen2world(q);
                        // _p1 = new Point_dt(99792.03,1073355.0,30.0);

                        // _t1 = _ajd.find(_p1);
                        _stage = SECTION2;
                        break;
                    }
                case SECTION2:
                    {
                        Point_dt q = new Point_dt(xx, yy);
                        _p2 = screen2world(q);
                        // _p2 = new Point_dt(149587.055,1040477.0,5.0);

                        // _t2 = _ajd.find(_p2);
                        _los = new Visibility(_ajd);
                        _los.computeSection(_p1, _p2);
                        Refresh();
                        _stage = SECTION1;
                        break;
                    }
                case GUARD:
                    {
                        Point_dt q = new Point_dt(xx, yy);
                        _p1 = screen2world(q);
                        if (_guards == null)
                            _guards = new List<Point_dt>();
                        _guards.Add(new Point_dt(_p1.x, _p1.y, GH));
                        /*
                         * if(_p2!=null) { _los = new Visibility(_ajd);
                         * _los.computeSection(_p1,_p2); _visible =
                         * _los.isVisible(30,5); }
                         */
                        Refresh();
                        break;
                    }
                case CLIENT:
                    {
                        Point_dt q = new Point_dt(xx, yy);
                        _p2 = screen2world(q);
                        if (_clients == null)
                            _clients = new List<Point_dt>();
                        _clients.Add(new Point_dt(_p2.x, _p2.y, CH));
                        /*
                         * if(_p1!=null) { _los = new Visibility(_ajd);
                         * _los.computeSection(_p1,_p2); _visible =
                         * _los.isVisible(30,5); }
                         */
                        Refresh();
                        break;
                    }
            }
        }
Exemplo 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);
            }
        }