TriangleNet.Tools.AdjacencyMatrix.AdjacencyCount C# (CSharp) Method

AdjacencyCount() private method

Counts adjacencies in a triangulation.
This routine is called to count the adjacencies, so that the appropriate amount of memory can be set aside for storage when the adjacency structure is created. The triangulation is assumed to involve 3-node triangles. Two nodes are "adjacent" if they are both nodes in some triangle. Also, a node is considered to be adjacent to itself. Diagram: 3 s |\ i | \ d | \ e | \ side 1 | \ 2 | \ | \ 1-------2 side 3
private AdjacencyCount ( Mesh mesh ) : int[]
mesh Mesh
return int[]
        int[] AdjacencyCount(Mesh mesh)
        {
            int i;
            int node;
            int n1, n2, n3;
            int tri_id;
            int neigh_id;

            int[] adj_rows = new int[node_num + 1];

            // Set every node to be adjacent to itself.
            for (node = 0; node < node_num; node++)
            {
                adj_rows[node] = 1;
            }

            // Examine each triangle.
            foreach (var tri in mesh.triangles.Values)
            {
                tri_id = tri.id;

                n1 = tri.vertices[0].id;
                n2 = tri.vertices[1].id;
                n3 = tri.vertices[2].id;

                // Add edge (1,2) if this is the first occurrence, that is, if
                // the edge (1,2) is on a boundary (nid <= 0) or if this triangle
                // is the first of the pair in which the edge occurs (tid < nid).
                neigh_id = tri.neighbors[2].triangle.id;

                if (neigh_id < 0 || tri_id < neigh_id)
                {
                    adj_rows[n1] += 1;
                    adj_rows[n2] += 1;
                }

                // Add edge (2,3).
                neigh_id = tri.neighbors[0].triangle.id;

                if (neigh_id < 0 || tri_id < neigh_id)
                {
                    adj_rows[n2] += 1;
                    adj_rows[n3] += 1;
                }

                // Add edge (3,1).
                neigh_id = tri.neighbors[1].triangle.id;

                if (neigh_id < 0 || tri_id < neigh_id)
                {
                    adj_rows[n3] += 1;
                    adj_rows[n1] += 1;
                }
            }

            // We used ADJ_COL to count the number of entries in each column.
            // Convert it to pointers into the ADJ array.
            for (node = node_num; 1 <= node; node--)
            {
                adj_rows[node] = adj_rows[node - 1];
            }

            adj_rows[0] = 1;
            for (i = 1; i <= node_num; i++)
            {
                adj_rows[i] = adj_rows[i - 1] + adj_rows[i];
            }

            return adj_rows;
        }