public void TestEnumerateTriangles()
        {
            var mesh = CreateMesh(out var vertices);

            var circulator = new VertexCirculator(mesh);

            var p = vertices[0];

            var list = circulator.EnumerateTriangles(p).ToList();

            Assert.AreEqual(1, list.Count);
        }
Esempio n. 2
0
        /// <summary>
        /// Find boundary triangles using vertices.
        /// </summary>
        private static void FindBoundary2(IMesh mesh)
        {
            var circulator = new VertexCirculator((Mesh)mesh);

            foreach (var vertex in mesh.Vertices)
            {
                int label = vertex.Label;

                if (label > 0)
                {
                    var star = circulator.EnumerateTriangles(vertex);

                    foreach (var triangle in star)
                    {
                        triangle.Label = label;
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Find boundary triangles using vertices.
        /// </summary>
        private static void FindBoundary2(Mesh mesh)
        {
            var circulator = new VertexCirculator(mesh);

            foreach (var vertex in mesh.Vertices)
            {
                int label = vertex.Label;

                if (label > 0)
                {
                    var star = circulator.EnumerateTriangles(vertex);

                    // WARNING: triangles will be processed multiple times.
                    foreach (var triangle in star)
                    {
                        triangle.Label = label;
                    }
                }
            }
        }
Esempio n. 4
0
        private static bool FindAdjacencyMatrix(Mesh mesh)
        {
            mesh.Renumber();

            var ap = new List <int>(mesh.Vertices.Count);     // Column pointers.
            var ai = new List <int>(4 * mesh.Vertices.Count); // Row indices.

            var circulator = new VertexCirculator(mesh);

            int k = 0;

            foreach (var vertex in mesh.Vertices)
            {
                var star = circulator.EnumerateVertices(vertex);

                ap.Add(k);

                // Each vertex is adjacent to itself.
                ai.Add(vertex.ID);
                k++;

                foreach (var item in star)
                {
                    ai.Add(item.ID);
                    k++;
                }
            }

            ap.Add(k);

            var matrix1 = new AdjacencyMatrix(ap.ToArray(), ai.ToArray());
            var matrix2 = new AdjacencyMatrix(mesh);

            // Column pointers should be exactly the same.
            if (!CompareArray(matrix1.ColumnPointers, matrix2.ColumnPointers))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Find boundary triangles using segments.
        /// </summary>
        private static void FindBoundary1(IMesh mesh, bool neigbours = true)
        {
            mesh.Renumber();

            var cache = new List <Vertex>(mesh.Segments.Count + 1);

            var circulator = new VertexCirculator((Mesh)mesh);

            foreach (var s in mesh.Segments)
            {
                int label = s.Label;

                for (int i = 0; i < 2; i++)
                {
                    var vertex = s.GetVertex(i);

                    // Check the vertex ID to see if it was processed already.
                    if (vertex.ID >= 0)
                    {
                        var star = circulator.EnumerateTriangles(vertex);

                        foreach (var triangle in star)
                        {
                            triangle.Label = label;
                        }

                        // Mark the vertex as "processed".
                        vertex.ID = -vertex.ID;

                        cache.Add(vertex);
                    }
                }
            }

            // Undo the vertex ID changes.
            foreach (var vertex in cache)
            {
                vertex.ID = -vertex.ID;
            }
        }
        public void TestEnumerateVertices()
        {
            //           5
            //          /\
            //         /  \
            //        /    \
            //      3/______\4
            //      /\      /\
            //     /  \    /  \
            //    /    \  /    \
            //  0/______\/______\2
            //           1

            var mesh = CreateMesh(out var vertices);

            var circulator = new VertexCirculator(mesh);

            var p = vertices[0];

            var list = circulator.EnumerateVertices(p).ToList();

            Assert.AreEqual(2, list.Count);
        }