Isosurface.ManifoldDC.OctreeNode.ClusterIndexes C# (CSharp) Method

ClusterIndexes() public static method

public static ClusterIndexes ( OctreeNode nodes, int direction, int &max_surface_index, List collected_vertices ) : void
nodes OctreeNode
direction int
max_surface_index int
collected_vertices List
return void
        public static void ClusterIndexes(OctreeNode[] nodes, int direction, ref int max_surface_index, List<Vertex> collected_vertices)
        {
            if (nodes[0] == null && nodes[1] == null && nodes[2] == null && nodes[3] == null)
                return;

            Vertex[] vertices = new Vertex[4];
            int v_count = 0;
            int node_count = 0;

            for (int i = 0; i < 4; i++)
            {
                if (nodes[i] == null)
                    continue;
                if (nodes[i].size > 1)
                {
                }
                node_count++;
                if (nodes[i].vertices.Length > 1)
                {
                }

                int edge = Utilities.TProcessEdgeMask[direction, i];
                int c1 = Utilities.TEdgePairs[edge, 0];
                int c2 = Utilities.TEdgePairs[edge, 1];

                int m1 = (nodes[i].corners >> c1) & 1;
                int m2 = (nodes[i].corners >> c2) & 1;

                //if (!((m1 == 0 && m2 != 0) || (m1 != 0 && m2 == 0)))
                //	continue;

                //find the vertex index
                int index = 0;
                bool skip = false;
                for (int k = 0; k < 16; k++)
                {
                    int e = Utilities.TransformedEdgesTable[nodes[i].corners, k];
                    if (e == -1)
                    {
                        index++;
                        continue;
                    }
                    if (e == -2)
                    {
                        if (!((m1 == 0 && m2 != 0) || (m1 != 0 && m2 == 0)))
                            skip = true;
                        break;
                    }
                    if (e == edge)
                        break;
                }

                if (!skip && index < nodes[i].vertices.Length)
                {
                    if (nodes[i].index == 30733)
                    {
                    }
                    if (nodes[i].index == 12)
                    {
                    }
                    vertices[i] = nodes[i].vertices[index];
                    while (vertices[i].parent != null)
                        vertices[i] = vertices[i].parent;
                    if (i > v_count)
                    {
                    }
                    v_count++;
                }
            }

            if (v_count == 0)
                return;
            if (node_count != v_count)
            {
            }

            if (!(vertices[0] != vertices[1] && vertices[1] != vertices[2] && vertices[2] != vertices[3]))
            {
                //return;
            }

            int surface_index = -1;

            for (int i = 0; i < 4; i++)
            {
                Vertex v = vertices[i];
                if (v == null)
                    continue;
                //while (v != null)
                //{
                if (v.surface_index != -1)
                {
                    if (surface_index != -1 && surface_index != v.surface_index)
                    {
                        AssignSurface(collected_vertices, v.surface_index, surface_index);
                    }
                    else if (surface_index == -1)
                        surface_index = v.surface_index;
                    //break;
                }

                //break;
                //v = v.parent;
                //}
            }

            if (surface_index == -1)
                surface_index = max_surface_index++;

            for (int i = 0; i < 4; i++)
            {
                Vertex v = vertices[i];
                if (v == null)
                    continue;
                //while (v.parent != null)
                //	v = v.parent;
                //while (v != null)
                //{
                if (v.surface_index == -1)
                {
                    collected_vertices.Add(v);
                }
                v.surface_index = surface_index;
                //v = v.parent;
                //}
            }
        }