OpenWalnut  1.4.0
WDataSetFiberClustering.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 WDATASETFIBERCLUSTERING_H
26 #define WDATASETFIBERCLUSTERING_H
27 
28 #include <map>
29 #include <string>
30 
31 #include <boost/shared_ptr.hpp>
32 
33 #include "datastructures/WFiberCluster.h"
34 
35 #include "../common/exceptions/WInvalidID.h"
36 #include "../common/WTransferable.h"
37 
38 /**
39  * This is a dataset which represent a clustering of fibers. It does not itself contain the fiber-data. This dataset only contains the indices of
40  * fibers belonging to the clusters.
41  *
42  * Each cluster has its own ID. A mapping between names and IDs is possible.
43  */
45 {
46 public:
47  /**
48  * Convenience typedef for a boost::shared_ptr< WDataSetFiberClustering >.
49  */
50  typedef boost::shared_ptr< WDataSetFiberClustering > SPtr;
51 
52  /**
53  * Convenience typedef for a boost::shared_ptr< const WDataSetFiberClustering >.
54  */
55  typedef boost::shared_ptr< const WDataSetFiberClustering > ConstSPtr;
56 
57  /**
58  * The type of the cluster map
59  */
60  typedef std::map< size_t, WFiberCluster::SPtr > ClusterMap;
61 
62  /**
63  * Default constructor.
64  */
66 
67  /**
68  * constructor with cluster list.
69  *
70  * \param clustering the cluster map defining the clustering
71  */
72  explicit WDataSetFiberClustering( const ClusterMap &clustering );
73 
74  /**
75  * Destructor.
76  */
77  virtual ~WDataSetFiberClustering();
78 
79  /**
80  * The name of this transferable. This is useful information for the users.
81  *
82  * \return the name.
83  */
84  virtual const std::string getName() const;
85 
86  /**
87  *
88  * The description of this transferable. This is useful information for the users.
89  *
90  * \return A description
91  */
92  virtual const std::string getDescription() const;
93 
94  /**
95  * Returns a prototype instantiated with the true type of the deriving class.
96  *
97  * \return the prototype.
98  */
99  static boost::shared_ptr< WPrototyped > getPrototype();
100 
101  /**
102  * Sets the cluster at the given ID. If there is a cluster at this ID, it is replaced.
103  *
104  * \param id the ID of the cluster
105  * \param cluster the cluster
106  */
107  virtual void setCluster( size_t id, WFiberCluster::SPtr cluster );
108 
109  /**
110  * Returns the cluster with the given ID.
111  *
112  * \throw WInvalidID if the ID is not known.
113  *
114  * \param id the ID of the cluster to get
115  *
116  * \return the cluster
117  */
118  virtual WFiberCluster::SPtr getCluster( size_t id );
119 
120  /**
121  * Returns the cluster with the given ID.
122  *
123  * \throw WInvalidID if the ID is not known.
124  *
125  * \param id the ID of the cluster to get
126  *
127  * \return the cluster
128  */
129  virtual WFiberCluster::ConstSPtr getCluster( size_t id ) const;
130 
131  /**
132  * Returns the cluster with the given ID. If there is no cluster with this ID, an empty one is returned.
133  *
134  * \param id the ID of the cluster to get
135  *
136  * \return the cluster
137  */
138  virtual WFiberCluster::SPtr getOrCreateCluster( size_t id );
139 
140  /**
141  * Removes the cluster with the specified ID. If it does not exist, nothing happens.
142  *
143  * \param id the id of the cluster
144  */
145  virtual void removeCluster( size_t id );
146 
147  /**
148  * The begin iterator of the clustering for const iteration.
149  *
150  * \return the begin iterator
151  */
152  ClusterMap::const_iterator begin() const;
153 
154  /**
155  * The begin iterator of the clustering for non-const iteration.
156  *
157  * \return the begin iterator
158  */
159  ClusterMap::iterator begin();
160 
161  /**
162  * The end iterator of the clustering for const iteration.
163  *
164  * \return the begin iterator
165  */
166  ClusterMap::const_iterator end() const;
167 
168  /**
169  * The end iterator of the clustering for non-const iteration.
170  *
171  * \return the end iterator
172  */
173  ClusterMap::iterator end();
174 
175  /**
176  * Returns the amount of clusters in the clustering
177  *
178  * \return the amount of clusters in the clustering
179  */
180  size_t size() const;
181 
182 protected:
183  /**
184  * Prototype for this dataset
185  */
186  static boost::shared_ptr< WPrototyped > m_prototype;
187 private:
188  /**
189  * The map between ID and cluster.
190  */
191  std::map< size_t, WFiberCluster::SPtr > m_clusters;
192 };
193 
194 #endif // WDATASETFIBERCLUSTERING_H