]> Creatis software - FrontAlgorithms.git/blobdiff - tests/image/Dijkstra_Identity.cxx
...
[FrontAlgorithms.git] / tests / image / Dijkstra_Identity.cxx
diff --git a/tests/image/Dijkstra_Identity.cxx b/tests/image/Dijkstra_Identity.cxx
new file mode 100644 (file)
index 0000000..57f3593
--- /dev/null
@@ -0,0 +1,87 @@
+#include "BaseFunctions.h"
+#include <itkImage.h>
+#include <fpa/Image/Dijkstra.h>
+#include <fpa/Image/Functors/Dijkstra/Identity.h>
+
+// -------------------------------------------------------------------------
+const unsigned int Dim = 2;
+typedef unsigned char TPixel;
+typedef float         TScalar;
+
+typedef itk::Image< TPixel, Dim >                                    TInputImage;
+typedef itk::Image< TScalar, Dim >                                  TScalarImage;
+typedef fpa::Image::Dijkstra< TInputImage, TScalarImage >                TFilter;
+typedef fpa::Image::Functors::Dijkstra::Identity< TInputImage, TScalar > TWeight;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  // Get arguments
+  if( argc < 6 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " output_image output_marks width height visual_debug ..."
+      << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string output_image_filename = argv[ 1 ];
+  std::string output_marks_filename = argv[ 2 ];
+  int width = std::atoi( argv[ 3 ] );
+  int height = std::atoi( argv[ 4 ] );
+  bool visual_debug = ( argv[ 5 ][ 0 ] == '1' );
+
+  // Create image
+  TInputImage::Pointer image;
+  fpa::tests::image::CreateImage( image, 1, width, height, 1.0, 1.0 );
+
+  // Interact with image
+  fpa::tests::image::Viewer< TFilter > viewer( image );
+  if( visual_debug )
+  {
+    viewer.ActivateSeedWidget( );
+    viewer.Show( );
+
+  } // fi
+
+  // Prepare weight
+  TWeight::Pointer weight = TWeight::New( );
+
+  // Prepare filter
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( image );
+  filter->SetWeightFunction( weight );
+
+  // Get all seeds
+  for( int i = 6; i < argc; i += 2 )
+  {
+    if( i + 1 < argc )
+    {
+      TInputImage::IndexType seed;
+      seed[ 0 ] = std::atoi( argv[ i ] );
+      seed[ 1 ] = std::atoi( argv[ i + 1 ] );
+      filter->AddSeed( seed );
+
+    } // fi
+
+  } // rof
+  viewer.AssociateSeedsTo( filter );
+
+  // Prepare visual debug and update
+  if( visual_debug )
+    viewer.ObserveFilter( filter );
+  filter->Update( );
+
+  // Save results
+  std::string err1 =
+    fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
+  std::string err2 =
+    fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
+  if( err1 != "" ) std::cerr << err1 << std::endl;
+  if( err2 != "" ) std::cerr << err2 << std::endl;
+
+  return( 0 );
+}
+
+// eof - $RCSfile$