]> Creatis software - FrontAlgorithms.git/blobdiff - tests/image/RegionGrow/Tautology.cxx
...
[FrontAlgorithms.git] / tests / image / RegionGrow / Tautology.cxx
diff --git a/tests/image/RegionGrow/Tautology.cxx b/tests/image/RegionGrow/Tautology.cxx
new file mode 100644 (file)
index 0000000..0bbdc45
--- /dev/null
@@ -0,0 +1,92 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#include <itkImage.h>
+#include <itkImageFileWriter.h>
+#include <fpa/Filters/Image/RegionGrow.h>
+#include <fpa/Functors/RegionGrow/Tautology.h>
+
+// -------------------------------------------------------------------------
+const unsigned int Dim = 2;
+typedef unsigned char TPixel;
+typedef itk::Image< TPixel, Dim > TImage;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  // Get arguments
+  if( argc < 4 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " output_image output_marks size [seeds]"
+      << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string output_image_filename = argv[ 1 ];
+  std::string output_marks_filename = argv[ 2 ];
+  TImage::SizeType size;
+  size.Fill( std::atoi( argv[ 3 ] ) );
+
+  // Create image
+  TImage::Pointer image = TImage::New( );
+  image->SetRegions( size );
+  image->Allocate( );
+  image->FillBuffer( TPixel( 0 ) );
+
+  // Prepare predicate
+  typedef fpa::Functors::RegionGrow::Tautology< TPixel > TPredicate;
+  TPredicate::Pointer predicate = TPredicate::New( );
+
+  // Prepare filter
+  typedef fpa::Filters::Image::RegionGrow< TImage, TImage > TFilter;
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( image );
+  filter->SetPredicate( predicate );
+  filter->SetInsideValue( std::numeric_limits< TPixel >::max( ) );
+  filter->SetOutsideValue( TPixel( 0 ) );
+
+  // Get all seeds
+  for( int i = 4; i < argc; i += Dim )
+  {
+    TImage::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 );
+
+  try
+  {
+    output_writer->Update( );
+    marks_writer->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+
+  return( 0 );
+}
+
+// eof - $RCSfile$