示例#1
0
        //============================================================
        // <T>移除子节点。</T>
        //============================================================
        public int RemoveLeaves()
        {
            if (_pixelCount > 0)
            {
                throw new FFatalException();
            }
            int count = 0;

            for (int n = 0; n < 8; n++)
            {
                FOctreeNode node = _nodes[n];
                if (null != node)
                {
                    // 计算颜色总和
                    _red   += node._red;
                    _green += node._green;
                    _blue  += node._blue;
                    // 计算使用数
                    _pixelCount += node._pixelCount;
                    // 移除子节点
                    _nodes[n] = null;
                    count++;
                }
            }
            return((count > 0) ? count - 1 : 0);
        }
示例#2
0
 //============================================================
 // <T>构造OCTree颜色优化器。</T>
 //============================================================
 public FOctreeQuantizer()
 {
     for (int n = 0; n < 7; n++)
     {
         _levels[n] = new FOctreeNodes();
     }
     _root = new FOctreeNode(this, 0);
 }
示例#3
0
 //============================================================
 // <T>清除所有内容。</T>
 //============================================================
 public void Clear()
 {
     for (int n = 0; n < 8; n++)
     {
         _levels[n].Clear();
     }
     _root = new FOctreeNode(this, 0);
 }
示例#4
0
        //============================================================
        // <T>获得使用节点集合。</T>
        //============================================================
        public int NodeCount()
        {
            int count = 0;

            for (int index = 0; index < 8; index++)
            {
                FOctreeNode node = _nodes[index];
                if (null != node)
                {
                    count++;
                }
            }
            return(count);
        }
示例#5
0
 //============================================================
 // <T>获得使用节点集合。</T>
 //============================================================
 public void FilterLeaf(FOctreeNodes leafs)
 {
     if (_pixelCount > 0)
     {
         leafs.Push(this);
     }
     for (int index = 0; index < 8; index++)
     {
         FOctreeNode node = _nodes[index];
         if (null != node)
         {
             node.FilterLeaf(leafs);
         }
     }
 }
示例#6
0
        //============================================================
        // <T>获得使用节点集合。</T>
        //============================================================
        public int LeafCount()
        {
            int count = 0;

            if (_pixelCount > 0)
            {
                count++;
            }
            for (int index = 0; index < 8; index++)
            {
                FOctreeNode node = _nodes[index];
                if (null != node)
                {
                    count += node.LeafCount();
                }
            }
            return(count);
        }
示例#7
0
 //============================================================
 // <T>增加颜色。</T>
 //============================================================
 public void AddColor(Color color, int level, FOctreeQuantizer quantizer)
 {
     if (level == 8)
     {
         _red   += color.R;
         _green += color.G;
         _blue  += color.B;
         _pixelCount++;
     }
     else if (level < 8)
     {
         int         index = GetColorIndexAtLevel(color, level);
         FOctreeNode node  = _nodes[index];
         if (null == node)
         {
             node          = new FOctreeNode(quantizer, level);
             _nodes[index] = node;
         }
         node.AddColor(color, level + 1, quantizer);
     }
 }
示例#8
0
 //============================================================
 // <T>增加一个叶节点到指定层级。</T>
 //
 // @param level 指定层级
 // @param node 叶节点
 //============================================================
 internal void AddLevelNode(int level, FOctreeNode node)
 {
     _levels[level].Push(node);
 }