コード例 #1
0
ファイル: ImageNet.cs プロジェクト: stephica/SNGEGT
        public RouteInfo CreateRoutes(Rectangle rect, Color searchcolor)
        {
            Node [,] Routes = new Node[rect.Width + 1, rect.Height + 1];
            //First search all pixels on the area

            bool found = false;
            for (int x = rect.X, i = 0; x <= rect.Right; x++, i++)
            {
                for (int y = rect.Y, j = 0; y <= rect.Bottom; y++, j++)
                {
                    Color color = ibmp.GetPixel(x, y);
                    bool enabled = (color.R == searchcolor.R) && (color.G == searchcolor.G) && (color.B == searchcolor.B);
                    found = found | enabled;
                    Routes[i, j] = new Node(new Point(x, y), enabled);
                }
            }

            if (!found)
                return null;

            for (int x = rect.X, i = 0; x <= rect.Right; x++, i++)
            {
                for (int y = rect.Y, j = 0; y <= rect.Bottom; y++, j++)
                {

                    List<Point> CheckPoints = new List<Point>(5);

                    for (int xdiff = -1; xdiff < 2; xdiff++)
                        for (int ydiff = -1; ydiff < 2; ydiff++)
                        {
                            if (xdiff != 0 || ydiff != 0)
                                CheckPoints.Add(new Point(x + xdiff, y + ydiff));
                        }

                    foreach (Point checkpoint in CheckPoints)
                    {
                        int xidx = checkpoint.X - rect.X;
                        int yidx = checkpoint.Y - rect.Y;

                        if (xidx < 0 || yidx < 0 || xidx >= Routes.GetLength(0) || yidx >= Routes.GetLength(1))
                            continue;

                        if (Routes[xidx, yidx].Enabled)
                            Routes[x-rect.X,y-rect.Y].AddNeighbour(Routes[xidx, yidx]);
                    }
                }
            }

            return new RouteInfo(rect.Location,Routes); //True
        }
コード例 #2
0
ファイル: ImageNet.cs プロジェクト: stephica/SNGEGT
 public void AddNeighbour(Node node)
 {
     iNeighbours.Add(node);
 }
コード例 #3
0
ファイル: ImageNet.cs プロジェクト: stephica/SNGEGT
        internal RouteInfo(Point aSearchPoint, Node[,] aRoutes)
        {
            iSearchPoint = aSearchPoint;
            iRoutes = aRoutes;
            left = new Point(Int32.MaxValue, -1);
            right = new Point(-1, -1);
            top = new Point(-1, Int32.MaxValue);
            bottom = new Point(-1, -1);

            for (int i = 0; i < iRoutes.GetLength(0); i++)
            {
                for (int j = 0; j < iRoutes.GetLength(1); j++)
                {
                    if (iRoutes[i, j].Enabled)
                    {

                        int x = iSearchPoint.X + i;
                        int y = iSearchPoint.Y + j;

                        if (left.X >= x)
                            left = new Point(x, y);
                        if (right.X < x )
                            right = new Point(x, y);
                        if (y < top.Y)
                            top = new Point(x, y);
                        if (y > bottom.Y)
                            bottom = new Point(x, y);
                    }
                }
            }
        }