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;
117 std::cerr << ( this->m_CurrentThreshold != this->m_Thresholds.end( ) ) << std::endl;
120 // -------------------------------------------------------------------------
121 template< class _TAlgorithm >
122 void fpa::Base::Mori< _TAlgorithm >::
125 if( this->m_Queues[ this->m_CurrentQueue ].size( ) == 0 )
127 this->m_Signal[ this->m_Signal.size( ) + 1 ] =
128 TSignalData( *this->m_CurrentThreshold, this->m_Count );
129 std::cerr << *( this->m_CurrentThreshold ) << std::endl;
130 this->m_CurrentThreshold++;
131 this->m_CurrentQueue = ( this->m_CurrentQueue + 1 ) % 2;
132 if( this->m_CurrentThreshold != this->m_Thresholds.end( ) )
134 this->m_Predicate->SetUpper( *( this->m_CurrentThreshold ) );
138 this->_QueueClear( );
143 // -------------------------------------------------------------------------
144 template< class _TAlgorithm >
145 bool fpa::Base::Mori< _TAlgorithm >::
146 _ComputeOutputValue( TNode& n )
148 TInputValue value = this->_GetInputValue( n.Vertex );
149 bool inside = this->m_Predicate->Evaluate( value );
150 n.Value = this->m_InsideValue;
154 this->m_Queues[ ( this->m_CurrentQueue + 1 ) % 2 ].push_back( n );
161 // -------------------------------------------------------------------------
162 template< class _TAlgorithm >
163 void fpa::Base::Mori< _TAlgorithm >::
166 this->m_Queues[ 0 ].clear( );
167 this->m_Queues[ 1 ].clear( );
170 // -------------------------------------------------------------------------
171 template< class _TAlgorithm >
172 typename fpa::Base::Mori< _TAlgorithm >::
173 TNode fpa::Base::Mori< _TAlgorithm >::
176 TNode n = this->m_Queues[ this->m_CurrentQueue ].front( );
177 this->m_Queues[ this->m_CurrentQueue ].pop_front( );
181 // -------------------------------------------------------------------------
182 template< class _TAlgorithm >
183 void fpa::Base::Mori< _TAlgorithm >::
184 _QueuePush( const TNode& node )
186 this->m_Queues[ this->m_CurrentQueue ].push_back( node );
189 // -------------------------------------------------------------------------
190 template< class _TAlgorithm >
191 unsigned long fpa::Base::Mori< _TAlgorithm >::
194 return( this->m_Queues[ this->m_CurrentQueue ].size( ) );
197 // -------------------------------------------------------------------------
198 template< class _TAlgorithm >
199 void fpa::Base::Mori< _TAlgorithm >::
200 _PrepareSeeds( TNodes& nodes )
202 typename TNodes::iterator nIt = nodes.begin( );
203 for( ; nIt != nodes.end( ); ++nIt )
204 nIt->Value = this->m_InsideValue;
207 #endif // __fpa__Base__Mori__hxx__