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 m_InsideValue( TInputPixel( 0 ) ),
31 m_OutsideValue( TInputPixel( 0 ) )
35 // -------------------------------------------------------------------------
36 template< class _TInputImage, class _TOutputImage >
37 fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
42 // -------------------------------------------------------------------------
43 template< class _TInputImage, class _TOutputImage >
44 void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
45 GenerateInputRequestedRegion( )
47 this->Superclass::GenerateInputRequestedRegion( );
48 if( this->GetInput( ) )
51 const_cast< TInputImage* >( this->GetInput( ) );
52 input->SetRequestedRegionToLargestPossibleRegion( );
57 // -------------------------------------------------------------------------
58 template< class _TInputImage, class _TOutputImage >
59 void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
60 EnlargeOutputRequestedRegion( itk::DataObject* output )
62 this->Superclass::EnlargeOutputRequestedRegion( output );
63 output->SetRequestedRegionToLargestPossibleRegion( );
66 // -------------------------------------------------------------------------
67 template< class _TInputImage, class _TOutputImage >
68 void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
71 const TInputImage* input = this->GetInput( );
72 TOutputImage* output = this->GetOutput( );
73 TRegion region = input->GetRequestedRegion( );
76 output->SetBufferedRegion( region );
78 output->FillBuffer( this->m_OutsideValue );
81 typedef itk::Image< bool, TInputImage::ImageDimension > _TMarks;
82 typename _TMarks::Pointer marks = _TMarks::New( );
83 marks->CopyInformation( input );
84 marks->SetRequestedRegion( region );
85 marks->SetBufferedRegion( input->GetBufferedRegion( ) );
87 marks->FillBuffer( false );
90 std::queue< TIndex > q;
91 for( TIndex seed: this->GetSeeds( ) )
95 while( q.size( ) > 0 )
98 TIndex node = q.front( );
100 if( marks->GetPixel( node ) )
102 marks->SetPixel( node, true );
104 // Apply inclusion predicate
105 TInputPixel value = input->GetPixel( node );
107 if( this->m_IntensityFunctor.IsNotNull( ) )
108 inside = this->m_IntensityFunctor->Evaluate( value );
112 // Ok, pixel lays inside region
113 output->SetPixel( node, this->m_InsideValue );
116 for( unsigned int d = 0; d < TInputImage::ImageDimension; ++d )
119 for( int i = -1; i <= 1; i += 2 )
121 neigh[ d ] = node[ d ] + i;
122 if( region.IsInside( neigh ) )
132 #endif // __fpa__Image__RegionGrow__hxx__