cmeans.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2015 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 #include <mia/core/probmap.hh>
23 #include <mia/core/factory.hh>
24 
26 
27 
28 
30 public:
31  typedef std::vector<double> DVector;
32  typedef std::vector<std::pair<int, unsigned long>> SparseHistogram;
33  typedef std::vector<std::pair<double, double>> NormalizedHistogram;
34 
36  public:
37  typedef std::pair<double, DVector> value_type;
38  typedef std::vector<std::pair<double, DVector>> Map;
39 
40  SparseProbmap() = delete;
41  SparseProbmap (size_t size);
42  SparseProbmap (const std::string& filename);
43 
44  value_type& operator [](int i){
45  return m_map[i];
46  }
47 
48  const value_type& operator [](int i) const{
49  return m_map[i];
50  }
51 
52  Map::const_iterator begin() const {
53  return m_map.begin();
54  }
55  Map::iterator begin() {
56  return m_map.begin();
57  }
58 
59  Map::const_iterator end() const {
60  return m_map.end();
61  }
62  Map::iterator end() {
63  return m_map.end();
64  }
65 
66  bool save(const std::string& filename) const;
67 
68 
69  DVector get_fuzzy(double x) const;
70 
71  size_t size() const {
72  return m_map.size();
73  }
74  private:
75  Map m_map;
76 
77  };
78 
79 
81  public:
84  static const char *data_descr;
85  static const char *type_descr;
86  virtual DVector run(const NormalizedHistogram& nh) const = 0;
87  };
88  typedef std::shared_ptr<Initializer> PInitializer;
89 
90  CMeans(double k, double epsilon, PInitializer class_center_initializer);
91 
92  ~CMeans();
93 
94  SparseProbmap run(const SparseHistogram& histogram, DVector& class_centers) const;
95 
96 private:
97  PInitializer m_cci;
98  struct CMeansImpl *impl;
99 
100 };
101 
102 
103 
105 
106 // the class that has only the size as a parameter
108 public:
109  CMeansInitializerSizedPlugin(const char *name);
110 protected:
111  size_t get_size_param() const;
112 private:
113  size_t m_size;
114 
115 };
116 
118 extern template class EXPORT_CORE TFactory<CMeans::Initializer>;
119 
120 template <> const char * const TPluginHandler<TFactory<CMeans::Initializer>>::m_help;
121 
123 
125 
126 
127 
128 
130 
134 
135 
137 
std::shared_ptr< Initializer > PInitializer
Definition: cmeans.hh:88
size_t size() const
Definition: cmeans.hh:71
the singleton that a plug-in handler really is
Definition: handler.hh:155
THandlerSingleton< TFactoryPluginHandler< CMeansInitializerPlugin > > CMeansInitializerPluginHandler
Definition: cmeans.hh:129
std::vector< std::pair< double, DVector > > Map
Definition: cmeans.hh:38
std::vector< std::pair< int, unsigned long > > SparseHistogram
Definition: cmeans.hh:32
TFactory< CMeans::Initializer > CMeansInitializerPlugin
Definition: cmeans.hh:104
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:43
Definition: cmeans.hh:29
Map::const_iterator begin() const
Definition: cmeans.hh:52
Initializer plugin_data
Definition: cmeans.hh:82
Map::iterator end()
Definition: cmeans.hh:62
#define FACTORY_TRAIT(F)
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:49
std::vector< double > DVector
Definition: cmeans.hh:31
Initializer plugin_type
Definition: cmeans.hh:83
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:110
The base class for all plug-in created object.
Definition: product_base.hh:40
static const char * data_descr
Definition: cmeans.hh:84
the Base class for all plugn handlers that deal with factory plugins.
Definition: factory.hh:93
static const char * type_descr
Definition: cmeans.hh:85
Map::const_iterator end() const
Definition: cmeans.hh:59
std::vector< std::pair< double, double > > NormalizedHistogram
Definition: cmeans.hh:33
std::pair< double, DVector > value_type
Definition: cmeans.hh:37
Map::iterator begin()
Definition: cmeans.hh:55
The generic base for all plug-ins.
Definition: plugin_base.hh:170
The basic template of all plugin handlers.
Definition: handler.hh:54
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46