]> Creatis software - FrontAlgorithms.git/blob - tests/image/Dijkstra_Identity.cxx
...
[FrontAlgorithms.git] / tests / image / Dijkstra_Identity.cxx
1 #include "BaseFunctions.h"
2 #include <itkImage.h>
3 #include <fpa/Image/Dijkstra.h>
4 #include <fpa/Image/Functors/Dijkstra/Identity.h>
5
6 // -------------------------------------------------------------------------
7 const unsigned int Dim = 2;
8 typedef unsigned char TPixel;
9 typedef float         TScalar;
10
11 typedef itk::Image< TPixel, Dim >                                    TInputImage;
12 typedef itk::Image< TScalar, Dim >                                  TScalarImage;
13 typedef fpa::Image::Dijkstra< TInputImage, TScalarImage >                TFilter;
14 typedef fpa::Image::Functors::Dijkstra::Identity< TInputImage, TScalar > TWeight;
15
16 // -------------------------------------------------------------------------
17 int main( int argc, char* argv[] )
18 {
19   // Get arguments
20   if( argc < 5 )
21   {
22     std::cerr
23       << "Usage: " << argv[ 0 ]
24       << " output_image output_marks width height ..."
25       << std::endl;
26     return( 1 );
27
28   } // fi
29   std::string output_image_filename = argv[ 1 ];
30   std::string output_marks_filename = argv[ 2 ];
31   int width = std::atoi( argv[ 3 ] );
32   int height = std::atoi( argv[ 4 ] );
33
34   // Create image
35   TInputImage::Pointer image;
36   fpa::tests::image::CreateImage( image, 1, width, height, 1.0, 1.0 );
37
38   // Prepare weight
39   TWeight::Pointer weight = TWeight::New( );
40
41   // Prepare filter
42   TFilter::Pointer filter = TFilter::New( );
43   filter->SetInput( image );
44   filter->SetWeightFunction( weight );
45
46   // Get all seeds
47   for( int i = 5; i < argc; i += 2 )
48   {
49     if( i + 1 < argc )
50     {
51       TInputImage::IndexType seed;
52       seed[ 0 ] = std::atoi( argv[ i ] );
53       seed[ 1 ] = std::atoi( argv[ i + 1 ] );
54       filter->AddSeed( seed );
55
56     } // fi
57
58   } // rof
59
60   // Execute filter
61   filter->Update( );
62
63   // Save results
64   std::string err1 =
65     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
66   std::string err2 =
67     fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
68   if( err1 != "" ) std::cerr << err1 << std::endl;
69   if( err2 != "" ) std::cerr << err2 << std::endl;
70
71   return( 0 );
72 }
73
74 // eof - $RCSfile$