]> Creatis software - FrontAlgorithms.git/blobdiff - examples/RegionGrow_Mori.cxx
...
[FrontAlgorithms.git] / examples / RegionGrow_Mori.cxx
index cf20cfafd70d30b49e6583df461c44ecb8b44ed6..7677fe5b96f5c2fd0b43ad251d3e990c23d8f15b 100644 (file)
@@ -1,3 +1,4 @@
+#include <chrono>
 #include <iomanip>
 #include <itkCommand.h>
 #include <itkImage.h>
@@ -58,23 +59,47 @@ int main( int argc, char* argv[] )
 
   TReader::Pointer reader = TReader::New( );
   reader->SetFileName( input_image_filename );
+  try
+  {
+    reader->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "ERROR: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
 
   TFilter::Pointer filter = TFilter::New( );
   filter->SetInput( reader->GetOutput( ) );
   filter->SetThresholdRange( lower, upper, delta );
-  TImage::IndexType seed;
+  TImage::PointType pnt;
   for( int i = 0; i < VDim; ++i )
-    seed[ i ] = std::atoi( argv[ i + 7 ] );
+    pnt[ i ] = std::atof( argv[ i + 7 ] );
+
+  TImage::IndexType seed;
+  if( !( reader->GetOutput( )->TransformPhysicalPointToIndex( pnt, seed ) ) )
+  {
+    std::cerr << "ERROR: seed outside image." << std::endl;
+    return( 1 );
+
+  } // fi
   filter->AddSeed( seed );
 
   // to test ProgressReporter
-  ShowProgressObject progressWatch( filter );
-  typedef itk::SimpleMemberCommand< ShowProgressObject > CommandType;
-  CommandType::Pointer command = CommandType::New();
-  command->SetCallbackFunction( &progressWatch,
-                                &ShowProgressObject::ShowProgress );
-  filter->AddObserver( itk::ProgressEvent( ), command );
+  /* TODO
+     ShowProgressObject progressWatch( filter );
+     typedef itk::SimpleMemberCommand< ShowProgressObject > CommandType;
+     CommandType::Pointer command = CommandType::New();
+     command->SetCallbackFunction( &progressWatch,
+     &ShowProgressObject::ShowProgress );
+     filter->AddObserver( itk::ProgressEvent( ), command );
+  */
+  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( ) );
@@ -108,14 +133,15 @@ int main( int argc, char* argv[] )
   {
     std::cout << data.XValue << " " << data.YValue << " " << data.Diff1 << std::endl;
   }
-  std::cerr
+  std::cout
     << std::endl
     << "# Opt: "
     << curve[ filter->GetOptimumThreshold( ) ].XValue
     << "("
     << filter->GetOptimumThreshold( )
-    << ")"
+     << ")"
     << std::endl;
+  std::cout << "Time: " << elapsed_seconds.count( ) << "s" << std::endl;
   return( 0 );
 }