Example #1
0
        //============================================================
        // <T>生成指定颜色数目的调色板。</T>
        //
        // @param count 颜色数目
        // @return 颜色列表;
        //============================================================
        public List <Color> MakePalette(int count)
        {
            // 获得所有节点
            int leafCount = _root.LeafCount;
            FOctreeNode16Sorter sorter = new FOctreeNode16Sorter();

            // 合并节点叶子
            for (int level = 6; level >= 0; level--)
            {
                FOctreeNode16s nodes = _levels[level];
                if (!nodes.IsEmpty)
                {
                    nodes.Sort(sorter);
                    foreach (FOctreeNode16 node in nodes)
                    {
                        int removeCount = node.RemoveLeaves(leafCount - count + 1);
                        leafCount -= removeCount;
                        if (leafCount <= count)
                        {
                            break;
                        }
                    }
                    if (leafCount <= count)
                    {
                        break;
                    }
                }
                nodes.Clear();
            }
            if (leafCount > count)
            {
                throw new FFatalException("Make palette failure. (count={0})", leafCount);
            }
            // 增加颜色列表
            int          paletteIndex = 0;
            List <Color> result       = new List <Color>();

            FilterLeaf(_leafs);
            foreach (FOctreeNode16 node in _leafs)
            {
                result.Add(node.Color);
                node.SetPaletteIndex(paletteIndex++);
            }
            // 检查结果
            return(result);
        }
Example #2
0
 //============================================================
 // <T>获得所有有效节点。</T>
 //============================================================
 public void FilterLeaf(FOctreeNode16s leafs)
 {
     leafs.Clear();
     _root.FilterLeaf(leafs);
 }