- this->Superclass::_BeforeGenerateData( );
- this->m_InitResult = this->GetOutsideValue( );
- TGrowFunction* grow =
- dynamic_cast< TGrowFunction* >( this->GetGrowFunction( ) );
- if( grow != NULL )
- grow->SetImage( this->GetInput( ) );
+ const TInputImage* input = this->GetInput( );
+ TOutputImage* output = this->GetOutput( );
+ TRegion region = input->GetRequestedRegion( );
+
+ // Configure output
+ output->SetBufferedRegion( region );
+ output->Allocate( );
+ output->FillBuffer( this->m_OutsideValue );
+
+ // Init marks
+ typedef itk::Image< bool, TInputImage::ImageDimension > _TMarks;
+ typename _TMarks::Pointer marks = _TMarks::New( );
+ marks->CopyInformation( input );
+ marks->SetRequestedRegion( region );
+ marks->SetBufferedRegion( input->GetBufferedRegion( ) );
+ marks->Allocate( );
+ marks->FillBuffer( false );
+
+ // Init queue
+ std::queue< TIndex > q;
+ for( TIndex seed: this->m_Seeds )
+ q.push( seed );
+
+ // Main loop
+ while( q.size( ) > 0 )
+ {
+ // Get next candidate
+ TIndex node = q.front( );
+ q.pop( );
+ if( marks->GetPixel( node ) )
+ continue;
+ marks->SetPixel( node, true );
+
+ // Apply inclusion predicate
+ TInputPixel value = input->GetPixel( node );
+ bool inside = false;
+ if( this->m_IntensityFunctor.IsNotNull( ) )
+ inside = this->m_IntensityFunctor->Evaluate( value );
+ if( !inside )
+ continue;
+
+ // Ok, pixel lays inside region
+ output->SetPixel( node, this->m_InsideValue );
+
+ // Add neighborhood
+ for( unsigned int d = 0; d < TInputImage::ImageDimension; ++d )
+ {
+ TIndex neigh = node;
+ for( int i = -1; i <= 1; i += 2 )
+ {
+ neigh[ d ] = node[ d ] + i;
+ if( region.IsInside( neigh ) )
+ q.push( neigh );
+
+ } // rof
+
+ } // rof
+
+ } // elihw