Commit a104fbfe authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] added improved version of Davids WHtree implementation

parent 771c29e9
......@@ -33,6 +33,15 @@
// www.cbs.mpg.de/~moreno//
// This file is also part of OpenWalnut ( http://www.openwalnut.org ).
//
// For more reference on the underlying algorithm and research they have been used for refer to:
// - Moreno-Dominguez, D., Anwander, A., & Knösche, T. R. (2014).
// A hierarchical method for whole-brain connectivity-based parcellation.
// Human Brain Mapping, 35(10), 5000-5025. doi: http://dx.doi.org/10.1002/hbm.22528
// - Moreno-Dominguez, D. (2014).
// Whole-brain cortical parcellation: A hierarchical method based on dMRI tractography.
// PhD Thesis, Max Planck Institute for Human Cognitive and Brain Sciences, Leipzig.
// ISBN 978-3-941504-45-5
//
// hClustering is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
......@@ -70,10 +79,21 @@ WHtree::WHtree( std::string filename ): m_loadStatus( false ), m_cpcc( 0 )
readTree( filename );
}
WHtree::WHtree( std::string treeName, WHcoord datasetSizeInit, std::vector<WHnode> leavesInit, std::vector<WHnode> nodesInit,
std::vector<WHcoord> coordInit, std::list<WHcoord> discardInit, HC_GRID datasetGridInit, float cpccInit ):
m_loadStatus( false ), m_datasetSize( datasetSizeInit ), m_datasetGrid( datasetGridInit ), m_cpcc( cpccInit ), m_treeName( treeName ),
m_leaves( leavesInit ), m_nodes( nodesInit ), m_coordinates( coordInit ), m_discarded( discardInit )
WHtree::WHtree( std::string treeName, HC_GRID datasetGridInit, WHcoord datasetSizeInit, size_t numStreamlinesInit, float logFactorInit,
std::vector< WHnode > leavesInit, std::vector< WHnode > nodesInit, std::vector< size_t > trackidInit,
std::vector< WHcoord > coordInit, std::list< WHcoord > discardInit, float cpccInit )
: m_loadStatus( false ),
m_datasetSize( datasetSizeInit ),
m_datasetGrid( datasetGridInit ),
m_numStreamlines( numStreamlinesInit ),
m_logFactor( logFactorInit ),
m_cpcc( cpccInit ),
m_treeName( treeName ),
m_leaves( leavesInit ),
m_nodes( nodesInit ),
m_coordinates( coordInit ),
m_trackids( trackidInit ),
m_discarded( discardInit )
{
if( check() )
{
......@@ -81,10 +101,20 @@ WHtree::WHtree( std::string treeName, WHcoord datasetSizeInit, std::vector<WHnod
}
}
WHtree::WHtree( const WHtree &object ):
m_loadStatus( object.m_loadStatus ), m_datasetSize( object.m_datasetSize ), m_datasetGrid( object.m_datasetGrid ), m_cpcc( object.m_cpcc ),
m_treeName( object.m_treeName ), m_leaves( object.m_leaves ), m_nodes( object.m_nodes ), m_coordinates( object.m_coordinates ),
m_discarded( object.m_discarded ), m_containedLeaves( object.m_containedLeaves )
WHtree::WHtree( const WHtree &object )
: m_loadStatus( object.m_loadStatus ),
m_datasetSize( object.m_datasetSize ),
m_datasetGrid( object.m_datasetGrid ),
m_numStreamlines( object.m_numStreamlines ),
m_logFactor( object.m_logFactor ),
m_cpcc( object.m_cpcc ),
m_treeName( object.m_treeName ),
m_leaves( object.m_leaves ),
m_nodes( object.m_nodes ),
m_coordinates( object.m_coordinates ),
m_trackids( object.m_trackids ),
m_discarded( object.m_discarded ),
m_containedLeaves( object.m_containedLeaves )
{
}
......@@ -904,6 +934,57 @@ bool WHtree::readTree( const std::string &filename )
m_datasetSize = datasetSize;
}
{
std::vector< std::vector< std::string > > streamNumberStrings = parser.getLinesForTagSeparated( "streams" );
if( streamNumberStrings.size() == 0 )
{
std::cerr << "WARNING @ WHtree::readTree(): tracking streams number was not found in tree file,";
std::cerr << " assuming streams=0 for compatibility" << std::endl;
m_numStreamlines = 0;
}
if( streamNumberStrings.size() > 1 )
{
std::cerr << "ERROR @ WHtree::readTree(): tracking streams number attribute has multiple lines" << std::endl;
return false;
}
if( streamNumberStrings[0].size() > 1 )
{
std::cerr << "ERROR @ WHtree::readTree(): tracking streams number attribute has multiple elements" << std::endl;
return false;
}
m_numStreamlines = string_utils::fromString< size_t >( streamNumberStrings[0][0] );
}
{
std::vector< std::vector< std::string > >logFactorStrings = parser.getLinesForTagSeparated( "logfactor" );
if( logFactorStrings.size() == 0 )
{
std::cerr << "WARNING @ WHtree::readTree(): logarithmic normalization factor was not found in tree file,";
std::cerr << " assuming logFactor=0 for compatibility" << std::endl;
m_logFactor = 0;
}
if( logFactorStrings.size() > 1 )
{
std::cerr << "ERROR @ WHtree::readTree():";
std::cerr << "logarithmic normalization factor attribute has multiple lines" << std::endl;
return false;
}
if( logFactorStrings[0].size() > 1 )
{
std::cerr << "ERROR @ WHtree::readTree(): logarithmic normalization factor attribute has multiple elements" << std::endl;
return false;
}
m_logFactor = string_utils::fromString< float >( logFactorStrings[0][0] );
if( m_logFactor != 0 && m_numStreamlines != 0 && m_logFactor != log10( m_numStreamlines ) )
{
std::cerr << "ERROR @ WHtree::readTree(): tracking streams number (";
std::cerr << m_numStreamlines << ") and logarithmic normalization factor (";
std::cerr << m_logFactor << ") are a missmatch " << std::endl;
return false;
}
}
{
std::vector< std::vector< std::string> >coordStrings = parser.getLinesForTagSeparated( "coordinates" );
m_coordinates.reserve( coordStrings.size() );
......@@ -1150,6 +1231,10 @@ bool WHtree::writeTree( const std::string &filename, const bool niftiMode ) cons
outFile << "#cpcc" << std::endl << string_utils::toString( m_cpcc ) << std::endl << "#endcpcc" << std::endl << std::endl;
}
outFile << "#streams" << std::endl << m_numStreamlines << std::endl << "#endstreams" << std::endl;
outFile << "#logfactor" << std::endl << m_logFactor << std::endl << "#endlogfactor" << std::endl;
outFile << "#coordinates" << std::endl;
for( std::vector<WHcoord>::const_iterator coordIter( m_coordinates.begin() ) ; coordIter != m_coordinates.end() ; ++coordIter )
{
......@@ -1266,7 +1351,13 @@ bool WHtree::writeTreeDebug( const std::string &filename ) const
outFile << "Dataset size: " << m_datasetSize << " " << getGridString( m_datasetGrid ) << std::endl;
if( m_cpcc != 0 )
{
outFile << "CPCC: " << string_utils::toString( m_cpcc ) << std::endl << std::endl;
}
outFile << "Streamlines per seed voxel: " << m_numStreamlines << std::endl;
outFile << "Logarithmic normalization factor: " << m_logFactor << std::endl << std::endl;
outFile << "============LEAVES============" << std::endl << std::endl;
for( std::vector<WHnode>::const_iterator leafIter( m_leaves.begin() ); leafIter != m_leaves.end(); ++leafIter )
......
......@@ -33,6 +33,15 @@
// www.cbs.mpg.de/~moreno//
// This file is also part of OpenWalnut ( http://www.openwalnut.org ).
//
// For more reference on the underlying algorithm and research they have been used for refer to:
// - Moreno-Dominguez, D., Anwander, A., & Knösche, T. R. (2014).
// A hierarchical method for whole-brain connectivity-based parcellation.
// Human Brain Mapping, 35(10), 5000-5025. doi: http://dx.doi.org/10.1002/hbm.22528
// - Moreno-Dominguez, D. (2014).
// Whole-brain cortical parcellation: A hierarchical method based on dMRI tractography.
// PhD Thesis, Max Planck Institute for Human Cognitive and Brain Sciences, Leipzig.
// ISBN 978-3-941504-45-5
//
// hClustering is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
......@@ -89,16 +98,20 @@ public:
/**
* Constructor
* \param treeName name of the tree
* \param datasetGridInit type of grid coordinate space
* \param datasetSizeInit size of the brain dataset
* \param numStreamlinesInit number of streamlines per voxel on the tractograms that were processed to build this tree
* \param logFactorInit logarithmic normalization factor that was applied on the tracts when building the tree
* \param leavesInit vector of leaves
* \param nodesInit vector of nodes
* \param trackidInit vector of seed track ids
* \param coordInit vector of seed voxel coordinates
* \param discardInit vector of discarded seed voxel coordinates
* \param datasetGridInit type of grid coordinate space
* \param cpccInit cpcc value of the tree
*/
explicit WHtree( std::string treeName, WHcoord datasetSizeInit, std::vector<WHnode> leavesInit, std::vector<WHnode> nodesInit,
std::vector<WHcoord> coordInit, std::list<WHcoord> discardInit, HC_GRID datasetGridInit, float cpccInit = 0 );
explicit WHtree( std::string treeName, HC_GRID datasetGridInit, WHcoord datasetSizeInit, size_t numStreamlinesInit, float logFactorInit,
std::vector<WHnode> leavesInit, std::vector<WHnode> nodesInit, std::vector<size_t> trackidInit, std::vector<WHcoord> coordInit,
std::list<WHcoord> discardInit, float cpccInit = 0 );
/**
* Constructor
......@@ -136,11 +149,23 @@ public:
size_t getNumLeaves() const;
/**
* Returns the number of leaves of the tree
* Returns the number of nodes of the tree
* \return number of leaves
*/
size_t getNumNodes() const;
/**
* Returns the leaves of the tree
* \return leaves vector
*/
std::vector<WHnode> getLeaves() const;
/**
* Returns the nodes of the tree
* \return nodes vector
*/
std::vector<WHnode> getNodes() const;
/**
* Returns the number of leaves of the tree
* \return number of leaves
......@@ -571,7 +596,7 @@ public:
friend class WHtreeProcesser;
friend class WHtreePartition;
friend class cnbTreeBuilder;
friend class CnbTreeBuilder;
friend class graphTreeBuilder;
friend class randCnbTreeBuilder;
friend class treeComparer;
......@@ -593,6 +618,12 @@ private:
//! Stores the the type of coordinate grid of the dataset
HC_GRID m_datasetGrid;
//! number of streamlines generated form each seed voxel in the tractograms used to build the tree
size_t m_numStreamlines;
//! logarithmic normalization factor used in the tractograms when building the tree
float m_logFactor;
//! Stores the cpcc value of the tree
float m_cpcc;
......@@ -798,6 +829,15 @@ inline size_t WHtree::getNumNodes() const
return m_nodes.size();
}
inline std::vector<WHnode> WHtree::getLeaves() const
{
return m_leaves;
}
inline std::vector<WHnode> WHtree::getNodes() const
{
return m_nodes;
}
inline size_t WHtree::getNumDiscarded() const
{
return m_discarded.size();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment