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: http://www.aei.mpg.de /~ 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:
- Root indicates the root node
- Joint indicates a general non-terminal node.
- 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:
- 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.
- 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/>}
Effect:
During traversal, the nodes are activated one by one, and the color turns yellow, increasing by a bit in half a kilo: