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 void fpa::Base::Mori< _TAlgorithm >::
41 this->m_Thresholds.clear( );
45 // -------------------------------------------------------------------------
46 template< class _TAlgorithm >
47 void fpa::Base::Mori< _TAlgorithm >::
48 AddThreshold( const TInputValue& thr )
50 if( this->m_Thresholds.insert( thr ).second )
54 // -------------------------------------------------------------------------
55 template< class _TAlgorithm >
56 void fpa::Base::Mori< _TAlgorithm >::
58 const TInputValue& init,
59 const TInputValue& end,
60 const TInputValue& delta
63 for( TInputValue thr = init; thr <= end; thr += delta )
64 this->AddThreshold( thr );
67 // -------------------------------------------------------------------------
68 template< class _TAlgorithm >
69 fpa::Base::Mori< _TAlgorithm >::
72 m_InsideValue( TOutputValue( 1 ) )
74 this->SetInitValue( TOutputValue( 0 ) );
75 this->m_Predicate = TPredicate::New( );
76 this->m_Predicate->StrictOff( );
79 // -------------------------------------------------------------------------
80 template< class _TAlgorithm >
81 fpa::Base::Mori< _TAlgorithm >::
86 // -------------------------------------------------------------------------
87 template< class _TAlgorithm >
88 void fpa::Base::Mori< _TAlgorithm >::
89 _BeforeGenerateData( )
91 this->Superclass::_BeforeGenerateData( );
94 this->m_CurrentQueue = 0;
95 this->m_CurrentThreshold = this->m_Thresholds.begin( );
96 this->m_Predicate->SetLower( *( this->m_CurrentThreshold ) );
97 this->m_CurrentThreshold++;
98 this->m_Predicate->SetUpper( *( this->m_CurrentThreshold ) );
100 this->m_Signal.clear( );
103 // -------------------------------------------------------------------------
104 template< class _TAlgorithm >
105 void fpa::Base::Mori< _TAlgorithm >::
106 _AfterGenerateData( )
108 // https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data
109 this->Superclass::_AfterGenerateData( );
111 typename TSignal::const_iterator sIt = this->m_Signal.begin( );
112 for( ; sIt != this->m_Signal.end( ); ++sIt )
114 std::cout << int( sIt->first ) << " " << int( sIt->second.first ) << " " << sIt->second.second << std::endl;
119 // -------------------------------------------------------------------------
120 template< class _TAlgorithm >
121 void fpa::Base::Mori< _TAlgorithm >::
124 if( this->m_Queues[ this->m_CurrentQueue ].size( ) == 0 )
126 this->m_Signal[ this->m_Signal.size( ) + 1 ] =
127 TSignalData( *this->m_CurrentThreshold, this->m_Count );
128 this->m_CurrentThreshold++;
129 this->m_CurrentQueue = ( this->m_CurrentQueue + 1 ) % 2;
130 if( this->m_CurrentThreshold != this->m_Thresholds.end( ) )
132 this->m_Predicate->SetUpper( *( this->m_CurrentThreshold ) );
136 this->_QueueClear( );
141 // -------------------------------------------------------------------------
142 template< class _TAlgorithm >
143 void fpa::Base::Mori< _TAlgorithm >::
144 _ComputeOutputValue( TNode& n )
149 // -------------------------------------------------------------------------
150 template< class _TAlgorithm >
151 void fpa::Base::Mori< _TAlgorithm >::
152 _UpdateOutputValue( TNode& n )
154 TInputValue value = this->_GetInputValue( n.Vertex );
155 bool inside = this->m_Predicate->Evaluate( value );
158 n.Value = this->m_InitValue;
160 this->m_Queues[ ( this->m_CurrentQueue + 1 ) % 2 ].push_back( n );
165 n.Value = this->m_InsideValue;
169 this->Superclass::_UpdateOutputValue( n );
172 // -------------------------------------------------------------------------
173 template< class _TAlgorithm >
174 void fpa::Base::Mori< _TAlgorithm >::
177 this->m_Queues[ 0 ].clear( );
178 this->m_Queues[ 1 ].clear( );
181 // -------------------------------------------------------------------------
182 template< class _TAlgorithm >
183 typename fpa::Base::Mori< _TAlgorithm >::
184 TNode fpa::Base::Mori< _TAlgorithm >::
187 TNode n = this->m_Queues[ this->m_CurrentQueue ].front( );
188 this->m_Queues[ this->m_CurrentQueue ].pop_front( );
192 // -------------------------------------------------------------------------
193 template< class _TAlgorithm >
194 void fpa::Base::Mori< _TAlgorithm >::
195 _QueuePush( const TNode& node )
197 this->m_Queues[ this->m_CurrentQueue ].push_back( node );
200 // -------------------------------------------------------------------------
201 template< class _TAlgorithm >
202 unsigned long fpa::Base::Mori< _TAlgorithm >::
205 return( this->m_Queues[ this->m_CurrentQueue ].size( ) );
208 // -------------------------------------------------------------------------
209 template< class _TAlgorithm >
210 void fpa::Base::Mori< _TAlgorithm >::
211 _PrepareSeeds( TNodes& nodes )
213 typename TNodes::iterator nIt = nodes.begin( );
214 for( ; nIt != nodes.end( ); ++nIt )
215 nIt->Value = this->m_InitValue;
218 #endif // __fpa__Base__Mori__hxx__