private static void block_border(List<Point> selected_points ,Boundary bondry) { for (int i = 0; i < selected_points.Count; i++) { int Xtmp = selected_points[i].X - bondry.MIN_X; // get the crossponding point in segment image int Ytmp = selected_points[i].Y - bondry.MIN_Y; selected_image[Ytmp, Xtmp].block = true; } }
public void update(MouseEventArgs e) { var g = pictureBox1.CreateGraphics(); if (clr > W8interval * 2) { if (ImageMatrix != null) { var mouseNode = Helper.Flatten(e.X, e.Y, ImageOperations.GetWidth(ImageMatrix)); if (curr_source != -1 && Prev_mouse_pos != mouseNode) { Prev_mouse_pos = mouseNode; if (Helper.IN_Boundary(mouseNode, SB, ImageOperations.GetWidth(ImageMatrix))) { int Segment_mouse = Helper.crosspond(mouseNode, SB, ImageOperations.GetWidth(ImageMatrix), ImageOperations.GetWidth(Square_segment)); List <Point> segmentpath = new List <Point>(); segmentpath = ShortestPath_Operations.Backtracking(parent_list, Segment_mouse, ImageOperations.GetWidth(Square_segment)); List <Point> Curpath = Helper.crosspond(segmentpath, SB); curr_path = Curpath.ToArray(); if (ismousedown && AutoAnchor_WORK) { double freq = (double)frequancy / 1000; Autoancor.Update(Curpath, freq); List <Point> cooledpath = Autoancor.anchor_path(); if (cooledpath.Count > 0) { Point anchor = cooledpath[cooledpath.Count - 1]; AnchorPts.Add(anchor); curr_source = Helper.Flatten(anchor.X, anchor.Y, ImageOperations.GetWidth(ImageMatrix)); //curr_path = cooledpath.ToArray(); Helper.AppendToList <Point>(Mainselction, cooledpath); SB = new Boundary(); SB = ShortestPath_Operations.Square_Boundary(curr_source, ImageOperations.GetWidth(ImageMatrix) - 1, ImageOperations.GetHeight(ImageMatrix) - 1); //make a square segment Square_segment = Helper.COPY_Segment(ImageMatrix, SB); // currsrc in segment int newsrc = Helper.crosspond(curr_source, SB, ImageOperations.GetWidth(ImageMatrix), ImageOperations.GetWidth(Square_segment)); parent_list = ShortestPath_Operations.Dijkstra(newsrc, Square_segment); Autoancor.reset(); } } } else { curr_path = null; } #region bounse // if (ismousedown && AutoAnchor_WORK) // { /* * //if (curr_path.Length >= frequancy) * if (Helper.Distance(curr_source, mouseNode, ImageOperations.GetWidth(ImageMatrix)) >= frequancy) * { * Helper.AppendToList<Point>(Mainselction, curr_path); * AnchorPts.Add(e.Location); * curr_source = mouseNode; * parent_list = ShortestPath_Operations.Dijkstra(Graph, curr_source); * } */ //} #endregion } } clr = 0.0f; } if (clr > W8interval) { pictureBox1.Refresh(); g.Dispose(); } clr += .019f; }
public void update(MouseEventArgs e) { var g = pictureBox1.CreateGraphics(); if (clr > W8interval * 2) { if (ImageMatrix != null) { var mouseNode = Helper.Flatten(e.X, e.Y, ImageOperations.GetWidth(ImageMatrix)); if (curr_source != -1 && Prev_mouse_pos != mouseNode) { Prev_mouse_pos = mouseNode; if (Helper.IN_Boundary(mouseNode, SB, ImageOperations.GetWidth(ImageMatrix))) { int Segment_mouse = Helper.crosspond(mouseNode, SB, ImageOperations.GetWidth(ImageMatrix), ImageOperations.GetWidth(Square_segment)); List<Point> segmentpath = new List<Point>(); segmentpath = ShortestPath_Operations.Backtracking(parent_list, Segment_mouse, ImageOperations.GetWidth(Square_segment)); List<Point> Curpath = Helper.crosspond(segmentpath, SB); curr_path = Curpath.ToArray(); if (AutoAnchor_WORK) { double freq = (double)frequancy / 1000; Autoancor.Update(Curpath, freq); List<Point> cooledpath = Autoancor.anchor_path(); if (cooledpath.Count > 0) { Point anchor = cooledpath[cooledpath.Count - 1]; AnchorPts.Add(anchor); curr_source = Helper.Flatten(anchor.X, anchor.Y, ImageOperations.GetWidth(ImageMatrix)); //curr_path = cooledpath.ToArray(); Helper.AppendToList<Point>(Mainselction, cooledpath); SB = new Boundary(); SB = ShortestPath_Operations.Square_Boundary(curr_source, ImageOperations.GetWidth(ImageMatrix) - 1, ImageOperations.GetHeight(ImageMatrix) - 1); //make a square segment Square_segment = Helper.COPY_Segment(ImageMatrix, SB); // currsrc in segment int newsrc = Helper.crosspond(curr_source, SB, ImageOperations.GetWidth(ImageMatrix), ImageOperations.GetWidth(Square_segment)); parent_list = ShortestPath_Operations.Dijkstra(newsrc, Square_segment); Autoancor.reset(); } } } else { curr_path = ShortestPath_Operations.GenerateShortestPath(curr_source, mouseNode, ImageMatrix).ToArray(); } } } clr = 0.0f; } if (clr > W8interval) { pictureBox1.Refresh(); g.Dispose(); } clr += .019f; }
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { if (pictureBox1.Image != null) { var clicked_node = Helper.Flatten(e.X, e.Y, ImageOperations.GetWidth(ImageMatrix)); if (curr_source != clicked_node) { if (curr_source == -1) // in the first click save frist clicked anchor main_source = clicked_node; else Helper.AppendToList<Point>(Mainselction, curr_path); curr_source = clicked_node; AnchorPts.Add(e.Location); SB = new Boundary(); SB = ShortestPath_Operations.Square_Boundary(curr_source, ImageOperations.GetWidth(ImageMatrix) - 1, ImageOperations.GetHeight(ImageMatrix) - 1); //make a square segment Square_segment = Helper.COPY_Segment(ImageMatrix, SB); // currsrc in segment int newsrc = Helper.crosspond(curr_source, SB, ImageOperations.GetWidth(ImageMatrix), ImageOperations.GetWidth(Square_segment)); parent_list = ShortestPath_Operations.Dijkstra(newsrc, Square_segment); Autoancor.reset(); } } }
// return bondry limit of dikstra public static Boundary Square_Boundary(int Src, int Width, int Height) { Vector2D Src2d = Helper.Unflatten(Src, Width + 1); //src node x y Boundary bondry = new Boundary(); int max_dist = 200; if (Src2d.X > max_dist) bondry.MIN_X = (int)Src2d.X - max_dist; else bondry.MIN_X = 0; if (Width - Src2d.X > max_dist) bondry.MAX_X = (int)Src2d.X + max_dist; else bondry.MAX_X = Width; if (Src2d.Y > max_dist) bondry.MIN_Y = (int)Src2d.Y - max_dist; else bondry.MIN_Y = 0; if (Height - Src2d.Y > max_dist) bondry.MAX_Y = (int)Src2d.Y + max_dist; else bondry.MAX_Y = Height; return bondry; }
//take point in a 2d plane and retrun the crossponding in(the small segment) boundry plane public static Point crosspond(Point P, Boundary bondry) { P.X = P.X + bondry.MIN_X; P.Y = P.Y + bondry.MIN_Y; return(P); }