예제 #1
0
 //============================================================
 // <T>构造OCTree颜色优化器。</T>
 //============================================================
 public FOctreeQuantizer16()
 {
     for (int n = 0; n < 7; n++)
     {
         _levels[n] = new FOctreeNode16s();
     }
     _root = new FOctreeNode16(this, 0);
 }
예제 #2
0
 //============================================================
 // <T>清除所有内容。</T>
 //============================================================
 public void Clear()
 {
     for (int n = 0; n < 16; n++)
     {
         _levels[n].Clear();
     }
     _root = new FOctreeNode16(this, 0);
 }
예제 #3
0
 //============================================================
 // <T>获得使用节点集合。</T>
 //============================================================
 public void FilterLeaf(FOctreeNode16s leafs)
 {
     if (_pixelCount > 0)
     {
         leafs.Push(this);
     }
     if (null != _nodes)
     {
         for (int index = 0; index < 16; index++)
         {
             FOctreeNode16 node = _nodes[index];
             if (null != node)
             {
                 node.FilterLeaf(leafs);
             }
         }
     }
 }
예제 #4
0
 //============================================================
 // <T>增加颜色。</T>
 //============================================================
 public void AddColor(Color color, int level, FOctreeQuantizer16 quantizer)
 {
     if (level == 8)
     {
         _alpha += color.A;
         _red   += color.R;
         _green += color.G;
         _blue  += color.B;
         _pixelCount++;
     }
     else if (level < 8)
     {
         int           index = GetColorIndexAtLevel(color, level);
         FOctreeNode16 node  = _nodes[index];
         if (null == node)
         {
             node          = new FOctreeNode16(quantizer, level);
             _nodes[index] = node;
         }
         node.AddColor(color, level + 1, quantizer);
     }
 }
예제 #5
0
        //============================================================
        // <T>移除子节点。</T>
        //============================================================
        public int RemoveLeaves(int limit)
        {
            if (_pixelCount > 0)
            {
                throw new FFatalException();
            }
            int count = 0;

            // 删除节点
            for (int n = 0; n < 16; n++)
            {
                FOctreeNode16 node = _nodes[n];
                if (null != node)
                {
                    // 计算颜色总和
                    _alpha += node._alpha;
                    _red   += node._red;
                    _green += node._green;
                    _blue  += node._blue;
                    // 计算使用数
                    _pixelCount += node._pixelCount;
                    // 移除子节点
                    _nodes[n] = null;
                    count++;
                    limit--;
                    if (limit <= 0)
                    {
                        break;
                    }
                }
            }
            // 删除节点集合
            if (0 == NodeCount)
            {
                _nodes = null;
            }
            return((count > 0) ? count - 1 : 0);
        }
예제 #6
0
 //============================================================
 // <T>增加一个叶节点到指定层级。</T>
 //
 // @param level 指定层级
 // @param node 叶节点
 //============================================================
 internal void AddLevelNode(int level, FOctreeNode16 node)
 {
     _levels[level].Push(node);
 }