OpenWalnut  1.5.0dev
WHnode.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 //---------------------------------------------------------------------------
26 //
27 // Project: hClustering
28 //
29 // Whole-Brain Connectivity-Based Hierarchical Parcellation Project
30 // David Moreno-Dominguez
31 // d.mor.dom@gmail.com
32 // moreno@cbs.mpg.de
33 // www.cbs.mpg.de/~moreno//
34 // This file is also part of OpenWalnut ( http://www.openwalnut.org ).
35 //
36 // hClustering is free software: you can redistribute it and/or modify
37 // it under the terms of the GNU Lesser General Public License as published by
38 // the Free Software Foundation, either version 3 of the License, or
39 // (at your option) any later version.
40 // http://creativecommons.org/licenses/by-nc/3.0
41 //
42 // hClustering is distributed in the hope that it will be useful,
43 // but WITHOUT ANY WARRANTY; without even the implied warranty of
44 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 // GNU Lesser General Public License for more details.
46 //
47 //---------------------------------------------------------------------------
48 
49 #ifndef WHNODE_H
50 #define WHNODE_H
51 
52 // std library
53 #include <vector>
54 #include <string>
55 #include <utility>
56 #include <iostream>
57 
58 // boost library
59 #include <boost/format.hpp>
60 
61 // typedefs
62 typedef float dist_t;
63 typedef std::pair<bool, size_t> nodeID_t;
64 
65 /**
66  * this class implements a hierarchical tree node with several relevant attributes
67  */
68 class WHnode
69 {
70 public:
71  /**
72  * Constructor
73  * \param idInit node id initializer
74  */
75  explicit WHnode( nodeID_t idInit );
76 
77  /**
78  * Constructor
79  * \param idInit node id initializer
80  * \param childrenInit children id vector initializer
81  * \param nodeSizeInit node size initializer
82  * \param distanceLevelInit node distance level initializer
83  * \param hLevelInit node hierarchical level initializer
84  */
85  WHnode( nodeID_t idInit, std::vector<nodeID_t>childrenInit, size_t nodeSizeInit, dist_t distanceLevelInit, size_t hLevelInit );
86 
87  //! Destructor
88  ~WHnode();
89 
90  // === PUBLIC MEMBER FUNCTIONS ===
91 
92  /**
93  * returns true if object is a node
94  * \return node indicator
95  */
96  bool isNode() const;
97 
98  /**
99  * returns true if object is a leaf
100  * \return leaf indicator
101  */
102  bool isLeaf() const;
103 
104  /**
105  * returns true if object is the root of the tree
106  * \return root indicator
107  */
108  bool isRoot() const;
109 
110  /**
111  * returns true if object is flagged for pruning
112  * \return flag indicator
113  */
114  bool isFlagged() const;
115 
116  /**
117  * returns node/leaf ID
118  * \return id indicator
119  */
120  size_t getID() const;
121 
122  /**
123  * returns full ID
124  * \return full id indicator
125  */
126  nodeID_t getFullID() const;
127 
128  /**
129  * returns parent ID
130  * \return parent id indicator
131  */
132  nodeID_t getParent() const;
133 
134  /**
135  * returns number of elements contained by the node
136  * \return size
137  */
138  size_t getSize() const;
139 
140  /**
141  * returns distance level at which the element was formed
142  * \return distance
143  */
144  dist_t getDistLevel() const;
145 
146  /**
147  * returns maximum number of nodes between the node and a leaf element
148  * \return hierarchical level
149  */
150  size_t getHLevel() const;
151 
152  /**
153  * returns a vector with the ids of the children of that node
154  * \return children vector
155  */
156  std::vector<nodeID_t> getChildren() const;
157 
158  /**
159  * sets the ID field to the specified value
160  * \param newID new ID
161  */
162  void setID( const nodeID_t newID );
163 
164  /**
165  * sets the parent id field to the specified value
166  * \param newDad new parent id
167  */
168  void setParent( const nodeID_t newDad );
169 
170  /**
171  * sets the size field to the specified value
172  * \param newSize new size
173  */
174  void setSize( const size_t newSize );
175 
176  /**
177  * sets the hierarchical level field to the specified value
178  * \param newLevel new hierarchical level
179  */
180  void setHLevel( const size_t newLevel );
181 
182  /**
183  * sets the distance level field to the specified value
184  * \param newLevel new distance level
185  */
186  void setDistLevel( const dist_t newLevel );
187 
188  /**
189  * sets the children vector to the input values
190  * \param newKids vector with the new children ids
191  */
192  void setChildren( std::vector<nodeID_t> newKids );
193 
194  /**
195  * sets the prune flag to the indicated value
196  * \param newFlag new value for the prune flag
197  */
198  void setFlag( const bool newFlag );
199 
200  /**
201  * prints out a string with the node data, in order to implement the operator <<
202  * \return a string with the node information
203  */
204  std::string printAllData() const;
205 
206  /**
207  * prints out a string with the node join data, (reduced version of the node data)
208  * \return a string with the node join information
209  */
210  std::string printJointData() const;
211 
212 private:
213  // === PRIVATE DATA MEMBERS ===
214 
215  nodeID_t m_fullID; //!< node ID
216  nodeID_t m_parent; //!< parent node ID
217  std::vector<nodeID_t> m_children; //!< chlidren nodes IDs
218  size_t m_nodeSize; //!< number of leaves contained on the node
219  dist_t m_distanceLevel; //!< distance level where the node was created
220  size_t m_hLevel; //!< level in the hierarchy (max number of nodes until reaching a leaf)
221  bool m_flag; //!< flag bit
222 };
223 
224 
225 // === IN-LINE MEMBER FUNCTIONS ===
226 
227 inline bool WHnode::isNode() const
228 {
229  return m_fullID.first;
230 }
231 
232 inline bool WHnode::isLeaf() const
233 {
234  return !( m_fullID.first );
235 }
236 
237 inline bool WHnode::isFlagged() const
238 {
239  return m_flag;
240 }
241 
242 inline size_t WHnode::getID() const
243 {
244  return m_fullID.second;
245 }
246 
247 inline nodeID_t WHnode::getFullID() const
248 {
249  return m_fullID;
250 }
251 
252 inline nodeID_t WHnode::getParent() const
253 {
254  return m_parent;
255 }
256 
257 inline size_t WHnode::getSize() const
258 {
259  return m_nodeSize;
260 }
261 
262 inline dist_t WHnode::getDistLevel() const
263 {
264  return m_distanceLevel;
265 }
266 
267 inline size_t WHnode::getHLevel() const
268 {
269  return m_hLevel;
270 }
271 
272 inline std::vector<nodeID_t> WHnode::getChildren() const
273 {
274  return m_children;
275 }
276 
277 
278 // === NON-MEMBER OPERATORS ===
279 
280 /**
281  * << operator for the node class
282  * \param os output stream
283  * \param object node to print out
284  * \return ostream with the node information
285  */
286 std::ostream& operator <<( std::ostream& os, const WHnode& object );
287 #endif // WHNODE_H
this class implements a hierarchical tree node with several relevant attributes
Definition: WHnode.h:69
size_t getSize() const
returns number of elements contained by the node
Definition: WHnode.h:257
size_t m_hLevel
level in the hierarchy (max number of nodes until reaching a leaf)
Definition: WHnode.h:220
WHnode(nodeID_t idInit)
Constructor.
Definition: WHnode.cpp:61
void setParent(const nodeID_t newDad)
sets the parent id field to the specified value
Definition: WHnode.cpp:87
dist_t m_distanceLevel
distance level where the node was created
Definition: WHnode.h:219
std::string printJointData() const
prints out a string with the node join data, (reduced version of the node data)
Definition: WHnode.cpp:142
nodeID_t m_parent
parent node ID
Definition: WHnode.h:216
bool isFlagged() const
returns true if object is flagged for pruning
Definition: WHnode.h:237
nodeID_t m_fullID
node ID
Definition: WHnode.h:215
void setChildren(std::vector< nodeID_t > newKids)
sets the children vector to the input values
Definition: WHnode.cpp:107
bool m_flag
flag bit
Definition: WHnode.h:221
void setHLevel(const size_t newLevel)
sets the hierarchical level field to the specified value
Definition: WHnode.cpp:97
bool isLeaf() const
returns true if object is a leaf
Definition: WHnode.h:232
std::vector< nodeID_t > m_children
chlidren nodes IDs
Definition: WHnode.h:217
size_t getHLevel() const
returns maximum number of nodes between the node and a leaf element
Definition: WHnode.h:267
void setSize(const size_t newSize)
sets the size field to the specified value
Definition: WHnode.cpp:92
size_t m_nodeSize
number of leaves contained on the node
Definition: WHnode.h:218
bool isRoot() const
returns true if object is the root of the tree
Definition: WHnode.cpp:77
size_t getID() const
returns node/leaf ID
Definition: WHnode.h:242
std::string printAllData() const
prints out a string with the node data, in order to implement the operator <<
Definition: WHnode.cpp:117
void setID(const nodeID_t newID)
sets the ID field to the specified value
Definition: WHnode.cpp:82
void setFlag(const bool newFlag)
sets the prune flag to the indicated value
Definition: WHnode.cpp:112
dist_t getDistLevel() const
returns distance level at which the element was formed
Definition: WHnode.h:262
~WHnode()
Destructor.
Definition: WHnode.cpp:72
void setDistLevel(const dist_t newLevel)
sets the distance level field to the specified value
Definition: WHnode.cpp:102
bool isNode() const
returns true if object is a node
Definition: WHnode.h:227
nodeID_t getFullID() const
returns full ID
Definition: WHnode.h:247
nodeID_t getParent() const
returns parent ID
Definition: WHnode.h:252
std::vector< nodeID_t > getChildren() const
returns a vector with the ids of the children of that node
Definition: WHnode.h:272