X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FFilters%2FMori.hxx;h=68048f1f1dd9b3e9e5c0b5bb6a3c4ca253b96f9b;hb=34f4ff5d31c70f1127d43865c61e9f57a7071190;hp=a3969c81e6e3bea3b236754326eea07bc713b297;hpb=e977d1bb57ca61759a1fb1a1d0d8937718ef8722;p=FrontAlgorithms.git diff --git a/lib/fpa/Filters/Mori.hxx b/lib/fpa/Filters/Mori.hxx index a3969c8..68048f1 100644 --- a/lib/fpa/Filters/Mori.hxx +++ b/lib/fpa/Filters/Mori.hxx @@ -5,34 +5,36 @@ #ifndef __fpa__Filters__Mori__hxx__ #define __fpa__Filters__Mori__hxx__ +#include + // ------------------------------------------------------------------------- -template< class _TTraits > -typename fpa::Filters::Mori< _TTraits >:: -TOutputValue fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +typename fpa::Filters::Mori< _TDataInterface >:: +TOutputValue fpa::Filters::Mori< _TDataInterface >:: GetOutsideValue( ) const { return( this->GetInitValue( ) ); } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: SetOutsideValue( const TOutputValue& v ) { this->SetInitValue( v ); } // ------------------------------------------------------------------------- -template< class _TTraits > -unsigned long fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +unsigned long fpa::Filters::Mori< _TDataInterface >:: GetSignalKernelSize( ) const { return( this->m_PeakDetector.GetKernelSize( ) ); } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: SetSignalKernelSize( unsigned long k ) { this->m_PeakDetector.SetKernelSize( k ); @@ -40,16 +42,16 @@ SetSignalKernelSize( unsigned long k ) } // ------------------------------------------------------------------------- -template< class _TTraits > -double fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +double fpa::Filters::Mori< _TDataInterface >:: GetSignalThreshold( ) const { return( this->m_PeakDetector.GetThreshold( ) ); } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: SetSignalThreshold( double t ) { this->m_PeakDetector.SetThreshold( t ); @@ -57,16 +59,16 @@ SetSignalThreshold( double t ) } // ------------------------------------------------------------------------- -template< class _TTraits > -double fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +double fpa::Filters::Mori< _TDataInterface >:: GetSignalInfluence( ) const { return( this->m_PeakDetector.GetInfluence( ) ); } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: SetSignalInfluence( double i ) { this->m_PeakDetector.SetInfluence( i ); @@ -74,8 +76,8 @@ SetSignalInfluence( double i ) } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: ClearThresholds( ) { this->m_Thresholds.clear( ); @@ -83,8 +85,8 @@ ClearThresholds( ) } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: AddThreshold( const TInputValue& thr ) { if( this->m_Thresholds.insert( thr ).second ) @@ -92,26 +94,39 @@ AddThreshold( const TInputValue& thr ) } // ------------------------------------------------------------------------- -template< class _TTraits > -const typename fpa::Filters::Mori< _TTraits >:: -TThresholds& fpa::Filters::Mori< _TTraits >:: +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 _TTraits > -unsigned long fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +unsigned long fpa::Filters::Mori< _TDataInterface >:: GetNumberOfEvaluatedThresholds( ) const { return( this->m_PeakDetector.GetNumberOfSamples( ) ); } // ------------------------------------------------------------------------- -template< class _TTraits > -typename fpa::Filters::Mori< _TTraits >:: -TInputValue fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +typename fpa::Filters::Mori< _TDataInterface >:: +TInputValue fpa::Filters::Mori< _TDataInterface >:: GetOptimumThreshold( ) const { TInputValue thr = TInputValue( 0 ); @@ -122,11 +137,9 @@ GetOptimumThreshold( ) const } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: -GetSignalValues( - unsigned long i, double& x, double& y, TPeak& p - ) const +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( ) ) { @@ -138,26 +151,13 @@ GetSignalValues( } // ------------------------------------------------------------------------- -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 >:: +template< class _TDataInterface > +fpa::Filters::Mori< _TDataInterface >:: Mori( ) - : Superclass( ), - m_InsideValue( TOutputValue( 1 ) ) + : Superclass( true ) { - this->SetOutsideValue( 0 ); + 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 ) @@ -170,22 +170,21 @@ Mori( ) } // ------------------------------------------------------------------------- -template< class _TTraits > -fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +fpa::Filters::Mori< _TDataInterface >:: ~Mori( ) { } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: _BeforeGenerateData( ) { this->Superclass::_BeforeGenerateData( ); // Prepare queues this->_QueueClear( ); - this->m_CurrQueue = 0; // Prepare iteration over all thresholds this->m_CurrThr = this->m_Thresholds.begin( ); @@ -199,41 +198,9 @@ _BeforeGenerateData( ) } // ------------------------------------------------------------------------- -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 ) +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: +_PostComputeOutputValue( TNode& n ) { TInputValue value = this->_GetInputValue( n.Vertex ); bool inside = this->m_Predicate->Evaluate( value ); @@ -241,7 +208,9 @@ _UpdateOutputValue( TNode& n ) { n.Value = this->m_InitValue; n.FrontId++; - this->m_Queues[ ( this->m_CurrQueue + 1 ) % 2 ].push_back( n ); + this->_QueueSwap( ); + this->_QueuePush( n ); + this->_QueueSwap( ); n.FrontId = 0; } else @@ -253,46 +222,43 @@ _UpdateOutputValue( TNode& n ) } // ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: -_QueueClear( ) +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: +_PreComputeOutputValue( TNode& n ) { - this->m_Queues[ 0 ].clear( ); - this->m_Queues[ 1 ].clear( ); + // Nothing to do with this algorithm } // ------------------------------------------------------------------------- -template< class _TTraits > -typename fpa::Filters::Mori< _TTraits >:: -TNode fpa::Filters::Mori< _TTraits >:: -_QueuePop( ) +template< class _TDataInterface > +void fpa::Filters::Mori< _TDataInterface >:: +_Reinitialize( ) { - TNode n = this->m_Queues[ this->m_CurrQueue ].front( ); - this->m_Queues[ this->m_CurrQueue ].pop_front( ); - return( n ); -} + 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 ); -// ------------------------------------------------------------------------- -template< class _TTraits > -void fpa::Filters::Mori< _TTraits >:: -_QueuePush( const TNode& n ) -{ - this->m_Queues[ this->m_CurrQueue ].push_back( n ); -} + // Peak detected? -> stop! + if( + p == TPeakDetector::PosPeak && + this->m_MinimumThreshold < *( this->m_CurrThr ) + ) + this->_QueueClear( ); + } + else + this->_QueueClear( ); -// ------------------------------------------------------------------------- -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 + } // fi } #endif // __fpa__Filters__Mori__hxx__