OpenWalnut  1.4.0
WDataSetHierarchicalClustering.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 #include <list>
26 #include <map>
27 #include <string>
28 #include <vector>
29 
30 #include "WDataSetHierarchicalClustering.h"
31 
32 // The prototype as singleton. Created during first getPrototype() call
33 boost::shared_ptr< WPrototyped > WDataSetHierarchicalClustering::m_prototype = boost::shared_ptr< WPrototyped >();
34 
36 {
37  // initialize members
38 }
39 
41  std::map< size_t, WFiberCluster::SPtr > allClusters )
42 {
43  m_rootNode = rootNode;
44  m_clusters = allClusters;
45 }
46 
47 
49 {
50  // cleanup
51 }
52 
53 boost::shared_ptr< WPrototyped > WDataSetHierarchicalClustering::getPrototype()
54 {
55  if( !m_prototype )
56  {
57  m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetHierarchicalClustering() );
58  }
59  return m_prototype;
60 }
61 
62 const std::string WDataSetHierarchicalClustering::getName() const
63 {
64  return "DataSetHierarchicalClustering";
65 }
66 
68 {
69  return "A tree of fiber clusters.";
70 }
71 
73 {
74  return m_rootNode;
75 }
76 
77 std::map< size_t, WFiberCluster::SPtr > WDataSetHierarchicalClustering::getClusterMap()
78 {
79  return m_clusters;
80 }
81 
82 
83 std::vector< WTreeNode::SPtr > WDataSetHierarchicalClustering::getClustersDownToLevel( WTreeNode::SPtr node, size_t level )
84 {
85  std::vector< WTreeNode::SPtr > result;
86 
87  if( node->level() <= level )
88  {
89  result.push_back( node );
90  return result;
91  }
92 
93  for( size_t i = 0; i < node->getChildren().size(); i++ )
94  {
95  std::vector< WTreeNode::SPtr > c = getClustersDownToLevel( node->getChildren()[i], level );
96  result.reserve( result.size() + c.size() ); // ensure capacity will last for insertion.
97  result.insert( result.end(), c.begin(), c.end() );
98  }
99 
100  return result;
101 }
102 
103 
104 
105 
106