X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=libs%2Ffpa%2FImage%2FRegionGrow.hxx;h=2208070885b1795365d98543c9a1fa10e6e8fd46;hb=1bde955a3f32330dcbbd2c190de75a8f77865de9;hp=facd9f80956f7da34923a8ff7f84fe80e5db4ca5;hpb=fa473b0493ad1f4b6e2fb15b180fc32c67e9c712;p=FrontAlgorithms.git diff --git a/libs/fpa/Image/RegionGrow.hxx b/libs/fpa/Image/RegionGrow.hxx index facd9f8..2208070 100644 --- a/libs/fpa/Image/RegionGrow.hxx +++ b/libs/fpa/Image/RegionGrow.hxx @@ -27,6 +27,7 @@ fpa::Image::RegionGrow< _TInputImage, _TOutputImage >:: RegionGrow( ) : Superclass( ), TSeedsInterface( this ), + TMarksInterface( this ), m_InsideValue( TInputPixel( 0 ) ), m_OutsideValue( TInputPixel( 0 ) ) { @@ -78,31 +79,27 @@ GenerateData( ) 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; + typedef std::pair< TIndex, unsigned long > _TNode; + std::queue< _TNode > q; + unsigned long frontId = 1; for( TIndex seed: this->GetSeeds( ) ) - q.push( seed ); + 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 ); @@ -110,23 +107,35 @@ GenerateData( ) 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__