OpenWalnut  1.5.0dev
WHnode.cpp
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 // std library
50 #include <vector>
51 #include <string>
52 #include <utility>
53 #include <iostream>
54 
55 #include "core/common/WStringUtils.h"
56 
57 #include "WHnode.h"
58 
59 // === PUBLIC MEMBER FUNCTIONS ===
60 
61 WHnode::WHnode( nodeID_t idInit ): m_fullID( idInit ), m_parent( std::make_pair( false, 0 ) ),
62  m_nodeSize( 1 ), m_distanceLevel( 0 ), m_hLevel( 0 ), m_flag( false )
63 {
64 }
65 
66 WHnode::WHnode( nodeID_t idInit, std::vector<nodeID_t>childrenInit, size_t nodeSizeInit, dist_t distanceLevelInit, size_t hLevelInit ):
67  m_fullID( idInit ), m_parent( std::make_pair( false, 0 ) ), m_children( childrenInit ), m_nodeSize( nodeSizeInit ),
68  m_distanceLevel( distanceLevelInit ), m_hLevel( hLevelInit ), m_flag( false )
69 {
70 }
71 
73 {
74  // Cleanup
75 }
76 
77 bool WHnode::isRoot() const
78 {
79  return ( ( m_fullID.first )&&( !m_parent.first )&&( !m_parent.second ) );
80 }
81 
82 void WHnode::setID( const nodeID_t newID )
83 {
84  m_fullID = newID;
85 }
86 
87 void WHnode::setParent( const nodeID_t newDad )
88 {
89  m_parent = newDad;
90 }
91 
92 void WHnode::setSize( const size_t newSize )
93 {
94  m_nodeSize = newSize;
95 }
96 
97 void WHnode::setHLevel( const size_t newLevel )
98 {
99  m_hLevel = newLevel;
100 }
101 
102 void WHnode::setDistLevel( const dist_t newLevel )
103 {
104  m_distanceLevel = newLevel;
105 }
106 
107 void WHnode::setChildren( std::vector<nodeID_t> newKids )
108 {
109  m_children = newKids;
110 }
111 
112 void WHnode::setFlag( const bool newFlag )
113 {
114  m_flag = newFlag;
115 }
116 
117 std::string WHnode::printAllData() const
118 {
119  std::string oString;
120  oString += ( "ID: " + string_utils::toString( m_fullID.first )+ "-" + str( boost::format( "%06d" ) % m_fullID.second ) );
121  oString += ". Dad: " + string_utils::toString( m_parent.first ) + "-" + str( boost::format( "%06d" ) % m_parent.second );
122  oString += ". Size: " + str( boost::format( "%06d" ) % m_nodeSize );
123  oString += ". HLevel: " + string_utils::toString( m_hLevel );
124  oString += ". DLevel: " + string_utils::toString( m_distanceLevel );
125  oString += ". Kids: (";
126  for( size_t i = 0; i < m_children.size(); ++i )
127  {
128  oString += " " + string_utils::toString( m_children[i].first ) + "-" + str( boost::format( "%06d" ) % m_children[i].second )+ " ";
129  if( i < ( m_children.size()-1 ) )
130  {
131  oString += ",";
132  }
133  }
134  oString += ")";
135  if( m_flag )
136  {
137  oString+=" F";
138  }
139  return oString;
140 } // end hNode::printAllData() -----------------------------------------------------------------
141 
142 std::string WHnode::printJointData() const
143 {
144  std::string oString;
146  for( size_t i = 0; i < m_children.size(); ++i )
147  {
148  oString += " " + string_utils::toString( m_children[i].first ) + " " + str( boost::format( "%06d" ) % m_children[i].second );
149  }
150  return oString;
151 } // end hNode::printJointData() -----------------------------------------------------------------
152 
153 
154 
155 // === NON-MEMBER OPERATORS ===
156 
157 
158 
159 std::ostream& operator <<( std::ostream& os, const WHnode& object )
160 {
161  os << object.printJointData();
162  return os;
163 } // end operator << -----------------------------------------------------------------
this class implements a hierarchical tree node with several relevant attributes
Definition: WHnode.h:69
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
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
std::vector< nodeID_t > m_children
chlidren nodes IDs
Definition: WHnode.h:217
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
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
~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
std::string toString(const T &value)
Convert a given value to a string.
Definition: WStringUtils.h:120