private void MakeAndSortAEL(List<float>[] yRows) { PointF currentPoint; int currentY; foreach (KeyValuePair<Point, Point> edge in data.GetAllEdges()) { for (EdgePixelsIterator iterator = new EdgePixelsIterator(edge); !iterator.End(); iterator.Next()) { currentPoint = iterator.Current(); if (!currentPoint.IsEmpty) { currentY = (int)(currentPoint.Y - 0.5); if (yRows[currentY] == null) yRows[currentY] = new List<float>(); yRows[currentY].Add(currentPoint.X); } } } foreach (List<float> currentList in yRows) { if (currentList != null) currentList.Sort(new Comparison<float>((float first, float second) => { if (first > second) return 1; else if (first == second) return 0; else return -1; })); } }
public override void FloodFill(FloodFillContext context) { Initialize(context); PointF currentPoint; int currentY; Rectangle bounds = data.GetPolygonBounds(); int currentColor; int xMin = bounds.Left, xMax = bounds.Right; foreach (KeyValuePair<Point, Point> edge in data.GetAllEdges()) { for (EdgePixelsIterator iterator = new EdgePixelsIterator(edge); !iterator.End(); iterator.Next()) { currentPoint = iterator.Current(); if (!currentPoint.IsEmpty) { currentY = (int)(currentPoint.Y - 0.5); for (int currentX = (int)Math.Ceiling(currentPoint.X); currentX < xMax; ++currentX) { currentColor = GetPixel(currentX, currentY); if (currentColor != aBorderColor) { if (currentColor == aBackColor) SetPixel(currentX, currentY, fillColor); else SetPixel(currentX, currentY, backColor); } } } } } }
public override void FloodFill(FloodFillContext context) { Initialize(context); PointF currentPoint; int currentY; Rectangle bounds = data.GetPolygonBounds(); int currentColor; int xMin = bounds.Left, xMax = bounds.Right; int yMin = bounds.Top, yMax = bounds.Bottom; float K = GetPartitionLineCoefK(), B = GetPartitionLineCoefB(); int startX, endX; foreach (KeyValuePair<Point, Point> edge in data.GetAllEdges()) { for (EdgePixelsIterator iterator = new EdgePixelsIterator(edge); !iterator.End(); iterator.Next()) { currentPoint = iterator.Current(); if (!currentPoint.IsEmpty) { currentY = (int)(currentPoint.Y - 0.5); if (K != float.MaxValue) { if ((K * currentPoint.X + B - currentPoint.Y) * (K * xMin + B - yMin) > 0) { startX = (int)Math.Ceiling(currentPoint.X); endX = (int)Math.Ceiling((currentPoint.Y - B) / K); } else { startX = (int)Math.Ceiling((currentPoint.Y - B) / K); endX = (int)Math.Ceiling(currentPoint.X); } } else { if (currentPoint.X < partitionBegin.X) { startX = (int)Math.Ceiling(currentPoint.X); endX = partitionBegin.X; } else { startX = partitionBegin.X; endX = (int)Math.Ceiling(currentPoint.X); } } for (int currentX = startX; currentX < endX; ++currentX) { currentColor = GetPixel(currentX, currentY); if (currentColor != aBorderColor) { if (currentColor == aBackColor) SetPixel(currentX, currentY, fillColor); else SetPixel(currentX, currentY, backColor); } } } } } System.Drawing.Graphics.FromImage(bmp).DrawLine(new Pen(fillColor), partitionBegin, partitionEnd); }