OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #include <list> 00026 #include <map> 00027 #include <string> 00028 #include <vector> 00029 00030 #include "WDataSetHierarchicalClustering.h" 00031 00032 // The prototype as singleton. Created during first getPrototype() call 00033 boost::shared_ptr< WPrototyped > WDataSetHierarchicalClustering::m_prototype = boost::shared_ptr< WPrototyped >(); 00034 00035 WDataSetHierarchicalClustering::WDataSetHierarchicalClustering() 00036 { 00037 // initialize members 00038 } 00039 00040 WDataSetHierarchicalClustering::WDataSetHierarchicalClustering( WTreeNode::SPtr rootNode, 00041 std::map< size_t, WFiberCluster::SPtr > allClusters ) 00042 { 00043 m_rootNode = rootNode; 00044 m_clusters = allClusters; 00045 } 00046 00047 00048 WDataSetHierarchicalClustering::~WDataSetHierarchicalClustering() 00049 { 00050 // cleanup 00051 } 00052 00053 boost::shared_ptr< WPrototyped > WDataSetHierarchicalClustering::getPrototype() 00054 { 00055 if( !m_prototype ) 00056 { 00057 m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetHierarchicalClustering() ); 00058 } 00059 return m_prototype; 00060 } 00061 00062 const std::string WDataSetHierarchicalClustering::getName() const 00063 { 00064 return "DataSetHierarchicalClustering"; 00065 } 00066 00067 const std::string WDataSetHierarchicalClustering::getDescription() const 00068 { 00069 return "A tree of fiber clusters."; 00070 } 00071 00072 WTreeNode::SPtr WDataSetHierarchicalClustering::getRootNode() 00073 { 00074 return m_rootNode; 00075 } 00076 00077 std::map< size_t, WFiberCluster::SPtr > WDataSetHierarchicalClustering::getClusterMap() 00078 { 00079 return m_clusters; 00080 } 00081 00082 00083 std::vector< WTreeNode::SPtr > WDataSetHierarchicalClustering::getClustersDownToLevel( WTreeNode::SPtr node, size_t level ) 00084 { 00085 std::vector< WTreeNode::SPtr > result; 00086 00087 if( node->level() <= level ) 00088 { 00089 result.push_back( node ); 00090 return result; 00091 } 00092 00093 for( size_t i = 0; i < node->getChildren().size(); i++ ) 00094 { 00095 std::vector< WTreeNode::SPtr > c = getClustersDownToLevel( node->getChildren()[i], level ); 00096 result.reserve( result.size() + c.size() ); // ensure capacity will last for insertion. 00097 result.insert( result.end(), c.begin(), c.end() ); 00098 } 00099 00100 return result; 00101 } 00102 00103 00104 00105 00106