Exemple #1
0
        static void ResetDataIDCounters <T>()
        {
            MICHVertex <T> .Clear();

            MICHDelaunayCell <T> .Clear();
        }
Exemple #2
0
        static (VariableCell <T>[] cells, Vertex[] vertices) CreateMeshLists(
            IEnumerable <MICHDelaunayCell <T> > delaCells,
            IEnumerable <MIConvexHull.VoronoiEdge
                         <MICHVertex <T>, MICHDelaunayCell <T> > > edges,
            int numberOfVoronois)
        {
            //remove zero-Edges
            foreach (var edge in edges)
            {
                Vertex start  = edge.Source.Circumcenter;
                Vertex end    = edge.Target.Circumcenter;
                double length = (start.Position - end.Position).AbsSquare();
                if (length < accuracy)
                {
                    edge.Source.Circumcenter = edge.Target.Circumcenter;
                }
            }

            Vertex[]           vertices = new Vertex[delaCells.Count()];
            VariableCell <T>[] cells    = new VariableCell <T> [numberOfVoronois];

            foreach (MICHDelaunayCell <T> delaCell in delaCells)
            {
                delaCell.done = true;
                MICHDelaunayCell <T>[] neighbors    = delaCell.Adjacency;
                VariableCell <T>[]     voronoiCells = new VariableCell <T> [3];
                vertices[delaCell.ID] = delaCell.Circumcenter;

                //Create Voronoi Cells
                //--------------------------------------------------------------
                for (int i = 0; i < 3; ++i)
                {
                    MICHVertex <T> vert = delaCell.Vertices[i];
                    //Create or pick cell
                    VariableCell <T> voronoiCell = null;
                    if (cells[vert.ID] == null)
                    {
                        voronoiCell = new VariableCell <T> {
                            ID = vert.ID, Node = vert.Node
                        };
                        cells[vert.ID] = voronoiCell;
                    }
                    else
                    {
                        voronoiCell = cells[vert.ID];
                    }
                    voronoiCells[i] = voronoiCell;
                }
                //Create Ridges for each neighbor
                //--------------------------------------------------------------
                for (int i = 0; i < 3; ++i)
                {
                    MICHDelaunayCell <T> neighbor = neighbors[i];
                    if (neighbor != null)
                    {
                        if (!neighbor.done)
                        {
                            (int k, int j) = OpposingIndices(i);
                            //Create Ridges
                            Edge <T> ridgeOutwards = new Edge <T>
                            {
                                Start = delaCell.Circumcenter,
                                End   = neighbor.Circumcenter,
                                Cell  = voronoiCells[k]
                            };
                            Edge <T> ridgeInwards = new Edge <T>
                            {
                                Start = neighbor.Circumcenter,
                                End   = delaCell.Circumcenter,
                                Cell  = voronoiCells[j]
                            };
                            ridgeInwards.Twin  = ridgeOutwards;
                            ridgeOutwards.Twin = ridgeInwards;
                            //add to the two cells

                            voronoiCells[k].Insert(ridgeOutwards);
                            voronoiCells[j].Insert(ridgeInwards);
                        }
                    }
                    else
                    {
                        (int k, int j)           = OpposingIndices(i);
                        voronoiCells[k].boundary = true;
                        voronoiCells[j].boundary = true;
                    }
                }
            }
            return(cells, vertices);
        }