33 #include "WHierarchicalTreeFibers.h"
56 std::pair<size_t, size_t>tmp2;
59 m_colors.push_back( WColor( 0.3, 0.3, 0.3, 1.0 ) );
75 m_colors.push_back( WColor( 0.3, 0.3, 0.3, 1.0 ) );
77 std::pair<size_t, size_t>childs( cluster1, cluster2 );
88 std::shared_ptr< std::vector< bool > > bf;
92 bf = std::shared_ptr< std::vector< bool > >(
new std::vector< bool >(
m_leafCount,
false ) );
93 ( *bf )[cluster] =
true;
102 bf = std::shared_ptr< std::vector< bool > >(
new std::vector< bool >(
m_leafCount,
false ) );
105 for(
size_t i = 0; i < fibers.size(); ++i )
107 ( *bf )[fibers[i]] =
true;
117 std::shared_ptr< std::vector< bool > > bf;
120 bf = std::shared_ptr< std::vector< bool > >(
new std::vector< bool >(
m_leafCount,
false ) );
122 for(
size_t k = 0; k < clusters.size(); ++k )
124 size_t cluster = clusters[k];
126 for(
size_t i = 0; i < fibers.size(); ++i )
128 ( *bf )[fibers[i]] =
true;
140 std::list<size_t>candidateList;
142 std::queue<size_t>worklist;
145 while( !worklist.empty() )
147 size_t current = worklist.front();
152 candidateList.push_back( current );
158 std::pair<size_t, size_t> children =
getChildren( current );
159 if(
getLevel( children.first ) > 0 )
161 worklist.push( children.first );
163 if(
getLevel( children.second ) > 0 )
165 worklist.push( children.second );
170 candidateList.sort(
compSize(
this ) );
172 std::vector<size_t>returnList;
174 std::list<size_t>::iterator it;
175 for( it = candidateList.begin(); it != candidateList.end(); ++it )
177 size_t current = *it;
178 returnList.push_back( current );
194 size_t countFibersInCluster = fibersInCluster.size();
195 size_t fibersFromClusterActive = 0;
197 for(
size_t i = 0; i < countFibersInCluster; ++i )
201 ++fibersFromClusterActive;
204 return static_cast<float>( fibersFromClusterActive ) /
static_cast<float>( countFibersInCluster );
~WHierarchicalTreeFibers()
destructor
void addCluster(size_t cluster1, size_t cluster2, size_t level, std::vector< size_t > leafes, float customData)
adds a cluster to the set, it combines 2 already existing clusters
std::shared_ptr< std::vector< bool > > m_roiSelection
stores a pointer to the bitfield by the current roi setting
std::shared_ptr< std::vector< bool > > getOutputBitfield(size_t cluster)
generates a bitfield where for every leaf in the selected cluster the value is true,...
std::vector< size_t > getBestClustersFittingRoi(float ratio=0.9, size_t number=1)
finds clusters that match a given ROI up to a certain percentage
WHierarchicalTreeFibers()
standard constructor
void addLeaf()
A leaf is at the very bottom of the tree, it represents a single fiber or voxel, for several purposes...
float getRatio(size_t cluster)
calculates the ratio of fibers in the roi for a given cluster
base class for hierarchical tree implementations
std::vector< float > m_customData
custom data for each cluster, this may some energy or similarity level generated by the clustering al...
std::vector< WColor > m_colors
a color value for each cluster
size_t m_clusterCount
overall number of cluster, counts both leafes ( clusters of size one ) and real clusters
std::vector< std::pair< size_t, size_t > > m_children
vector that stores the 2 children of each cluster, contains an empty pair for leafes
std::pair< size_t, size_t > getChildren(size_t cluster) const
getter
std::vector< size_t > m_parents
vector that stores the parent cluster for each cluster
size_t m_leafCount
number of leaf nodes
size_t m_maxLevel
the maximum level, naturally the level of the root node
size_t getLevel(size_t cluster) const
getter
std::vector< size_t > m_level
vector that stores the level of each cluster, the level is the maximum of the levels of the child clu...
bool m_leafesLocked
to enforce valid datastructures there will be no leaf with an id higher than a cluster,...
std::vector< std::vector< size_t > > m_containsLeafes
vector that stores the leaf id's for each cluster, this is quite memory intensive but speeds up selec...
size_t getClusterCount() const
getter
implements a compare operator for clusters, depending on leaf count