1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Filters__Mori__hxx__
6 #define __fpa__Filters__Mori__hxx__
10 // -------------------------------------------------------------------------
11 template< class _TDataInterface >
12 typename fpa::Filters::Mori< _TDataInterface >::
13 TOutputValue fpa::Filters::Mori< _TDataInterface >::
14 GetOutsideValue( ) const
16 return( this->GetInitValue( ) );
19 // -------------------------------------------------------------------------
20 template< class _TDataInterface >
21 void fpa::Filters::Mori< _TDataInterface >::
22 SetOutsideValue( const TOutputValue& v )
24 this->SetInitValue( v );
27 // -------------------------------------------------------------------------
28 template< class _TDataInterface >
29 unsigned long fpa::Filters::Mori< _TDataInterface >::
30 GetSignalKernelSize( ) const
32 return( this->m_PeakDetector.GetKernelSize( ) );
35 // -------------------------------------------------------------------------
36 template< class _TDataInterface >
37 void fpa::Filters::Mori< _TDataInterface >::
38 SetSignalKernelSize( unsigned long k )
40 this->m_PeakDetector.SetKernelSize( k );
44 // -------------------------------------------------------------------------
45 template< class _TDataInterface >
46 double fpa::Filters::Mori< _TDataInterface >::
47 GetSignalThreshold( ) const
49 return( this->m_PeakDetector.GetThreshold( ) );
52 // -------------------------------------------------------------------------
53 template< class _TDataInterface >
54 void fpa::Filters::Mori< _TDataInterface >::
55 SetSignalThreshold( double t )
57 this->m_PeakDetector.SetThreshold( t );
61 // -------------------------------------------------------------------------
62 template< class _TDataInterface >
63 double fpa::Filters::Mori< _TDataInterface >::
64 GetSignalInfluence( ) const
66 return( this->m_PeakDetector.GetInfluence( ) );
69 // -------------------------------------------------------------------------
70 template< class _TDataInterface >
71 void fpa::Filters::Mori< _TDataInterface >::
72 SetSignalInfluence( double i )
74 this->m_PeakDetector.SetInfluence( i );
78 // -------------------------------------------------------------------------
79 template< class _TDataInterface >
80 void fpa::Filters::Mori< _TDataInterface >::
83 this->m_Thresholds.clear( );
87 // -------------------------------------------------------------------------
88 template< class _TDataInterface >
89 void fpa::Filters::Mori< _TDataInterface >::
90 AddThreshold( const TInputValue& thr )
92 if( this->m_Thresholds.insert( thr ).second )
96 // -------------------------------------------------------------------------
97 template< class _TDataInterface >
98 void fpa::Filters::Mori< _TDataInterface >::
100 const TInputValue& lower,
101 const TInputValue& upper,
102 const TInputValue& delta
105 for( TInputValue t = lower; t <= upper; t += delta )
106 this->AddThreshold( t );
109 // -------------------------------------------------------------------------
110 template< class _TDataInterface >
111 const typename fpa::Filters::Mori< _TDataInterface >::
112 TThresholds& fpa::Filters::Mori< _TDataInterface >::
113 GetThresholds( ) const
115 return( this->m_Thresholds );
118 // -------------------------------------------------------------------------
119 template< class _TDataInterface >
120 unsigned long fpa::Filters::Mori< _TDataInterface >::
121 GetNumberOfEvaluatedThresholds( ) const
123 return( this->m_PeakDetector.GetNumberOfSamples( ) );
126 // -------------------------------------------------------------------------
127 template< class _TDataInterface >
128 typename fpa::Filters::Mori< _TDataInterface >::
129 TInputValue fpa::Filters::Mori< _TDataInterface >::
130 GetOptimumThreshold( ) const
132 TInputValue thr = TInputValue( 0 );
133 unsigned long n = this->m_PeakDetector.GetNumberOfSamples( );
135 thr = TInputValue( this->m_PeakDetector.GetXValues( )[ n - 2 ] );
139 // -------------------------------------------------------------------------
140 template< class _TDataInterface >
141 void fpa::Filters::Mori< _TDataInterface >::
142 GetSignalValues( unsigned long i, double& x, double& y, TPeak& p ) const
144 if( i < this->m_PeakDetector.GetNumberOfSamples( ) )
146 x = this->m_PeakDetector.GetXValues( )[ i ];
147 y = this->m_PeakDetector.GetYValues( )[ i ];
148 p = this->m_PeakDetector.GetPeaks( )[ i ];
153 // -------------------------------------------------------------------------
154 template< class _TDataInterface >
155 fpa::Filters::Mori< _TDataInterface >::
159 this->SetOutsideValue( TOutputValue( 0 ) );
160 this->m_InsideValue = std::numeric_limits< TOutputValue >::max( );
161 this->m_Predicate = TPredicate::New( );
162 this->m_Predicate->StrictOff( );
163 if( std::numeric_limits< TInputValue >::is_integer )
164 this->m_MinimumThreshold = std::numeric_limits< TInputValue >::min( );
166 this->m_MinimumThreshold = -std::numeric_limits< TInputValue >::max( );
167 this->m_PeakDetector.SetKernelSize( 20 );
168 this->m_PeakDetector.SetThreshold( 500 );
169 this->m_PeakDetector.SetInfluence( 0.5 );
172 // -------------------------------------------------------------------------
173 template< class _TDataInterface >
174 fpa::Filters::Mori< _TDataInterface >::
179 // -------------------------------------------------------------------------
180 template< class _TDataInterface >
181 void fpa::Filters::Mori< _TDataInterface >::
182 _BeforeGenerateData( )
184 this->Superclass::_BeforeGenerateData( );
187 this->_QueueClear( );
189 // Prepare iteration over all thresholds
190 this->m_CurrThr = this->m_Thresholds.begin( );
191 this->m_Predicate->SetLowerThreshold( *( this->m_CurrThr ) );
193 this->m_Predicate->SetUpperThreshold( *( this->m_CurrThr ) );
195 // Prepare counting signal
196 this->m_CurrCount = double( 0 );
197 this->m_PeakDetector.Clear( );
200 // -------------------------------------------------------------------------
201 template< class _TDataInterface >
202 void fpa::Filters::Mori< _TDataInterface >::
203 _PostComputeOutputValue( TNode& n )
205 TInputValue value = this->_GetInputValue( n.Vertex );
206 bool inside = this->m_Predicate->Evaluate( value );
209 n.Value = this->m_InitValue;
212 this->_QueuePush( n );
218 n.Value = this->m_InsideValue;
219 this->m_CurrCount += double( 1 );
224 // -------------------------------------------------------------------------
225 template< class _TDataInterface >
226 void fpa::Filters::Mori< _TDataInterface >::
227 _PreComputeOutputValue( TNode& n )
229 // Nothing to do with this algorithm
232 // -------------------------------------------------------------------------
233 template< class _TDataInterface >
234 void fpa::Filters::Mori< _TDataInterface >::
237 if( this->_QueueSize( ) == 0 )
239 // Update peak detector
240 TPeak p = this->m_PeakDetector.AddValue(
241 *this->m_CurrThr, this->m_CurrCount
245 if( this->m_CurrThr != this->m_Thresholds.end( ) )
247 // Update predicate and counting value
248 this->m_Predicate->SetUpperThreshold( *( this->m_CurrThr ) );
249 this->m_CurrCount = double( 0 );
251 // Peak detected? -> stop!
253 p == TPeakDetector::PosPeak &&
254 this->m_MinimumThreshold < *( this->m_CurrThr )
256 this->_QueueClear( );
259 this->_QueueClear( );
264 #endif // __fpa__Filters__Mori__hxx__