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 unsigned long number_of_thresholds
63 double i = double( init );
64 double e = double( end );
65 double n = double( number_of_thresholds );
66 double d = ( e - i ) / n;
67 for( unsigned long c = 0; c <= number_of_thresholds; ++c )
68 this->AddThreshold( TInputValue( i + ( d * double( c ) ) ) );
71 // -------------------------------------------------------------------------
72 template< class _TAlgorithm >
73 fpa::Base::Mori< _TAlgorithm >::
76 m_InsideValue( TOutputValue( 1 ) )
78 this->SetInitValue( TOutputValue( 0 ) );
79 this->m_Predicate = TPredicate::New( );
82 // -------------------------------------------------------------------------
83 template< class _TAlgorithm >
84 fpa::Base::Mori< _TAlgorithm >::
89 // -------------------------------------------------------------------------
90 template< class _TAlgorithm >
91 void fpa::Base::Mori< _TAlgorithm >::
92 _BeforeGenerateData( )
94 this->Superclass::_BeforeGenerateData( );
97 this->m_CurrentQueue = 0;
100 // -------------------------------------------------------------------------
101 template< class _TAlgorithm >
102 void fpa::Base::Mori< _TAlgorithm >::
103 _AfterGenerateData( )
105 this->Superclass::_AfterGenerateData( );
108 // -------------------------------------------------------------------------
109 template< class _TAlgorithm >
110 typename fpa::Base::Mori< _TAlgorithm >::
111 TOutputValue fpa::Base::Mori< _TAlgorithm >::
112 _ComputeOutputValue( const TNode& n )
114 TInputValue value = this->_GetInputValue( n.Vertex );
115 bool inside = this->m_Predicate->Evaluate( value );
118 // TODO: Update new queue
119 return( this->m_InitValue );
122 return( this->m_InsideValue );
125 // -------------------------------------------------------------------------
126 template< class _TAlgorithm >
127 void fpa::Base::Mori< _TAlgorithm >::
130 this->m_Queues[ 0 ].clear( );
131 this->m_Queues[ 1 ].clear( );
134 // -------------------------------------------------------------------------
135 template< class _TAlgorithm >
136 typename fpa::Base::Mori< _TAlgorithm >::
137 TNode fpa::Base::Mori< _TAlgorithm >::
140 TNode n = this->m_Queues[ this->m_CurrentQueue ].front( );
141 this->m_Queues[ this->m_CurrentQueue ].pop_front( );
145 // -------------------------------------------------------------------------
146 template< class _TAlgorithm >
147 void fpa::Base::Mori< _TAlgorithm >::
148 _QueuePush( const TNode& node )
151 this->m_Queues[ this->m_CurrentQueue ].push_back( node );
154 // -------------------------------------------------------------------------
155 template< class _TAlgorithm >
156 unsigned long fpa::Base::Mori< _TAlgorithm >::
159 return( this->m_Queues[ this->m_CurrentQueue ].size( ) );
162 // -------------------------------------------------------------------------
163 template< class _TAlgorithm >
164 void fpa::Base::Mori< _TAlgorithm >::
165 _PrepareSeeds( TNodes& nodes )
167 typename TNodes::iterator nIt = nodes.begin( );
168 for( ; nIt != nodes.end( ); ++nIt )
169 nIt->Value = this->m_InsideValue;
173 typename TPredicate::Pointer m_Predicate;
174 TThresholds m_Thresholds;
175 TQueue m_Queues[ 2 ];
176 unsigned int m_CurrentQueue;
177 TOutputValue m_InsideValue;
180 #endif // __fpa__Base__Mori__hxx__