OpenWalnut  1.5.0dev
WTreeNode.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WTREENODE_H
26 #define WTREENODE_H
27 
28 #include <memory>
29 #include <sstream>
30 #include <string>
31 #include <vector>
32 
33 #include "../../common/datastructures/WDendrogram.h"
34 
35 /**
36  * A node in a tree, holding an index, a level in the tree and pointers to its child nodes
37  */
38 class WTreeNode : public std::enable_shared_from_this<WTreeNode>
39 {
40 public:
41  /**
42  * Shared pointer abbreviation.
43  */
44  typedef std::shared_ptr< WTreeNode > SPtr;
45 
46  /**
47  * Constructs a new TreeNode.
48  *
49  * \param index the index of the new Node.
50  * \param level the level of the Node in the Tree
51  */
52  WTreeNode( size_t index, double level );
53 
54  /**
55  * Constructs a tree of WTreeNodes from a WDendrogram with this WTreeNode as root
56  *
57  * \param dendrogram Reference to the dendrogram to construct the tree from
58  */
59  explicit WTreeNode( const WDendrogram &dendrogram );
60 
61  /**
62  * Default destructor.
63  */
64  ~WTreeNode();
65 
66  /**
67  * Adds a childnode to this node
68  *
69  * \param child the child node to add
70  */
71  void addChild( WTreeNode::SPtr child );
72 
73  /**
74  * Returns the index of the TreeNode
75  *
76  * \return the node's index
77  */
78  size_t index();
79 
80  /**
81  * Returns the level of the TreeNode. All level-0-nodes are leaves.
82  *
83  * \return the node's level
84  */
85  double level();
86 
87  /**
88  * Returns the child nodes of this node
89  *
90  * \return the child nodes of this node
91  */
92  std::vector< WTreeNode::SPtr > getChildren();
93 
94  /**
95  * Returns the parent node of this node
96  *
97  * \return the parent node of this node
98  */
100 
101 private:
102  /**
103  * Stores the childnodes of this node
104  */
105  std::vector< WTreeNode::SPtr > m_children;
106 
107  /**
108  * Stores the level of this node
109  */
110  double m_level;
111 
112  /**
113  * Stores the index of this node
114  */
115  size_t m_index;
116 
117  /**
118  * Stores the parent node
119  */
121 };
122 
123 #endif // WTREENODE_H
Hirachical binary tree datastructure with spatial layout information called dendrogram.
Definition: WDendrogram.h:63
A node in a tree, holding an index, a level in the tree and pointers to its child nodes.
Definition: WTreeNode.h:39
void addChild(WTreeNode::SPtr child)
Adds a childnode to this node.
Definition: WTreeNode.cpp:88
WTreeNode(size_t index, double level)
Constructs a new TreeNode.
Definition: WTreeNode.cpp:32
double m_level
Stores the level of this node.
Definition: WTreeNode.h:110
WTreeNode::SPtr getParent()
Returns the parent node of this node.
Definition: WTreeNode.cpp:94
WTreeNode::SPtr m_parent
Stores the parent node.
Definition: WTreeNode.h:120
~WTreeNode()
Default destructor.
Definition: WTreeNode.cpp:74
double level()
Returns the level of the TreeNode.
Definition: WTreeNode.cpp:78
std::vector< WTreeNode::SPtr > getChildren()
Returns the child nodes of this node.
Definition: WTreeNode.cpp:99
size_t index()
Returns the index of the TreeNode.
Definition: WTreeNode.cpp:83
size_t m_index
Stores the index of this node.
Definition: WTreeNode.h:115
std::shared_ptr< WTreeNode > SPtr
Shared pointer abbreviation.
Definition: WTreeNode.h:44
std::vector< WTreeNode::SPtr > m_children
Stores the childnodes of this node.
Definition: WTreeNode.h:105