private void CheckRange(int yleft, int yright, int x, ParentDirectionsY ptype) { for (int i = yleft; i <= yright;) { if ((!flagsMap.GetFlagOn(x, i)) && IncludePredicate(x, i)) { int lb = i; int rb = i + 1; while (rb <= yright && (!flagsMap.GetFlagOn(x, rb)) && IncludePredicate(x, rb)) { rb++; } rb--; SpanY span = new SpanY(); span.YLeft = lb; span.YRight = rb; span.X = x; if (lb == yleft && rb == yright) { span.Extended = ExtendTypesY.UnRez; } else if (rb == yright) { span.Extended = ExtendTypesY.RightRequired; } else if (lb == yleft) { span.Extended = ExtendTypesY.LeftRequired; } else { span.Extended = ExtendTypesY.AllRez; } span.ParentDirection = ptype; for (int j = lb; j <= rb; j++) { flagsMap.SetFlagOn(x, j, true); Process(new Int16Double(x, j)); } queue.Push(span); i = rb + 1; } else { i++; } } }
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 } }