| Line | |
|---|
| 1 | #include "muscle.h" |
|---|
| 2 | #include "tree.h" |
|---|
| 3 | |
|---|
| 4 | /*** |
|---|
| 5 | Simple tree drawing algorithm. |
|---|
| 6 | |
|---|
| 7 | y coordinate of node is index in depth-first traversal. |
|---|
| 8 | x coordinate is distance from root. |
|---|
| 9 | ***/ |
|---|
| 10 | |
|---|
| 11 | static unsigned DistFromRoot(const Tree &tree, unsigned uNodeIndex) |
|---|
| 12 | { |
|---|
| 13 | const unsigned uRoot = tree.GetRootNodeIndex(); |
|---|
| 14 | unsigned uDist = 0; |
|---|
| 15 | while (uNodeIndex != uRoot) |
|---|
| 16 | { |
|---|
| 17 | ++uDist; |
|---|
| 18 | uNodeIndex = tree.GetParent(uNodeIndex); |
|---|
| 19 | } |
|---|
| 20 | return uDist; |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | static void DrawNode(const Tree &tree, unsigned uNodeIndex) |
|---|
| 24 | { |
|---|
| 25 | if (!tree.IsLeaf(uNodeIndex)) |
|---|
| 26 | DrawNode(tree, tree.GetLeft(uNodeIndex)); |
|---|
| 27 | |
|---|
| 28 | unsigned uDist = DistFromRoot(tree, uNodeIndex); |
|---|
| 29 | for (unsigned i = 0; i < 5*uDist; ++i) |
|---|
| 30 | Log(" "); |
|---|
| 31 | Log("%d\n", uNodeIndex); |
|---|
| 32 | |
|---|
| 33 | if (!tree.IsLeaf(uNodeIndex)) |
|---|
| 34 | DrawNode(tree, tree.GetRight(uNodeIndex)); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | void DrawTree(const Tree &tree) |
|---|
| 38 | { |
|---|
| 39 | unsigned uRoot = tree.GetRootNodeIndex(); |
|---|
| 40 | DrawNode(tree, uRoot); |
|---|
| 41 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.