+++ /dev/null
-// =========================================================================
-// @author Leonardo Florez Valencia
-// @email florez-l@javeriana.edu.co
-// =========================================================================
-#ifndef __fpa__Filters__Mori__hxx__
-#define __fpa__Filters__Mori__hxx__
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-typename fpa::Filters::Mori< _TTraits >::
-TOutputValue fpa::Filters::Mori< _TTraits >::
-GetOutsideValue( ) const
-{
- return( this->GetInitValue( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-SetOutsideValue( const TOutputValue& v )
-{
- this->SetInitValue( v );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-unsigned long fpa::Filters::Mori< _TTraits >::
-GetSignalKernelSize( ) const
-{
- return( this->m_PeakDetector.GetKernelSize( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-SetSignalKernelSize( unsigned long k )
-{
- this->m_PeakDetector.SetKernelSize( k );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-double fpa::Filters::Mori< _TTraits >::
-GetSignalThreshold( ) const
-{
- return( this->m_PeakDetector.GetThreshold( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-SetSignalThreshold( double t )
-{
- this->m_PeakDetector.SetThreshold( t );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-double fpa::Filters::Mori< _TTraits >::
-GetSignalInfluence( ) const
-{
- return( this->m_PeakDetector.GetInfluence( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-SetSignalInfluence( double i )
-{
- this->m_PeakDetector.SetInfluence( i );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-ClearThresholds( )
-{
- this->m_Thresholds.clear( );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-AddThreshold( const TInputValue& thr )
-{
- if( this->m_Thresholds.insert( thr ).second )
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-const typename fpa::Filters::Mori< _TTraits >::
-TThresholds& fpa::Filters::Mori< _TTraits >::
-GetThresholds( ) const
-{
- return( this->m_Thresholds );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-unsigned long fpa::Filters::Mori< _TTraits >::
-GetNumberOfEvaluatedThresholds( ) const
-{
- return( this->m_PeakDetector.GetNumberOfSamples( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-typename fpa::Filters::Mori< _TTraits >::
-TInputValue fpa::Filters::Mori< _TTraits >::
-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 _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-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 _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-SetThresholds(
- const TInputValue& lower,
- const TInputValue& upper,
- const TInputValue& delta
- )
-{
- for( TInputValue t = lower; t <= upper; t += delta )
- this->AddThreshold( t );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-fpa::Filters::Mori< _TTraits >::
-Mori( )
- : Superclass( ),
- m_InsideValue( TOutputValue( 1 ) )
-{
- this->SetOutsideValue( 0 );
- 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 _TTraits >
-fpa::Filters::Mori< _TTraits >::
-~Mori( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-_BeforeGenerateData( )
-{
- this->Superclass::_BeforeGenerateData( );
-
- // Prepare queues
- this->_QueueClear( );
- this->m_CurrQueue = 0;
-
- // 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 _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-_Reinitialize( )
-{
- if( this->m_Queues[ this->m_CurrQueue ].size( ) == 0 )
- {
- // Update peak detector
- TPeak p = this->m_PeakDetector.AddValue(
- *this->m_CurrThr, this->m_CurrCount
- );
- this->m_CurrThr++;
- this->m_CurrQueue = ( this->m_CurrQueue + 1 ) % 2;
- 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
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-_UpdateOutputValue( 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->m_Queues[ ( this->m_CurrQueue + 1 ) % 2 ].push_back( n );
- n.FrontId = 0;
- }
- else
- {
- n.Value = this->m_InsideValue;
- this->m_CurrCount += double( 1 );
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-_QueueClear( )
-{
- this->m_Queues[ 0 ].clear( );
- this->m_Queues[ 1 ].clear( );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-typename fpa::Filters::Mori< _TTraits >::
-TNode fpa::Filters::Mori< _TTraits >::
-_QueuePop( )
-{
- TNode n = this->m_Queues[ this->m_CurrQueue ].front( );
- this->m_Queues[ this->m_CurrQueue ].pop_front( );
- return( n );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-_QueuePush( const TNode& n )
-{
- this->m_Queues[ this->m_CurrQueue ].push_back( n );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-unsigned long fpa::Filters::Mori< _TTraits >::
-_QueueSize( ) const
-{
- return( this->m_Queues[ this->m_CurrQueue ].size( ) );
-}
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Mori< _TTraits >::
-_ComputeOutputValue( TNode& n )
-{
- // Do nothing
-}
-
-#endif // __fpa__Filters__Mori__hxx__
-// eof - $RCSfile$