public RGBOctreeNode newLeaf(Color c, RGBOctreeNode cur, int level) { int whichChild = ColorToIndex(c, 8 - level); RGBOctreeNode nextNode = new RGBOctreeNode(level + 1); bool newd = false; if (cur.isCulled) { // cur.blend.Add(c); //if (Form1.rng.NextDouble() > .90 && cur.blend.Count > 10) // cur.color = avgColor(cur.blend); return(null); } if (cur.children[whichChild] == null) { cur.children[whichChild] = nextNode; newd = true; } else //if (cur.children[whichChild] != null) { nextNode = cur.children[whichChild]; } nextNode.parent = cur; if (level + 1 == treeDepth) { if (newd) { nextNode.color = c; nextNode.r = c.R; nextNode.g = c.G; nextNode.b = c.B; nextNode.blend = new List <Color>(); nextNode.blend.Add(c); nextNode.isLeaf = true; leafCount++; leafNodes.Add(nextNode); // MessageBox.Show(nextNode.color.R + " " + nextNode.color.G + " " + nextNode.color.B); } nextNode.pixelCount++; return(nextNode); } return(newLeaf(c, nextNode, level + 1)); }
public void ReduceChildren(RGBOctreeNode leafParent) { // MessageBox.Show("TRY"); if (leafParent == null) { MessageBox.Show("FAIL "); return; } long R, G, B, S, PC; R = G = B = S = PC = 0; //MessageBox.Show("PRE DEL " + leafNodes.Count); List <Color> childColors = new List <Color>(); for (int i = 0; i < 8; i++) { if (leafParent.children[i] != null) { RGBOctreeNode child = leafParent.children[i]; leafParent.blend.AddRange(leafParent.children[i].blend); childColors.Add(child.color); R += child.r * child.pixelCount; G += child.g * child.pixelCount; B += child.b * child.pixelCount; S += 1 * child.pixelCount; child.decomissioned = true; //child.isLeaf = false; PC += child.pixelCount; leafParent.color = leafParent.children[i].color; leafNodes.Remove(child); } } // MessageBox.Show("POST DEL " + leafNodes.Count); leafParent.isLeaf = true; leafParent.isCulled = true; leafParent.pixelCount = PC; leafNodes.Add(leafParent); leafParent.r = R; leafParent.g = G; leafParent.b = B; // R /= S; G /= S; B /= S; leafParent.color = avgColor(childColors); // MessageBox.Show(leafParent.color.R + ""); // MessageBox.Show(avgColor }
public RGBOctreeNode addColorToOctree(Color c) { if (head == null) { head = new RGBOctreeNode(0); } RGBOctreeNode cur = head; RGBOctreeNode ret = newLeaf(c, cur, 0); if (leafNodes.Count > 160) { reduceCheck(colorDepth); } return(ret); }
public int comp(RGBOctreeNode a, RGBOctreeNode b) { if (a == null || b == null) { return(0); } if (a.pixelCount > b.pixelCount) { return(1); } if (a.pixelCount < b.pixelCount) { return(-1); } return(0); }