]> Creatis software - FrontAlgorithms.git/blobdiff - examples/SkeletonFilter.cxx
...
[FrontAlgorithms.git] / examples / SkeletonFilter.cxx
index 25d54c4eac74ed807f8a7f30a8bb4a2a99d736c6..4e1b316c5bb880edf4f110efb05601d30708737d 100644 (file)
@@ -4,28 +4,17 @@
 #include <itkImage.h>
 #include <itkImageFileReader.h>
 
+#include <fpa/Base/SkeletonWriter.h>
 #include <fpa/Image/SkeletonFilter.h>
 
-/* TODO
-   #include <itkCommand.h>
-   #include <itkImageFileWriter.h>
-   #include <itkBinaryThresholdImageFilter.h>
-   #include <fpa/Image/MoriRegionGrow.h>
-*/
-
 // -------------------------------------------------------------------------
 static const unsigned int VDim = 3;
-typedef unsigned char                                 TPixel;
-typedef double                                        TScalar;
-typedef itk::Image< TPixel, VDim >                    TImage;
-typedef itk::ImageFileReader< TImage >                TReader;
-typedef fpa::Image::SkeletonFilter< TImage, TScalar > TFilter;
-
-/* TODO
-   typedef itk::ImageFileWriter< TImage >                    TWriter;
-   typedef fpa::Image::MoriRegionGrow< TImage, TImage >      TFilter;
-   typedef itk::BinaryThresholdImageFilter< TImage, TImage > TThreshold;
-*/
+typedef unsigned char                                   TPixel;
+typedef double                                          TScalar;
+typedef itk::Image< TPixel, VDim >                      TImage;
+typedef itk::ImageFileReader< TImage >                  TReader;
+typedef fpa::Image::SkeletonFilter< TImage, TScalar >   TFilter;
+typedef fpa::Base::SkeletonWriter< TFilter::TSkeleton > TWriter;
 
 // -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
@@ -61,64 +50,46 @@ int main( int argc, char* argv[] )
   TFilter::Pointer filter = TFilter::New( );
   filter->SetInput( reader->GetOutput( ) );
 
-  /* TODO
-     filter->SetThresholdRange( lower, upper, delta );
-     TImage::PointType pnt;
-     for( int i = 0; i < VDim; ++i )
-     pnt[ i ] = std::atof( argv[ i + 6 ] );
-
-     TImage::IndexType seed;
-     if( !( reader->GetOutput( )->TransformPhysicalPointToIndex( pnt, seed ) ) )
-     {
-     std::cerr << "ERROR: seed outside image." << std::endl;
-     return( 1 );
-
-     } // fi
-     filter->AddSeed( seed );
-
-     std::chrono::time_point< std::chrono::system_clock > start, end;
-     start = std::chrono::system_clock::now( );
-     filter->Update( );
-     end = std::chrono::system_clock::now( );
-     std::chrono::duration< double > elapsed_seconds = end - start;
-
-     TThreshold::Pointer threshold = TThreshold::New( );
-     threshold->SetInput( filter->GetOutput( ) );
-     threshold->SetInsideValue( 255 );
-     threshold->SetOutsideValue( 0 );
-     threshold->SetLowerThreshold( 0 );
-     threshold->SetUpperThreshold( filter->GetOptimumThreshold( ) );
-  
-     TWriter::Pointer writer = TWriter::New( );
-     writer->SetInput( threshold->GetOutput( ) );
-     writer->SetFileName( output_image_filename );
-     try
-     {
-     writer->Update( );
-     }
-     catch( std::exception& err )
-     {
-     std::cerr << "ERROR: " << err.what( ) << std::endl;
-     return( 1 );
+  if( argc > 3 )
+  {
+    filter->SeedFromMaximumDistanceOff( );
+    TImage::PointType pnt;
+    for( int i = 0; i < VDim; ++i )
+      pnt[ i ] = std::atof( argv[ i + 3 ] );
+    TImage::IndexType seed;
+    if( !( reader->GetOutput( )->TransformPhysicalPointToIndex( pnt, seed ) ) )
+    {
+      std::cerr << "ERROR: seed outside image." << std::endl;
+      return( 1 );
+
+    } // fi
+    filter->AddSeed( seed );
+  }
+  else
+    filter->SeedFromMaximumDistanceOn( );
+
+  std::chrono::time_point< std::chrono::system_clock > start, end;
+  start = std::chrono::system_clock::now( );
+  filter->Update( );
+  end = std::chrono::system_clock::now( );
+  std::chrono::duration< double > elapsed_seconds = end - start;
+
+  TWriter::Pointer writer = TWriter::New( );
+  writer->SetInput( filter->GetSkeleton( ) );
+  writer->SetFileName( output_skeleton_filename );
+  try
+  {
+    writer->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "ERROR: " << err.what( ) << std::endl;
+    return( 1 );
 
-     } // yrt
+  } // yrt
 
-     // Show data
-     TFilter::TCurve curve = filter->GetCurve( );
-     for( TFilter::TCurveData data: curve )
-     {
-     std::cout << data.XValue << " " << data.YValue << " " << data.Diff1 << std::endl;
-     }
-     std::cout
-     << std::endl
-     << "# Opt: "
-     << curve[ filter->GetOptimumThreshold( ) ].XValue
-     << "("
-     << filter->GetOptimumThreshold( )
-     << ")"
-     << std::endl;
-     std::cout << "Time: " << elapsed_seconds.count( ) << "s" << std::endl;
-  */
+  // Show data
+  std::cout << "Time: " << elapsed_seconds.count( ) << "s" << std::endl;
   return( 0 );
 }