]> Creatis software - FrontAlgorithms.git/blob - appli/examples/ImageDijkstra.cxx
2dede622dd4b7f3b2d26aa18755ba8d1ce0ceab7
[FrontAlgorithms.git] / appli / examples / ImageDijkstra.cxx
1 #include <itkImage.h>
2 #include <itkRandomImageSource.h>
3 #include <itkImageFileWriter.h>
4
5 #include <fpa/Image/Functors/SimpleNeighborhood.h>
6 #include <fpa/Image/Functors/SimpleDijkstraCost.h>
7 #include <fpa/Base/Functors/Inverse.h>
8 #include <fpa/Image/Dijkstra.h>
9
10 // -------------------------------------------------------------------------
11 static const unsigned int VDim = 2;
12 typedef float TScalar;
13 typedef itk::Image< unsigned char, VDim > TInputImage;
14 typedef itk::Image< TScalar, VDim > TOutputImage;
15
16 typedef itk::RandomImageSource< TInputImage > TImageSource;
17 typedef itk::ImageFileWriter< TOutputImage >  TImageWriter;
18
19 typedef fpa::Image::Functors::SimpleNeighborhood< itk::ImageBase< VDim > > TNeighFunction;
20 typedef fpa::Image::Functors::SimpleDijkstraCost< TInputImage, TScalar > TCostFunction;
21 typedef fpa::Base::Functors::Inverse< TScalar, TScalar > TCostConversionFunction;
22
23 typedef fpa::Image::Dijkstra< TInputImage, TOutputImage > TFilter;
24
25 // -------------------------------------------------------------------------
26 int main( int argc, char* argv[] )
27 {
28   static const unsigned long SIZE = 100;
29   unsigned long size[] = { SIZE, SIZE };
30
31   unsigned int neigh_order = 2;
32   TInputImage::IndexType seed0, seed1;
33
34   seed0.Fill( 0 );
35   seed1.Fill( SIZE - 1 );
36
37   TImageSource::Pointer source = TImageSource::New( );
38   source->SetSize( size );
39   source->SetSpacing( 1 );
40   source->Update( );
41   TInputImage::Pointer input = source->GetOutput( );
42
43   TNeighFunction::Pointer neigh_function = TNeighFunction::New( );
44   neigh_function->SetOrder( neigh_order );
45
46   TCostFunction::Pointer cost_function = TCostFunction::New( );
47
48   TCostConversionFunction::Pointer cost_conversion_function =
49     TCostConversionFunction::New( );
50
51   TFilter::Pointer filter = TFilter::New( );
52   filter->SetInput( input );
53   filter->SetNeighborhoodFunction( neigh_function );
54   filter->SetCostFunction( cost_function );
55   filter->SetCostConversionFunction( cost_conversion_function );
56   filter->AddSeed( seed0, 0 );
57   filter->AddSeed( seed1, 0 );
58   filter->StopAtOneFrontOn( );
59   filter->Update( );
60
61   TImageWriter::Pointer writer = TImageWriter::New( );
62   writer->SetInput( filter->GetOutput( ) );
63   writer->SetFileName( "dijkstra.mhd" );
64   writer->Update( );
65
66   return( 0 );
67 }
68
69 // eof - $RCSfile$