OpenWalnut  1.5.0dev
WReaderClustering.h
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 #ifndef WREADERCLUSTERING_H_
26 #define WREADERCLUSTERING_H_
27 
28 #include <fstream>
29 #include <map>
30 #include <memory>
31 #include <string>
32 #include <vector>
33 
34 
35 #include "core/common/WStringUtils.h"
36 #include "core/dataHandler/WDataSetHierarchicalClustering.h"
37 #include "core/dataHandler/datastructures/WTreeNode.h"
38 #include "core/dataHandler/exceptions/WDHIOFailure.h"
39 #include "core/dataHandler/exceptions/WDHNoSuchFile.h"
40 #include "core/dataHandler/exceptions/WDHParseError.h"
41 #include "core/dataHandler/io/WReader.h"
42 
43 /**
44  * Reads a hierarchical clustering from a FDG file.
45  *
46  * \ingroup dataHandler
47  */
48 class WReaderClustering : public WReader // NOLINT
49 {
50 /**
51 * Only UnitTests may be friends.
52 */
53 friend class WReaderClusteringTest;
54 public:
55  /**
56  * Constructs and makes a new FDG reader for separate thread start.
57  *
58  * \param fname File name where to read data from
59  * \throws WDHNoSuchFile
60  */
61  explicit WReaderClustering( std::string fname );
62 
63  /**
64  * Destroys this instance and closes the file.
65  */
66  virtual ~WReaderClustering() throw();
67 
68  /**
69  * Reads the clustering file and creates a dataset out of it.
70  *
71  * \return Reference to the dataset.
72  */
73  virtual std::shared_ptr< WDataSetHierarchicalClustering > read();
74 
75 protected:
76  /**
77  * Stores the hierarchical clustering map
78  */
79  std::map< size_t, WFiberCluster::SPtr > m_clustering;
80 
81  /**
82  * Stores the hierarchical clustering map
83  */
84  std::map< size_t, WTreeNode::SPtr > m_nodes;
85 
86  /**
87  * The lines of the fdg file
88  */
89  std::vector< std::string > m_lines;
90 
91  /**
92  * The current hierarchy level the reader is reading
93  */
94  std::shared_ptr<size_t> m_level;
95 };
96 
97 #endif // WREADERCLUSTERING_H
Represents a hierarchy of clusters.
Represents a cluster of indices of a WDataSetFiberVector.
Definition: WFiberCluster.h:45
Reads a hierarchical clustering from a FDG file.
std::map< size_t, WFiberCluster::SPtr > m_clustering
Stores the hierarchical clustering map.
friend class WReaderClusteringTest
Only UnitTests may be friends.
virtual std::shared_ptr< WDataSetHierarchicalClustering > read()
Reads the clustering file and creates a dataset out of it.
std::shared_ptr< size_t > m_level
The current hierarchy level the reader is reading.
virtual ~WReaderClustering()
Destroys this instance and closes the file.
std::map< size_t, WTreeNode::SPtr > m_nodes
Stores the hierarchical clustering map.
std::vector< std::string > m_lines
The lines of the fdg file.
WReaderClustering(std::string fname)
Constructs and makes a new FDG reader for separate thread start.
Read some data from a given file.
Definition: WReader.h:40
A node in a tree, holding an index, a level in the tree and pointers to its child nodes.
Definition: WTreeNode.h:39