]> Creatis software - FrontAlgorithms.git/blob - tests/image/Dijkstra_Identity.cxx
57f35935a965ffe8926742b088eae85f60e0aebd
[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 < 6 )
21   {
22     std::cerr
23       << "Usage: " << argv[ 0 ]
24       << " output_image output_marks width height visual_debug ..."
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   bool visual_debug = ( argv[ 5 ][ 0 ] == '1' );
34
35   // Create image
36   TInputImage::Pointer image;
37   fpa::tests::image::CreateImage( image, 1, width, height, 1.0, 1.0 );
38
39   // Interact with image
40   fpa::tests::image::Viewer< TFilter > viewer( image );
41   if( visual_debug )
42   {
43     viewer.ActivateSeedWidget( );
44     viewer.Show( );
45
46   } // fi
47
48   // Prepare weight
49   TWeight::Pointer weight = TWeight::New( );
50
51   // Prepare filter
52   TFilter::Pointer filter = TFilter::New( );
53   filter->SetInput( image );
54   filter->SetWeightFunction( weight );
55
56   // Get all seeds
57   for( int i = 6; i < argc; i += 2 )
58   {
59     if( i + 1 < argc )
60     {
61       TInputImage::IndexType seed;
62       seed[ 0 ] = std::atoi( argv[ i ] );
63       seed[ 1 ] = std::atoi( argv[ i + 1 ] );
64       filter->AddSeed( seed );
65
66     } // fi
67
68   } // rof
69   viewer.AssociateSeedsTo( filter );
70
71   // Prepare visual debug and update
72   if( visual_debug )
73     viewer.ObserveFilter( filter );
74   filter->Update( );
75
76   // Save results
77   std::string err1 =
78     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
79   std::string err2 =
80     fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
81   if( err1 != "" ) std::cerr << err1 << std::endl;
82   if( err2 != "" ) std::cerr << err2 << std::endl;
83
84   return( 0 );
85 }
86
87 // eof - $RCSfile$