Beispiel #1
0
    public int ConnectTriByArea(List <int> highlights)
    {
        TriangleDisjointSets  tds      = new TriangleDisjointSets(highlights.Count);
        Dictionary <int, int> refIndex = new Dictionary <int, int>();

        for (int i = 0; i < highlights.Count; i++)
        {
            refIndex.Add(highlights[i], i);
        }

        for (int i = 0; i < highlights.Count; i++)
        {
            // Condition 1: must be adjacent
            foreach (var j in TriList[highlights[i]].adjList)
            {
                // Condition 2: must be highlighted
                if (refIndex.ContainsKey(j))
                {
                    tds.union(i, refIndex[j]);
                }
            }
        }
        refIndex.Clear();
        return(tds.totalSets());
    }
    public int ConnectTriByArea(List <int> highlights)
    {
        int n = highlights.Count;

        tds = new TriangleDisjointSets(n);
        Dictionary <int, int> refIndex = new Dictionary <int, int>();

        //int[] meshIndex = new int[n]; // to map result back to mesh triangle index
        for (int i = 0; i < n; i++)
        {
            refIndex.Add(highlights[i], i);
            //meshIndex[i] = highlights[i];
            tds.meshIndex[i] = highlights[i];
        }
        for (int i = 0; i < n; i++)
        {
            // Condition 1: must be adjacent
            foreach (var j in TriList[highlights[i]].adjList)
            {
                // Condition 2: must be highlighted
                if (refIndex.ContainsKey(j))
                {
                    tds.union(i, refIndex[j]);
                }
            }
        }

        refIndex.Clear();
        return(tds.totalSets());
    }