public static DelaunayTriangulation Create()
 {
     DelaunayTriangulation delaunay = new DelaunayTriangulation();
     delaunay.points = Input.Points;
     delaunay.triangles = new Dictionary<Polygon, Triad>();
     delaunay.circles = new Dictionary<Polygon, Path>();
     delaunay.triadsDict = new Dictionary<Triad, Polygon>();
     Triangulator angulator = new Triangulator();
     delaunay.triads = angulator.Triangulation(delaunay.points, true);
     return delaunay;
 }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool flagempty = true;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells[2].Value == null || dataGridView1.Rows[i].Cells[3].Value == null)
                {
                    flagempty = false;
                }
            }

            if (flagempty)
            {
                DelaunayTriangulator.Triangulator  triangulate = new DelaunayTriangulator.Triangulator();
                List <DelaunayTriangulator.Vertex> listvertex  = new List <DelaunayTriangulator.Vertex>();


                for (int i = 0; i < graph.verteex.Count; i++)
                {
                    listvertex.Add(graph.verteex[i]);

                    //дописать tryparse-условие
                    float x = Convert.ToSingle(dataGridView1.Rows[i].Cells[2].Value.ToString());
                    float y = Convert.ToSingle(dataGridView1.Rows[i].Cells[3].Value.ToString());
                    listvertex[i].Vector = new Vector(x, y);
                }

                List <DelaunayTriangulator.Triangle> tr = triangulate.Triangulation(listvertex);

                Program.monitor = new Monitoring(tr);

                Program.monitor.GetArrayOfOutsideEdge();
                Program.monitor.AllDensities();
                Stopwatch sp = new Stopwatch();
                sp.Start();

                sp.Stop();

                foreach (Triangle t in Program.monitor.triangles)
                {
                    G.BrushTriangle(t);
                    richTextBox1.Text += t.ToString();
                }

                foreach (DelaunayTriangulator.Triangle t in tr)
                {
                    G.drawTriangle(t);
                }

                //переписать не под вызов конструктора, а под вызов метода, который будет сравнивать треугольники.
                //т.е. Equals для треугольников, который сравнивает по вершинам.


                MessageBox.Show(sp.Elapsed.Milliseconds.ToString());

                foreach (DelaunayTriangulator.Triangle t in tr)
                {
                    for (int i = 0; i < t.edgemas.Length; i++)
                    {
                        if (t.edgemas[i].isOuside)
                        {
                            G.drawEdge(t.edgemas[i]);
                        }
                        //if (t.edgemas[i].brother != null) G.drawEdge(t.edgemas[i].brother, new Pen(Color.Aqua));
                    }
                    G.drawVector(t);
                }



                sheet.Image = G.GetBitmap();
            }
            else
            {
                MessageBox.Show("Заполните значения векторов", "Ошибка заполнения");
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            Random randy = new Random(138);

            List <Vertex> points = new List <Vertex>();

            if (args.Length == 0)
            {
                // Generate random points.
                SortedDictionary <int, Point> ps = new SortedDictionary <int, Point>();
                for (int i = 0; i < 100000; i++)
                {
                    int x = randy.Next(100000);
                    int y = randy.Next(100000);
                    points.Add(new Vertex(x, y));
                }
            }
            else
            {
                // Read a points file as used by the Delaunay Triangulation Tester program DTT
                // (See http://gemma.uni-mb.si/dtt/)
                using (StreamReader reader = new StreamReader(args[0]))
                {
                    int count = int.Parse(reader.ReadLine());
                    for (int i = 0; i < count; i++)
                    {
                        string   line  = reader.ReadLine();
                        string[] split = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        points.Add(new Vertex(float.Parse(split[0]), float.Parse(split[1])));
                    }
                }
            }

            // Write the points in the format suitable for DTT
            using (StreamWriter writer = new StreamWriter("Triangulation c#.pnt"))
            {
                writer.WriteLine(points.Count);
                for (int i = 0; i < points.Count; i++)
                {
                    writer.WriteLine(String.Format("{0},{1}", points[i].x, points[i].y));
                }
            }

            // Write out the data set we're actually going to triangulate
            Triangulator angulator = new Triangulator();

            Stopwatch watch = new Stopwatch();

            watch.Start();
            List <Triad> triangles = angulator.Triangulation(points, true);

            watch.Stop();

            Debug.WriteLine(watch.ElapsedMilliseconds + " ms");

            // Write the triangulation results in the format suitable for DTT
            using (StreamWriter writer = new StreamWriter("Triangulation c#.dtt"))
            {
                writer.WriteLine(triangles.Count.ToString());
                for (int i = 0; i < triangles.Count; i++)
                {
                    Triad t = triangles[i];
                    writer.WriteLine(string.Format("{0}: {1} {2} {3} - {4} {5} {6}",
                                                   i + 1,
                                                   t.a, t.b, t.c,
                                                   t.ab + 1, t.bc + 1, t.ac + 1));
                }
            }
        }