コード例 #1
0
ファイル: VoronoiOutput.cs プロジェクト: aaronchun7/C-Voronoi
        /// <summary>
        ///     This method seeks to return a collection of every point within a region, given the lines (from OutputLines) and one
        ///     point (the origin)
        ///     Using psuedocode pulled from
        ///     <source>https://en.wikipedia.org/wiki/Flood_fill#Alternative_implementations</source>
        /// </summary>
        public List <IntPoint2D> OutputRegion(Point2D origin, bool[,] array)
        {
            var intPointList  = new List <IntPoint2D>();
            var intPointQueue = new Queue <IntPoint2D>();
            var originPoint   = new IntPoint2D(origin);

            intPointQueue.Enqueue(originPoint);
            while (intPointQueue.Count > 0)
            {
                var point = intPointQueue.Dequeue();
                if (array[point.X, point.Y] && (point != originPoint))
                {
                    continue;
                }
                var eastX = point.X;
                var eastY = point.Y;
                var westX = point.X;
                var westY = point.Y;
                while (!((westX <= 0) || array[westX - 1, westY]))
                {
                    westX = westX - 1;
                }
                while (!((eastX >= array.GetUpperBound(0)) || array[eastX + 1, eastY]))
                {
                    eastX = eastX + 1;
                }
                var above = false;
                var below = false;
                for (var x = westX; x <= eastX; x++)
                {
                    array[x, point.Y] = true;
                    intPointList.Add(new IntPoint2D(x, point.Y));
                    if (!above && !((point.Y == array.GetUpperBound(1)) || array[x, point.Y + 1]))
                    {
                        intPointQueue.Enqueue(new IntPoint2D(x, point.Y + 1));
                        above = true;
                    }

                    if (below || (point.Y == 0) || array[x, point.Y - 1])
                    {
                        continue;
                    }
                    intPointQueue.Enqueue(new IntPoint2D(x, point.Y - 1));
                    below = true;
                }
            }
            return(intPointList);
        }
コード例 #2
0
ファイル: Point2D.cs プロジェクト: aaronchun7/C-Voronoi
 public IntPoint2D(IntPoint2D p)
 {
     X = p.X;
     Y = p.Y;
 }
コード例 #3
0
        public List <double> CalculateRegionsDeltaEList(Bitmap originalBitmap, List <IntPoint2D> listOfPoints, IntPoint2D originPoint)
        {
            if (originalBitmap == null)
            {
                throw new ArgumentNullException(nameof(originalBitmap));
            }
            if (!listOfPoints.Any())
            {
                throw new ArgumentNullException(nameof(listOfPoints));
            }
            if (originPoint == null)
            {
                throw new ArgumentNullException(nameof(originPoint));
            }

            var originPixelColor = originalBitmap.GetPixel(originPoint.X, originPoint.Y);
            var originPixelRgb   = new Rgb {
                R = originPixelColor.R, B = originPixelColor.B, G = originPixelColor.G
            };

            return(listOfPoints.Select(point => originalBitmap.GetPixel(point.X, point.Y))
                   .Select(imagePixelColor => new Rgb {
                R = imagePixelColor.R, B = imagePixelColor.B, G = imagePixelColor.G
            })
                   .Select(imageRgb => imageRgb.Compare(originPixelRgb, new CieDe2000Comparison())).ToList());
        }