private List <TNetMesh> ConstructTNetMeshFromCellmap(List <VFace> cellmap)
        {
            List <Vertex>   vertices = new List <Vertex>();
            List <TNetMesh> result   = new List <TNetMesh>();

            TriangleNet.Configuration config = new TriangleNet.Configuration();
            SweepLine sweepline = new SweepLine();

            foreach (VFace face in cellmap)
            {
                vertices.Clear();
                foreach (VHEdge he in face.EnumerateEdges())
                {
                    Vertex v = new Vertex(he.Origin.X, he.Origin.Y);
                    v.Z = he.Origin.Z;
                    if (!vertices.Contains(v))
                    {
                        vertices.Add(v);
                    }
                }

                TNetMesh tMesh = (TNetMesh)sweepline.Triangulate(vertices, config);
                result.Add(tMesh);
            }

            return(result);
        }
Exemple #2
0
    public GameObject voronoiFaceToGO(TriangleNet.Topology.DCEL.Face face)
    {
        GameObject cell;

        if (face.Bounded)
        {
            cell = new GameObject("FaceID: " + face.ID);
            MeshFilter   mFilter = cell.AddComponent <MeshFilter>();
            MeshRenderer mRender = cell.AddComponent <MeshRenderer>();
            mRender.material       = new Material(Shader.Find("Diffuse"));
            mRender.material.color = new Color(1f, 1f, 1f);

            List <Vertex> vertices = new List <Vertex>();
            foreach (TriangleNet.Topology.DCEL.HalfEdge he in face.EnumerateEdges())
            {
                Vertex v = new Vertex(he.Origin.X, he.Origin.Y);
                vertices.Add(v);
            }
            SweepLine sl = new SweepLine();
            TriangleNet.Configuration conf      = new TriangleNet.Configuration();
            TriangleNet.Mesh          tMeshCell = (TriangleNet.Mesh)sl.Triangulate(vertices, conf);
            mFilter.mesh = OsgiViz.Helperfunctions.convertTriangleNETMesh(tMeshCell);
        }
        else
        {
            cell = new GameObject("unbounded cell");
        }

        return(cell);
    }
        public BoundedVoronoi CreateRelaxedVoronoi(int lloydRelaxations, float cellScale, int seed)
        {
            System.Random random = new System.Random(seed);

            List <Vertex> startingVertices = CreatePointsOnPlane(cellScale, cellScale, 50, 50, 1.0f, random);
            List <Vertex> vertices         = new List <Vertex>();

            TriangleNet.Configuration config = new TriangleNet.Configuration();
            SweepLine sweepline = new SweepLine();

            TNetMesh       tMesh   = (TNetMesh)sweepline.Triangulate(startingVertices, config);
            BoundedVoronoi voronoi = new BoundedVoronoi(tMesh);

            for (int i = 0; i < lloydRelaxations; i++)
            {
                foreach (VFace face in voronoi.Faces)
                {
                    if (CheckCell(face))
                    {
                        Vertex newCentroid = new Vertex(0, 0);
                        int    vertexCount = 0;
                        foreach (VHEdge edge in face.EnumerateEdges())
                        {
                            newCentroid.X += edge.Origin.X;
                            newCentroid.Y += edge.Origin.Y;
                            vertexCount++;
                        }
                        newCentroid.X /= vertexCount;
                        newCentroid.Y /= vertexCount;
                        vertices.Add(newCentroid);
                    }
                }

                tMesh   = (TNetMesh)sweepline.Triangulate(vertices, config);
                voronoi = new BoundedVoronoi(tMesh);
                vertices.Clear();
            }

            return(voronoi);
        }
        public void TestTriangulateSweepLine()
        {
            var t = new SweepLine();

            var vertices = GetVertices();

            var mesh = t.Triangulate(vertices, new Configuration());

            Assert.AreEqual(6, vertices.Count);
            Assert.AreEqual(6, mesh.Vertices.Count);
            Assert.AreEqual(1, mesh.Vertices
                            .Where(v => v.Type == VertexType.UndeadVertex)
                            .Count());
        }
Exemple #5
0
        public static BoundedVoronoi createRelaxedVoronoi(List <Vertex> startingVertices, int numLloydRelaxations)
        {
            TriangleNet.Configuration conf = new TriangleNet.Configuration();
            SweepLine     sl       = new SweepLine();
            List <Vertex> vertices = new List <Vertex>();

            TnetMesh       tMesh   = (TnetMesh)sl.Triangulate(startingVertices, conf);
            BoundedVoronoi voronoi = new BoundedVoronoi(tMesh);

            for (int i = 0; i < numLloydRelaxations; i++)
            {
                foreach (VFace face in voronoi.Faces)
                {
                    if (checkCell(face))
                    {
                        Vertex newCentroid = new Vertex(0, 0);
                        int    vertexCount = 0;
                        foreach (VHEdge edge in face.EnumerateEdges())
                        {
                            newCentroid.X += edge.Origin.X;
                            newCentroid.Y += edge.Origin.Y;
                            vertexCount++;
                        }
                        newCentroid.X /= vertexCount;
                        newCentroid.Y /= vertexCount;
                        vertices.Add(newCentroid);
                    }
                }

                tMesh   = (TnetMesh)sl.Triangulate(vertices, conf);
                voronoi = new BoundedVoronoi(tMesh);
                vertices.Clear();
            }

            return(voronoi);
        }
Exemple #6
0
    // Use this for initialization
    void Start()
    {
        TriangleNet.Configuration conf = new TriangleNet.Configuration();


        List <Vertex> vertices = OsgiViz.Helperfunctions.createPointsOnPlane(1f, 1f, 50, 50, 1f, new System.Random());
        SweepLine     sl       = new SweepLine();

        //TriangleNet.Mesh tMesh = (TriangleNet.Mesh)TriangleNet.Meshing.GenericMesher.StructuredMesh(1f, 1f, 10, 10);
        TriangleNet.Mesh tMesh = (TriangleNet.Mesh)sl.Triangulate(vertices, conf);
        TriangleNet.Voronoi.BoundedVoronoi voronoi = new TriangleNet.Voronoi.BoundedVoronoi(tMesh);

        foreach (TriangleNet.Topology.DCEL.Face vf in voronoi.Faces)
        {
            voronoiFaceToGO(vf);
        }
    }