1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Base__RegionGrow__hxx__
7 #define __fpa__Base__RegionGrow__hxx__
11 // -------------------------------------------------------------------------
12 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
14 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
16 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
17 GetIntensityPredicate( ) const
19 return( this->m_IntensityFunctor );
22 // -------------------------------------------------------------------------
23 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
25 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
27 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
28 GetVertexPredicate( ) const
30 return( this->m_VertexFunctor );
33 // -------------------------------------------------------------------------
34 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
36 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
37 SetPredicate( TIntensityFunctor* functor )
39 if( this->m_IntensityFunctor.GetPointer( ) != functor )
41 this->m_IntensityFunctor = functor;
47 // -------------------------------------------------------------------------
48 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
50 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
51 SetPredicate( TVertexFunctor* functor )
53 if( this->m_VertexFunctor.GetPointer( ) != functor )
55 this->m_VertexFunctor = functor;
61 // -------------------------------------------------------------------------
62 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
63 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
66 _TMarksInterface( this ),
67 _TSeedsInterface( this ),
68 m_InsideValue( TOutputValue( 1 ) ),
69 m_OutsideValue( TOutputValue( 0 ) )
73 // -------------------------------------------------------------------------
74 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
75 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
80 // -------------------------------------------------------------------------
81 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
83 fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
87 this->_ConfigureOutputs( this->m_OutsideValue );
88 this->_InitMarks( this->GetNumberOfSeeds( ) );
91 typedef std::pair< TVertex, unsigned long > _TNode;
92 std::queue< _TNode > q;
93 unsigned long frontId = 1;
94 for( TVertex seed: this->GetSeeds( ) )
95 q.push( _TNode( seed, frontId++ ) );
98 while( q.size( ) > 0 )
100 // Get next candidate
101 _TNode node = q.front( );
103 if( this->_IsMarked( node.first ) )
105 this->_Mark( node.first, node.second );
107 // Apply inclusion predicate
108 TInputValue value = this->_GetInputValue( node.first );
110 if( this->m_IntensityFunctor.IsNotNull( ) )
111 inside = this->m_IntensityFunctor->Evaluate( value );
112 if( this->m_VertexFunctor.IsNotNull( ) )
113 inside &= this->m_VertexFunctor->Evaluate( node.first );
117 // Ok, pixel lays inside region
118 this->_SetOutputValue( node.first, this->m_InsideValue );
121 TVertices neighbors = this->_GetNeighbors( node.first );
122 for( TVertex neigh: neighbors )
124 if( this->_IsMarked( neigh ) )
126 // Invoke stop at collisions
127 unsigned long nColl = this->_Collisions( node.first, neigh );
129 this->StopAtOneFront( ) &&
130 this->GetNumberOfSeeds( ) > 1 &&
133 while( q.size( ) > 0 )
137 q.push( _TNode( neigh, node.second ) );
145 #endif // __fpa__Base__RegionGrow__hxx__