]> Creatis software - FrontAlgorithms.git/blobdiff - appli/examples/example_ImageAlgorithmDijkstra_03.cxx
Visual debugging improved
[FrontAlgorithms.git] / appli / examples / example_ImageAlgorithmDijkstra_03.cxx
index f2d140be01904e105c78c80299241cd3cbf1ab25..3b354baf3b1dfcc2728596a24a0bceddbbc705cc 100644 (file)
@@ -133,11 +133,11 @@ protected:
       marks->Allocate( );
       marks->FillBuffer( _TMark( 0 ) );
 
-      // Iterate over the candidates, starting fromt the candidates that
+      // Iterate over the candidates, starting from the candidates that
       // are near thin branches
       _TCandidates::const_reverse_iterator cIt =
         this->m_Candidates.rbegin( );
-      for( int leo = 0; leo < 100 && cIt != this->m_Candidates.rend( ); ++cIt )
+      for( int leo = 0; leo < 1 && cIt != this->m_Candidates.rend( ); ++cIt )
       {
         // If pixel hasn't been visited, continue
         TVertex v = cIt->second;
@@ -154,83 +154,78 @@ protected:
         unsigned int nN = 1;
         for( unsigned int d = 0; d < TImage::ImageDimension; ++d )
           nN *= iIt.GetSize( )[ d ];
-        TImage::PixelType min_value = iIt.GetPixel( 0 );
-        TVertex min_vertex = iIt.GetIndex( 0 );
-        if( !( min_value > TImage::PixelType( 0 ) ) )
-          min_value = std::numeric_limits< TImage::PixelType >::max( );
+        TVertex max_vertex = iIt.GetIndex( 0 );
+        TImage::PixelType max_value = iIt.GetPixel( 0 );
         for( unsigned int i = 1; i < nN; ++i )
         {
           TImage::PixelType value = iIt.GetPixel( i );
-          if( !( value > TImage::PixelType( 0 ) ) )
-            value = std::numeric_limits< TImage::PixelType >::max( );
-          if( value < min_value )
+          if( value > max_value )
           {
-            min_value = value;
-            min_vertex = iIt.GetIndex( i );
+            max_value = value;
+            max_vertex = iIt.GetIndex( i );
 
           } // fi
 
         } // rof
 
-        if( min_value < std::numeric_limits< TImage::PixelType >::max( ) )
+        if( marks->GetPixel( max_vertex ) != _TMark( 0 ) )
+          continue;
+        leo++;
+        std::cout << "Leaf: " << leo << " " << max_value << " " << max_vertex << std::endl;
+
+        bool start = true;
+        do
         {
-          if( marks->GetPixel( min_vertex ) != _TMark( 0 ) )
-            continue;
-          leo++;
-          std::cout << "Leaf: " << leo << " " << min_value << " " << min_vertex << std::endl;
+          double dist = double( 1.5 ) * std::sqrt( double( input->GetPixel( max_vertex ) ) );
+          for( unsigned int d = 0; d < TImage::ImageDimension; ++d )
+            radius[ d ] =
+              ( unsigned long )( dist / spacing[ d ] ) + 1;
+          itk::NeighborhoodIterator< _TMarkImage > mIt(
+            radius, marks, marks->GetRequestedRegion( )
+            );
+          mIt.SetLocation( max_vertex );
+          nN = 1;
+          for( unsigned int d = 0; d < TImage::ImageDimension; ++d )
+            nN *= mIt.GetSize( )[ d ];
+          for( unsigned int i = 0; i < nN; ++i )
+            if( marks->GetRequestedRegion( ).IsInside( mIt.GetIndex( i ) ) )
+            {
+              mIt.SetPixel( i, ( start )? 255: 100 );
+              start = false;
+            }
 
-          bool start = true;
-          do
-          {
-            double dist = double( 1.5 ) * std::sqrt( double( input->GetPixel( min_vertex ) ) );
-            for( unsigned int d = 0; d < TImage::ImageDimension; ++d )
-              radius[ d ] =
-                ( unsigned long )( dist / spacing[ d ] ) + 1;
-            itk::NeighborhoodIterator< _TMarkImage > mIt(
-              radius, marks, marks->GetRequestedRegion( )
-              );
-            mIt.SetLocation( min_vertex );
-            nN = 1;
+          /*
+            TImage::SizeType radius;
+            mIt.GoToBegin( );
+            mIt.SetLocation( vIt );
+
+            TImage::SizeType size = mIt.GetSize( );
+            unsigned int nN = 1;
             for( unsigned int d = 0; d < TImage::ImageDimension; ++d )
-              nN *= mIt.GetSize( )[ d ];
+            nN *= size[ d ];
             for( unsigned int i = 0; i < nN; ++i )
-              if( marks->GetRequestedRegion( ).IsInside( mIt.GetIndex( i ) ) )
-              {
-                mIt.SetPixel( i, ( start )? 255: 100 );
-                start = false;
-              }
-
-            /*
-              TImage::SizeType radius;
-              mIt.GoToBegin( );
-              mIt.SetLocation( vIt );
-
-              TImage::SizeType size = mIt.GetSize( );
-              unsigned int nN = 1;
-              for( unsigned int d = 0; d < TImage::ImageDimension; ++d )
-              nN *= size[ d ];
-              for( unsigned int i = 0; i < nN; ++i )
-              if( marks->GetRequestedRegion( ).IsInside( mIt.GetIndex( i ) ) )
-              mIt.SetPixel( i, ( start )? 255: 100 );
+            if( marks->GetRequestedRegion( ).IsInside( mIt.GetIndex( i ) ) )
+            mIt.SetPixel( i, ( start )? 255: 100 );
 
-              start = false;
-            */
-            // Next vertex in current path
-            min_vertex = this->_Parent( min_vertex );
+            start = false;
+          */
+          // Next vertex in current path
+          max_vertex = this->_Parent( max_vertex );
 
-          } while( min_vertex != this->_Parent( min_vertex ) );
-        }
-        else
-          marks->SetPixel( v, _TMark( 1 ) );
+        } while( max_vertex != this->_Parent( max_vertex ) );
 
       } // rof
+      /*
+        else
+        marks->SetPixel( v, _TMark( 1 ) );
+        } // rof
+      */
 
       itk::ImageFileWriter< _TMarkImage >::Pointer w =
         itk::ImageFileWriter< _TMarkImage >::New( );
       w->SetInput( marks );
       w->SetFileName( "marks.mhd" );
       w->Update( );
-      std::exit( 1 );
 
       /*
 
@@ -421,7 +416,7 @@ int main( int argc, char* argv[] )
   {
     // Configure observer
     TDijkstraObs::Pointer obs = TDijkstraObs::New( );
-    obs->SetImage( input_image, view.GetWindow( ) );
+    obs->SetRenderWindow( view.GetWindow( ) );
     paths->AddObserver( itk::AnyEvent( ), obs );
     paths->ThrowEventsOn( );
   }