00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkGaussianDensityFunction_h
00018 #define __itkGaussianDensityFunction_h
00019
00020 #include "itkArray.h"
00021 #include "itkVariableSizeMatrix.h"
00022 #include "vnl/algo/vnl_matrix_inverse.h"
00023 #include "vnl/algo/vnl_determinant.h"
00024 #include "vnl/vnl_math.h"
00025
00026 #include "itkMatrix.h"
00027 #include "itkDensityFunction.h"
00028
00029 namespace itk{
00030 namespace Statistics{
00031
00054 template< class TMeasurementVector >
00055 class ITK_EXPORT GaussianDensityFunction :
00056 public DensityFunction< TMeasurementVector >
00057 {
00058 public:
00060 typedef GaussianDensityFunction Self;
00061 typedef DensityFunction< TMeasurementVector > Superclass ;
00062 typedef SmartPointer<Self> Pointer;
00063 typedef SmartPointer<const Self> ConstPointer;
00064
00066 itkTypeMacro(GaussianDensityFunction, DensityFunction);
00067 itkNewMacro(Self);
00068
00070 typedef TMeasurementVector MeasurementVectorType ;
00071
00073 typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
00074
00076 typedef Array< double > MeanType;
00077
00079 typedef VariableSizeMatrix< double > CovarianceType;
00080
00082 void SetMean( const MeanType * mean )
00083 {
00084 if( this->GetMeasurementVectorSize() )
00085 {
00086 MeasurementVectorTraits::Assert(mean, this->GetMeasurementVectorSize(),
00087 "GaussianDensityFunction::SetMean Size of measurement vectors in the sample must the same as the size of the mean." );
00088 }
00089 else
00090 {
00091 this->SetMeasurementVectorSize( mean->Size() );
00092 }
00093
00094 if ( m_Mean != mean)
00095 {
00096 m_Mean = mean ;
00097 this->Modified() ;
00098 }
00099 }
00100
00102 const MeanType * GetMean() const
00103 { return m_Mean ; }
00104
00108 void SetCovariance(const CovarianceType* cov);
00109
00111 const CovarianceType* GetCovariance() const ;
00112
00114 double Evaluate(const MeasurementVectorType &measurement) const ;
00115
00116 protected:
00117 GaussianDensityFunction(void) ;
00118 virtual ~GaussianDensityFunction(void) {}
00119 void PrintSelf(std::ostream& os, Indent indent) const;
00120
00121 private:
00122 const MeanType * m_Mean;
00123 const CovarianceType * m_Covariance;
00124
00125
00126
00127 CovarianceType m_InverseCovariance;
00128
00129
00130
00131 double m_PreFactor;
00132
00135 bool m_IsCovarianceZero ;
00136 };
00137
00138 }
00139 }
00140
00141 #ifndef ITK_MANUAL_INSTANTIATION
00142 #include "itkGaussianDensityFunction.txx"
00143 #endif
00144
00145 #endif