]> Creatis software - FrontAlgorithms.git/blob - tests/image/Dijkstra/Identity.cxx
223283a9ca6470833d8a8bef44e60c80a264309f
[FrontAlgorithms.git] / tests / image / Dijkstra / Identity.cxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #include <itkImage.h>
7 #include <itkImageFileWriter.h>
8 #include <fpa/Filters/Image/Dijkstra.h>
9
10 // -------------------------------------------------------------------------
11 const unsigned int Dim = 2;
12 typedef unsigned char TInputPixel;
13 typedef float         TOutputPixel;
14 typedef itk::Image< TInputPixel, Dim >  TInputImage;
15 typedef itk::Image< TOutputPixel, Dim > TOutputImage;
16
17 // -------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
19 {
20   // Get arguments
21   if( argc < 5 )
22   {
23     std::cerr
24       << "Usage: " << argv[ 0 ]
25       << " output_image output_marks output_mst size [seeds]"
26       << std::endl;
27     return( 1 );
28
29   } // fi
30   std::string output_image_filename = argv[ 1 ];
31   std::string output_marks_filename = argv[ 2 ];
32   std::string output_mst_filename = argv[ 3 ];
33   TInputImage::SizeType size;
34   size.Fill( std::atoi( argv[ 4 ] ) );
35
36   // Create image
37   TInputImage::Pointer image = TInputImage::New( );
38   image->SetRegions( size );
39   image->Allocate( );
40   image->FillBuffer( TInputPixel( 1 ) );
41
42   // Prepare filter
43   typedef fpa::Filters::Image::Dijkstra< TInputImage, TOutputImage > TFilter;
44   TFilter::Pointer filter = TFilter::New( );
45   filter->SetInput( image );
46
47   // Get all seeds
48   for( int i = 5; i < argc; i += Dim )
49   {
50     TInputImage::IndexType seed;
51     for( int j = 0; j < Dim; ++j )
52       if( i + j < argc )
53         seed[ j ] = std::atoi( argv[ i + j ] );
54     filter->AddSeed( seed );
55
56   } // rof
57
58   // Execute filter
59   filter->Update( );
60
61   // Save results
62   typedef itk::ImageFileWriter< TFilter::TOutputImage > TOutputWriter;
63   TOutputWriter::Pointer output_writer = TOutputWriter::New( );
64   output_writer->SetInput( filter->GetOutput( ) );
65   output_writer->SetFileName( output_image_filename );
66
67   typedef itk::ImageFileWriter< TFilter::TMarksImage > TMarksWriter;
68   TMarksWriter::Pointer marks_writer = TMarksWriter::New( );
69   marks_writer->SetInput( filter->GetMarks( ) );
70   marks_writer->SetFileName( output_marks_filename );
71
72   typedef itk::ImageFileWriter< TFilter::TMST > TMSTWriter;
73   TMSTWriter::Pointer mst_writer = TMSTWriter::New( );
74   mst_writer->SetInput( filter->GetMinimumSpanningTree( ) );
75   mst_writer->SetFileName( output_mst_filename );
76
77   try
78   {
79     output_writer->Update( );
80     marks_writer->Update( );
81     mst_writer->Update( );
82   }
83   catch( std::exception& err )
84   {
85     std::cerr << "Error caught: " << err.what( ) << std::endl;
86     return( 1 );
87
88   } // yrt
89
90   return( 0 );
91 }
92
93 // eof - $RCSfile$