source: branches/stable/GDE/MUSCLE/src/drawtree.cpp

Last change on this file was 10390, checked in by aboeckma, 11 years ago

added muscle sourcles amd makefile

File size: 919 bytes
Line 
1#include "muscle.h"
2#include "tree.h"
3
4/***
5Simple tree drawing algorithm.
6
7y coordinate of node is index in depth-first traversal.
8x coordinate is distance from root.
9***/
10
11static 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
23static 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
37void 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.