Esempio n. 1
0
        public void FloodFillTest()
        {
            List <int> labels = FMath.FloodFill <Object>(10, new Dictionary <int, List <int> >(), null, null);

            Assert.AreEqual(new HashSet <int>(labels).Count, 10);

            labels = FMath.FloodFill <Object>(10, new Dictionary <int, List <int> >()
            {
                { 0, new List <int>()
                  {
                      2, 8, 4, 6, 0, 2
                  } }
            }, null, null);
            Assert.AreEqual(new HashSet <int>(labels).Count, 6);

            Dictionary <int, List <int> > edges = new Dictionary <int, List <int> >();

            for (int i = 0; i < 10; i++)
            {
                edges[i] = new List <int>();
                for (int j = 0; j < 10; j++)
                {
                    edges[i].Add(j);
                }
            }
            labels = FMath.FloodFill <Object>(10, edges, cond, null);
            Assert.AreEqual(new HashSet <int>(labels).Count, 2);
        }
Esempio n. 2
0
        // pathをpartinLineで分割した小さい領域が複数できる
        // ptsの各点が各領域のどれに含まれるかの情報をoutPtToPartに格納する
        // 分割線は交差しないものとする
        static void Parting(List <PointF> pts, List <TriMesh> tris, List <PointF> partingLine, List <int> outPtToPart)
        {
            if (outPtToPart == null)
            {
                return;
            }
            if (pts == null)
            {
                return;
            }

            // デフォルトでは全部0にする
            for (int i = 0; i < pts.Count; i++)
            {
                outPtToPart.Add(0);
            }

            if (partingLine == null || partingLine.Count <= 1)
            {
                return;
            }

            Dictionary <int, List <int> > edges = GetEdges(pts, tris);
            HashSet <int> boarderEdgeCodes      = GetEdgeCodeNearLine(pts, edges, partingLine);
            var           labels = FMath.FloodFill(pts.Count, edges, cond, boarderEdgeCodes);

            FillPointsNearBoarder(pts, edges, boarderEdgeCodes, labels);

            outPtToPart.Clear();
            if (labels != null && labels.Count == pts.Count)
            {
                for (int i = 0; i < labels.Count; i++)
                {
                    outPtToPart.Add(labels[i]);
                }
            }
        }