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 typename TSeedsInterface::TSeeds::const_iterator sIt = this->BeginSeeds( );
95 for( ; sIt != this->EndSeeds( ); ++sIt )
96 q.push( _TNode( *sIt, frontId++ ) );
99 while( q.size( ) > 0 )
101 // Get next candidate
102 _TNode node = q.front( );
104 if( this->_IsMarked( node.first ) )
106 this->_Mark( node.first, node.second );
108 // Apply inclusion predicate
109 TInputValue value = this->_GetInputValue( node.first );
111 if( this->m_IntensityFunctor.IsNotNull( ) )
112 inside = this->m_IntensityFunctor->Evaluate( value );
113 if( this->m_VertexFunctor.IsNotNull( ) )
114 inside &= this->m_VertexFunctor->Evaluate( node.first );
118 // Ok, pixel lays inside region
119 this->_SetOutputValue( node.first, this->m_InsideValue );
122 TVertices neighbors = this->_GetNeighbors( node.first );
123 typename TVertices::const_iterator neighIt = neighbors.begin( );
124 for( ; neighIt != neighbors.end( ); ++neighIt )
126 TVertex neigh = *neighIt;
127 if( this->_IsMarked( neigh ) )
129 // Invoke stop at collisions
130 unsigned long nColl = this->_Collisions( node.first, neigh );
132 this->StopAtOneFront( ) &&
133 this->GetNumberOfSeeds( ) > 1 &&
136 while( q.size( ) > 0 )
140 q.push( _TNode( neigh, node.second ) );
148 #endif // __fpa__Base__RegionGrow__hxx__