OpenWalnut  1.4.0
WDataSetFiberClustering.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WDATASETFIBERCLUSTERING_H
00026 #define WDATASETFIBERCLUSTERING_H
00027 
00028 #include <map>
00029 #include <string>
00030 
00031 #include <boost/shared_ptr.hpp>
00032 
00033 #include "datastructures/WFiberCluster.h"
00034 
00035 #include "../common/exceptions/WInvalidID.h"
00036 #include "../common/WTransferable.h"
00037 
00038 /**
00039  * 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
00040  * fibers belonging to the clusters.
00041  *
00042  * Each cluster has its own ID. A mapping between names and IDs is possible.
00043  */
00044 class WDataSetFiberClustering: public WTransferable
00045 {
00046 public:
00047     /**
00048      * Convenience typedef for a boost::shared_ptr< WDataSetFiberClustering >.
00049      */
00050     typedef boost::shared_ptr< WDataSetFiberClustering > SPtr;
00051 
00052     /**
00053      * Convenience typedef for a boost::shared_ptr< const WDataSetFiberClustering >.
00054      */
00055     typedef boost::shared_ptr< const WDataSetFiberClustering > ConstSPtr;
00056 
00057     /**
00058      * The type of the cluster map
00059      */
00060     typedef std::map< size_t, WFiberCluster::SPtr > ClusterMap;
00061 
00062     /**
00063      * Default constructor.
00064      */
00065     WDataSetFiberClustering();
00066 
00067     /**
00068      * constructor with cluster list.
00069      *
00070      * \param clustering the cluster map defining the clustering
00071      */
00072     explicit WDataSetFiberClustering( const ClusterMap &clustering );
00073 
00074     /**
00075      * Destructor.
00076      */
00077     virtual ~WDataSetFiberClustering();
00078 
00079     /**
00080      * The name of this transferable. This is useful information for the users.
00081      *
00082      * \return the name.
00083      */
00084     virtual const std::string getName() const;
00085 
00086     /**
00087      *
00088      * The description of this transferable. This is useful information for the users.
00089      *
00090      * \return A description
00091      */
00092     virtual const std::string getDescription() const;
00093 
00094     /**
00095      * Returns a prototype instantiated with the true type of the deriving class.
00096      *
00097      * \return the prototype.
00098      */
00099     static boost::shared_ptr< WPrototyped > getPrototype();
00100 
00101     /**
00102      * Sets the cluster at the given ID. If there is a cluster at this ID, it is replaced.
00103      *
00104      * \param id the ID of the cluster
00105      * \param cluster the cluster
00106      */
00107     virtual void setCluster( size_t id, WFiberCluster::SPtr cluster );
00108 
00109     /**
00110      * Returns the cluster with the given ID.
00111      *
00112      * \throw WInvalidID if the ID is not known.
00113      *
00114      * \param id the ID of the cluster to get
00115      *
00116      * \return the cluster
00117      */
00118     virtual WFiberCluster::SPtr getCluster( size_t id );
00119 
00120     /**
00121      * Returns the cluster with the given ID.
00122      *
00123      * \throw WInvalidID if the ID is not known.
00124      *
00125      * \param id the ID of the cluster to get
00126      *
00127      * \return the cluster
00128      */
00129     virtual WFiberCluster::ConstSPtr getCluster( size_t id ) const;
00130 
00131     /**
00132      * Returns the cluster with the given ID. If there is no cluster with this ID, an empty one is returned.
00133      *
00134      * \param id the ID of the cluster to get
00135      *
00136      * \return the cluster
00137      */
00138     virtual WFiberCluster::SPtr getOrCreateCluster( size_t id );
00139 
00140     /**
00141      * Removes the cluster with the specified ID. If it does not exist, nothing happens.
00142      *
00143      * \param id the id of the cluster
00144      */
00145     virtual void removeCluster( size_t id );
00146 
00147     /**
00148      * The begin iterator of the clustering for const iteration.
00149      *
00150      * \return the begin iterator
00151      */
00152     ClusterMap::const_iterator begin() const;
00153 
00154     /**
00155      * The begin iterator of the clustering for non-const iteration.
00156      *
00157      * \return the begin iterator
00158      */
00159     ClusterMap::iterator begin();
00160 
00161     /**
00162      * The end iterator of the clustering for const iteration.
00163      *
00164      * \return the begin iterator
00165      */
00166     ClusterMap::const_iterator end() const;
00167 
00168     /**
00169      * The end iterator of the clustering for non-const iteration.
00170      *
00171      * \return the end iterator
00172      */
00173     ClusterMap::iterator end();
00174 
00175     /**
00176      * Returns the amount of clusters in the clustering
00177      *
00178      * \return the amount of clusters in the clustering
00179      */
00180     size_t size() const;
00181 
00182 protected:
00183     /**
00184      * Prototype for this dataset
00185      */
00186     static boost::shared_ptr< WPrototyped > m_prototype;
00187 private:
00188     /**
00189      * The map between ID and cluster.
00190      */
00191     std::map< size_t, WFiberCluster::SPtr > m_clusters;
00192 };
00193 
00194 #endif  // WDATASETFIBERCLUSTERING_H