// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #ifndef __fpa__Base__RegionGrow__hxx__ #define __fpa__Base__RegionGrow__hxx__ #include // ------------------------------------------------------------------------- template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > const typename fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: TIntensityFunctor* fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: GetIntensityPredicate( ) const { return( this->m_IntensityFunctor ); } // ------------------------------------------------------------------------- template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > const typename fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: TVertexFunctor* fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: GetVertexPredicate( ) const { return( this->m_VertexFunctor ); } // ------------------------------------------------------------------------- template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > void fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: SetPredicate( TIntensityFunctor* functor ) { if( this->m_IntensityFunctor.GetPointer( ) != functor ) { this->m_IntensityFunctor = functor; this->Modified( ); } // fi } // ------------------------------------------------------------------------- template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > void fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: SetPredicate( TVertexFunctor* functor ) { if( this->m_VertexFunctor.GetPointer( ) != functor ) { this->m_VertexFunctor = functor; this->Modified( ); } // fi } // ------------------------------------------------------------------------- template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: RegionGrow( ) : Superclass( ), _TMarksInterface( this ), _TSeedsInterface( this ), m_InsideValue( TOutputValue( 1 ) ), m_OutsideValue( TOutputValue( 0 ) ) { } // ------------------------------------------------------------------------- template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: ~RegionGrow( ) { } // ------------------------------------------------------------------------- template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > void fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: GenerateData( ) { // Init objects this->_ConfigureOutputs( this->m_OutsideValue ); this->_InitMarks( this->GetNumberOfSeeds( ) ); // Init queue typedef std::pair< TVertex, unsigned long > _TNode; std::queue< _TNode > q; unsigned long frontId = 1; typename TSeedsInterface::TSeeds::const_iterator sIt = this->BeginSeeds( ); for( ; sIt != this->EndSeeds( ); ++sIt ) q.push( _TNode( *sIt, frontId++ ) ); // Main loop while( q.size( ) > 0 ) { // Get next candidate _TNode node = q.front( ); q.pop( ); if( this->_IsMarked( node.first ) ) continue; this->_Mark( node.first, node.second ); // Apply inclusion predicate TInputValue value = this->_GetInputValue( node.first ); bool inside = false; if( this->m_IntensityFunctor.IsNotNull( ) ) inside = this->m_IntensityFunctor->Evaluate( value ); if( this->m_VertexFunctor.IsNotNull( ) ) inside &= this->m_VertexFunctor->Evaluate( node.first ); if( !inside ) continue; // Ok, pixel lays inside region this->_SetOutputValue( node.first, this->m_InsideValue ); // Add neighborhood TVertices neighbors = this->_GetNeighbors( node.first ); typename TVertices::const_iterator neighIt = neighbors.begin( ); bool coll = false; while( neighIt != neighbors.end( ) && !coll ) { TVertex neigh = *neighIt; if( this->_IsMarked( neigh ) ) { // Invoke stop at collisions unsigned long nColl = this->_Collisions( node.first, neigh ); if( this->StopAtOneFront( ) && this->GetNumberOfSeeds( ) > 1 && nColl == 1 ) { while( q.size( ) > 0 ) q.pop( ); coll = true; } // fi } else q.push( _TNode( neigh, node.second ) ); ++neighIt; } // elihw } // elihw this->_FreeMarks( ); } #endif // __fpa__Base__RegionGrow__hxx__ // eof - $RCSfile$