OpenWalnut  1.4.0
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 <string>
26 #include <map>
27 #include "WDataSetFiberClustering.h"
28 
29 // The prototype as singleton. Created during first getPrototype() call
30 boost::shared_ptr< WPrototyped > WDataSetFiberClustering::m_prototype = boost::shared_ptr< WPrototyped >();
31 
33 {
34  // initialize members
35 }
36 
38 {
39  m_clusters = clustering;
40 }
41 
42 
44 {
45  // cleanup
46 }
47 
48 boost::shared_ptr< WPrototyped > WDataSetFiberClustering::getPrototype()
49 {
50  if( !m_prototype )
51  {
52  m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetFiberClustering() );
53  }
54  return m_prototype;
55 }
56 
57 const std::string WDataSetFiberClustering::getName() const
58 {
59  return "DataSetFiberClustering";
60 }
61 
62 const std::string WDataSetFiberClustering::getDescription() const
63 {
64  return "A collection of fiber clusters.";
65 }
66 
68 {
69  m_clusters[ id ] = cluster;
70 }
71 
73 {
74  WFiberCluster::SPtr result = m_clusters[ id ];
75  if( !result )
76  {
77  throw WInvalidID( "The cluster with the specified ID does not exist." );
78  }
79  return result;
80 }
81 
83 {
84  ClusterMap::const_iterator it = m_clusters.find( id );
85  if( it == m_clusters.end() )
86  {
87  throw WInvalidID( "The cluster with the specified ID does not exist." );
88  }
89  return it->second;
90 }
91 
93 {
94  WFiberCluster::SPtr result = m_clusters[ id ];
95  if( !result )
96  {
97  // create an empty one
98  WFiberCluster::SPtr newCluster( new WFiberCluster() );
99  m_clusters[ id ] = newCluster;
100  return newCluster;
101  }
102  return result;
103 }
104 
106 {
107  if( !m_clusters.count( id ) )
108  {
109  return;
110  }
111  m_clusters.erase( id );
112 }
113 
114 WDataSetFiberClustering::ClusterMap::const_iterator WDataSetFiberClustering::begin() const
115 {
116  return m_clusters.begin();
117 }
118 
119 WDataSetFiberClustering::ClusterMap::iterator WDataSetFiberClustering::begin()
120 {
121  return m_clusters.begin();
122 }
123 
124 WDataSetFiberClustering::ClusterMap::const_iterator WDataSetFiberClustering::end() const
125 {
126  return m_clusters.end();
127 }
128 
129 WDataSetFiberClustering::ClusterMap::iterator WDataSetFiberClustering::end()
130 {
131  return m_clusters.end();
132 }
133 
135 {
136  return m_clusters.size();
137 }
138 
139