private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { Point FreePoint = new Point(e.X, e.Y); if (ImageMatrix != null) { AnchorList.Add(FreePoint); } if (AnchorList.Count != 0 && ImageMatrix != null) { Graphics g = pictureBox1.CreateGraphics(); Pen pencil = new Pen(Brushes.Black); Assistant.DrawCircle(g, pencil, AnchorList[AnchorList.Count - 1].X, AnchorList[AnchorList.Count - 1].Y, 2); Assistant.FillCircle(g, Brushes.Black, AnchorList[AnchorList.Count - 1].X, AnchorList[AnchorList.Count - 1].Y, 2); } if (AnchorList.Count > 1 && ImageMatrix != null) { int Source = Assistant.Tabular(AnchorList[AnchorList.Count - 2].X, AnchorList[AnchorList.Count - 2].Y, ImageOperations.GetHeight(ImageMatrix)); int Dest = Assistant.Tabular(AnchorList[AnchorList.Count - 1].X, AnchorList[AnchorList.Count - 1].Y, ImageOperations.GetHeight(ImageMatrix)); List <Point> path = ShortestpathSubroutiens.DetermineShortestPath(Source, Dest, ImageMatrix); Assistant.AppendToList <Point>(MainSelection, path.ToArray()); Graphics g = pictureBox1.CreateGraphics(); Pen Pencil = new Pen(Color.Yellow); for (int i = 0; i < path.Count - 1; i++) { g.DrawLine(Pencil, path[i], path[i + 1]); } } }
private void closeShape_Click(object sender, EventArgs e) { if (ImageMatrix != null && AnchorList.Count > 1) { int src = Assistant.Tabular(AnchorList[0].X, AnchorList[0].Y, ImageOperations.GetHeight(ImageMatrix)); int dest = Assistant.Tabular(AnchorList[AnchorList.Count - 1].X, AnchorList[AnchorList.Count - 1].Y, ImageOperations.GetHeight(ImageMatrix)); List <Point> path = ShortestpathSubroutiens.DetermineShortestPath(src, dest, ImageMatrix); Assistant.AppendToList(MainSelection, path.ToArray()); Graphics g = pictureBox1.CreateGraphics(); Pen Pencil = new Pen(Color.Yellow); for (int i = 0; i < path.Count - 1; i++) { g.DrawLine(Pencil, path[i], path[i + 1]); } } }
public static List <List <Edge> > GraphConstruction(RGBPixel[,] ImageMatrix) { int width = ImageOperations.GetWidth(ImageMatrix); int Height = ImageOperations.GetHeight(ImageMatrix); int ToatalSize = width * Height; List <List <Edge> > Graph = new List <List <Edge> >(); for (int i = 0; i < width; i++) { for (int j = 0; j < Height; j++) { int node_idx = Assistant.Tabular(i, j, Height); List <Edge> neighbours = Get_neighbours(node_idx, ImageMatrix); Graph.Add(neighbours); } } return(Graph); }
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); }