1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Base__Mori__hxx__
7 #define __fpa__Base__Mori__hxx__
9 // -------------------------------------------------------------------------
10 template< class _TAlgorithm >
11 itk::ModifiedTimeType fpa::Base::Mori< _TAlgorithm >::
14 itk::ModifiedTimeType t = this->Superclass::GetMTime( );
15 itk::ModifiedTimeType q = this->m_Predicate->GetMTime( );
16 return( ( q < t )? q: t );
19 // -------------------------------------------------------------------------
20 template< class _TAlgorithm >
21 typename fpa::Base::Mori< _TAlgorithm >::
22 TOutputValue fpa::Base::Mori< _TAlgorithm >::
23 GetOutsideValue( ) const
25 return( this->GetInitValue( ) );
28 // -------------------------------------------------------------------------
29 template< class _TAlgorithm >
30 void fpa::Base::Mori< _TAlgorithm >::
31 SetOutsideValue( const TOutputValue& v )
33 this->SetInitValue( v );
36 // -------------------------------------------------------------------------
37 template< class _TAlgorithm >
38 unsigned long fpa::Base::Mori< _TAlgorithm >::
39 GetSignalKernelSize( ) const
41 return( this->m_PeakDetector.GetKernelSize( ) );
44 // -------------------------------------------------------------------------
45 template< class _TAlgorithm >
46 double fpa::Base::Mori< _TAlgorithm >::
47 GetSignalThreshold( ) const
49 return( this->m_PeakDetector.GetThreshold( ) );
52 // -------------------------------------------------------------------------
53 template< class _TAlgorithm >
54 double fpa::Base::Mori< _TAlgorithm >::
55 GetSignalInfluence( ) const
57 return( this->m_PeakDetector.GetInfluence( ) );
60 // -------------------------------------------------------------------------
61 template< class _TAlgorithm >
62 void fpa::Base::Mori< _TAlgorithm >::
63 SetSignalKernelSize( unsigned long k )
65 this->m_PeakDetector.SetKernelSize( k );
69 // -------------------------------------------------------------------------
70 template< class _TAlgorithm >
71 void fpa::Base::Mori< _TAlgorithm >::
72 SetSignalThreshold( double t )
74 this->m_PeakDetector.SetThreshold( t );
78 // -------------------------------------------------------------------------
79 template< class _TAlgorithm >
80 void fpa::Base::Mori< _TAlgorithm >::
81 SetSignalInfluence( double i )
83 this->m_PeakDetector.SetInfluence( i );
87 // -------------------------------------------------------------------------
88 template< class _TAlgorithm >
89 void fpa::Base::Mori< _TAlgorithm >::
92 this->m_Thresholds.clear( );
96 // -------------------------------------------------------------------------
97 template< class _TAlgorithm >
98 void fpa::Base::Mori< _TAlgorithm >::
99 AddThreshold( const TInputValue& thr )
101 if( this->m_Thresholds.insert( thr ).second )
105 // -------------------------------------------------------------------------
106 template< class _TAlgorithm >
107 void fpa::Base::Mori< _TAlgorithm >::
109 const TInputValue& init,
110 const TInputValue& end,
111 const TInputValue& delta
114 for( TInputValue thr = init; thr <= end; thr += delta )
115 this->AddThreshold( thr );
118 // -------------------------------------------------------------------------
119 template< class _TAlgorithm >
120 const typename fpa::Base::Mori< _TAlgorithm >::
121 TThresholds& fpa::Base::Mori< _TAlgorithm >::
122 GetThresholds( ) const
124 return( this->m_Thresholds );
127 // -------------------------------------------------------------------------
128 template< class _TAlgorithm >
129 unsigned long fpa::Base::Mori< _TAlgorithm >::
130 GetNumberOfEvaluatedThresholds( ) const
132 return( this->m_PeakDetector.GetNumberOfSamples( ) );
135 // -------------------------------------------------------------------------
136 template< class _TAlgorithm >
137 typename fpa::Base::Mori< _TAlgorithm >::
138 TInputValue fpa::Base::Mori< _TAlgorithm >::
139 GetOptimumThreshold( ) const
141 TInputValue thr = TInputValue( 0 );
142 unsigned long n = this->m_PeakDetector.GetNumberOfSamples( );
144 thr = TInputValue( this->m_PeakDetector.GetXValues( )[ n - 2 ] );
148 // -------------------------------------------------------------------------
149 template< class _TAlgorithm >
150 void fpa::Base::Mori< _TAlgorithm >::
151 GetSignalValues( unsigned long i, double& x, double& y, TPeak& p ) const
153 if( i < this->m_PeakDetector.GetNumberOfSamples( ) )
155 x = this->m_PeakDetector.GetXValues( )[ i ];
156 y = this->m_PeakDetector.GetYValues( )[ i ];
157 p = this->m_PeakDetector.GetPeaks( )[ i ];
162 // -------------------------------------------------------------------------
163 template< class _TAlgorithm >
164 fpa::Base::Mori< _TAlgorithm >::
167 m_InsideValue( TOutputValue( 1 ) )
169 this->SetInitValue( TOutputValue( 0 ) );
170 this->m_Predicate = TPredicate::New( );
171 this->m_Predicate->StrictOff( );
172 if( std::numeric_limits< TInputValue >::is_integer )
173 this->m_MinimumThreshold = std::numeric_limits< TInputValue >::min( );
175 this->m_MinimumThreshold = -std::numeric_limits< TInputValue >::max( );
176 this->m_PeakDetector.SetKernelSize( 20 );
177 this->m_PeakDetector.SetThreshold( 500 );
178 this->m_PeakDetector.SetInfluence( 0.5 );
181 // -------------------------------------------------------------------------
182 template< class _TAlgorithm >
183 fpa::Base::Mori< _TAlgorithm >::
188 // -------------------------------------------------------------------------
189 template< class _TAlgorithm >
190 void fpa::Base::Mori< _TAlgorithm >::
191 _BeforeGenerateData( )
193 this->Superclass::_BeforeGenerateData( );
196 this->_QueueClear( );
197 this->m_CurrQueue = 0;
199 // Prepare iteration over all thresholds
200 this->m_CurrThr = this->m_Thresholds.begin( );
201 this->m_Predicate->SetLower( *( this->m_CurrThr ) );
203 this->m_Predicate->SetUpper( *( this->m_CurrThr ) );
205 // Prepare counting signal
206 this->m_CurrCount = double( 0 );
207 this->m_PeakDetector.Clear( );
210 // -------------------------------------------------------------------------
211 template< class _TAlgorithm >
212 void fpa::Base::Mori< _TAlgorithm >::
215 if( this->m_Queues[ this->m_CurrQueue ].size( ) == 0 )
217 // Update peak detector
218 TPeak p = this->m_PeakDetector.AddValue(
219 *this->m_CurrThr, this->m_CurrCount
222 this->m_CurrQueue = ( this->m_CurrQueue + 1 ) % 2;
223 if( this->m_CurrThr != this->m_Thresholds.end( ) )
225 // Update predicate and counting value
226 this->m_Predicate->SetUpper( *( this->m_CurrThr ) );
227 this->m_CurrCount = double( 0 );
229 // Peak detected? -> stop!
231 p == TPeakDetector::PosPeak &&
232 this->m_MinimumThreshold < *( this->m_CurrThr )
234 this->_QueueClear( );
237 this->_QueueClear( );
242 // -------------------------------------------------------------------------
243 template< class _TAlgorithm >
244 void fpa::Base::Mori< _TAlgorithm >::
245 _ComputeOutputValue( TNode& n )
250 // -------------------------------------------------------------------------
251 template< class _TAlgorithm >
252 void fpa::Base::Mori< _TAlgorithm >::
253 _UpdateOutputValue( TNode& n )
255 TInputValue value = this->_GetInputValue( n.Vertex );
256 bool inside = this->m_Predicate->Evaluate( value );
259 n.Value = this->m_InitValue;
261 this->m_Queues[ ( this->m_CurrQueue + 1 ) % 2 ].push_back( n );
266 n.Value = this->m_InsideValue;
267 this->m_CurrCount += double( 1 );
270 this->Superclass::_UpdateOutputValue( n );
273 // -------------------------------------------------------------------------
274 template< class _TAlgorithm >
275 void fpa::Base::Mori< _TAlgorithm >::
278 this->m_Queues[ 0 ].clear( );
279 this->m_Queues[ 1 ].clear( );
282 // -------------------------------------------------------------------------
283 template< class _TAlgorithm >
284 typename fpa::Base::Mori< _TAlgorithm >::
285 TNode fpa::Base::Mori< _TAlgorithm >::
288 TNode n = this->m_Queues[ this->m_CurrQueue ].front( );
289 this->m_Queues[ this->m_CurrQueue ].pop_front( );
293 // -------------------------------------------------------------------------
294 template< class _TAlgorithm >
295 void fpa::Base::Mori< _TAlgorithm >::
296 _QueuePush( const TNode& node )
298 this->m_Queues[ this->m_CurrQueue ].push_back( node );
301 // -------------------------------------------------------------------------
302 template< class _TAlgorithm >
303 unsigned long fpa::Base::Mori< _TAlgorithm >::
306 return( this->m_Queues[ this->m_CurrQueue ].size( ) );
309 // -------------------------------------------------------------------------
310 template< class _TAlgorithm >
311 void fpa::Base::Mori< _TAlgorithm >::
312 _PrepareSeeds( TNodes& nodes )
314 typename TNodes::iterator nIt = nodes.begin( );
315 for( ; nIt != nodes.end( ); ++nIt )
316 nIt->Value = this->m_InitValue;
319 #endif // __fpa__Base__Mori__hxx__