OpenWalnut  1.5.0dev
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 <memory>
28 #include <string>
29 #include <vector>
30 
31 #include "WDataSetHierarchicalClustering.h"
32 
33 // The prototype as singleton. Created during first getPrototype() call
34 std::shared_ptr< WPrototyped > WDataSetHierarchicalClustering::m_prototype = std::shared_ptr< WPrototyped >();
35 
37 {
38  // initialize members
39 }
40 
42  std::map< size_t, WFiberCluster::SPtr > allClusters )
43 {
44  m_rootNode = rootNode;
45  m_clusters = allClusters;
46 }
47 
48 
50 {
51  // cleanup
52 }
53 
54 std::shared_ptr< WPrototyped > WDataSetHierarchicalClustering::getPrototype()
55 {
56  if( !m_prototype )
57  {
58  m_prototype = std::shared_ptr< WPrototyped >( new WDataSetHierarchicalClustering() );
59  }
60  return m_prototype;
61 }
62 
63 const std::string WDataSetHierarchicalClustering::getName() const
64 {
65  return "DataSetHierarchicalClustering";
66 }
67 
69 {
70  return "A tree of fiber clusters.";
71 }
72 
74 {
75  return m_rootNode;
76 }
77 
78 std::map< size_t, WFiberCluster::SPtr > WDataSetHierarchicalClustering::getClusterMap()
79 {
80  return m_clusters;
81 }
82 
83 
84 std::vector< WTreeNode::SPtr > WDataSetHierarchicalClustering::getClustersDownToLevel( WTreeNode::SPtr node, size_t level )
85 {
86  std::vector< WTreeNode::SPtr > result;
87 
88  if( node->level() <= level )
89  {
90  result.push_back( node );
91  return result;
92  }
93 
94  for( size_t i = 0; i < node->getChildren().size(); i++ )
95  {
96  std::vector< WTreeNode::SPtr > c = getClustersDownToLevel( node->getChildren()[i], level );
97  result.reserve( result.size() + c.size() ); // ensure capacity will last for insertion.
98  result.insert( result.end(), c.begin(), c.end() );
99  }
100 
101  return result;
102 }
103 
104 
105 
106 
107 
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
virtual const std::string getName() const
Gets the name of this prototype.
std::vector< WTreeNode::SPtr > getClustersDownToLevel(WTreeNode::SPtr node, size_t level)
Returns all clusters down (root node has highest level) to a certain level in the hierarchy.
WTreeNode::SPtr m_rootNode
Pointer to the root cluster.
WTreeNode::SPtr getRootNode()
Returns the root cluster.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
std::map< size_t, WFiberCluster::SPtr > m_clusters
Stores the cluster map.
WDataSetHierarchicalClustering()
Constructs a new set of tracts.
std::map< size_t, WFiberCluster::SPtr > getClusterMap()
Returns the whole cluster map.
virtual const std::string getDescription() const
Gets the description for this prototype.
std::shared_ptr< WTreeNode > SPtr
Shared pointer abbreviation.
Definition: WTreeNode.h:44