public void Initialize(Transform root, string[] j_ori, string[] j_red) { Debug.Assert(j_ori.Length == j_red.Length); Dictionary <string, string> Ori2Redu = new Dictionary <string, string>(); Dictionary <string, string> Redu2Ori = new Dictionary <string, string>(); for (int i_map = 0; i_map < j_ori.Length; i_map++) { string ori = j_ori[i_map]; string red = j_red[i_map]; Ori2Redu[ori] = red; Redu2Ori[red] = ori; } string name_c; bool verify = Ori2Redu.TryGetValue(root.name, out name_c); Debug.Assert(verify); Stack <MapNode> dfcSt = new Stack <MapNode>(); MapNode n_dfc = new MapNode(root, name_c, null); dfcSt.Push(n_dfc); //depth first traversing the joint tree Stack <TransNodeDFT> dftSt = new Stack <TransNodeDFT>(); TransNodeDFT n_dft = new TransNodeDFT(root); dftSt.Push(n_dft); string logSrc = null; if (DFN_DBGLOG) { logSrc = string.Format("{0}\n", n_dft.node_this.name); } while (dftSt.Count > 0) { Debug.Assert(dfcSt.Count > 0); TransNodeDFT p_node = dftSt.Peek(); Transform c_tran = p_node.nextChild(); if (null != c_tran) { if (DFN_DBGLOG) { for (int c_indent = 0; c_indent < dftSt.Count; c_indent++) { logSrc += "\t"; } logSrc += string.Format("{0}\n", c_tran.name); } TransNodeDFT c_node = new TransNodeDFT(c_tran); dftSt.Push(c_node); if (Ori2Redu.TryGetValue(c_tran.name, out name_c)) { MapNode p = dfcSt.Peek(); MapNode c = new MapNode(c_tran, name_c, p); p.children.Add(c); dfcSt.Push(c); } } else { dftSt.Pop(); if (Ori2Redu.TryGetValue(p_node.node_this.name, out name_c)) { dfcSt.Pop(); } } } m_rootOut = n_dfc; if (DFN_DBGLOG) { Debug.Log(logSrc); Stack <MapNodeDFT> dft = new Stack <MapNodeDFT>(); MapNodeDFT dftNode = new MapNodeDFT(m_rootOut); dft.Push(dftNode); logSrc = string.Format("{0}\n", m_rootOut.name); while (dft.Count > 0) { MapNodeDFT p_nodeDFT = dft.Peek(); MapNode c_node = p_nodeDFT.nextChild(); if (null != c_node) { for (int i = 0; i < dft.Count; i++) { logSrc += "\t"; } logSrc += string.Format("{0}\n", c_node.name); MapNodeDFT c_nodeDFT = new MapNodeDFT(c_node); dft.Push(c_nodeDFT); } else { dft.Pop(); } } Debug.Log(logSrc); } }
public MapNodeDFT(MapNode a_this) { i_nextchild = 0; n_this = a_this; }