]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/RegionGrow.hxx
...
[FrontAlgorithms.git] / lib / fpa / Base / RegionGrow.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __fpa__Base__RegionGrow__hxx__
7 #define __fpa__Base__RegionGrow__hxx__
8
9 // -------------------------------------------------------------------------
10 template< class _TAlgorithm >
11 itk::ModifiedTimeType fpa::Base::RegionGrow< _TAlgorithm >::
12 GetMTime( ) const
13 {
14   itk::ModifiedTimeType t = this->Superclass::GetMTime( );
15   if( this->m_ValuePredicate.IsNotNull( ) )
16   {
17     itk::ModifiedTimeType q = this->m_ValuePredicate->GetMTime( );
18     t = ( q < t )? q: t;
19
20   } // fi
21   if( this->m_VertexPredicate.IsNotNull( ) )
22   {
23     itk::ModifiedTimeType q = this->m_VertexPredicate->GetMTime( );
24     t = ( q < t )? q: t;
25
26   } // fi
27
28   return( t );
29 }
30
31 // -------------------------------------------------------------------------
32 template< class _TAlgorithm >
33 typename fpa::Base::RegionGrow< _TAlgorithm >::
34 TOutputValue fpa::Base::RegionGrow< _TAlgorithm >::
35 GetOutsideValue( ) const
36 {
37   return( this->GetInitValue( ) );
38 }
39
40 // -------------------------------------------------------------------------
41 template< class _TAlgorithm >
42 void fpa::Base::RegionGrow< _TAlgorithm >::
43 SetOutsideValue( const TOutputValue& v )
44 {
45   this->SetInitValue( v );
46 }
47
48 // -------------------------------------------------------------------------
49 template< class _TAlgorithm >
50 void fpa::Base::RegionGrow< _TAlgorithm >::
51 SetPredicate( TValuePredicate* p )
52 {
53   if( this->m_ValuePredicate.GetPointer( ) != p )
54   {
55     this->m_ValuePredicate = p;
56     this->Modified( );
57
58   } // fi
59 }
60
61 // -------------------------------------------------------------------------
62 template< class _TAlgorithm >
63 void fpa::Base::RegionGrow< _TAlgorithm >::
64 SetPredicate( TVertexPredicate* p )
65 {
66   if( this->m_VertexPredicate.GetPointer( ) != p )
67   {
68     this->m_VertexPredicate = p;
69     this->Modified( );
70
71   } // fi
72 }
73
74 // -------------------------------------------------------------------------
75 template< class _TAlgorithm >
76 fpa::Base::RegionGrow< _TAlgorithm >::
77 RegionGrow( )
78   : Superclass( ),
79     m_InsideValue( TOutputValue( 1 ) )
80 {
81   this->SetInitValue( TOutputValue( 0 ) );
82 }
83
84 // -------------------------------------------------------------------------
85 template< class _TAlgorithm >
86 fpa::Base::RegionGrow< _TAlgorithm >::
87 ~RegionGrow( )
88 {
89 }
90
91 // -------------------------------------------------------------------------
92 template< class _TAlgorithm >
93 void fpa::Base::RegionGrow< _TAlgorithm >::
94 _ComputeOutputValue( TNode& n )
95 {
96   // Do nothing!!!
97 }
98
99 // -------------------------------------------------------------------------
100 template< class _TAlgorithm >
101 void fpa::Base::RegionGrow< _TAlgorithm >::
102 _UpdateOutputValue( TNode& n )
103 {
104   TInputValue value = this->_GetInputValue( n.Vertex );
105   bool inside = false;
106   if( this->m_ValuePredicate.IsNotNull( ) )
107     inside = this->m_ValuePredicate->Evaluate( value );
108   if( this->m_VertexPredicate.IsNotNull( ) )
109     inside &= this->m_VertexPredicate->Evaluate( n.Vertex );
110   if( !inside )
111   {
112     n.Value = this->m_InitValue;
113     n.FrontId = 0;
114   }
115   else
116     n.Value = this->m_InsideValue;
117   this->Superclass::_UpdateOutputValue( n );
118 }
119
120 // -------------------------------------------------------------------------
121 template< class _TAlgorithm >
122 void fpa::Base::RegionGrow< _TAlgorithm >::
123 _QueueClear( )
124 {
125   this->m_Queue.clear( );
126 }
127
128 // -------------------------------------------------------------------------
129 template< class _TAlgorithm >
130 typename fpa::Base::RegionGrow< _TAlgorithm >::
131 TNode fpa::Base::RegionGrow< _TAlgorithm >::
132 _QueuePop( )
133 {
134   TNode n = this->m_Queue.front( );
135   this->m_Queue.pop_front( );
136   return( n );
137 }
138
139 // -------------------------------------------------------------------------
140 template< class _TAlgorithm >
141 void fpa::Base::RegionGrow< _TAlgorithm >::
142 _QueuePush( const TNode& node )
143 {
144   this->m_Queue.push_back( node );
145 }
146
147 // -------------------------------------------------------------------------
148 template< class _TAlgorithm >
149 unsigned long fpa::Base::RegionGrow< _TAlgorithm >::
150 _QueueSize( ) const
151 {
152   return( this->m_Queue.size( ) );
153 }
154
155 // -------------------------------------------------------------------------
156 template< class _TAlgorithm >
157 void fpa::Base::RegionGrow< _TAlgorithm >::
158 _PrepareSeeds( TNodes& nodes )
159 {
160   typename TNodes::iterator nIt = nodes.begin( );
161   for( ; nIt != nodes.end( ); ++nIt )
162     nIt->Value = this->m_InitValue;
163 }
164
165 #endif // __fpa__Base__RegionGrow__hxx__
166
167 // eof - $RCSfile$