/// <summary> /// puts QT mesh /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void putSubdivision(QTnode root, int delay, string color) { System.Threading.Thread.Sleep(delay); if (root.rect != null) { //put diagonal // g.DrawLine( //new Pen(Color.DeepPink, 1), //(int)root.rect.origin.x + (float)root.rect.width, (int)root.rect.origin.y, // (float)root.rect.origin.x, (float)root.rect.origin.y + (float)root.rect.height); //put traingle //Point[] triangle = new Point[] { new Point((int)root.rect.origin.x, (int)root.rect.origin.y), // new Point((float)root.rect.origin.x, (float)root.rect.origin.y, // new Point((int)root.rect.origin.x+(int)root.rect.width, (int)root.rect.origin.y) }; //g.DrawPolygon(new Pen(Color.Cyan, 1), triangle); if (graph.BackgroundImage != null) { using (Graphics g = Graphics.FromImage(graph.BackgroundImage)) { //put rectangle g.DrawRectangle(setPenColor(color), (float)root.rect.origin.x, (float)root.rect.origin.y, (float)root.rect.width, (float)root.rect.height); } } else { g.DrawRectangle(setPenColor(color), (float)root.rect.origin.x, (float)root.rect.origin.y, (float)root.rect.width, (float)root.rect.height); } //matrix // g.FillEllipse( //Brushes.Cyan, //(float)(float)root.rect.origin.x-1, // (float)root.rect.origin.y-1, // 2, // 2); } if (root.n1 != null) { putSubdivision(root.n1, delay, color); } if (root.n2 != null) { putSubdivision(root.n2, delay, color); } if (root.n3 != null) { putSubdivision(root.n3, delay, color); } if (root.n4 != null) { putSubdivision(root.n4, delay, color); } }
public void putSubdivision_ByPoints(List <PointModel> points) { Rectangle rect = new Rectangle(0, 0, graph.Width, graph.Height); g.FillRectangle(Brushes.Black, rect); foreach (PointModel point in points) { g.FillEllipse( Brushes.DeepPink, (float)point.x - 1, (float)point.y - 1, 3, 3); } rootNode = Engine.quadTreeGenerator_ByPoint(points, graph.Width, graph.Height, 3); putSubdivision(rootNode, 0, "cyan"); }
// QT private void QTbutton_Click(object sender, EventArgs e) { refreshGraph(false); try { rootNode = null; 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 = Engine.quadTreeGenerator(image, graph.Width, graph.Height, tolerance); //rectangle //putSubdivision(rootNode,0); Bitmap bmp = new Bitmap(image); ///rect Engine.onlyFigure(rootNode, bmp, false); //only fig // Engine.deleteRedundant(rootNode, bmp); putSubdivision(rootNode, 0, "pink"); graph.Refresh(); } } catch (Exception ex) { CustomMessageBox msg = new CustomMessageBox(ex.ToString()); msg.Show(); } }
private void DITHERINGbutton1_Click(object sender, EventArgs e) { raycasting = false; setQTP = false; rootNode = 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) { // get path var filePath = dialog.FileName; //result (List <PointModel> matrix, Bitmap bmp) = Engine.dithering_GenerateMatrix(Image.FromFile(filePath), graph.Width, graph.Height); graph.BackgroundImage = bmp; graph.Refresh(); } }