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__
8 // -------------------------------------------------------------------------
9 template< class _TTraits >
10 typename fpa::Filters::Mori< _TTraits >::
11 TOutputValue fpa::Filters::Mori< _TTraits >::
12 GetOutsideValue( ) const
14 return( this->GetInitValue( ) );
17 // -------------------------------------------------------------------------
18 template< class _TTraits >
19 void fpa::Filters::Mori< _TTraits >::
20 SetOutsideValue( const TOutputValue& v )
22 this->SetInitValue( v );
25 // -------------------------------------------------------------------------
26 template< class _TTraits >
27 unsigned long fpa::Filters::Mori< _TTraits >::
28 GetSignalKernelSize( ) const
30 return( this->m_PeakDetector.GetKernelSize( ) );
33 // -------------------------------------------------------------------------
34 template< class _TTraits >
35 void fpa::Filters::Mori< _TTraits >::
36 SetSignalKernelSize( unsigned long k )
38 this->m_PeakDetector.SetKernelSize( k );
42 // -------------------------------------------------------------------------
43 template< class _TTraits >
44 double fpa::Filters::Mori< _TTraits >::
45 GetSignalThreshold( ) const
47 return( this->m_PeakDetector.GetThreshold( ) );
50 // -------------------------------------------------------------------------
51 template< class _TTraits >
52 void fpa::Filters::Mori< _TTraits >::
53 SetSignalThreshold( double t )
55 this->m_PeakDetector.SetThreshold( t );
59 // -------------------------------------------------------------------------
60 template< class _TTraits >
61 double fpa::Filters::Mori< _TTraits >::
62 GetSignalInfluence( ) const
64 return( this->m_PeakDetector.GetInfluence( ) );
67 // -------------------------------------------------------------------------
68 template< class _TTraits >
69 void fpa::Filters::Mori< _TTraits >::
70 SetSignalInfluence( double i )
72 this->m_PeakDetector.SetInfluence( i );
76 // -------------------------------------------------------------------------
77 template< class _TTraits >
78 void fpa::Filters::Mori< _TTraits >::
81 this->m_Thresholds.clear( );
85 // -------------------------------------------------------------------------
86 template< class _TTraits >
87 void fpa::Filters::Mori< _TTraits >::
88 AddThreshold( const TInputValue& thr )
90 if( this->m_Thresholds.insert( thr ).second )
94 // -------------------------------------------------------------------------
95 template< class _TTraits >
96 const typename fpa::Filters::Mori< _TTraits >::
97 TThresholds& fpa::Filters::Mori< _TTraits >::
98 GetThresholds( ) const
100 return( this->m_Thresholds );
103 // -------------------------------------------------------------------------
104 template< class _TTraits >
105 unsigned long fpa::Filters::Mori< _TTraits >::
106 GetNumberOfEvaluatedThresholds( ) const
108 return( this->m_PeakDetector.GetNumberOfSamples( ) );
111 // -------------------------------------------------------------------------
112 template< class _TTraits >
113 typename fpa::Filters::Mori< _TTraits >::
114 TInputValue fpa::Filters::Mori< _TTraits >::
115 GetOptimumThreshold( ) const
117 TInputValue thr = TInputValue( 0 );
118 unsigned long n = this->m_PeakDetector.GetNumberOfSamples( );
120 thr = TInputValue( this->m_PeakDetector.GetXValues( )[ n - 2 ] );
124 // -------------------------------------------------------------------------
125 template< class _TTraits >
126 void fpa::Filters::Mori< _TTraits >::
128 unsigned long i, double& x, double& y, TPeak& p
131 if( i < this->m_PeakDetector.GetNumberOfSamples( ) )
133 x = this->m_PeakDetector.GetXValues( )[ i ];
134 y = this->m_PeakDetector.GetYValues( )[ i ];
135 p = this->m_PeakDetector.GetPeaks( )[ i ];
140 // -------------------------------------------------------------------------
141 template< class _TTraits >
142 void fpa::Filters::Mori< _TTraits >::
144 const TInputValue& lower,
145 const TInputValue& upper,
146 const TInputValue& delta
149 for( TInputValue t = lower; t <= upper; t += delta )
150 this->AddThreshold( t );
153 // -------------------------------------------------------------------------
154 template< class _TTraits >
155 fpa::Filters::Mori< _TTraits >::
158 m_InsideValue( TOutputValue( 1 ) )
160 this->SetOutsideValue( 0 );
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 _TTraits >
174 fpa::Filters::Mori< _TTraits >::
179 // -------------------------------------------------------------------------
180 template< class _TTraits >
181 void fpa::Filters::Mori< _TTraits >::
182 _BeforeGenerateData( )
184 this->Superclass::_BeforeGenerateData( );
187 this->_QueueClear( );
188 this->m_CurrQueue = 0;
190 // Prepare iteration over all thresholds
191 this->m_CurrThr = this->m_Thresholds.begin( );
192 this->m_Predicate->SetLowerThreshold( *( this->m_CurrThr ) );
194 this->m_Predicate->SetUpperThreshold( *( this->m_CurrThr ) );
196 // Prepare counting signal
197 this->m_CurrCount = double( 0 );
198 this->m_PeakDetector.Clear( );
201 // -------------------------------------------------------------------------
202 template< class _TTraits >
203 void fpa::Filters::Mori< _TTraits >::
206 if( this->m_Queues[ this->m_CurrQueue ].size( ) == 0 )
208 // Update peak detector
209 TPeak p = this->m_PeakDetector.AddValue(
210 *this->m_CurrThr, this->m_CurrCount
213 this->m_CurrQueue = ( this->m_CurrQueue + 1 ) % 2;
214 if( this->m_CurrThr != this->m_Thresholds.end( ) )
216 // Update predicate and counting value
217 this->m_Predicate->SetUpperThreshold( *( this->m_CurrThr ) );
218 this->m_CurrCount = double( 0 );
220 // Peak detected? -> stop!
222 p == TPeakDetector::PosPeak &&
223 this->m_MinimumThreshold < *( this->m_CurrThr )
225 this->_QueueClear( );
228 this->_QueueClear( );
233 // -------------------------------------------------------------------------
234 template< class _TTraits >
235 void fpa::Filters::Mori< _TTraits >::
236 _UpdateOutputValue( TNode& n )
238 TInputValue value = this->_GetInputValue( n.Vertex );
239 bool inside = this->m_Predicate->Evaluate( value );
242 n.Value = this->m_InitValue;
244 this->m_Queues[ ( this->m_CurrQueue + 1 ) % 2 ].push_back( n );
249 n.Value = this->m_InsideValue;
250 this->m_CurrCount += double( 1 );
255 // -------------------------------------------------------------------------
256 template< class _TTraits >
257 void fpa::Filters::Mori< _TTraits >::
260 this->m_Queues[ 0 ].clear( );
261 this->m_Queues[ 1 ].clear( );
264 // -------------------------------------------------------------------------
265 template< class _TTraits >
266 typename fpa::Filters::Mori< _TTraits >::
267 TNode fpa::Filters::Mori< _TTraits >::
270 TNode n = this->m_Queues[ this->m_CurrQueue ].front( );
271 this->m_Queues[ this->m_CurrQueue ].pop_front( );
275 // -------------------------------------------------------------------------
276 template< class _TTraits >
277 void fpa::Filters::Mori< _TTraits >::
278 _QueuePush( const TNode& n )
280 this->m_Queues[ this->m_CurrQueue ].push_back( n );
283 // -------------------------------------------------------------------------
284 template< class _TTraits >
285 unsigned long fpa::Filters::Mori< _TTraits >::
288 return( this->m_Queues[ this->m_CurrQueue ].size( ) );
290 // -------------------------------------------------------------------------
291 template< class _TTraits >
292 void fpa::Filters::Mori< _TTraits >::
293 _ComputeOutputValue( TNode& n )
298 #endif // __fpa__Filters__Mori__hxx__