X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tests%2Fimage%2FDijkstra%2FIdentity.cxx;fp=tests%2Fimage%2FDijkstra%2FIdentity.cxx;h=223283a9ca6470833d8a8bef44e60c80a264309f;hb=2047276c8f1a02432fbcc7014722d460d6c1e60f;hp=0000000000000000000000000000000000000000;hpb=3c639e5da479c7216a0a302ffa156ac6762caeed;p=FrontAlgorithms.git diff --git a/tests/image/Dijkstra/Identity.cxx b/tests/image/Dijkstra/Identity.cxx new file mode 100644 index 0000000..223283a --- /dev/null +++ b/tests/image/Dijkstra/Identity.cxx @@ -0,0 +1,93 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + +#include +#include +#include + +// ------------------------------------------------------------------------- +const unsigned int Dim = 2; +typedef unsigned char TInputPixel; +typedef float TOutputPixel; +typedef itk::Image< TInputPixel, Dim > TInputImage; +typedef itk::Image< TOutputPixel, Dim > TOutputImage; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + // Get arguments + if( argc < 5 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " output_image output_marks output_mst size [seeds]" + << std::endl; + return( 1 ); + + } // fi + std::string output_image_filename = argv[ 1 ]; + std::string output_marks_filename = argv[ 2 ]; + std::string output_mst_filename = argv[ 3 ]; + TInputImage::SizeType size; + size.Fill( std::atoi( argv[ 4 ] ) ); + + // Create image + TInputImage::Pointer image = TInputImage::New( ); + image->SetRegions( size ); + image->Allocate( ); + image->FillBuffer( TInputPixel( 1 ) ); + + // Prepare filter + typedef fpa::Filters::Image::Dijkstra< TInputImage, TOutputImage > TFilter; + TFilter::Pointer filter = TFilter::New( ); + filter->SetInput( image ); + + // Get all seeds + for( int i = 5; i < argc; i += Dim ) + { + TInputImage::IndexType seed; + for( int j = 0; j < Dim; ++j ) + if( i + j < argc ) + seed[ j ] = std::atoi( argv[ i + j ] ); + filter->AddSeed( seed ); + + } // rof + + // Execute filter + filter->Update( ); + + // Save results + typedef itk::ImageFileWriter< TFilter::TOutputImage > TOutputWriter; + TOutputWriter::Pointer output_writer = TOutputWriter::New( ); + output_writer->SetInput( filter->GetOutput( ) ); + output_writer->SetFileName( output_image_filename ); + + typedef itk::ImageFileWriter< TFilter::TMarksImage > TMarksWriter; + TMarksWriter::Pointer marks_writer = TMarksWriter::New( ); + marks_writer->SetInput( filter->GetMarks( ) ); + marks_writer->SetFileName( output_marks_filename ); + + typedef itk::ImageFileWriter< TFilter::TMST > TMSTWriter; + TMSTWriter::Pointer mst_writer = TMSTWriter::New( ); + mst_writer->SetInput( filter->GetMinimumSpanningTree( ) ); + mst_writer->SetFileName( output_mst_filename ); + + try + { + output_writer->Update( ); + marks_writer->Update( ); + mst_writer->Update( ); + } + catch( std::exception& err ) + { + std::cerr << "Error caught: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + + return( 0 ); +} + +// eof - $RCSfile$