]> Creatis software - FrontAlgorithms.git/blobdiff - libs/fpa/Image/RegionGrow.hxx
...
[FrontAlgorithms.git] / libs / fpa / Image / RegionGrow.hxx
index facd9f80956f7da34923a8ff7f84fe80e5db4ca5..2208070885b1795365d98543c9a1fa10e6e8fd46 100644 (file)
@@ -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__