5 void Tree::InitCache(unsigned uCacheCount)
\r
7 m_uCacheCount = uCacheCount;
\r
9 m_uNeighbor1 = new unsigned[m_uCacheCount];
\r
10 m_uNeighbor2 = new unsigned[m_uCacheCount];
\r
11 m_uNeighbor3 = new unsigned[m_uCacheCount];
\r
13 m_Ids = new unsigned[m_uCacheCount];
\r
15 m_dEdgeLength1 = new double[m_uCacheCount];
\r
16 m_dEdgeLength2 = new double[m_uCacheCount];
\r
17 m_dEdgeLength3 = new double[m_uCacheCount];
\r
18 m_dHeight = new double[m_uCacheCount];
\r
20 m_bHasEdgeLength1 = new bool[m_uCacheCount];
\r
21 m_bHasEdgeLength2 = new bool[m_uCacheCount];
\r
22 m_bHasEdgeLength3 = new bool[m_uCacheCount];
\r
23 m_bHasHeight = new bool[m_uCacheCount];
\r
25 m_ptrName = new char *[m_uCacheCount];
\r
27 for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex)
\r
29 m_uNeighbor1[uNodeIndex] = NULL_NEIGHBOR;
\r
30 m_uNeighbor2[uNodeIndex] = NULL_NEIGHBOR;
\r
31 m_uNeighbor3[uNodeIndex] = NULL_NEIGHBOR;
\r
32 m_bHasEdgeLength1[uNodeIndex] = false;
\r
33 m_bHasEdgeLength2[uNodeIndex] = false;
\r
34 m_bHasEdgeLength3[uNodeIndex] = false;
\r
35 m_bHasHeight[uNodeIndex] = false;
\r
36 m_dEdgeLength1[uNodeIndex] = dInsane;
\r
37 m_dEdgeLength2[uNodeIndex] = dInsane;
\r
38 m_dEdgeLength3[uNodeIndex] = dInsane;
\r
39 m_dHeight[uNodeIndex] = dInsane;
\r
40 m_ptrName[uNodeIndex] = 0;
\r
41 m_Ids[uNodeIndex] = uInsane;
\r
45 void Tree::FromClust(Clust &C)
\r
49 m_uNodeCount = C.GetNodeCount();
\r
50 InitCache(m_uNodeCount);
\r
52 // Cluster is always rooted. An unrooted cluster
\r
53 // is represented by a pseudo-root, which we fix later.
\r
55 const unsigned uRoot = C.GetRootNodeIndex();
\r
56 m_uRootNodeIndex = uRoot;
\r
57 m_uNeighbor1[uRoot] = NULL_NEIGHBOR;
\r
58 m_bHasEdgeLength1[uRoot] = false;
\r
60 for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex)
\r
62 if (C.IsLeaf(uNodeIndex))
\r
64 const char *ptrName = C.GetNodeName(uNodeIndex);
\r
65 m_ptrName[uNodeIndex] = strsave(ptrName);
\r
66 m_Ids[uNodeIndex] = C.GetNodeId(uNodeIndex);
\r
70 const unsigned uLeft = C.GetLeftIndex(uNodeIndex);
\r
71 const unsigned uRight = C.GetRightIndex(uNodeIndex);
\r
73 const double dLeftLength = C.GetLength(uLeft);
\r
74 const double dRightLength = C.GetLength(uRight);
\r
76 m_uNeighbor2[uNodeIndex] = uLeft;
\r
77 m_uNeighbor3[uNodeIndex] = uRight;
\r
79 m_dEdgeLength1[uLeft] = dLeftLength;
\r
80 m_dEdgeLength1[uRight] = dRightLength;
\r
82 m_uNeighbor1[uLeft] = uNodeIndex;
\r
83 m_uNeighbor1[uRight] = uNodeIndex;
\r
85 m_bHasEdgeLength1[uLeft] = true;
\r
86 m_bHasEdgeLength1[uRight] = true;
\r
88 m_dEdgeLength2[uNodeIndex] = dLeftLength;
\r
89 m_dEdgeLength3[uNodeIndex] = dRightLength;
\r
91 m_bHasEdgeLength2[uNodeIndex] = true;
\r
92 m_bHasEdgeLength3[uNodeIndex] = true;
\r