]> Creatis software - FrontAlgorithms.git/blobdiff - examples/Dijkstra_Gaussian.cxx
...
[FrontAlgorithms.git] / examples / Dijkstra_Gaussian.cxx
diff --git a/examples/Dijkstra_Gaussian.cxx b/examples/Dijkstra_Gaussian.cxx
new file mode 100644 (file)
index 0000000..7befb2b
--- /dev/null
@@ -0,0 +1,79 @@
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+
+#include <fpa/Image/Dijkstra.h>
+#include <fpa/Image/Functors/GaussianWeight.h>
+
+// -------------------------------------------------------------------------
+static const unsigned int VDim = 2;
+typedef double                                                 TPixel;
+typedef itk::Image< TPixel, VDim >                             TImage;
+typedef itk::ImageFileReader< TImage >                         TReader;
+typedef itk::ImageFileWriter< TImage >                         TWriter;
+typedef fpa::Image::Dijkstra< TImage, TImage >                 TFilter;
+typedef fpa::Image::Functors::GaussianWeight< TImage, TPixel > TVertexFunc;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  // Get arguments
+  if( argc < 5 + VDim )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " input_image output_image stop_at_one_front beta";
+    for( unsigned int i = 0; i < VDim; ++i )
+      std::cerr << " s_" << i;
+    std::cerr << " ..." << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string input_image_filename = argv[ 1 ];
+  std::string output_image_filename = argv[ 2 ];
+  bool stop_at_one_front = ( std::atoi( argv[ 3 ] ) == 1 );
+  double beta = std::atof( argv[ 4 ] );
+
+  TReader::Pointer reader = TReader::New( );
+  reader->SetFileName( input_image_filename );
+
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( reader->GetOutput( ) );
+  filter->SetStopAtOneFront( stop_at_one_front );
+
+  for( int i = 5; i < argc; i += VDim )
+  {
+    if( i + VDim <= argc )
+    {
+      TImage::IndexType seed;
+      for( int j = 0; j < VDim; ++j )
+        seed[ j ] = std::atoi( argv[ i + j ] );
+      filter->AddSeed( seed );
+
+    } // fi
+
+  } // rof
+
+  TVertexFunc::Pointer vertex_func = TVertexFunc::New( );
+  vertex_func->SetBeta( beta );
+  vertex_func->InvertOn( );
+  filter->SetFunctor( vertex_func );
+
+  TWriter::Pointer writer = TWriter::New( );
+  writer->SetInput( filter->GetOutput( ) );
+  writer->SetFileName( output_image_filename );
+
+  try
+  {
+    writer->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "ERROR: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+  return( 0 );
+}
+
+// eof - $RCSfile$