Exemple #1
0
        /// <summary>
        /// Scan each row of the shape to update shape data between the contour values..
        /// </summary>
        /// <param name="pixels"></param>
        private void PopulatePixels(PixelCollection pixels)
        {
            foreach (var row in pixels.Rows)
            {
                var keys  = row.Value.Keys;
                int index = 0;
                int y     = row.Key;

                while (keys[index] != keys[^ 1])
                {
                    int start = keys[index];
                    int end   = keys[index + 1];

                    for (int x = start + 1; x < end; x++)
                    {
                        if (!_pixelMap.PixelInShape(x, y))
                        {
                            break;
                        }

                        // Update data.
                        pixels.AddPixel(x, y);
                        _pixelMap.SetVisited(x, y);
                    }

                    index++;
                }
            }
        }
Exemple #2
0
 public Shape(List <Point> contour,
              PixelCollection pixels,
              List <Line> lines,
              List <Corner> corners)
 {
     Contour = contour;
     Pixels  = pixels;
     Lines   = lines;
     Corners = corners;
 }
Exemple #3
0
        /// <summary>
        /// Crawl around the contour of a shape in an image.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="pixels"></param>
        /// <returns></returns>
        private List <Point> DefineContour(int x, int y, PixelCollection pixels)
        {
            // Define contour.
            var contour = new List <Point>();

            // Start from the end of the top line.
            while (_pixelMap.PixelInShape(x + 1, y))
            {
                x += 1;
            }

            var initial = new Point(x, y);

            // Initialise data.
            contour.Add(initial);
            pixels.AddPixel(initial);
            _pixelMap.SetVisited(x, y);

            // Used to hold the previous pixel co-ords.
            var last = initial;

            // Initialise current to be the next pixel along the edge.

            // Next pixel will be on the next line.
            y = last.Y + 1;

            // If line does not have a pixel to the bottom right then it must be below
            // initial pixel.
            x = _pixelMap.PixelInShape(last.X + 1, y) ? last.X + 1 : last.X;

            var current = new Point(x, y);

            // Crawl around contour until back at start.
            while (current != initial)
            {
                // Update data.
                contour.Add(current);
                pixels.AddPixel(current);
                _pixelMap.SetVisited(current.X, current.Y);

                // Find the position of the first empty pixel next to the previous one
                // in a clockwise direction.
                Zone initialSearchZone = FindSearchZone(current, last);

                // Search in a clockwise direction until the first shape pixel is found.
                Point found = FindNextPixel(initialSearchZone, current);

                // Increment
                last    = current;
                current = found;
            }

            return(contour);
        }
Exemple #4
0
        /// <summary>
        /// Scan around a shape contour in an image and collect data.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public ShapeData Scan(int x, int y)
        {
            var          pixels  = new PixelCollection(x, y);
            List <Point> contour = DefineContour(x, y, pixels);

            // Populate visited array.
            PopulatePixels(pixels);

            return(new ShapeData()
            {
                Contour = contour,
                Pixels = pixels
            });
        }
Exemple #5
0
 public Triangle(List <Point> contour,
                 PixelCollection pixels,
                 List <Line> lines,
                 List <Corner> corners) : base(contour, pixels, lines, corners)
 {
 }
 public Quadralateral(List <Point> contour,
                      PixelCollection pixels,
                      List <Line> lines,
                      List <Corner> corners) : base(contour, pixels, lines, corners)
 {
 }