Beispiel #1
0
 internal OcTree(int colorDepth)
 {
     this._colorDepth = colorDepth;
     _maxColors       = 1 << _colorDepth;
     ReducibleNodes   = new OcTreeNode[colorDepth];
     _rootNode        = new OcTreeNode(colorDepth, 0, this);
 }
Beispiel #2
0
        void Reduce()
        {
            int index;

            for (index = _colorDepth - 1; (index > 0 && ReducibleNodes[index] == null); index--)
            {
            }
            OcTreeNode node = ReducibleNodes[index];

            ReducibleNodes[index] = node.NextReducible;
            leaves     -= node.Reduce();
            _prefixNode = null;
        }
Beispiel #3
0
 /// <summary>
 /// 八叉树的构造函数
 /// </summary>
 /// <param name="leaf">是否是叶子节点</param>
 /// <param name="level">层级</param>
 /// <param name="parent">父节点</param>
 public OcTreeNode(int colorDepth, int level, OcTree tree)
 {
     this.ColorDepth = colorDepth;
     this.Leaf       = (colorDepth == level);
     this.Level      = level;
     if (!Leaf)
     {
         NextReducible = tree.ReducibleNodes[level];
         tree.ReducibleNodes[level] = this;
         Children = new OcTreeNode[8];
     }
     else
     {
         tree.IncrementLeaves();
     }
 }
Beispiel #4
0
 /// <summary>
 /// �˲����Ĺ��캯��
 /// </summary>
 /// <param name="leaf">�Ƿ���Ҷ�ӽڵ�</param>
 /// <param name="level">�㼶</param>
 /// <param name="parent">���ڵ�</param>
 internal OcTreeNode(int colorDepth,int level,OcTree tree)
 {
     this.ColorDepth = colorDepth;
     this.Leaf = (colorDepth==level);
     this.Level = level;
     if (!Leaf)
     {
         NextReducible = tree.ReducibleNodes[level];
         tree.ReducibleNodes[level] = this;
         Children = new OcTreeNode[8];
     }
     else
     {
         tree.IncrementLeaves();
     }
 }
Beispiel #5
0
        public int GetPaletteIndex(Color32 *pixel, int level)
        {
            int pindex = paletteIndex;

            if (!Leaf)
            {
                int shift = 7 - level;
                int index = ((pixel->Red & mask[level]) >> (shift - 2)) |
                            ((pixel->Green & mask[level]) >> (shift - 1)) |
                            ((pixel->Blue & mask[level]) >> (shift));
                OcTreeNode child = Children[index];
                if (child != null)
                {
                    child.GetPaletteIndex(pixel, level + 1);
                }
                else
                {
                    throw new Exception("不可预料的事情发生了!");
                }
            }
            return(pindex);
        }
Beispiel #6
0
        public void AddColor(Color32 *pixel, int level, OcTree tree)
        {
            //如果是树叶了,表示一个颜色像素添加完成
            if (this.Leaf)
            {
                Increment(pixel);
                tree.TracePrevious(this);
                return;
            }
            int shift = 7 - level;
            int index = ((pixel->Red & mask[level]) >> (shift - 2)) |
                        ((pixel->Green & mask[level]) >> (shift - 1)) |
                        ((pixel->Blue & mask[level]) >> (shift));
            OcTreeNode child = Children[index];

            if (child == null)
            {
                child           = new OcTreeNode(ColorDepth, level + 1, tree);
                Children[index] = child;
            }
            child.AddColor(pixel, ++level, tree);
        }
Beispiel #7
0
 internal void TracePrevious(OcTreeNode node)
 {
     this._prefixNode = node;
 }
Beispiel #8
0
 internal void AddColor(Color32* pixel, int level,OcTree tree)
 {
     //�������Ҷ�ˣ���ʾһ����ɫ����������
     if (this.Leaf)
     {
         Increment(pixel);
         tree.TracePrevious(this);
         return;
     }
     int shift = 7 - level;
     int index = ((pixel->Red & mask[level]) >> (shift - 2)) |
                   ((pixel->Green & mask[level]) >> (shift - 1)) |
                   ((pixel->Blue & mask[level]) >> (shift));
     OcTreeNode child = Children[index];
     if (child == null)
     {
         child = new OcTreeNode(ColorDepth, level+1, tree);
         Children[index] = child;
     }
     child.AddColor(pixel, ++level,tree);
 }
Beispiel #9
0
 public void TracePrevious(OcTreeNode node)
 {
     this._prefixNode = node;
 }