public void ReduceColorsCount(IOctreeNode nodeToReduce, Color avgFamilyColor) { if (nodes.Values.Contains(nodeToReduce)) { int key = 0; foreach (var node in nodes) { if (node.Value == nodeToReduce) { key = node.Key; break; } } nodes[key] = new OctreeLeaf(nodeToReduce.GetAvgColor(), nodeToReduce.GetColorPixelsCount(), Index + 1); BestColorFamilyToReduce = null; foreach (IOctreeNode octreeNode in nodes.Values) { SetBestColorFamilyToReduce(octreeNode.BestColorFamilyToReduce); } SetBestColorFamilyToReduce(this); } else { int nodeKey = GetNodeKeyForColor(avgFamilyColor); nodes[nodeKey].ReduceColorsCount(nodeToReduce, avgFamilyColor); BestColorFamilyToReduce = null; foreach (IOctreeNode octreeNode in nodes.Values) { SetBestColorFamilyToReduce(octreeNode.BestColorFamilyToReduce); } } }
public void ReduceColorsCount(int limit) { while (ColorsCount > limit) { if (root == root.BestColorFamilyToReduce) { ColorsCount = 1; root = new OctreeLeaf(root.GetAvgColor(), root.GetColorPixelsCount(), 0); return; } else { ColorsCount -= (root.BestColorFamilyToReduce.GetColorsCount() - 1); root.ReduceColorsCount(root.BestColorFamilyToReduce, root.BestColorFamilyToReduce.GetAvgColor()); } } }