]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/Mori.hxx
cff5fe8957e7128fb2e1c821d8b8396cfa8b845e
[FrontAlgorithms.git] / lib / fpa / Base / Mori.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __fpa__Base__Mori__hxx__
7 #define __fpa__Base__Mori__hxx__
8
9 // -------------------------------------------------------------------------
10 template< class _TAlgorithm >
11 itk::ModifiedTimeType fpa::Base::Mori< _TAlgorithm >::
12 GetMTime( ) const
13 {
14   itk::ModifiedTimeType t = this->Superclass::GetMTime( );
15   itk::ModifiedTimeType q = this->m_Predicate->GetMTime( );
16   return( ( q < t )? q: t );
17 }
18
19 // -------------------------------------------------------------------------
20 template< class _TAlgorithm >
21 typename fpa::Base::Mori< _TAlgorithm >::
22 TOutputValue fpa::Base::Mori< _TAlgorithm >::
23 GetOutsideValue( ) const
24 {
25   return( this->GetInitValue( ) );
26 }
27
28 // -------------------------------------------------------------------------
29 template< class _TAlgorithm >
30 void fpa::Base::Mori< _TAlgorithm >::
31 SetOutsideValue( const TOutputValue& v )
32 {
33   this->SetInitValue( v );
34 }
35
36 // -------------------------------------------------------------------------
37 template< class _TAlgorithm >
38 void fpa::Base::Mori< _TAlgorithm >::
39 ClearThresholds( )
40 {
41   this->m_Thresholds.clear( );
42   this->Modified( );
43 }
44
45 // -------------------------------------------------------------------------
46 template< class _TAlgorithm >
47 void fpa::Base::Mori< _TAlgorithm >::
48 AddThreshold( const TInputValue& thr )
49 {
50   if( this->m_Thresholds.insert( thr ).second )
51     this->Modified( );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class _TAlgorithm >
56 void fpa::Base::Mori< _TAlgorithm >::
57 SetThresholds(
58   const TInputValue& init,
59   const TInputValue& end,
60   unsigned long number_of_thresholds
61   )
62 {
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 ) ) ) );
69 }
70
71 // -------------------------------------------------------------------------
72 template< class _TAlgorithm >
73 fpa::Base::Mori< _TAlgorithm >::
74 Mori( )
75   : Superclass( ),
76     m_InsideValue( TOutputValue( 1 ) )
77 {
78   this->SetInitValue( TOutputValue( 0 ) );
79   this->m_Predicate = TPredicate::New( );
80 }
81
82 // -------------------------------------------------------------------------
83 template< class _TAlgorithm >
84 fpa::Base::Mori< _TAlgorithm >::
85 ~Mori( )
86 {
87 }
88
89 // -------------------------------------------------------------------------
90 template< class _TAlgorithm >
91 void fpa::Base::Mori< _TAlgorithm >::
92 _BeforeGenerateData( )
93 {
94   this->Superclass::_BeforeGenerateData( );
95
96   this->_QueueClear( );
97   this->m_CurrentQueue = 0;
98 }
99
100 // -------------------------------------------------------------------------
101 template< class _TAlgorithm >
102 void fpa::Base::Mori< _TAlgorithm >::
103 _AfterGenerateData( )
104 {
105   this->Superclass::_AfterGenerateData( );
106 }
107
108 // -------------------------------------------------------------------------
109 template< class _TAlgorithm >
110 typename fpa::Base::Mori< _TAlgorithm >::
111 TOutputValue fpa::Base::Mori< _TAlgorithm >::
112 _ComputeOutputValue( const TNode& n )
113 {
114   TInputValue value = this->_GetInputValue( n.Vertex );
115   bool inside = this->m_Predicate->Evaluate( value );
116   if( !inside )
117   {
118     // TODO: Update new queue
119     return( this->m_InitValue );
120   }
121   else
122     return( this->m_InsideValue );
123 }
124   
125 // -------------------------------------------------------------------------
126 template< class _TAlgorithm >
127 void fpa::Base::Mori< _TAlgorithm >::
128 _QueueClear( )
129 {
130   this->m_Queues[ 0 ].clear( );
131   this->m_Queues[ 1 ].clear( );
132 }
133
134 // -------------------------------------------------------------------------
135 template< class _TAlgorithm >
136 typename fpa::Base::Mori< _TAlgorithm >::
137 TNode fpa::Base::Mori< _TAlgorithm >::
138 _QueuePop( )
139 {
140   TNode n = this->m_Queues[ this->m_CurrentQueue ].front( );
141   this->m_Queues[ this->m_CurrentQueue ].pop_front( );
142   return( n );
143 }
144
145 // -------------------------------------------------------------------------
146 template< class _TAlgorithm >
147 void fpa::Base::Mori< _TAlgorithm >::
148 _QueuePush( const TNode& node )
149 {
150   // TODO: Update mark
151   this->m_Queues[ this->m_CurrentQueue ].push_back( node );
152 }
153
154 // -------------------------------------------------------------------------
155 template< class _TAlgorithm >
156 unsigned long fpa::Base::Mori< _TAlgorithm >::
157 _QueueSize( ) const
158 {
159   return( this->m_Queues[ this->m_CurrentQueue ].size( ) );
160 }
161
162 // -------------------------------------------------------------------------
163 template< class _TAlgorithm >
164 void fpa::Base::Mori< _TAlgorithm >::
165 _PrepareSeeds( TNodes& nodes )
166 {
167   typename TNodes::iterator nIt = nodes.begin( );
168   for( ; nIt != nodes.end( ); ++nIt )
169     nIt->Value = this->m_InsideValue;
170 }
171
172 /* TODO
173    typename TPredicate::Pointer m_Predicate;
174    TThresholds m_Thresholds;
175    TQueue m_Queues[ 2 ];
176    unsigned int m_CurrentQueue;
177    TOutputValue m_InsideValue;
178 */
179
180 #endif // __fpa__Base__Mori__hxx__
181
182 // eof - $RCSfile$