Пример #1
0
 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);
         }
     }
 }
Пример #2
0
 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());
         }
     }
 }
Пример #3
0
 private void SetBestColorFamilyToReduce(IOctreeNode newFamily)
 {
     if (newFamily == null)
     {
         return;
     }
     if (BestColorFamilyToReduce == null || BestColorFamilyToReduce.Index < newFamily.Index)
     {
         BestColorFamilyToReduce = newFamily;
     }
     else if (newFamily.Index == BestColorFamilyToReduce.Index)
     {
         if (newFamily.GetColorPixelsCount() < BestColorFamilyToReduce.GetColorPixelsCount())
         {
             BestColorFamilyToReduce = newFamily;
         }
     }
 }