public FindCirclesCentersForm(Bitmap img) { this.img = new Bitmap(img); this.pointList = new List <Point>(); this.radiusList = new List <int>(); InitializeComponent(); FindCirclesCenters findCC = new FindCirclesCenters(img, pointList, radiusList); try { findCC.FindCircle(); } catch (ArgumentOutOfRangeException) // Failed to process image { fail = true; CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm(); DialogResult result = msgBoxWindow.Show("Failed to process image!"); if (result == DialogResult.OK) { msgBoxWindow.Close(); } } this.pictureBoxFindCC.Image = findCC.ProImage; // Gets image from findCC and sets it to the pictureBox listBoxCenters.Items.Clear(); // Adds points to the listBox foreach (Point p in pointList) { listBoxCenters.Items.Add(p); } pointList.Clear(); }
// Window constructor public GraphForm(Bitmap img) { this.graph = new Graph(); this.imgGraph = new Bitmap(img); this.pointList = new List <Point>(); this.radiusList = new List <int>(); this.imgFront = new Bitmap(imgGraph.Width, imgGraph.Height); InitializeComponent(); wF = (double)img.Width / pictureBoxGraph.Width; hF = (double)img.Height / pictureBoxGraph.Height; if (wF > hF) { rF = wF; yDisplacement = (int)(pictureBoxGraph.Height - (img.Height / rF)) / 2; } else { rF = hF; xDisplacement = (int)(pictureBoxGraph.Width - (img.Width / rF)) / 2; } int i = 0; // index for treeView component FindCirclesCenters findCC = new FindCirclesCenters(img, pointList, radiusList); try { findCC.FindCircle(); } catch (ArgumentOutOfRangeException) // Failed to process image { fail = true; CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm(); DialogResult result = msgBoxWindow.Show("Failed to process image!"); if (result == DialogResult.OK) { msgBoxWindow.Close(); } } graph.InitializeGraph(pointList, radiusList); graph.GraphWithObstruction(img); using (var graphics = Graphics.FromImage(imgGraph)) // Draws graph { foreach (Node n in graph.NodeList) { foreach (Arc a in n.ArcList) { graphics.DrawLine(Pens.Black, n.NodePoint, a.ArcNode.NodePoint); } } foreach (Node n in graph.NodeList) { int recenter = 15; // Adjust string position Point centerPoint = new Point(n.NodePoint.X - recenter, n.NodePoint.Y - recenter); graphics.DrawString(n.NodeNum.ToString(), drawFont, Brushes.White, centerPoint); } } pictureBoxGraph.BackgroundImage = imgGraph; pictureBoxGraph.Image = imgFront; foreach (Node n in graph.NodeList) // Adds nodes and arcs to treeView component { treeViewGraph.Nodes.Add("Node " + n.ToString()); foreach (Arc a in n.ArcList) { treeViewGraph.Nodes[i].Nodes.Add("Arc " + a.ArcNode.ToString() + " (Weight:\t" + a.ArcWeight.ToString() + ")"); } i++; } }