ANIMA  4.0
animaKMeansFilter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 namespace anima {
6 
7 template <class DataType, unsigned int PointDimension>
9 {
10 public:
11  typedef DataType VectorType;
12  typedef std::vector < VectorType > DataHolderType;
13  typedef std::vector < unsigned int > MembershipType;
14 
15  KMeansFilter();
16  virtual ~KMeansFilter();
17 
18  void SetInputData(DataHolderType &data);
19  void SetNumberOfClasses(unsigned int nbC)
20  {
21  m_NbClass = nbC;
22  m_NumberPerClass.resize(m_NbClass);
23  }
24 
25  void SetMaxIterations(unsigned int mIt) {m_MaxIterations = mIt;}
26 
27  void ComputeCentroids();
28  void UpdateMemberships();
29 
31  void InitializeClassesMemberships(MembershipType &classM);
32  void ResetClassesMemberships() {m_ClassesMembership.clear();}
33 
34  bool endConditionReached(MembershipType &oldMemberships);
35  void SetVerbose(bool verb) {m_Verbose = verb;}
36 
37  void Update();
38 
39  VectorType GetCentroid(unsigned int i) {return m_Centroids[i];}
40  unsigned int GetClassMembership(unsigned int i) {return m_ClassesMembership[i];}
41  MembershipType &GetClassesMemberships() {return m_ClassesMembership;}
42 
43  unsigned int GetNumberPerClass(unsigned int i) {return m_NumberPerClass[i];}
44 
45 private:
46  double computeDistance(VectorType &vec1, VectorType &vec2);
47 
48  MembershipType m_ClassesMembership;
49  DataHolderType m_Centroids;
50  DataHolderType m_InputData;
51 
52  std::vector <unsigned int> m_NumberPerClass;
53 
54  unsigned int m_NbClass, m_NbInputs;
55  unsigned int m_MaxIterations;
56 
57  bool m_Verbose;
58 };
59 
60 } // end namespace anima
61 
62 #include "animaKMeansFilter.hxx"
void SetVerbose(bool verb)
MembershipType & GetClassesMemberships()
unsigned int GetClassMembership(unsigned int i)
void InitializeClassesMemberships(MembershipType &classM)
std::vector< VectorType > DataHolderType
void SetInputData(DataHolderType &data)
std::vector< unsigned int > MembershipType
VectorType GetCentroid(unsigned int i)
void SetMaxIterations(unsigned int mIt)
unsigned int GetNumberPerClass(unsigned int i)
void SetNumberOfClasses(unsigned int nbC)
bool endConditionReached(MembershipType &oldMemberships)