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);
00069
00071 typedef TMeasurementVector MeasurementVectorType ;
00072
00074 typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
00075
00077 typedef Array< double > MeanType;
00078
00080 typedef VariableSizeMatrix< double > CovarianceType;
00081
00083 void SetMean( const MeanType * mean )
00084 {
00085 if( this->GetMeasurementVectorSize() )
00086 {
00087 MeasurementVectorTraits::Assert(mean, this->GetMeasurementVectorSize(),
00088 "GaussianDensityFunction::SetMean Size of measurement vectors in the sample must the same as the size of the mean." );
00089 }
00090 else
00091 {
00092 this->SetMeasurementVectorSize( mean->Size() );
00093 }
00095
00096 if ( m_Mean != mean)
00097 {
00098 m_Mean = mean ;
00099 this->Modified() ;
00100 }
00101 }
00102
00104 const MeanType * GetMean() const
00105 { return m_Mean ; }
00106
00110 void SetCovariance(const CovarianceType* cov);
00111
00113 const CovarianceType* GetCovariance() const ;
00114
00116 double Evaluate(const MeasurementVectorType &measurement) const ;
00117
00118 protected:
00119 GaussianDensityFunction(void) ;
00120 virtual ~GaussianDensityFunction(void) {}
00121 void PrintSelf(std::ostream& os, Indent indent) const;
00122
00123 private:
00124 const MeanType * m_Mean;
00125 const CovarianceType * m_Covariance;
00126
00127
00128
00129 CovarianceType m_InverseCovariance;
00130
00131
00132
00133 double m_PreFactor;
00134
00137 bool m_IsCovarianceZero ;
00138 };
00139
00140 }
00141 }
00142
00143 #ifndef ITK_MANUAL_INSTANTIATION
00144 #include "itkGaussianDensityFunction.txx"
00145 #endif
00146
00147 #endif
00148