protected void Generate(IList <VERTEX> input, IDelaunayTriangulation <VERTEX> delaunay, bool assignIds, bool checkInput = false)
        {
            Clear();

            delaunay.Generate(input, assignIds, checkInput);

            for (int i = 0; i < delaunay.Vertices.Count; i++)
            {
                delaunay.Vertices[i].Tag = i;
            }

            for (int i = 0; i < delaunay.Cells.Count; i++)
            {
                delaunay.Cells[i].CircumCenter.Id = i;
                delaunay.Cells[i].Simplex.Tag     = i;
                Cells.Add(delaunay.Cells[i]);
            }

            List <DelaunayCell <VERTEX> >            cells         = new List <DelaunayCell <VERTEX> >();
            Dictionary <int, DelaunayCell <VERTEX> > neighbourCell = new Dictionary <int, DelaunayCell <VERTEX> >();

            for (int i = 0; i < delaunay.Vertices.Count; i++)
            {
                cells.Clear();

                VERTEX vertex = delaunay.Vertices[i];

                for (int j = 0; j < delaunay.Cells.Count; j++)
                {
                    Simplex <VERTEX> simplex = delaunay.Cells[j].Simplex;

                    for (int k = 0; k < simplex.Vertices.Length; k++)
                    {
                        if (simplex.Vertices[k].Tag == vertex.Tag)
                        {
                            cells.Add(delaunay.Cells[j]);
                            break;
                        }
                    }
                }

                if (cells.Count > 0)
                {
                    VoronoiRegion <VERTEX> region = new VoronoiRegion <VERTEX>();

                    for (int j = 0; j < cells.Count; j++)
                    {
                        region.Cells.Add(cells[j]);
                    }

                    neighbourCell.Clear();

                    for (int j = 0; j < cells.Count; j++)
                    {
                        neighbourCell.Add(cells[j].CircumCenter.Id, cells[j]);
                    }

                    for (int j = 0; j < cells.Count; j++)
                    {
                        Simplex <VERTEX> simplex = cells[j].Simplex;

                        for (int k = 0; k < simplex.Adjacent.Length; k++)
                        {
                            if (simplex.Adjacent[k] == null)
                            {
                                continue;
                            }

                            int tag = simplex.Adjacent[k].Tag;

                            if (neighbourCell.ContainsKey(tag))
                            {
                                VoronoiEdge <VERTEX> edge = new VoronoiEdge <VERTEX>(cells[j], neighbourCell[tag]);
                                region.Edges.Add(edge);
                            }
                        }
                    }

                    region.Id = Regions.Count;
                    Regions.Add(region);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Is the key equal to another key.
        /// </summary>
        public override bool Equals(object o)
        {
            VoronoiEdge <VERTEX> k = o as VoronoiEdge <VERTEX>;

            return(k != null && k == this);
        }
Beispiel #3
0
        /// <summary>
        /// Is the key equal to another key.
        /// </summary>
        public bool Equals(IVoronoiEdge <VERTEX> o)
        {
            VoronoiEdge <VERTEX> k = o as VoronoiEdge <VERTEX>;

            return(k == this);
        }
 /// <summary>
 /// Is the key equal to another key.
 /// </summary>
 public bool Equals(VoronoiEdge <VERTEX> k)
 {
     return(k == this);
 }