public void putSubdivision_Triangle(QTnodeTriangle root, int delay, string color) { System.Threading.Thread.Sleep(delay); if (root.triaUp != null) { using (Graphics g = Graphics.FromImage(graph.BackgroundImage)) { Point[] triangleUp = new Point[] { new Point((int)root.triaUp.origin.x, (int)root.triaUp.origin.y), new Point((int)root.triaUp.origin.x + (int)root.triaUp.width, (int)root.triaUp.origin.y), new Point((int)root.triaUp.origin.x, (int)root.triaUp.origin.y + (int)root.triaUp.height) }; g.DrawPolygon(new Pen(Color.DeepPink, 1), triangleUp); } } if (root.triaDown != null) { using (Graphics g = Graphics.FromImage(graph.BackgroundImage)) { Point[] triangleDown = new Point[] { new Point((int)root.triaDown.origin.x, (int)root.triaDown.origin.y), new Point((int)root.triaDown.origin.x - (int)root.triaDown.width, (int)root.triaDown.origin.y), new Point((int)root.triaDown.origin.x, (int)root.triaDown.origin.y - (int)root.triaDown.height) }; g.DrawPolygon(new Pen(Color.Cyan, 1), triangleDown); } } if (root.n1 != null) { putSubdivision_Triangle(root.n1, delay, color); } if (root.n2 != null) { putSubdivision_Triangle(root.n2, delay, color); } if (root.n3 != null) { putSubdivision_Triangle(root.n3, delay, color); } if (root.n4 != null) { putSubdivision_Triangle(root.n4, delay, color); } }
private void graph_MouseDown(object sender, MouseEventArgs e) { if (setQTP) { pointsQTP.Add(new PointModel(mouse_x, mouse_y)); graph.Refresh(); } if (setQTS) { image = Image.FromFile(imPath); graph.BackgroundImage = image; graph.Width = image.Width; graph.Height = image.Height; Bitmap bmp = new Bitmap(image); Color pixColor = bmp.GetPixel(e.X, e.Y); int tolerance = 1; //default CustomDialogBox tol = new CustomDialogBox("tolerance", "E N G A G E"); if (tol.ShowDialog() == DialogResult.OK) { int.TryParse(tol.fileName, out tolerance); } //rootNode = Engine.quadTreeGenerator_Seed(bmp, im.Width, im.Height, 2, pixColor); //rectangle //Engine.onlyFigure_Seed(rootNode, bmp, pixColor); //only fig rootNode_Triangle = Engine.quadTreeGenerator_Triangle_Seed(bmp, image.Width, image.Height, tolerance, pixColor); //triangle Engine.onlyFigure_Triangle_Seed(rootNode_Triangle, bmp, pixColor); //only fig //putSubdivision(rootNode, 0, "red"); putSubdivision_Triangle(rootNode_Triangle, 0, "pink"); graph.DrawToBitmap(bmp, new Rectangle(0, 0, image.Width, image.Height)); temp = bmp; //bmp.Dispose(); graph.Refresh(); } }
private void QTTbutton_Click(object sender, EventArgs e) { refreshGraph(false); try { rootNode_Triangle = null; refreshGraph(false); OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png"; if (dialog.ShowDialog() == DialogResult.OK) { int tolerance = 3; //default CustomDialogBox tol = new CustomDialogBox("tolerance", "E N G A G E"); if (tol.ShowDialog() == DialogResult.OK) { int.TryParse(tol.fileName, out tolerance); } // get path var filePath = dialog.FileName; //add picture image = Image.FromFile(filePath); graph.BackgroundImage = image; //generate QT rootNode_Triangle = Engine.quadTreeGenerator_Triangle(image, graph.Width - 1, graph.Height, tolerance); //triangle Bitmap bmp = new Bitmap(image); Engine.onlyFigure_Triangle(rootNode_Triangle, bmp, false); //only fig putSubdivision_Triangle(rootNode_Triangle, 0, "pink"); graph.Refresh(); } } catch (Exception ex) { CustomMessageBox msg = new CustomMessageBox(ex.ToString()); msg.Show(); } }