Example #1
0
 void LoadBool(bool[] columnBool,
               BitmapData bmData, int x)
 {
     for (int y = 0; y < bmData.Height; y++)
     {
         if (x < 0)
         {
             columnBool[y] = false;
         }
         else
         {
             columnBool[y] = NuGenDiscretize.ProcessedPixelIsOn(bmData, x, y);
         }
     }
 }
Example #2
0
        private static void ConvertImageToArray(Image imageProcessed, out int[,] imageArray, out int imageWidth, out int imageHeight)
        {
            // compute bounds
            imageWidth  = imageProcessed.Width;
            imageHeight = imageProcessed.Height;

            // allocate memory
            imageArray = new int[imageWidth, imageHeight];

            // initialize memory
            Bitmap     b      = new Bitmap(imageProcessed);
            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, b.PixelFormat);

            for (int x = 0; x < imageWidth; x++)
            {
                for (int y = 0; y < imageHeight; y++)
                {
                    imageArray[x, y] = NuGenDiscretize.ProcessedPixelIsOn(bmData, x, y) ? (int)PixelStates.PixelOnUnscanned : (int)PixelStates.PixelOff;
                }
            }

            b.UnlockBits(bmData);
        }
Example #3
0
        //Highlights a point in point match mode that is a candidate for the start of
        // a point match sequence
        public void HighlightCandidateMatchPoint(Point p)
        {
            Bitmap     b      = new Bitmap(processedImage);
            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, b.PixelFormat);

            if (NuGenDiscretize.ProcessedPixelIsOn(bmData, p.X, p.Y))
            {
                // pixel is on
                bool found = (samplePointPixels.Count > 0);
                if (found)
                {
                    foreach (Point sample in samplePointPixels)
                    {
                        if (sample.X == p.X && sample.Y == p.Y)
                        {
                            found = true;
                            break;
                        }

                        found = false;
                    }
                }

                if (!found)
                {
                    NuGenPointMatch.IsolateSampleMatchPoint(samplePointPixels,
                                                            bmData, pointMatchSettings,
                                                            p.X, p.Y, p.X, p.Y);
                }
            }
            else
            {
                samplePointPixels.Clear();
            }

            b.UnlockBits(bmData);
        }
Example #4
0
        public static bool IsolateSampleMatchPoint(List <Point> samplePointPixels, BitmapData bmData, PointMatchSettings settings,
                                                   int xStart, int yStart, int x, int y)
        {
            if ((x < 0) || (y < 0) || (bmData.Width <= x) || (bmData.Height <= y))
            {
                return(false); // out of bounds
            }
            if (!NuGenDiscretize.ProcessedPixelIsOn(bmData, x, y))
            {
                return(false); // pixel is off
            }
            if (Math.Abs(x - xStart) > settings.pointSize / 2)
            {
                return(false); // point is too far from start
            }
            if (Math.Abs(y - yStart) > settings.pointSize / 2)
            {
                return(false); // point is too far from start
            }
            bool found = (samplePointPixels.Count > 0);

            if (found)
            {
                foreach (Point p in samplePointPixels)
                {
                    if (p.X == x && p.Y == y)
                    {
                        found = true;
                        break;
                    }
                    found = false;
                }
            }

            if (found)
            {
                return(true); // already in list
            }
            // add this point
            samplePointPixels.Add(new Point(x, y));

            // recurse. diagonal points are included so single-pixel wide polygonal outlines will be traversed,
            // but for a 2x speed increase we only go diagonal if the adjacent nondiagonal pixels are off
            bool right =
                IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x + 1, y);
            bool up =
                IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x, y + 1);
            bool left =
                IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x - 1, y);
            bool down =
                IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x, y - 1);

            if (!right && !up)
            {
                IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x + 1, y + 1);
            }
            if (!up && !left)
            {
                IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x - 1, y + 1);
            }
            if (!left && !down)
            {
                IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x - 1, y - 1);
            }
            if (!down && !right)
            {
                IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x + 1, y - 1);
            }

            return(true);
        }