コード例 #1
0
        // TODO: three different point classes coord3d, point_dt !!
        private List <Polygon> getFacets()
        {
            int xlen = _x.Length;

            for (int i = 0; i <= xlen - 1; i++)
            {
                Point_dt point_dt = new Point_dt(x[i], y[i], z_as_fxy[i, i]);
                _triangulator.insertPoint(point_dt);
            }
            List <Polygon>            polygons      = new List <Polygon>();
            IEnumerator <Triangle_dt> trianglesIter = _triangulator.trianglesIterator();

            while ((trianglesIter.MoveNext()))
            {
                Triangle_dt triangle = trianglesIter.Current;
                // isHalfplane means a degenerated triangle
                if ((triangle.isHalfplane))
                {
                    continue;
                }
                Polygon newPolygon = buildPolygonFrom(triangle);
                polygons.Add(newPolygon);
            }
            return(polygons);
        }
コード例 #2
0
        static void DoMemoryTest()
        {
            int i = 0;

            try
            {
                Point_dt           p1  = new Point_dt(1, 1);
                Point_dt           p3  = new Point_dt(1, 0);
                Point_dt           p2  = new Point_dt(0, 0);
                List <Triangle_dt> vec = new List <Triangle_dt>();
                while (true)
                {
                    Triangle_dt t = new Triangle_dt(p1, p2, p3);
                    vec.Add(t);
                    i++;
                    if (i % 10000 == 0)
                    {
                        Console.WriteLine(i);
                    }
                }
            }
            catch (OutOfMemoryException oome)
            {
                Console.WriteLine("out of MEMORY: points: " + i);
            }
            catch (Exception e)
            {
                Console.WriteLine("out of MEMORY: points: " + i);
            }
        }
コード例 #3
0
ファイル: Visibility.cs プロジェクト: VKaban/jdt
        internal void computeSection(Point_dt p1, Point_dt p2)
        {
            Triangle_dt t1 = _dt.find(p1);
            Triangle_dt t2 = _dt.find(p2);

            _p1 = t1.z(p1);
            _p2 = t2.z(p2);
            if (_tr == null)
            {
                _tr = new List <Triangle_dt>();
            }
            else
            {
                _tr.Clear();
            }
            if (_section == null)
            {
                _section = new List <Point_dt>();
            }
            else
            {
                _section.Clear();
            }
            Triangle_dt curr_t = t1;

            while (curr_t != t2 && curr_t != null)
            {
                _tr.Add(curr_t);
                cut(curr_t);
                curr_t = next_t(p1, p2, curr_t, _tr);
            }
            _tr.Add(t2);
        }
コード例 #4
0
ファイル: Visibility.cs プロジェクト: VKaban/jdt
        /**
         * Add the intersections of triangle t with the section to the list of
         * intersection (set)
         */
        void cut(Triangle_dt t)
        {
            if (t.isHalfplane())
            {
                return;
            }
            Point_dt p1 = t.p1(), p2 = t.p2(), p3 = t.p3();
            int      f1 = p1.pointLineTest(_p1, _p2);
            int      f2 = p2.pointLineTest(_p1, _p2);
            int      f3 = p3.pointLineTest(_p1, _p2);

            if ((f1 == Point_dt.LEFT | f1 == Point_dt.RIGHT) &&
                (f1 == f2 && f1 == f3))
            {
                return;
            }
            if (f1 != f2 && _p1.pointLineTest(p1, p2) != _p2.pointLineTest(p1, p2))
            {
                Add(intersection(p1, p2));
            }
            if (f2 != f3 && _p1.pointLineTest(p2, p3) != _p2.pointLineTest(p2, p3))
            {
                Add(intersection(p2, p3));
            }
            if (f3 != f1 && _p1.pointLineTest(p3, p1) != _p2.pointLineTest(p3, p1))
            {
                Add(intersection(p3, p1));
            }
        }
