示例#1
0
        public void OnAfterDeserialize()
        {
            if (m_serials == null || m_serials.Count == 0)
            {
                return;
            }

            List <KDTreeNode> nodes = new List <KDTreeNode>();

            for (int i = 0; i < m_serials.Count; ++i)
            { //populate all KDTreeNode first
                KDTreeSerial s    = m_serials[i];
                KDTreeNode   node = new KDTreeNode();
                node.pos = s.pos;
                nodes.Add(node);
            }
            for (int i = 0; i < nodes.Count; ++i)
            { //recover the links
                int l = m_serials[i].leftIdx;
                nodes[i].left = l >= 0 ? nodes[l] : null;
                int r = m_serials[i].rightIdx;
                nodes[i].right = r >= 0 ? nodes[r] : null;
                int p = m_serials[i].parentIdx;
                nodes[i].parent = p >= 0 ? nodes[p] : null;
            }

            m_rootNode = nodes[nodes.Count - 1]; //post-order serialization
        }
示例#2
0
        private int _Recur_Serialize(KDTreeNode nd)
        {
            KDTreeSerial s = new KDTreeSerial();

            if (nd.left != null)
            {
                s.leftIdx = _Recur_Serialize(nd.left);
            }
            if (nd.right != null)
            {
                s.rightIdx = _Recur_Serialize(nd.right);
            }

            s.pos = nd.pos;
            m_serials.Add(s);
            int curId = m_serials.Count - 1;

            if (s.leftIdx >= 0)
            {
                m_serials[s.leftIdx].parentIdx = curId;
            }
            if (s.rightIdx >= 0)
            {
                m_serials[s.rightIdx].parentIdx = curId;
            }

            return(curId);
        }