Exemplo n.º 1
0
        public static List <Edge> Get_neighbours(int node_idx, RGBPixel[,] ImageMatrix)
        {
            List <Edge> neighbours = new List <Edge>();

            int Width  = ImageOperations.GetWidth(ImageMatrix);
            int Height = ImageOperations.GetHeight(ImageMatrix);

            var Node_coordinates = Assistant.Untabular(node_idx, Height);
            int X = (int)Node_coordinates.X;
            int Y = (int)Node_coordinates.Y;

            var Energy = ImageOperations.CalculatePixelEnergies(X, Y, ImageMatrix);

            if (X < Width - 1)    // Have a right node ?
            {
                if (Energy.X == 0)
                {
                    Edge newEdge = new Edge(node_idx, Assistant.Tabular(X + 1, Y, Height), 10000000000000000);
                    neighbours.Add(newEdge);
                }
                else
                {
                    Edge newEdge = new Edge(node_idx, Assistant.Tabular(X + 1, Y, Height), (1 / (Energy.X)));
                    neighbours.Add(newEdge);
                }
            }
            if (Y < Height - 1)    // Have a bottom node ?
            {
                if (Energy.Y == 0)
                {
                    Edge newEdge = new Edge(node_idx, Assistant.Tabular(X, Y + 1, Height), 10000000000000000);
                    neighbours.Add(newEdge);
                }
                else
                {
                    Edge newEdge = new Edge(node_idx, Assistant.Tabular(X, Y + 1, Height), (1 / (Energy.Y)));
                    neighbours.Add(newEdge);
                }
            }
            if (X > 0)    // Have a left node ?
            {
                Energy = ImageOperations.CalculatePixelEnergies(X - 1, Y, ImageMatrix);

                if (Energy.X == 0)
                {
                    Edge newEdge = new Edge(node_idx, Assistant.Tabular(X - 1, Y, Height), 10000000000000000);
                    neighbours.Add(newEdge);
                }
                else
                {
                    Edge newEdge = new Edge(node_idx, Assistant.Tabular(X - 1, Y, Height), (1 / (Energy.X)));
                    neighbours.Add(newEdge);
                }
            }
            if (Y > 0)     // Have a top node ?
            {
                Energy = ImageOperations.CalculatePixelEnergies(X, Y - 1, ImageMatrix);

                if (Energy.Y == 0)
                {
                    Edge newEdge = new Edge(node_idx, Assistant.Tabular(X, Y - 1, Height), 10000000000000000);
                    neighbours.Add(newEdge);
                }
                else
                {
                    Edge newEdge = new Edge(node_idx, Assistant.Tabular(X, Y - 1, Height), (1 / (Energy.Y)));
                    neighbours.Add(newEdge);
                }
            }
            return(neighbours);
        }