Exemplo n.º 1
0
        /// <summary>
        /// Generate the Voronoi diagram from given triangle mesh..
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="bounded"></param>
        protected void Generate(Mesh mesh)
        {
            mesh.Renumber();

            base.edges = new List <HalfEdge>();
            this.rays  = new List <HalfEdge>();

            // Allocate space for Voronoi diagram.
            var vertices = new Vertex[mesh.triangles.Count + mesh.hullsize];
            var faces    = new Face[mesh.vertices.Count];

            if (factory == null)
            {
                factory = new DefaultVoronoiFactory();
            }

            factory.Initialize(vertices.Length, 2 * mesh.NumberOfEdges, faces.Length);

            // Compute triangles circumcenters.
            var map = ComputeVertices(mesh, vertices);

            // Create all Voronoi faces.
            foreach (var vertex in mesh.vertices.Values)
            {
                faces[vertex.id] = factory.CreateFace(vertex);
            }

            ComputeEdges(mesh, vertices, faces, map);

            // At this point all edges are computed, but the (edge.next) pointers aren't set.
            ConnectEdges(map);

            base.vertices = new List <Vertex>(vertices);
            base.faces    = new List <Face>(faces);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate the Voronoi diagram from given triangle mesh..
        /// </summary>
        /// <param name="mesh"></param>
        protected void Generate(Mesh mesh)
        {
            base.edges = new List <HalfEdge>();
            this.rays  = new List <HalfEdge>();

            // Undead vertices cannot be Voronoi cell generators.
            int count = mesh.vertices.Count - mesh.undeads;

            // Allocate space for Voronoi diagram.
            var vertices = new Vertex[mesh.triangles.Count + mesh.hullsize];
            var faces    = new Face[count];

            if (factory == null)
            {
                factory = new DefaultVoronoiFactory();
            }

            factory.Initialize(vertices.Length, 2 * mesh.NumberOfEdges, faces.Length);

            // Compute triangles circumcenters.
            var map = ComputeVertices(mesh, vertices);

            // Ensure linear numbering of vertices (excluding undeads).
            int vid = 0;

            // Create all Voronoi faces, skipping undead vertices.
            foreach (var vertex in mesh.vertices.Values)
            {
                if (vertex.type == VertexType.UndeadVertex)
                {
                    vertex.id = count++;
                }
                else
                {
                    vertex.id        = vid++;
                    faces[vertex.id] = factory.CreateFace(vertex);
                }
            }

            ComputeEdges(mesh, vertices, faces, map);

            // At this point all edges are computed, but the (edge.next) pointers aren't set.
            ConnectEdges(map);

            base.vertices = new List <Vertex>(vertices);
            base.faces    = new List <Face>(faces);
        }