コード例 #5
0
ファイル: Visibility.cs プロジェクト: VKaban/jdt
        /** return true iff the segment _p1,_p2 is cutting t */
        bool cut(Point_dt pp1, Point_dt pp2, Triangle_dt t)
        {
            bool ans = false;

            if (t.isHalfplane())
            {
                return(false);
            }
            Point_dt p1 = t.p1(), p2 = t.p2(), p3 = t.p3();
            int      f1 = p1.pointLineTest(pp1, pp2);
            int      f2 = p2.pointLineTest(pp1, pp2);
            int      f3 = p3.pointLineTest(pp1, pp2);

            if ((f1 == Point_dt.LEFT | f1 == Point_dt.RIGHT) &&
                (f1 == f2 && f1 == f3))
            {
                return(false);
            }

            if (f1 != f2 && pp1.pointLineTest(p1, p2) != pp2.pointLineTest(p1, p2))
            {
                return(true);
            }
            if (f2 != f3 && pp1.pointLineTest(p2, p3) != pp2.pointLineTest(p2, p3))
            {
                return(true);
            }
            if (f3 != f1 && pp1.pointLineTest(p3, p1) != pp2.pointLineTest(p3, p1))
            {
                return(true);
            }

            return(ans);
        }
コード例 #6
0
        private Polygon buildPolygonFrom(Triangle_dt triangle)
        {
            Coord3d c1      = triangle.p1.Coord3d;
            Coord3d c2      = triangle.p2.Coord3d;
            Coord3d c3      = triangle.p3.Coord3d;
            Polygon polygon = new Polygon();

            polygon.Add(new Point(c1));
            polygon.Add(new Point(c2));
            polygon.Add(new Point(c3));
            return(polygon);
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: Visibility.cs プロジェクト: VKaban/jdt
        Triangle_dt next_t(Point_dt pp1, Point_dt pp2, Triangle_dt curr,
                           List <Triangle_dt> tr)
        {
            Triangle_dt ans = null, t12, t23, t31;

            t12 = curr.next_12();
            t23 = curr.next_23();
            t31 = curr.next_31();
            if (t12 != null && cut(pp1, pp2, t12) && !tr.Contains(t12))
            {
                ans = t12;
            }
            else if (t23 != null && cut(pp1, pp2, t23) && !tr.Contains(t23))
            {
                ans = t23;
            }
            else if (t31 != null && cut(pp1, pp2, t31) && !tr.Contains(t31))
            {
                ans = t31;
            }
            return(ans);
        }
コード例 #9
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;
            }
            }
        }
コード例 #10
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));
                // ////////////////////////////////////
            }
        }
コード例 #11
0
        void drawTriangleTopoLines(Graphics g, Triangle_dt t, double dz, Color cl)
        {
            if (t.p1().z < 0 | t.p2().z < 0 | t.p3().z < 0)
            {
                return;
            }

            Point_dt[] p12 = computePoints(t.p1(), t.p2(), dz);
            Point_dt[] p23 = computePoints(t.p2(), t.p3(), dz);
            Point_dt[] p31 = computePoints(t.p3(), t.p1(), dz);

            int  i12 = 0, i23 = 0, i31 = 0;
            bool cont = true;

            while (cont)
            {
                cont = false;

                if (i12 < p12.Length && i23 < p23.Length && p12[i12].z == p23[i23].z)
                {
                    if (p12[i12].z % 200 > 100)
                    {
                        drawLine(g, p12[i12], p23[i23], Color.Red);
                    }
                    else
                    {
                        drawLine(g, p12[i12], p23[i23], Color.Yellow);
                    }
                    i12++;
                    i23++;
                    cont = true;
                }
                if (i23 < p23.Length && i31 < p31.Length && p23[i23].z == p31[i31].z)
                {
                    if (p23[i23].z % 200 > 100)
                    {
                        drawLine(g, p23[i23], p31[i31], Color.Red);
                    }
                    else
                    {
                        drawLine(g, p23[i23], p31[i31], Color.Yellow);
                    }

                    i23++;
                    i31++;
                    cont = true;
                }
                if (i12 < p12.Length && i31 < p31.Length && p12[i12].z == p31[i31].z)
                {
                    if (p12[i12].z % 200 > 100)
                    {
                        drawLine(g, p12[i12], p31[i31], Color.Red);
                    }
                    else
                    {
                        drawLine(g, p12[i12], p31[i31], Color.Yellow);
                    }

                    i12++;
                    i31++;
                    cont = true;
                }
            }
        }
コード例 #12
0
 public void GivenIHaveATriangleWithCoordinates__(double p0, double p1, double p2, double p3, double p4, double p5)
 {
     triangle = new Triangle_dt(new Point_dt(p0, p1), new Point_dt(p2, p3), new Point_dt(p4, p5));
 }