} // fi
}
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TOutputImage >
-void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
-AddSeed( const TIndex& seed )
-{
- if( this->m_Seeds.insert( seed ).second )
- this->Modified( );
-}
-
// -------------------------------------------------------------------------
template< class _TInputImage, class _TOutputImage >
fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
RegionGrow( )
: Superclass( ),
+ TSeedsInterface( this ),
+ TMarksInterface( this ),
m_InsideValue( TInputPixel( 0 ) ),
m_OutsideValue( TInputPixel( 0 ) )
{
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 );
+ this->_InitMarks( this->GetNumberOfSeeds( ) );
// Init queue
- std::queue< TIndex > q;
- for( TIndex seed: this->m_Seeds )
- q.push( seed );
+ typedef std::pair< TIndex, unsigned long > _TNode;
+ std::queue< _TNode > q;
+ unsigned long frontId = 1;
+ for( TIndex seed: this->GetSeeds( ) )
+ q.push( _TNode( seed, frontId++ ) );
// Main loop
while( q.size( ) > 0 )
{
// Get next candidate
- TIndex node = q.front( );
+ _TNode node = q.front( );
q.pop( );
- if( marks->GetPixel( node ) )
+ if( this->_IsMarked( node.first ) )
continue;
- marks->SetPixel( node, true );
+ this->_Mark( node.first, node.second );
// Apply inclusion predicate
- TInputPixel value = input->GetPixel( node );
+ TInputPixel value = input->GetPixel( node.first );
bool inside = false;
if( this->m_IntensityFunctor.IsNotNull( ) )
inside = this->m_IntensityFunctor->Evaluate( value );
continue;
// Ok, pixel lays inside region
- output->SetPixel( node, this->m_InsideValue );
+ output->SetPixel( node.first, this->m_InsideValue );
// Add neighborhood
for( unsigned int d = 0; d < TInputImage::ImageDimension; ++d )
{
- TIndex neigh = node;
+ TIndex neigh = node.first;
for( int i = -1; i <= 1; i += 2 )
{
- neigh[ d ] = node[ d ] + i;
+ neigh[ d ] = node.first[ d ] + i;
if( region.IsInside( neigh ) )
- q.push( neigh );
+ {
+ if( this->_IsMarked( neigh ) )
+ {
+ unsigned long nColl = this->_Collisions( node.first, neigh );
+ if( nColl == 1 && this->StopAtOneFront( ) )
+ while( q.size( ) > 0 )
+ q.pop( );
+ }
+ else
+ q.push( _TNode( neigh, node.second ) );
+
+ } // fi
} // rof
} // rof
} // elihw
+ this->_FreeMarks( );
}
#endif // __fpa__Image__RegionGrow__hxx__