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

ProcessIndexes() public static method

public static ProcessIndexes ( OctreeNode nodes, int direction, List indexes, List tri_count, float threshold ) : void
nodes OctreeNode
direction int
indexes List
tri_count List
threshold float
return void
        public static void ProcessIndexes(OctreeNode[] nodes, int direction, List<int> indexes, List<int> tri_count, float threshold)
        {
            int min_size = 10000000;
            int min_index = 0;
            int[] indices = { -1, -1, -1, -1 };
            bool flip = false;
            bool sign_changed = false;
            int v_count = 0;
            //return;

            for (int i = 0; i < 4; i++)
            {
                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 (nodes[i].size < min_size)
                {
                    min_size = nodes[i].size;
                    min_index = i;
                    flip = m1 == 1;
                    sign_changed = ((m1 == 0 && m2 != 0) || (m1 != 0 && m2 == 0));
                }

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

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

                if (skip)
                    continue;
                if (nodes[i].index == 30733)
                {
                }

                v_count++;
                if (index >= nodes[i].vertices.Length)
                    return;
                Vertex v = nodes[i].vertices[index];
                Vertex highest = v;
                while (highest.parent != null)
                {
                    if ((highest.parent.error <= threshold && (!EnforceManifold || (highest.parent.euler == 1 && highest.parent.face_prop2))))
                        highest = v = highest.parent;
                    else
                        highest = highest.parent;
                }

                //Vector3 p = v.qef.Solve(1e-6f, 4, 1e-6f);
                indices[i] = v.index;
                if (v.index == -1)
                {
                }

                //sign_changed = true;
            }

            if (v_count > 0 && v_count < 4)
            {
            }

            /*
             * Next generate the triangles.
             * Because we're generating from the finest levels that were collapsed, many triangles will collapse to edges or vertices.
             * That's why we check if the indices are different and discard the triangle, as mentioned in the paper.
             */
            if (sign_changed)
            {
                int count = 0;
                if (!flip)
                {
                    if (indices[0] != -1 && indices[1] != -1 && indices[2] != -1 && indices[0] != indices[1] && indices[1] != indices[3])
                    {
                        indexes.Add(indices[0]);
                        indexes.Add(indices[1]);
                        indexes.Add(indices[3]);
                        count++;
                    }

                    if (indices[0] != -1 && indices[2] != -1 && indices[3] != -1 && indices[0] != indices[2] && indices[2] != indices[3])
                    {
                        indexes.Add(indices[0]);
                        indexes.Add(indices[3]);
                        indexes.Add(indices[2]);
                        count++;
                    }
                }
                else
                {
                    if (indices[0] != -1 && indices[3] != -1 && indices[1] != -1 && indices[0] != indices[1] && indices[1] != indices[3])
                    {
                        indexes.Add(0x10000000 | indices[0]);
                        indexes.Add(0x10000000 | indices[3]);
                        indexes.Add(0x10000000 | indices[1]);
                        count++;
                    }

                    if (indices[0] != -1 && indices[2] != -1 && indices[3] != -1 && indices[0] != indices[2] && indices[2] != indices[3])
                    {
                        indexes.Add(0x10000000 | indices[0]);
                        indexes.Add(0x10000000 | indices[2]);
                        indexes.Add(0x10000000 | indices[3]);
                        count++;
                    }
                }

                if (count > 0)
                    tri_count.Add(count);
            }
        }