Visualization and traversal of Multi-tree

Source: Internet
Author: User

Recently, I have been busy working on the design. The skeleton system is simply a multi-Cross-layered tree structure. When the overall framework is almost the same, I have been thinking about restructuring it.CodeBecause it was originally intended to achieve results, the design in many places is not very reasonable.

First, I wrote a small multi-tree library, which can be created with an iterator, recursively traversed and destroyed. I tried to add some other functions, for example, operator ++ is added to the previous iterator, but it is found that many places are restricted by the node structure. The node data structure of the Multi-tree is as follows:

Class node <br/>{< br/> node * parent; <br/> vector <node *> children; <br/> };

Of course, the actual implementation is to use a template.


I found a kptree on the Internet and found a multi-tree.

URL: /~ Peekas/tree/

Its node structure is as follows:

Template <class T> <br/> class tree_node _ {<br/> Public: <br/> tree_node _ <t> * parent; <br/> tree_node _ <t> * first_child, * last_child; <br/> tree_node _ <t> * prev_sibling, * next_sibling; <br/> T data; <br/> };

In addition, this database basically implements all the operations on the Multi-tree. Similar to STL operations based on the iterator. No recursive operations on trees are not supported.


So I wrote a script configuration based on this library.ProgramClass scriptparser, inherited from the tree class

Script format:

Node Type:

    1. Root indicates the root node
    2. Joint indicates a general non-terminal node.
    3. End indicates the terminal leaf node.

The hierarchical inclusion relationships in the tree are represented by curly brackets.

Finally, OpenGL is used to achieve visualization. A figure class inheritance and scriptparser class are written, and the multi-Cross Tree is displayed through the script;

The multi-Tree display is visually pleasing. Detailed handling:

    1. When two children exist, the parent node is located at the midpoint of the child node. There is a height difference in the Y direction.
    2. When multiple children exist, make sure that the parent node on the XOZ plane is located at the center of the outer circle of the child node.

Final script:

Root 1 <br/>{< br/> joint 2 <br/>{< br/> end 3 <br/>{< br/>}< br/> joint 4 <br/>{< br/> end 5 <br/>{< br/>}< br/> end 6 <br/>{< br/>}< br/> end 7 <br/>{< br/>}< br/> end 8 <br/>{< br/>}< br/> end 9 <br/>{< br/>}< br/> end 10 <br/>{< br/>}< br/> joint 11 <br/ >{< br/> joint 12 <br/>{< br/> end 13 <br/>{< br/>}< br/> end 14 <br/> {<br/>}< br/> end 15 <br/>{< br/>}< br/> end 16 <br/>{< br/>}< br/ >}< br/> end 17 <br/>{< br/>}< br/> end 18 <br/>{< br/>}< br/> end 19 <br/>{< br/>}< br/>}


During traversal, the nodes are activated one by one, and the color turns yellow, increasing by a bit in half a kilo:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.