]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Algorithms/IterativeGaussianModelEstimator.h
Bezier function added.
[cpPlugins.git] / lib / cpPlugins / Extensions / Algorithms / IterativeGaussianModelEstimator.h
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
6 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
7
8 #include <vector>
9 #include <itkConceptChecking.h>
10 #include <itkObject.h>
11 #include <vnl/vnl_matrix.h>
12
13 namespace cpPlugins
14 {
15   namespace Extensions
16   {
17     namespace Algorithms
18     {
19       /**
20        */
21       template< class S, unsigned int D >
22       class IterativeGaussianModelEstimator
23         : public itk::Object
24       {
25       public:
26         typedef IterativeGaussianModelEstimator Self;
27         typedef itk::Object                     Superclass;
28         typedef itk::SmartPointer< Self >       Pointer;
29         typedef itk::SmartPointer< const Self > ConstPointer;
30
31         typedef S TScalar;
32         itkStaticConstMacro( Dimension, unsigned int, D );
33
34         // Begin concept checking
35 #ifdef ITK_USE_CONCEPT_CHECKING
36         itkConceptMacro(
37           ScalarTypeHasFloatResolution,
38           ( itk::Concept::IsFloatingPoint< S > )
39           );
40 #endif
41         // End concept checking
42
43         typedef vnl_matrix< S >        TMatrix;
44         typedef std::vector< TMatrix > TMatrices;
45
46       public:
47         itkNewMacro( Self );
48         itkTypeMacro( IterativeGaussianModelEstimator, itkObject );
49
50       public:
51         unsigned long GetNumberOfSamples( ) const
52           { return( ( unsigned long )( this->m_N ) ); }
53         const TMatrix& GetMu( ) const
54           { return( this->m_M ); }
55         const TMatrix& GetOmega( ) const
56           { return( this->m_O ); }
57
58         void SetNumberOfSamples( unsigned long n );
59         void SetMu( const TMatrix& m );
60         void SetOmega( const TMatrix& O );
61
62         bool SaveModelToFile( const std::string& filename ) const;
63         bool LoadModelFromFile( const std::string& filename );
64
65         template< class V >
66         S Probability( const V& sample ) const;
67
68         S Probability( const S& s_x, const S& s_y, ... ) const;
69
70         template< class V, class M >
71         void GetModel( V& m, M& E ) const;
72
73         void Clear( );
74
75         template< class V >
76         void AddSample( const V& sample );
77
78         void AddSample( const S& s_x, const S& s_y, ... );
79
80       protected:
81         IterativeGaussianModelEstimator( );
82         virtual ~IterativeGaussianModelEstimator( );
83
84       protected:
85         void _UpdateModel( ) const;
86
87       private:
88         // Purposely not implemented
89         IterativeGaussianModelEstimator( const Self& other );
90         void operator=( const Self& other );
91
92       protected:
93         S m_N;
94         TMatrix m_M;
95         TMatrix m_O;
96
97         mutable bool m_Updated;
98         mutable TMatrix m_Cov;
99         mutable TMatrix m_Inv;
100         mutable S m_Norm;
101       };
102
103     } // ecapseman
104
105   } // ecapseman
106
107 } // ecapseman
108
109 #include <cpPlugins/Extensions/Algorithms/IterativeGaussianModelEstimator.hxx>
110
111 #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
112
113 // eof - $RCSfile$