Esempio n. 1
0
        public void FloodFill(int x, int y)
        {
            _ranges = new FloodFillRangeQueue((_fillLayer.TilesWide + _fillLayer.TilesHigh) / 2 * 5);

            _matchStack = _fillLayer[x, y];

            LinearFill(ref x, ref y);

            while (_ranges.Count > 0) {
                FloodFillRange range = _ranges.Dequeue();

                int upY = range.Y - 1;
                int downY = range.Y + 1;

                TileCoord tid;
                for (int i = range.StartX; i <= range.EndX; i++) {
                    tid = new TileCoord(i, upY);
                    if (range.Y > 0 && /*!_sourceStack.Equals(_fillLayer[tid]) &&*/
                        (_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                        LinearFill(ref i, ref upY);

                    tid = new TileCoord(i, downY);
                    if (range.Y < (_fillLayer.TilesHigh - 1) && /*!_sourceStack.Equals(_fillLayer[tid]) &&*/
                        (_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                        LinearFill(ref i, ref downY);
                }
            }
        }
Esempio n. 2
0
        public void FloodFill(int x, int y)
        {
            _ranges = new FloodFillRangeQueue((_fillLayer.TilesWide + _fillLayer.TilesHigh) / 2 * 5);

            _matchStack = _fillLayer[x, y];

            LinearFill(ref x, ref y);

            while (_ranges.Count > 0)
            {
                FloodFillRange range = _ranges.Dequeue();

                int upY   = range.Y - 1;
                int downY = range.Y + 1;

                TileCoord tid;
                for (int i = range.StartX; i <= range.EndX; i++)
                {
                    tid = new TileCoord(i, upY);
                    if (range.Y > 0 && /*!_sourceStack.Equals(_fillLayer[tid]) &&*/
                        (_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                    {
                        LinearFill(ref i, ref upY);
                    }

                    tid = new TileCoord(i, downY);
                    if (range.Y < (_fillLayer.TilesHigh - 1) && /*!_sourceStack.Equals(_fillLayer[tid]) &&*/
                        (_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                    {
                        LinearFill(ref i, ref downY);
                    }
                }
            }
        }
Esempio n. 3
0
        public void Flood(Vector2Int32 pt)
        {
            int bitmapWidth  = _wvm.CurrentWorld.TilesWide;
            int bitmapHeight = _wvm.CurrentWorld.TilesHigh;

            int x = pt.X;
            int y = pt.Y;

            _wvm.CheckTiles = new bool[bitmapWidth * bitmapHeight];

            var originTile = (Tile)_wvm.CurrentWorld.Tiles[x, y].Clone();

            LinearFloodFill(ref x, ref y, ref originTile);

            while (_ranges.Count > 0)
            {
                //**Get Next Range Off the Queue
                FloodFillRange range = _ranges.Dequeue();

                //**Check Above and Below Each Pixel in the Floodfill Range
                int downPxIdx = (bitmapWidth * (range.Y + 1)) + range.StartX; //CoordsToPixelIndex(lFillLoc,y+1);
                int upPxIdx   = (bitmapWidth * (range.Y - 1)) + range.StartX; //CoordsToPixelIndex(lFillLoc, y - 1);
                int upY       = range.Y - 1;                                  //so we can pass the y coord by ref
                int downY     = range.Y + 1;
                for (int i = range.StartX; i <= range.EndX; i++)
                {
                    //*Start Fill Upwards
                    //if we're not above the top of the bitmap and the pixel above this one is within the color tolerance
                    if (range.Y > 0 && (!_wvm.CheckTiles[upPxIdx]) && CheckTileMatch(ref originTile, ref _wvm.CurrentWorld.Tiles[i, upY]) && _wvm.Selection.IsValid(i, upY))
                    {
                        LinearFloodFill(ref i, ref upY, ref originTile);
                    }

                    //*Start Fill Downwards
                    //if we're not below the bottom of the bitmap and the pixel below this one is within the color tolerance
                    if (range.Y < (bitmapHeight - 1) && (!_wvm.CheckTiles[downPxIdx]) && CheckTileMatch(ref originTile, ref _wvm.CurrentWorld.Tiles[i, downY]) && _wvm.Selection.IsValid(i, downY))
                    {
                        LinearFloodFill(ref i, ref downY, ref originTile);
                    }
                    downPxIdx++;
                    upPxIdx++;
                }

                if (upY < _minY)
                {
                    _minY = upY;
                }
                if (downY > _maxY)
                {
                    _maxY = downY;
                }
            }
        }
Esempio n. 4
0
            public override void FloodFill(CvPoint pt)
            {
                PrepareForFloodFill();

                unsafe
                {
                    scan0 = (byte *)bitmap.DataByte;
                    int   x = pt.X; int y = pt.Y;
                    int   loc      = CoordsToIndex(ref x, ref y);
                    byte *colorPtr = ((byte *)(scan0 + loc));
                    startColor = new byte[] { colorPtr[0], colorPtr[1], colorPtr[2] };
                    LinearFloodFill4(ref x, ref y);

                    bool[] pixelsChecked = this.pixelsChecked;

                    while (ranges.Count > 0)
                    {
                        FloodFillRange range = ranges.Dequeue();

                        //START THE LOOP UPWARDS AND DOWNWARDS
                        int   upY       = range.Y - 1;                //so we can pass the y coord by ref
                        int   downY     = range.Y + 1;
                        byte *upPtr     = (byte *)(scan0 + CoordsToIndex(ref range.StartX, ref upY));
                        byte *downPtr   = (byte *)(scan0 + CoordsToIndex(ref range.StartX, ref downY));
                        int   downPxIdx = (bitmapWidth * (range.Y + 1)) + range.StartX;                    //CoordsToPixelIndex(range.StartX,range.Y+1);
                        int   upPxIdx   = (bitmapWidth * (range.Y - 1)) + range.StartX;                    //CoordsToPixelIndex(range.StartX, range.Y - 1);
                        for (int i = range.StartX; i <= range.EndX; i++)
                        {
                            //START LOOP UPWARDS
                            //if we're not above the top of the bitmap and the pixel above this one is within the color tolerance
                            if (range.Y > 0 && CheckPixel(ref upPtr) && (!(pixelsChecked[upPxIdx])))
                            {
                                LinearFloodFill4(ref i, ref upY);
                            }
                            //START LOOP DOWNWARDS
                            if (range.Y < (bitmapHeight - 1) && CheckPixel(ref downPtr) && (!(pixelsChecked[downPxIdx])))
                            {
                                LinearFloodFill4(ref i, ref downY);
                            }
                            upPtr   += bitmapPixelFormatSize;
                            downPtr += bitmapPixelFormatSize;
                            downPxIdx++;
                            upPxIdx++;
                        }
                    }
                }
            }
Esempio n. 5
0
        public static void Flood(Vector2Int32 start, Vector2Int32 minBound, Vector2Int32 maxBound, Func <Vector2Int32, bool> validation)
        {
            var ranges = new FloodFillRangeQueue();
            var points = new HashSet <Vector2Int32>();

            LinearFloodFill(ref start, ref minBound, ref maxBound, validation, ref ranges, ref points);

            while (ranges.Count > 0)
            {
                //**Get Next Range Off the Queue
                FloodFillRange range = ranges.Dequeue();

                //**Check Above and Below Each Pixel in the Floodfill Range
                int upY      = range.Y - 1;//so we can pass the y coord by ref
                int downY    = range.Y + 1;
                var curPoint = new Vector2Int32();
                for (int i = range.StartX; i <= range.EndX; i++)
                {
                    //*Start Fill Upwards
                    //if we're not above the top of the bitmap and the pixel above this one is within the color tolerance
                    curPoint = new Vector2Int32(i, upY);
                    if (range.Y > 0 && (!points.Contains(curPoint) && validation(curPoint)))
                    {
                        LinearFloodFill(ref curPoint, ref minBound, ref maxBound, validation, ref ranges, ref points);
                    }

                    //*Start Fill Downwards
                    //if we're not below the bottom of the bitmap and the pixel below this one is within the color tolerance
                    curPoint = new Vector2Int32(i, downY);
                    if (range.Y < (maxBound.Y - 1) && (!points.Contains(curPoint) && validation(curPoint)))
                    {
                        LinearFloodFill(ref curPoint, ref minBound, ref maxBound, validation, ref ranges, ref points);
                    }
                }
            }
        }
Esempio n. 6
0
        public static void Flood(Vector2Int32 start, Vector2Int32 minBound, Vector2Int32 maxBound, Func<Vector2Int32, bool> validation)
        {
            var ranges = new FloodFillRangeQueue();
            var points = new HashSet<Vector2Int32>();

            LinearFloodFill(ref start, ref minBound, ref maxBound, validation, ref ranges, ref points);

            while (ranges.Count > 0)
            {
                //**Get Next Range Off the Queue
                FloodFillRange range = ranges.Dequeue();

                //**Check Above and Below Each Pixel in the Floodfill Range
                int upY = range.Y - 1;//so we can pass the y coord by ref
                int downY = range.Y + 1;
                var curPoint = new Vector2Int32();
                for (int i = range.StartX; i <= range.EndX; i++)
                {
                    //*Start Fill Upwards
                    //if we're not above the top of the bitmap and the pixel above this one is within the color tolerance
                    curPoint = new Vector2Int32(i, upY);
                    if (range.Y > 0 && (!points.Contains(curPoint) && validation(curPoint)))
                        LinearFloodFill(ref curPoint, ref minBound, ref maxBound, validation, ref ranges, ref points);

                    //*Start Fill Downwards
                    //if we're not below the bottom of the bitmap and the pixel below this one is within the color tolerance
                    curPoint = new Vector2Int32(i, downY);
                    if (range.Y < (maxBound.Y - 1) && (!points.Contains(curPoint) && validation(curPoint)))
                        LinearFloodFill(ref curPoint, ref minBound, ref maxBound, validation, ref ranges, ref points);
                }
            }
        }