Beispiel #1
0
        static BitMap2d GetSampleTest3()
        {
            BitMap2d bmp = new BitMap2d(1694, 1257, BitMap2d.BLACK);

            bmp.ReadBitmap(@"D:\VTKproj\FF2TEST\test3.bmp");
            return(bmp);
        }
Beispiel #2
0
 protected virtual void ExcuteFloodFill(BitMap2d data, Int16Double seed)
 {
     this.bmp = data;
     data.ResetVisitCount();
     flagsMap = new FlagMap2d(data.width, data.height);
     Int16Double[] adjPoints4 = new Int16Double[4];
     flagsMap.SetFlagOn(seed.X, seed.Y, true);
     container.Push(seed);
     Process(seed);
     while (!container.Empty())
     {
         Int16Double p = container.Pop();
         InitAdj4(ref adjPoints4, ref p);
         for (int adjIndex = 0; adjIndex < 4; adjIndex++)
         {
             Int16Double t = adjPoints4[adjIndex];
             if (t.X < data.width && t.X >= 0 && t.Y < data.height && t.Y >= 0)
             {
                 if (!flagsMap.GetFlagOn(t.X, t.Y) && IncludePredicate(t))
                 {
                     flagsMap.SetFlagOn(t.X, t.Y, true);
                     container.Push(t);
                     Process(t);
                 }
             }
         }
     }
     return;
 }
Beispiel #3
0
        static BitMap2d GetSampleTest1()
        {
            BitMap2d bmp = new BitMap2d(1124, 1924, BitMap2d.BLACK);

            bmp.ReadBitmap(@"D:\VTKproj\FF2TEST\test1.bmp");
            return(bmp);
        }
Beispiel #4
0
        static void Test5()
        {
            BitMap2d bmp = GetSampleTest5();

            TestFloodFill(bmp, seed_5);
            TestScanlineFill(bmp, seed_5);
            TestSpanFill(bmp, seed_5);
        }
Beispiel #5
0
 static void TestScanlineFill(BitMap2d bmp, Int16Double seed)
 {
     {
         ScanlineFill2d_T ff = new ScanlineFill2d_T();
         ff.ExcuteScanlineFill_Stack(bmp, seed);
         ff.report.PrintInfo();
     }
     {
         ScanlineFill2d_T ff = new ScanlineFill2d_T();
         ff.ExcuteScanlineFill_Queue(bmp, seed);
         ff.report.PrintInfo();
     }
 }
Beispiel #6
0
 static void TestFloodFill(BitMap2d bmp, Int16Double seed)
 {
     {
         FloodFill2d_T ff = new FloodFill2d_T();
         ff.ExcuteFloodFill_Stack(bmp, seed);
         ff.report.PrintInfo();
     }
     {
         FloodFill2d_T ff = new FloodFill2d_T();
         ff.ExcuteFloodFill_Queue(bmp, seed);
         ff.report.PrintInfo();
     }
 }
Beispiel #7
0
 static void TestSpanFill(BitMap2d bmp, Int16Double seed)
 {
     {
         SpanFill2d_T ff2 = new SpanFill2d_T();
         ff2.ExcuteSpanFill_Stack(bmp, seed);
         ff2.report.PrintInfo();
     }
     {
         SpanFill2d_T ff2 = new SpanFill2d_T();
         ff2.ExcuteSpanFill_Queue(bmp, seed);
         ff2.report.PrintInfo();
         //ff2.report.OutPutMap(ff2.flagsMap, "result.bmp");
     }
 }
Beispiel #8
0
 static void TestXY()
 {
     BitMap2d bmp = GetSampleTest6();
     {
         SpanYFill2d_T ff = new SpanYFill2d_T();
         ff.ExcuteSpanFill_S(bmp, seed_1);
         ff.report.PrintInfo();
     }
     {
         SpanFill2d_T ff = new SpanFill2d_T();
         ff.ExcuteSpanFill_Stack(bmp, seed_1);
         ff.report.PrintInfo();
     }
 }
