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();
        }
Ejemplo n.º 2
0
        // Open FindCenters window if image processing is succesfull
        private void buttonFindCenters_Click(object sender, EventArgs e)
        {
            try
            {
                Bitmap img = new Bitmap(path);
                FindCirclesCentersForm findCentersWindow = new FindCirclesCentersForm(img);
                if (findCentersWindow.Fail == false)
                {
                    findCentersWindow.ShowDialog();
                }
            }
            catch (ArgumentNullException)
            {
                CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm();
                DialogResult result = msgBoxWindow.Show("Image was not selected!");
                if (result == DialogResult.OK)
                {
                    msgBoxWindow.Close();
                }

            }
            catch (ArgumentException)
            {
                CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm();
                DialogResult result = msgBoxWindow.Show("Image was not selected!");
                if (result == DialogResult.OK)
                {
                    msgBoxWindow.Close();
                }
            }
        }
Ejemplo n.º 3
0
        // Open Graph window if image processing is succesfull
        private void buttonGraph_Click(object sender, EventArgs e)
        {
            try
            {
                Bitmap img = new Bitmap(path);
                GraphForm graphWindow = new GraphForm(img);
                if (graphWindow.Fail == false)
                {
                    graphWindow.ShowDialog();
                }
            }
            catch (ArgumentNullException)
            {
                CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm();
                DialogResult result = msgBoxWindow.Show("Image was not selected!");
                if (result == DialogResult.OK)
                {
                    msgBoxWindow.Close();
                }

            }
            catch (ArgumentException)
            {
                CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm();
                DialogResult result = msgBoxWindow.Show("Image was not selected!");
                if (result == DialogResult.OK)
                {
                    msgBoxWindow.Close();
                }
            }
        }
Ejemplo n.º 4
0
 // ShortestPath call and draw
 private void buttonShortest_Click(object sender, EventArgs e)
 {
     if (shortestFlag == false)
     {
         graph.BruteForceShortest();
         if (graph.ShortestPath.Count > 3)
         {
             using (var graphics = Graphics.FromImage(imgFront))
             {
                 for (int i = 0; i < 3; i++)
                 {
                     graphics.DrawLine(transparentPen, graph.ShortestPath[i].NodePoint, graph.ShortestPath[i + 1].NodePoint);
                 }
             }
             pictureBoxGraph.Image = imgFront;
             pictureBoxGraph.Refresh();
             shortestFlag = true;
             labelShortestPath.Visible = true;
             labelShortestPath.Text   += graph.MinWeight;
         }
         else
         {
             CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm();
             DialogResult     result       = msgBoxWindow.Show("Graph must have at least 4 connected nodes!");
             if (result == DialogResult.OK)
             {
                 msgBoxWindow.Close();
             }
         }
     }
 }
Ejemplo n.º 5
0
 private void buttonNearest_Click(object sender, EventArgs e)
 {
     if (nearestFlag == false)
     {
         graph.BruteForceNearest();
         if (graph.NearestNodes.Count > 1)
         {
             using (var graphics = Graphics.FromImage(imgFront))
             {
                 graphics.DrawLine(transparentPen2, graph.NearestNodes[0].NodePoint, graph.NearestNodes[1].NodePoint);
             }
             nearestFlag           = true;
             pictureBoxGraph.Image = imgFront;
             pictureBoxGraph.Refresh();
         }
         else
         {
             CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm();
             DialogResult     result       = msgBoxWindow.Show("Graph must have at least 2 connected nodes!");
             if (result == DialogResult.OK)
             {
                 msgBoxWindow.Close();
             }
         }
     }
 }
Ejemplo n.º 6
0
 // Load Image to pictureBox
 private void buttonSelectImg_Click(object sender, EventArgs e)
 {
     this.openFileDialogImg.ShowDialog();
     path = openFileDialogImg.FileName;
     try
     {
         pictureBoxImg.Load(path);
         correct = path;
     }
     catch (FileNotFoundException)
     {               
     }
     catch (InvalidOperationException)
     {
         if (correct != string.Empty)
         {
             pictureBoxImg.Load(correct);    // Reloads current image
             path = correct;
         }               
     }
     catch (ArgumentException)
     {
         if (correct != string.Empty)
         {
             pictureBoxImg.Load(correct);    // Reloads current image
             path = correct;
         }
             CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm();
             DialogResult result = msgBoxWindow.Show("File Format is not valid!");
             if (result == DialogResult.OK)
         {
             openFileDialogImg.Reset();  // Resets openDialog.FileName
             msgBoxWindow.Close();
         }
     }
     
 }
Ejemplo n.º 7
0
        // 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++;
            }
        }
Ejemplo n.º 8
0
        private void pictureBoxGraph_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Node   found = null;
            double graphImgX;
            double graphImgY;

            graphImgX = (e.X - xDisplacement) * rF;
            graphImgY = (e.Y - yDisplacement) * rF;
            foreach (Node n in graph.NodeList)
            {
                Point nodePoint = n.NodePoint;
                if ((int)graphImgX > nodePoint.X - n.NodeRadius && (int)graphImgX < nodePoint.X + n.NodeRadius)
                {
                    if ((int)graphImgY > nodePoint.Y - n.NodeRadius && (int)graphImgY < nodePoint.Y + n.NodeRadius)
                    {
                        found = n;
                    }
                }
            }
            if (found != null)
            {
                if (isfound)
                {
                    isConnected = false;
                    foreach (Arc a in moveNode.ArcList)
                    {
                        if (a.ArcNode == found)
                        {
                            isConnected = true;
                            using (var graphics = Graphics.FromImage(imgFront))
                            {
                                for (int i = 0; i < a.AnimationList.Count; i += 4)
                                {
                                    graphics.Clear(Color.Transparent);
                                    graphics.FillEllipse(Brushes.LightBlue, a.AnimationList[i].X - 10, a.AnimationList[i].Y - 10, 15, 15);
                                    pictureBoxGraph.Refresh();
                                }
                            }
                            moveNode = found;
                            break;
                        }
                    }
                    if (!isConnected)
                    {
                        CustomMsgBoxForm msgBoxWindow = new CustomMsgBoxForm();
                        DialogResult     result       = msgBoxWindow.Show("Node is not connected!");
                        if (result == DialogResult.OK)
                        {
                            msgBoxWindow.Close();
                        }
                    }
                }
                Particle particle = new Particle(found);
                if (!isfound)
                {
                    labelHelp.Text = "Double click on a new connected node to move the particle";
                    moveNode       = found;
                    using (var graphics = Graphics.FromImage(imgFront))
                    {
                        graphics.FillEllipse(Brushes.LightBlue, found.NodePoint.X - 10, found.NodePoint.Y - 10, 15, 15);
                        pictureBoxGraph.Refresh();
                    }
                    isfound = true;
                }
            }
        }