Example #1
0
        // Modes: 0: centroids, 1: any vertex, 2: 2 vertices, 3: all vertices
        // ContainF should return true if 3D position is in set (eg inside box, etc)
        // If mode = 0, will be called with (centroid, tri_idx)
        // If mode = 1/2/3, will be called with (vtx_pos, vtx_idx)
        // AddF is called with triangle IDs that are in set
        public static void TrianglesContained(NGonsCore.geometry3Sharp.mesh.DMesh3 mesh, Func <Vector3D, int, bool> ContainF, Action <int> AddF, int nMode = 0)
        {
            BitArray inV = null;

            if (nMode != 0)
            {
                inV = new BitArray(mesh.MaxVertexID);
                foreach (int vid in mesh.VertexIndices())
                {
                    if (ContainF(mesh.GetVertex(vid), vid))
                    {
                        inV[vid] = true;
                    }
                }
            }

            foreach (int tid in mesh.TriangleIndices())
            {
                Index3i tri = mesh.GetTriangle(tid);

                bool bIn = false;
                if (nMode == 0)
                {
                    if (ContainF(mesh.GetTriCentroid(tid), tid))
                    {
                        bIn = true;
                    }
                }
                else
                {
                    int countIn = (inV[tri.a] ? 1 : 0) + (inV[tri.b] ? 1 : 0) + (inV[tri.c] ? 1 : 0);
                    bIn = (countIn >= nMode);
                }

                if (bIn)
                {
                    AddF(tid);
                }
            }
        }