Beispiel #9
0
 public override void ExcuteSpanFill_S(BitMap2d data, Int16Double seed)
 {
     watch.Start();
     base.ExcuteSpanFill_S(data, seed);
     watch.Stop();
     report.time = watch.ElapsedMilliseconds;
     report.result_point_count   = count;
     report.bmp_get_count        = data.action_get_count;
     report.bmp_set_count        = data.action_set_count;
     report.container_pop_count  = queue.action_pop_count;
     report.container_push_count = queue.action_push_count;
     report.container_max_size   = queue.max_contain_count;
     report.flag_get_count       = flagsMap.action_get_count;
     report.flag_set_count       = flagsMap.action_set_count;
     return;
 }
Beispiel #10
0
 public void ExcuteFloodFill_Stack(BitMap2d data, Int16Double seed)
 {
     watch.Start();
     container = new Container_Stack <Int16Double>();
     base.ExcuteFloodFill(data, seed);
     watch.Stop();
     report.time = watch.ElapsedMilliseconds;
     report.result_point_count   = count;
     report.bmp_get_count        = data.action_get_count;
     report.bmp_set_count        = data.action_set_count;
     report.container_pop_count  = container.action_pop_count;
     report.container_push_count = container.action_push_count;
     report.container_max_size   = container.max_contain_count;
     report.flag_get_count       = flagsMap.action_get_count;
     report.flag_set_count       = flagsMap.action_set_count;
     return;
 }
Beispiel #11
0
        static BitMap2d GetSampleTest5()
        {
            BitMap2d bmp   = new BitMap2d(2300, 2300, BitMap2d.BLACK);
            int      width = bmp.width;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    double distence = Math.Sqrt((i - width / 2) * (i - width / 2) + (j - width / 2) * (j - width / 2));
                    if (distence < width / 2)
                    {
                        bmp.SetPixel(i, j, BitMap2d.WHITE);
                    }
                }
            }
            bmp.ResetVisitCount();
            return(bmp);
        }
Beispiel #12
0
 protected virtual void ExcuteScanlineFill(BitMap2d data, Int16Double seed)
 {
     this.bmp = data;
     data.ResetVisitCount();
     flagsMap = new FlagMap2d(data.width, data.height);
     flagsMap.SetFlagOn(seed.X, seed.Y, true);
     container.Push(seed);
     Process(seed);
     while (!container.Empty())
     {
         Int16Double p      = container.Pop();
         int         xleft  = FindXLeft(p);
         int         xright = FindXRight(p);
         if (p.Y - 1 >= 0)
         {
             CheckRange(xleft, xright, p.Y - 1);
         }
         if (p.Y + 1 < data.height)
         {
             CheckRange(xleft, xright, p.Y + 1);
         }
     }
 }//该函数为扫描线法主体
Beispiel #13
0
        static BitMap2d GetSampleTest6()
        {
            BitMap2d bmp = new BitMap2d(10000, 10000, BitMap2d.WHITE);

            return(bmp);
        }
Beispiel #14
0
        static BitMap2d GetSampleTest4()
        {
            BitMap2d bmp = new BitMap2d(5000, 5000, BitMap2d.WHITE);

            return(bmp);
        }
Beispiel #15
0
        public virtual void ExcuteSpanFill_S(BitMap2d data, Int16Double seed)
        {
            this.bmp = data;
            data.ResetVisitCount();
            flagsMap = new FlagMap2d(data.width, data.height);
            queue    = new Container_Stack <SpanY>();
            Process(seed);
            flagsMap.SetFlagOn(seed.X, seed.Y, true);
            SpanY seedspan = new SpanY();

            seedspan.YLeft           = seed.Y;
            seedspan.YRight          = seed.Y;
            seedspan.X               = seed.X;
            seedspan.ParentDirection = ParentDirectionsY.Non;
            seedspan.Extended        = ExtendTypesY.UnRez;
            queue.Push(seedspan);

            while (!queue.Empty())
            {
                SpanY span = queue.Pop();
                #region AllRez
                if (span.Extended == ExtendTypesY.AllRez)
                {
                    if (span.ParentDirection == ParentDirectionsY.X2)
                    {
                        if (span.X - 1 >= 0)
                        {
                            CheckRange(span.YLeft, span.YRight, span.X - 1, ParentDirectionsY.X2);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirectionsY.X0)
                    {
                        if (span.X + 1 < bmp.width)
                        {
                            CheckRange(span.YLeft, span.YRight, span.X + 1, ParentDirectionsY.X0);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region UnRez
                if (span.Extended == ExtendTypesY.UnRez)
                {
                    int yl = FindYLeft(span.YLeft, span.X);
                    int yr = FindYRight(span.YRight, span.X);
                    if (span.ParentDirection == ParentDirectionsY.X2)
                    {
                        if (span.X - 1 >= 0)
                        {
                            CheckRange(yl, yr, span.X - 1, ParentDirectionsY.X2);
                        }
                        if (span.X + 1 < bmp.width)
                        {
                            if (yl != span.YLeft)
                            {
                                CheckRange(yl, span.YLeft, span.X + 1, ParentDirectionsY.X0);
                            }
                            if (span.YRight != yr)
                            {
                                CheckRange(span.YRight, yr, span.X + 1, ParentDirectionsY.X0);
                            }
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirectionsY.X0)
                    {
                        if (span.X + 1 < bmp.width)
                        {
                            CheckRange(yl, yr, span.X + 1, ParentDirectionsY.X0);
                        }
                        if (span.X - 1 >= 0)
                        {
                            if (yl != span.YLeft)
                            {
                                CheckRange(yl, span.YLeft, span.X - 1, ParentDirectionsY.X2);
                            }
                            if (span.YRight != yr)
                            {
                                CheckRange(span.YRight, yr, span.X - 1, ParentDirectionsY.X2);
                            }
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirectionsY.Non)
                    {
                        if (span.X + 1 < bmp.width)
                        {
                            CheckRange(yl, yr, span.X + 1, ParentDirectionsY.X0);
                        }
                        if (span.X - 1 >= 0)
                        {
                            CheckRange(yl, yr, span.X - 1, ParentDirectionsY.X2);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region LeftRequired
                if (span.Extended == ExtendTypesY.LeftRequired)
                {
                    int yl = FindYLeft(span.YLeft, span.X);
                    if (span.ParentDirection == ParentDirectionsY.X2)
                    {
                        if (span.X - 1 >= 0)
                        {
                            CheckRange(yl, span.YRight, span.X - 1, ParentDirectionsY.X2);
                        }
                        if (span.X + 1 < bmp.width && yl != span.YLeft)
                        {
                            CheckRange(yl, span.YLeft, span.X + 1, ParentDirectionsY.X0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirectionsY.X0)
                    {
                        if (span.X + 1 < bmp.width)
                        {
                            CheckRange(yl, span.YRight, span.X + 1, ParentDirectionsY.X0);
                        }
                        if (span.X - 1 >= 0 && yl != span.YLeft)
                        {
                            CheckRange(yl, span.YLeft, span.X - 1, ParentDirectionsY.X2);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region RightRequired
                if (span.Extended == ExtendTypesY.RightRequired)
                {
                    int yr = FindYRight(span.YRight, span.X);

                    if (span.ParentDirection == ParentDirectionsY.X2)
                    {
                        if (span.X - 1 >= 0)
                        {
                            CheckRange(span.YLeft, yr, span.X - 1, ParentDirectionsY.X2);
                        }
                        if (span.X + 1 < bmp.width && span.YRight != yr)
                        {
                            CheckRange(span.YRight, yr, span.X + 1, ParentDirectionsY.X0);
                        }
                        continue;
                    }

                    if (span.ParentDirection == ParentDirectionsY.X0)
                    {
                        if (span.X + 1 < bmp.width)
                        {
                            CheckRange(span.YLeft, yr, span.X + 1, ParentDirectionsY.X0);
                        }
                        if (span.X - 1 >= 0 && span.YRight != yr)
                        {
                            CheckRange(span.YRight, yr, span.X - 1, ParentDirectionsY.X2);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
            }
        }
Beispiel #16
0
        protected Container <Span> container;//以Span为单位的Queue或Stack容器
        protected virtual void ExcuteSpanFill(BitMap2d data, Int16Double seed)
        {
            this.bmp = data;
            data.ResetVisitCount();
            flagsMap = new FlagMap2d(data.width, data.height);
            Process(seed);
            flagsMap.SetFlagOn(seed.X, seed.Y, true);
            Span seedspan = new Span();

            seedspan.XLeft           = seed.X;
            seedspan.XRight          = seed.X;
            seedspan.Y               = seed.Y;
            seedspan.ParentDirection = ParentDirections.Non;
            seedspan.Extended        = ExtendTypes.UnRez;
            container.Push(seedspan);

            while (!container.Empty())
            {
                Span span = container.Pop();
                #region AllRez
                if (span.Extended == ExtendTypes.AllRez)
                {
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y - 1, ParentDirections.Y2);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(span.XLeft, span.XRight, span.Y + 1, ParentDirections.Y0);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region UnRez
                if (span.Extended == ExtendTypes.UnRez)
                {
                    int xl = FindXLeft(span.XLeft, span.Y);
                    int xr = FindXRight(span.XRight, span.Y);
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y + 1, ParentDirections.Y0);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y + 1, ParentDirections.Y0);
                            }
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, ParentDirections.Y0);
                        }
                        if (span.Y - 1 >= 0)
                        {
                            if (xl != span.XLeft)
                            {
                                CheckRange(xl, span.XLeft, span.Y - 1, ParentDirections.Y2);
                            }
                            if (span.XRight != xr)
                            {
                                CheckRange(span.XRight, xr, span.Y - 1, ParentDirections.Y2);
                            }
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Non)
                    {
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, xr, span.Y + 1, ParentDirections.Y0);
                        }
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, xr, span.Y - 1, ParentDirections.Y2);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region LeftRequired
                if (span.Extended == ExtendTypes.LeftRequired)
                {
                    int xl = FindXLeft(span.XLeft, span.Y);
                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(xl, span.XRight, span.Y - 1, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y + 1, ParentDirections.Y0);
                        }
                        continue;
                    }
                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(xl, span.XRight, span.Y + 1, ParentDirections.Y0);
                        }
                        if (span.Y - 1 >= 0 && xl != span.XLeft)
                        {
                            CheckRange(xl, span.XLeft, span.Y - 1, ParentDirections.Y2);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
                #region RightRequired
                if (span.Extended == ExtendTypes.RightRequired)
                {
                    int xr = FindXRight(span.XRight, span.Y);

                    if (span.ParentDirection == ParentDirections.Y2)
                    {
                        if (span.Y - 1 >= 0)
                        {
                            CheckRange(span.XLeft, xr, span.Y - 1, ParentDirections.Y2);
                        }
                        if (span.Y + 1 < bmp.height && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y + 1, ParentDirections.Y0);
                        }
                        continue;
                    }

                    if (span.ParentDirection == ParentDirections.Y0)
                    {
                        if (span.Y + 1 < bmp.height)
                        {
                            CheckRange(span.XLeft, xr, span.Y + 1, ParentDirections.Y0);
                        }
                        if (span.Y - 1 >= 0 && span.XRight != xr)
                        {
                            CheckRange(span.XRight, xr, span.Y - 1, ParentDirections.Y2);
                        }
                        continue;
                    }
                    throw new Exception();
                }
                #endregion
            }
        }