public RTree(PixelMatrix pm, RNode rt, byte tr, byte tg, byte tb, int dr, int dg, int db, int dx) { if (rt != null && pm != null) { this.pm = pm; this.root = rt; r = tr; g = tg; b = tb; diffR = dr; diffG = dg; diffB = db; diffX = dx; GetBranches(this.root); } else { throw new NullReferenceException(); } }
private void GetOneBrance(int x, int y, ref RNode tr) { if (pm.IsInside(x, y)) { RNode rn = pm.nodes[x, y]; if (Verify(rn.R, rn.G, rn.B, r, g, b, diffR, diffG, diffB)) { tr = rn; GetBranches(rn); return; } } }
private void GetBranches(RNode r) { r.reached = true; num_elem++; if (pm.IsInside(r.x, r.y - 1)) { if (!pm.nodes[r.x, r.y - 1].reached) GetOneBrance(r.x, r.y - 1, ref r.u); } if (pm.IsInside(r.x + 1, r.y - 1)) if (!pm.nodes[r.x, r.y - 1].reached) GetOneBrance(r.x + 1, r.y - 1, ref r.ur); if (pm.IsInside(r.x + 1, r.y)) if (!pm.nodes[r.x + 1, r.y].reached) GetOneBrance(r.x + 1, r.y, ref r.r); if (pm.IsInside(r.x + 1, r.y + 1)) if (!pm.nodes[r.x + 1, r.y + 1].reached) GetOneBrance(r.x + 1, r.y + 1, ref r.br); if (pm.IsInside(r.x, r.y + 1)) if (!pm.nodes[r.x, r.y + 1].reached) GetOneBrance(r.x, r.y + 1, ref r.b); if (pm.IsInside(r.x - 1, r.y + 1)) if (!pm.nodes[r.x - 1, r.y + 1].reached) GetOneBrance(r.x - 1, r.y + 1, ref r.bl); if (pm.IsInside(r.x - 1, r.y)) if (!pm.nodes[r.x - 1, r.y].reached) GetOneBrance(r.x - 1, r.y, ref r.l); if (pm.IsInside(r.x - 1, r.y - 1)) if (!pm.nodes[r.x - 1, r.y - 1].reached) GetOneBrance(r.x - 1, r.y - 1, ref r.ul); return; }
public void DrawNodes(RNode r, Bitmap bmp) { if (r.u != null) DrawNodes(r.u, bmp); if (r.ur != null) DrawNodes(r.ur, bmp); if (r.r != null) DrawNodes(r.r, bmp); if (r.br != null) DrawNodes(r.br, bmp); if (r.b != null) DrawNodes(r.b, bmp); if (r.bl != null) DrawNodes(r.bl, bmp); if (r.l != null) DrawNodes(r.l, bmp); if (r.ul != null) DrawNodes(r.ul, bmp); bmp.SetPixel(r.x, r.y, Color.FromArgb(r.R, r.G, r.B)); }
private void TraverseNode(RNode r) { }
private void button4_Click(object sender, EventArgs e) { r = byte.Parse(labelR.Text); g = byte.Parse(labelG.Text); b = byte.Parse(labelB.Text); diffR = (int)numericUpDownR.Value; diffG = (int)numericUpDownG.Value; diffB = (int)numericUpDownB.Value; diffX = (int)numericUpDownX.Value; if (pictureBox1.Image != null) { Bitmap bmp = new Bitmap(pictureBox1.Image); Bitmap tbmp = new Bitmap(bmp.Width, bmp.Height); PixelMatrix matrix = new PixelMatrix(bmp.Width, bmp.Height); for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { Color c = bmp.GetPixel(x, y); RNode node = new RNode(); node.R = c.R; node.G = c.G; node.B = c.B; node.x = x; node.y = y; matrix.nodes[x, y] = node; } } RTree.Verify += new VerifyDelegate(VerifyRGB); List<RTree> rtrees = new List<RTree>(); for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { RNode node = matrix.nodes[x, y]; if (!node.reached) { if (RTree.Verify(node.R, node.G, node.B, r, g, b, diffR, diffG, diffB)) { RTree rtree = new RTree(matrix, node, r, g, b, diffR, diffG, diffB, diffX); rtrees.Add(rtree); } } } } foreach (RTree rt in rtrees) { rt.DrawNodes(rt.root, tbmp); } pictureBox4.Image = tbmp; rtrees.Clear(); } }