]> Creatis software - FrontAlgorithms.git/blobdiff - examples/Dijkstra_Maurer.cxx
...
[FrontAlgorithms.git] / examples / Dijkstra_Maurer.cxx
index 88759597496bc98a149697f11bb4c2ff11d663a8..c67024a12fc0215b15f4e628c1e50ecdc44ca48c 100644 (file)
@@ -7,6 +7,7 @@
 #include <fpa/Image/Dijkstra.h>
 #include <fpa/Image/Functors/VertexIdentity.h>
 #include <fpa/Base/Functors/InvertValue.h>
+#include <fpa/Image/MinimumSpanningTreeToImageFilter.h>
 
 // -------------------------------------------------------------------------
 static const unsigned int VDim = 2;
@@ -20,12 +21,19 @@ typedef fpa::Image::Dijkstra< TScalarImage, TScalarImage > TFilter;
 typedef itk::MinimumMaximumImageCalculator< TImage >       TMinMax;
 typedef itk::SignedMaurerDistanceMapImageFilter< TImage, TScalarImage > TDMap;
 
+typedef TImage::IndexType TIndex;
+
 typedef fpa::Image::Functors::VertexIdentity< TScalarImage, TScalar > TVertexFunc;
 typedef fpa::Base::Functors::InvertValue< TScalar, TScalar > TValueFunc;
 
 typedef TFilter::TMST                TMST;
 typedef itk::ImageFileWriter< TMST > TMSTWriter;
 
+typedef unsigned char TColorValue;
+typedef fpa::Image::MinimumSpanningTreeToImageFilter< TMST, TColorValue > TMSTToImage;
+typedef TMSTToImage::TOutputImage TColorImage;
+typedef itk::ImageFileWriter< TColorImage > TColorImageWriter;
+
 // -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
 {
@@ -34,7 +42,7 @@ int main( int argc, char* argv[] )
   {
     std::cerr
       << "Usage: " << argv[ 0 ]
-      << " input_image output_image output_mst stop_at_one_front";
+      << " input_image output_image output_paths stop_at_one_front";
     for( unsigned int i = 0; i < VDim; ++i )
       std::cerr << " s_" << i;
     std::cerr << " ..." << std::endl;
@@ -43,7 +51,7 @@ int main( int argc, char* argv[] )
   } // fi
   std::string input_image_filename = argv[ 1 ];
   std::string output_image_filename = argv[ 2 ];
-  std::string output_mst_filename = argv[ 3 ];
+  std::string output_paths_filename = argv[ 3 ];
   bool stop_at_one_front = ( std::atoi( argv[ 4 ] ) == 1 );
 
   TReader::Pointer reader = TReader::New( );
@@ -99,14 +107,20 @@ int main( int argc, char* argv[] )
   writer->SetInput( filter->GetOutput( ) );
   writer->SetFileName( output_image_filename );
 
-  TMSTWriter::Pointer mst_writer = TMSTWriter::New( );
-  mst_writer->SetInput( filter->GetMinimumSpanningTree( ) );
-  mst_writer->SetFileName( output_mst_filename );
+  TMSTToImage::Pointer mst_image = TMSTToImage::New( );
+  mst_image->SetInput( filter->GetMinimumSpanningTree( ) );
+  for( TIndex iseed: filter->GetSeeds( ) )
+    for( TIndex jseed: filter->GetSeeds( ) )
+      mst_image->AddPath( iseed, jseed, 255, 0, 0 );
+
+  TColorImageWriter::Pointer paths_writer = TColorImageWriter::New( );
+  paths_writer->SetInput( mst_image->GetOutput( ) );
+  paths_writer->SetFileName( output_paths_filename );
 
   try
   {
     writer->Update( );
-    mst_writer->Update( );
+    paths_writer->Update( );
   }
   catch( std::exception& err )
   {