]> Creatis software - FrontAlgorithms.git/blobdiff - appli/examples/ImageDijkstra.cxx
...
[FrontAlgorithms.git] / appli / examples / ImageDijkstra.cxx
diff --git a/appli/examples/ImageDijkstra.cxx b/appli/examples/ImageDijkstra.cxx
new file mode 100644 (file)
index 0000000..1b56263
--- /dev/null
@@ -0,0 +1,69 @@
+#include <itkImage.h>
+#include <itkRandomImageSource.h>
+#include <itkImageFileWriter.h>
+
+#include <fpa/Image/Functors/SimpleNeighborhood.h>
+#include <fpa/Image/Functors/SimpleDijkstraCost.h>
+#include <fpa/Base/Functors/Inverse.h>
+#include <fpa/Image/Dijkstra.h>
+
+// -------------------------------------------------------------------------
+static const unsigned int VDim = 2;
+typedef float TScalar;
+typedef itk::Image< unsigned char, VDim > TInputImage;
+typedef itk::Image< TScalar, VDim > TOutputImage;
+
+typedef itk::RandomImageSource< TInputImage > TImageSource;
+typedef itk::ImageFileWriter< TOutputImage >  TImageWriter;
+
+typedef fpa::Image::Functors::SimpleNeighborhood< TInputImage > TNeighFunction;
+typedef fpa::Image::Functors::SimpleDijkstraCost< TInputImage, TScalar > TCostFunction;
+typedef fpa::Base::Functors::Inverse< TScalar, TScalar > TCostConversionFunction;
+
+typedef fpa::Image::Dijkstra< TInputImage, TOutputImage > TFilter;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  static const unsigned long SIZE = 100;
+  unsigned long size[] = { SIZE, SIZE };
+
+  unsigned int neigh_order = 1;
+  TInputImage::IndexType seed0, seed1;
+
+  seed0.Fill( 0 );
+  seed1.Fill( SIZE - 1 );
+
+  TImageSource::Pointer source = TImageSource::New( );
+  source->SetSize( size );
+  source->SetSpacing( 1 );
+  source->Update( );
+  TInputImage::Pointer input = source->GetOutput( );
+
+  TNeighFunction::Pointer neigh_function = TNeighFunction::New( );
+  neigh_function->SetOrder( neigh_order );
+
+  TCostFunction::Pointer cost_function = TCostFunction::New( );
+
+  TCostConversionFunction::Pointer cost_conversion_function =
+    TCostConversionFunction::New( );
+
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( input );
+  filter->SetNeighborhoodFunction( neigh_function );
+  filter->SetCostFunction( cost_function );
+  filter->SetCostConversionFunction( cost_conversion_function );
+  filter->AddSeed( seed0, 0 );
+  filter->AddSeed( seed1, 0 );
+  filter->StopAtOneFrontOn( );
+  filter->Update( );
+
+  TImageWriter::Pointer writer = TImageWriter::New( );
+  writer->SetInput( filter->GetOutput( ) );
+  writer->SetFileName( "dijkstra.mhd" );
+  writer->Update( );
+
+  return( 0 );
+}
+
+// eof - $RCSfile$