1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Image__RegionGrow__hxx__
7 #define __fpa__Image__RegionGrow__hxx__
11 // -------------------------------------------------------------------------
12 template< class _TInputImage, class _TOutputImage >
13 void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
14 SetPredicate( TIntensityFunctor* functor )
16 if( this->m_IntensityFunctor.GetPointer( ) != functor )
18 this->m_IntensityFunctor = functor;
24 // -------------------------------------------------------------------------
25 template< class _TInputImage, class _TOutputImage >
26 fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
29 TSeedsInterface( this ),
30 TMarksInterface( this ),
31 m_InsideValue( TInputPixel( 0 ) ),
32 m_OutsideValue( TInputPixel( 0 ) )
36 // -------------------------------------------------------------------------
37 template< class _TInputImage, class _TOutputImage >
38 fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
43 // -------------------------------------------------------------------------
44 template< class _TInputImage, class _TOutputImage >
45 void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
46 GenerateInputRequestedRegion( )
48 this->Superclass::GenerateInputRequestedRegion( );
49 if( this->GetInput( ) )
52 const_cast< TInputImage* >( this->GetInput( ) );
53 input->SetRequestedRegionToLargestPossibleRegion( );
58 // -------------------------------------------------------------------------
59 template< class _TInputImage, class _TOutputImage >
60 void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
61 EnlargeOutputRequestedRegion( itk::DataObject* output )
63 this->Superclass::EnlargeOutputRequestedRegion( output );
64 output->SetRequestedRegionToLargestPossibleRegion( );
67 // -------------------------------------------------------------------------
68 template< class _TInputImage, class _TOutputImage >
69 void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
72 const TInputImage* input = this->GetInput( );
73 TOutputImage* output = this->GetOutput( );
74 TRegion region = input->GetRequestedRegion( );
77 output->SetBufferedRegion( region );
79 output->FillBuffer( this->m_OutsideValue );
82 this->_InitMarks( this->GetNumberOfSeeds( ) );
85 typedef std::pair< TIndex, unsigned long > _TNode;
86 std::queue< _TNode > q;
87 unsigned long frontId = 1;
88 for( TIndex seed: this->GetSeeds( ) )
89 q.push( _TNode( seed, frontId++ ) );
92 while( q.size( ) > 0 )
95 _TNode node = q.front( );
97 if( this->_IsMarked( node.first ) )
99 this->_Mark( node.first, node.second );
101 // Apply inclusion predicate
102 TInputPixel value = input->GetPixel( node.first );
104 if( this->m_IntensityFunctor.IsNotNull( ) )
105 inside = this->m_IntensityFunctor->Evaluate( value );
109 // Ok, pixel lays inside region
110 output->SetPixel( node.first, this->m_InsideValue );
113 for( unsigned int d = 0; d < TInputImage::ImageDimension; ++d )
115 TIndex neigh = node.first;
116 for( int i = -1; i <= 1; i += 2 )
118 neigh[ d ] = node.first[ d ] + i;
119 if( region.IsInside( neigh ) )
121 if( this->_IsMarked( neigh ) )
123 unsigned long nColl = this->_Collisions( node.first, neigh );
124 if( nColl == 1 && this->StopAtOneFront( ) )
125 while( q.size( ) > 0 )
129 q.push( _TNode( neigh, node.second ) );
141 #endif // __fpa__Image__RegionGrow__hxx__