OpenWalnut  1.5.0dev
WDataSetFiberClustering.cpp
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 #include <map>
26 #include <memory>
27 #include <string>
28 
29 #include "WDataSetFiberClustering.h"
30 
31 // The prototype as singleton. Created during first getPrototype() call
32 std::shared_ptr< WPrototyped > WDataSetFiberClustering::m_prototype = std::shared_ptr< WPrototyped >();
33 
35 {
36  // initialize members
37 }
38 
40 {
41  m_clusters = clustering;
42 }
43 
44 
46 {
47  // cleanup
48 }
49 
50 std::shared_ptr< WPrototyped > WDataSetFiberClustering::getPrototype()
51 {
52  if( !m_prototype )
53  {
54  m_prototype = std::shared_ptr< WPrototyped >( new WDataSetFiberClustering() );
55  }
56  return m_prototype;
57 }
58 
59 const std::string WDataSetFiberClustering::getName() const
60 {
61  return "DataSetFiberClustering";
62 }
63 
64 const std::string WDataSetFiberClustering::getDescription() const
65 {
66  return "A collection of fiber clusters.";
67 }
68 
70 {
71  m_clusters[ id ] = cluster;
72 }
73 
75 {
76  WFiberCluster::SPtr result = m_clusters[ id ];
77  if( !result )
78  {
79  throw WInvalidID( "The cluster with the specified ID does not exist." );
80  }
81  return result;
82 }
83 
85 {
86  ClusterMap::const_iterator it = m_clusters.find( id );
87  if( it == m_clusters.end() )
88  {
89  throw WInvalidID( "The cluster with the specified ID does not exist." );
90  }
91  return it->second;
92 }
93 
95 {
96  WFiberCluster::SPtr result = m_clusters[ id ];
97  if( !result )
98  {
99  // create an empty one
100  WFiberCluster::SPtr newCluster( new WFiberCluster() );
101  m_clusters[ id ] = newCluster;
102  return newCluster;
103  }
104  return result;
105 }
106 
108 {
109  if( !m_clusters.count( id ) )
110  {
111  return;
112  }
113  m_clusters.erase( id );
114 }
115 
116 WDataSetFiberClustering::ClusterMap::const_iterator WDataSetFiberClustering::begin() const
117 {
118  return m_clusters.begin();
119 }
120 
121 WDataSetFiberClustering::ClusterMap::iterator WDataSetFiberClustering::begin()
122 {
123  return m_clusters.begin();
124 }
125 
126 WDataSetFiberClustering::ClusterMap::const_iterator WDataSetFiberClustering::end() const
127 {
128  return m_clusters.end();
129 }
130 
131 WDataSetFiberClustering::ClusterMap::iterator WDataSetFiberClustering::end()
132 {
133  return m_clusters.end();
134 }
135 
137 {
138  return m_clusters.size();
139 }
140 
141 
virtual WFiberCluster::SPtr getOrCreateCluster(size_t id)
Returns the cluster with the given ID.
static std::shared_ptr< WPrototyped > m_prototype
Prototype for this dataset.
WDataSetFiberClustering()
Default constructor.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
virtual ~WDataSetFiberClustering()
Destructor.
ClusterMap::const_iterator begin() const
The begin iterator of the clustering for const iteration.
size_t size() const
Returns the amount of clusters in the clustering.
virtual const std::string getName() const
The name of this transferable.
ClusterMap::const_iterator end() const
The end iterator of the clustering for const iteration.
virtual const std::string getDescription() const
The description of this transferable.
virtual void setCluster(size_t id, WFiberCluster::SPtr cluster)
Sets the cluster at the given ID.
std::map< size_t, WFiberCluster::SPtr > m_clusters
The map between ID and cluster.
std::map< size_t, WFiberCluster::SPtr > ClusterMap
The type of the cluster map.
virtual WFiberCluster::SPtr getCluster(size_t id)
Returns the cluster with the given ID.
virtual void removeCluster(size_t id)
Removes the cluster with the specified ID.
Represents a cluster of indices of a WDataSetFiberVector.
Definition: WFiberCluster.h:45
std::shared_ptr< WFiberCluster > SPtr
Shared pointer abbreviation.
Definition: WFiberCluster.h:51
std::shared_ptr< const WFiberCluster > ConstSPtr
Const shared pointer abbreviation.
Definition: WFiberCluster.h:56
Indicates invalid element access of a container.
Definition: WInvalidID.h:37