示例#1
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);
        }
        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);
        }