public Color GetColor(BinaryColor color) { Octree tmp = this; int depth = 0; while (!tmp.isLeaf) { tmp = tmp.Next[Branch(color.R[8 - depth], color.G[8 - depth], color.B[8 - depth])]; depth++; } return(tmp.color); }
private void InitTree() { tree = new Octree(); for (int i = 0; i < picAfterConstruction.Width; i++) { for (int j = 0; j < picAfterConstruction.Height; j++) { var a = new BinaryColor(bitmapColors[i, j]); tree.InsertTree(a, 0); barAfterConstruction.Increment(1); } } }
private void InitSecondTree() { secondTree = new Octree(); for (int i = 0; i < picAlongConstruction.Width; i++) { for (int j = 0; j < picAlongConstruction.Height; j++) { var a = new BinaryColor(bitmapColors[i, j]); secondTree.InsertTreeSecondVersion(a, 0, colorsNumber); barAlongConstruction.Increment(1); } } var b = secondTree.GetLeafParents(); var c = secondTree.GetLeafCount(b); UpdateColors(secondTree, colorsSecondVersion, lblAlongConstruction, picAlongConstruction, barAlongConstruction); }
public void InsertTree(BinaryColor color, int depth) { //depth >=8 means that node is leaf if (depth >= 8) { this.color = color.GetColor(); isLeaf = true; parent.isLeafParent = true; Next = null; sum++; } else { //if node is leaf, then update it and return if (isLeaf) { Color newColor = color.GetColor(); int R = this.color.R * sum + newColor.R; int G = this.color.G * sum + newColor.G; int B = this.color.B * sum + newColor.B; sum++; this.color = Color.FromArgb((int)((double)R / (double)sum), (int)((double)G / (double)sum), (int)((double)B / (double)sum)); return; } //if node is not leaf then we have to create another level of tree structure sum++; int depth2 = 8 - depth; if (Next[Branch(color.R[depth2], color.G[depth2], color.B[depth2])] == null) { Next[Branch(color.R[depth2], color.G[depth2], color.B[depth2])] = new Octree(); Next[Branch(color.R[depth2], color.G[depth2], color.B[depth2])].parent = this; } Next[Branch(color.R[depth2], color.G[depth2], color.B[depth2])] .InsertTree(color, depth + 1); } }
public void InsertTreeSecondVersion(BinaryColor color, int depth, int maxLeafNumber) { InsertTree(color, depth); Reduce(maxLeafNumber); }