X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FCommon%2FPeakDetector.cxx;fp=lib%2Ffpa%2FCommon%2FPeakDetector.cxx;h=0a53e1e38d8bd0ea14d9ab499db58123b68b9492;hb=bd89a1af0c14ed2ac0afeca923103de54283cbaf;hp=0000000000000000000000000000000000000000;hpb=a8ac405fe1422bc0792a810f7f0693096a22c20e;p=FrontAlgorithms.git diff --git a/lib/fpa/Common/PeakDetector.cxx b/lib/fpa/Common/PeakDetector.cxx new file mode 100644 index 0000000..0a53e1e --- /dev/null +++ b/lib/fpa/Common/PeakDetector.cxx @@ -0,0 +1,187 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= +#include +#include + +// ------------------------------------------------------------------------- +fpa::Common::PeakDetector:: +PeakDetector( ) + : m_K( 3 ), + m_T( 3.5 ), + m_I( 0.5 ) +{ +} + +// ------------------------------------------------------------------------- +fpa::Common::PeakDetector:: +~PeakDetector( ) +{ +} + +// ------------------------------------------------------------------------- +unsigned long fpa::Common::PeakDetector:: +GetKernelSize( ) const +{ + return( this->m_K ); +} + +// ------------------------------------------------------------------------- +double fpa::Common::PeakDetector:: +GetThreshold( ) const +{ + return( this->m_T ); +} + +// ------------------------------------------------------------------------- +double fpa::Common::PeakDetector:: +GetInfluence( ) const +{ + return( this->m_I ); +} + +// ------------------------------------------------------------------------- +void fpa::Common::PeakDetector:: +SetKernelSize( unsigned long k ) +{ + this->m_K = k; + this->Clear( ); +} + +// ------------------------------------------------------------------------- +void fpa::Common::PeakDetector:: +SetThreshold( double t ) +{ + this->m_T = t; + this->Clear( ); +} + +// ------------------------------------------------------------------------- +void fpa::Common::PeakDetector:: +SetInfluence( double i ) +{ + this->m_I = i; + this->Clear( ); +} + +// ------------------------------------------------------------------------- +void fpa::Common::PeakDetector:: +Clear( ) +{ + this->m_X.clear( ); + this->m_Y.clear( ); + this->m_YF.clear( ); + this->m_Avg.clear( ); + this->m_STD.clear( ); + this->m_Peaks.clear( ); + this->m_MeanAndVar.Clear( ); +} + +// ------------------------------------------------------------------------- +const std::vector< double >& fpa::Common::PeakDetector:: +GetXValues( ) const +{ + return( this->m_X ); +} + +// ------------------------------------------------------------------------- +const std::vector< double >& fpa::Common::PeakDetector:: +GetYValues( ) const +{ + return( this->m_Y ); +} + +// ------------------------------------------------------------------------- +const std::vector< double >& fpa::Common::PeakDetector:: +GetFilteredYValues( ) const +{ + return( this->m_YF ); +} + +// ------------------------------------------------------------------------- +const std::vector< double >& fpa::Common::PeakDetector:: +GetAverages( ) const +{ + return( this->m_Avg ); +} + +// ------------------------------------------------------------------------- +const std::vector< double >& fpa::Common::PeakDetector:: +GetDeviations( ) const +{ + return( this->m_STD ); +} + +// ------------------------------------------------------------------------- +const std::vector< fpa::Common::PeakDetector::TPeak >& fpa::Common:: +PeakDetector::GetPeaks( ) const +{ + return( this->m_Peaks ); +} + +// ------------------------------------------------------------------------- +unsigned long fpa::Common::PeakDetector:: +GetNumberOfSamples( ) const +{ + return( this->m_X.size( ) ); +} + +// ------------------------------------------------------------------------- +fpa::Common::PeakDetector:: +TPeak fpa::Common::PeakDetector:: +AddValue( double x, double y ) +{ + this->m_X.push_back( x ); + this->m_Y.push_back( y ); + + if( this->m_YF.size( ) < this->m_K ) + { + this->m_YF.push_back( y ); + this->m_Avg.push_back( double( 0 ) ); + this->m_STD.push_back( double( 0 ) ); + this->m_Peaks.push_back( Self::NoPeak ); + + this->m_MeanAndVar.AddValue( y ); + if( this->m_YF.size( ) == this->m_K ) + { + this->m_Avg.push_back( this->m_MeanAndVar.GetMean( ) ); + this->m_STD.push_back( this->m_MeanAndVar.GetDeviation( ) ); + + } // fi + } + else + { + unsigned long i = this->m_X.size( ) - 1; + if( + ( std::fabs( y - this->m_Avg[ i - 1 ] ) ) > + ( this->m_T * this->m_STD[ i - 1 ] ) + ) + { + this->m_Peaks.push_back( + ( y > this->m_Avg[ i - 1 ] )? Self::PosPeak: Self::NegPeak + ); + this->m_YF.push_back( + ( this->m_I * y ) + + ( ( double( 1 ) - this->m_I ) * this->m_YF[ i - 1 ] ) + ); + } + else + { + this->m_Peaks.push_back( Self::NoPeak ); + this->m_YF.push_back( y ); + + } // fi + + this->m_MeanAndVar.Clear( ); + unsigned long k = 0; + for( unsigned long j = i - this->m_K; j <= i; ++j, ++k ) + this->m_MeanAndVar.AddValue( this->m_YF[ j ] ); + this->m_Avg.push_back( this->m_MeanAndVar.GetMean( ) ); + this->m_STD.push_back( this->m_MeanAndVar.GetDeviation( ) ); + + } // fi + return( this->m_Peaks.back( ) ); +} + +// eof - $RCSfile$