33 #include <boost/regex.hpp>
35 #include "WReaderClustering.h"
36 #include "core/common/WAssert.h"
37 #include "core/common/WIOTools.h"
38 #include "core/common/WLimits.h"
39 #include "core/common/WLogger.h"
40 #include "core/common/WStringUtils.h"
41 #include "core/dataHandler/WDataSetHierarchicalClustering.h"
42 #include "core/dataHandler/datastructures/WFiberCluster.h"
43 #include "core/dataHandler/exceptions/WDHIOFailure.h"
44 #include "core/dataHandler/exceptions/WDHNoSuchFile.h"
45 #include "core/dataHandler/exceptions/WDHParseError.h"
60 std::shared_ptr< std::ifstream > ifs(
new std::ifstream() );
61 ifs->open(
m_fname.c_str(), std::ifstream::in | std::ifstream::binary );
62 if( !ifs || ifs->bad() )
64 throw WDHIOFailure( std::string(
"internal error while opening file" ) );
67 std::vector< std::string > lines;
73 getline( *ifs, line );
74 lines.push_back( std::string( line ) );
79 for(
size_t i = 0; i < lines.size() - 1; ++i )
81 std::string &ls = lines[i];
83 boost::regex reg1(
"\\(" );
84 ls = boost::regex_replace( ls, reg1,
"(," );
86 boost::regex reg2(
"\\)" );
87 ls = boost::regex_replace( ls, reg2,
",)" );
89 boost::regex reg3(
"\\ " );
90 ls = boost::regex_replace( ls, reg3,
"" );
93 std::vector<std::string>svec;
96 for(
size_t i = 0; i < lines.size() - 1; ++i )
99 boost::regex reg(
"," );
100 boost::sregex_token_iterator it( lines[i].begin(), lines[i].end(), reg, -1 );
101 boost::sregex_token_iterator end;
104 svec.push_back( *it++ );
107 size_t level = string_utils::fromString< size_t >( svec[1] );
111 std::list< size_t > indices;
114 while( svec[k] !=
")" && svec[k] !=
"" )
116 indices.push_back( string_utils::fromString< size_t >( svec[k] ) );
119 WColor color( 1.0, 1.0, 0.0, 1.0 );
127 std::list< size_t > indices;
130 while( svec[k] !=
")" )
132 indices.push_back( string_utils::fromString< size_t >( svec[k] ) );
136 WColor color( 0.1 * ( i % 10 ), 0.1 * ( ( i + 5 ) % 10 ), 0.0, 1.0 );
144 std::vector< size_t > childIndices;
145 while( svec[k] !=
")" )
147 childIndices.push_back( string_utils::fromString< size_t >( svec[k] ) );
151 for(
size_t j = 0; j < childIndices.size(); j++ )
154 m_nodes[ i ]->addChild( childNode );
Use this for IO error handling.
Represents a hierarchy of clusters.
std::shared_ptr< WDataSetHierarchicalClustering > SPtr
Pointer to dataset.
Represents a cluster of indices of a WDataSetFiberVector.
std::shared_ptr< WFiberCluster > SPtr
Shared pointer abbreviation.
std::map< size_t, WFiberCluster::SPtr > m_clustering
Stores the hierarchical clustering map.
virtual std::shared_ptr< WDataSetHierarchicalClustering > read()
Reads the clustering file and creates a dataset out of it.
virtual ~WReaderClustering()
Destroys this instance and closes the file.
std::map< size_t, WTreeNode::SPtr > m_nodes
Stores the hierarchical clustering map.
WReaderClustering(std::string fname)
Constructs and makes a new FDG reader for separate thread start.
Read some data from a given file.
std::string m_fname
Absolute path of the file to read from.
A node in a tree, holding an index, a level in the tree and pointers to its child nodes.
std::shared_ptr< WTreeNode > SPtr
Shared pointer abbreviation.