示例#1
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;
 }
示例#2
0
 public void OutPutMap(FlagMap2d flagsmap, string path)
 {
     System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(flagsmap.width, flagsmap.height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
     for (int i = 0; i < flagsmap.width; i++)
     {
         for (int j = 0; j < flagsmap.height; j++)
         {
             bool s = flagsmap.GetFlagOn(i, j);
             if (s)
             {
                 bmp.SetPixel(i, j, System.Drawing.Color.White);
             }
             else
             {
                 bmp.SetPixel(i, j, System.Drawing.Color.Black);
             }
         }
     }
     bmp.Save(path);
 }
示例#3
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);
         }
     }
 }//该函数为扫描线法主体
示例#4
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
            }
        }
示例#5
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
            }
        }