// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #ifndef __fpa__Filters__Mori__hxx__ #define __fpa__Filters__Mori__hxx__ #include // ------------------------------------------------------------------------- template< class _TDataInterface > typename fpa::Filters::Mori< _TDataInterface >:: TOutputValue fpa::Filters::Mori< _TDataInterface >:: GetOutsideValue( ) const { return( this->GetInitValue( ) ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: SetOutsideValue( const TOutputValue& v ) { this->SetInitValue( v ); } // ------------------------------------------------------------------------- template< class _TDataInterface > unsigned long fpa::Filters::Mori< _TDataInterface >:: GetSignalKernelSize( ) const { return( this->m_PeakDetector.GetKernelSize( ) ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: SetSignalKernelSize( unsigned long k ) { this->m_PeakDetector.SetKernelSize( k ); this->Modified( ); } // ------------------------------------------------------------------------- template< class _TDataInterface > double fpa::Filters::Mori< _TDataInterface >:: GetSignalThreshold( ) const { return( this->m_PeakDetector.GetThreshold( ) ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: SetSignalThreshold( double t ) { this->m_PeakDetector.SetThreshold( t ); this->Modified( ); } // ------------------------------------------------------------------------- template< class _TDataInterface > double fpa::Filters::Mori< _TDataInterface >:: GetSignalInfluence( ) const { return( this->m_PeakDetector.GetInfluence( ) ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: SetSignalInfluence( double i ) { this->m_PeakDetector.SetInfluence( i ); this->Modified( ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: ClearThresholds( ) { this->m_Thresholds.clear( ); this->Modified( ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: AddThreshold( const TInputValue& thr ) { if( this->m_Thresholds.insert( thr ).second ) this->Modified( ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: SetThresholds( const TInputValue& lower, const TInputValue& upper, const TInputValue& delta ) { for( TInputValue t = lower; t <= upper; t += delta ) this->AddThreshold( t ); } // ------------------------------------------------------------------------- template< class _TDataInterface > const typename fpa::Filters::Mori< _TDataInterface >:: TThresholds& fpa::Filters::Mori< _TDataInterface >:: GetThresholds( ) const { return( this->m_Thresholds ); } // ------------------------------------------------------------------------- template< class _TDataInterface > unsigned long fpa::Filters::Mori< _TDataInterface >:: GetNumberOfEvaluatedThresholds( ) const { return( this->m_PeakDetector.GetNumberOfSamples( ) ); } // ------------------------------------------------------------------------- template< class _TDataInterface > typename fpa::Filters::Mori< _TDataInterface >:: TInputValue fpa::Filters::Mori< _TDataInterface >:: GetOptimumThreshold( ) const { TInputValue thr = TInputValue( 0 ); unsigned long n = this->m_PeakDetector.GetNumberOfSamples( ); if( n > 1 ) thr = TInputValue( this->m_PeakDetector.GetXValues( )[ n - 2 ] ); return( thr ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: GetSignalValues( unsigned long i, double& x, double& y, TPeak& p ) const { if( i < this->m_PeakDetector.GetNumberOfSamples( ) ) { x = this->m_PeakDetector.GetXValues( )[ i ]; y = this->m_PeakDetector.GetYValues( )[ i ]; p = this->m_PeakDetector.GetPeaks( )[ i ]; } // fi } // ------------------------------------------------------------------------- template< class _TDataInterface > fpa::Filters::Mori< _TDataInterface >:: Mori( ) : Superclass( true ) { this->SetOutsideValue( TOutputValue( 0 ) ); this->m_InsideValue = std::numeric_limits< TOutputValue >::max( ); this->m_Predicate = TPredicate::New( ); this->m_Predicate->StrictOff( ); if( std::numeric_limits< TInputValue >::is_integer ) this->m_MinimumThreshold = std::numeric_limits< TInputValue >::min( ); else this->m_MinimumThreshold = -std::numeric_limits< TInputValue >::max( ); this->m_PeakDetector.SetKernelSize( 20 ); this->m_PeakDetector.SetThreshold( 500 ); this->m_PeakDetector.SetInfluence( 0.5 ); } // ------------------------------------------------------------------------- template< class _TDataInterface > fpa::Filters::Mori< _TDataInterface >:: ~Mori( ) { } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: _BeforeGenerateData( ) { this->Superclass::_BeforeGenerateData( ); // Prepare queues this->_QueueClear( ); // Prepare iteration over all thresholds this->m_CurrThr = this->m_Thresholds.begin( ); this->m_Predicate->SetLowerThreshold( *( this->m_CurrThr ) ); this->m_CurrThr++; this->m_Predicate->SetUpperThreshold( *( this->m_CurrThr ) ); // Prepare counting signal this->m_CurrCount = double( 0 ); this->m_PeakDetector.Clear( ); } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: _PostComputeOutputValue( TNode& n ) { TInputValue value = this->_GetInputValue( n.Vertex ); bool inside = this->m_Predicate->Evaluate( value ); if( !inside ) { n.Value = this->m_InitValue; n.FrontId++; this->_QueueSwap( ); this->_QueuePush( n ); this->_QueueSwap( ); n.FrontId = 0; } else { n.Value = this->m_InsideValue; this->m_CurrCount += double( 1 ); } // fi } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: _PreComputeOutputValue( TNode& n ) { // Nothing to do with this algorithm } // ------------------------------------------------------------------------- template< class _TDataInterface > void fpa::Filters::Mori< _TDataInterface >:: _Reinitialize( ) { if( this->_QueueSize( ) == 0 ) { // Update peak detector TPeak p = this->m_PeakDetector.AddValue( *this->m_CurrThr, this->m_CurrCount ); this->m_CurrThr++; this->_QueueSwap( ); if( this->m_CurrThr != this->m_Thresholds.end( ) ) { // Update predicate and counting value this->m_Predicate->SetUpperThreshold( *( this->m_CurrThr ) ); this->m_CurrCount = double( 0 ); // Peak detected? -> stop! if( p == TPeakDetector::PosPeak && this->m_MinimumThreshold < *( this->m_CurrThr ) ) this->_QueueClear( ); } else this->_QueueClear( ); } // fi } #endif // __fpa__Filters__Mori__hxx__ // eof - $RCSfile$