]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorDuvan Gomez <da.gomez16@uniandes.edu.co>
Tue, 9 May 2017 20:47:50 +0000 (15:47 -0500)
committerDuvan Gomez <da.gomez16@uniandes.edu.co>
Tue, 9 May 2017 20:47:50 +0000 (15:47 -0500)
1  2 
CMakeLists.txt
examples/CMakeLists.txt
examples/RegionGrow_Mori.cxx

diff --cc CMakeLists.txt
index 4aa96867e0c75bb107a4b87c004ae2857ff73210,6b7dd54a0e7a3e89eb4446f6407656e4be0a6d4e..b2a6a18e5fb3952074891383ece9abf21f8521a3
@@@ -50,8 -51,32 +51,32 @@@ set(namespace "${PROJECT_NAME}::"
  ## == Build different parts ==
  ## ===========================
  
- FOREACH(_s ${_subdirs})
-   SUBDIRS(${_s})
- ENDFOREACH(_s)
 -subdirs(lib)
++subdirs(examples lib)
+ ## ===============================
+ ## == Global installation rules ==
+ ## ===============================
+ include(CMakePackageConfigHelpers)
+ write_basic_package_version_file(
+   "${version_config}" COMPATIBILITY SameMajorVersion
+   )
+ configure_package_config_file(
+   "cmake/${PROJECT_NAME}Config.cmake.in"
+   "${project_config}"
+   INSTALL_DESTINATION "${config_install_dir}"
+   )
+ install(
+   FILES
+   "${project_config}"
+   "${version_config}"
+   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/fpaBaseConfig.cmake"
+   DESTINATION "${config_install_dir}"
+   )
+ #install(
+ #  EXPORT "${targets_export_name}"
+ #  NAMESPACE "${namespace}"
+ #  DESTINATION "${config_install_dir}"
+ #  )
  
  ## eof - $RCSfile$
index e6d93b88d0f5e43c7f6e7a99216e2a0896750822,2bed4e539017b74d308ad932155737162d896e3e..4feb556f0db0c20ac5c29385713dcd31e7c34ff3
@@@ -1,21 -1,27 +1,27 @@@
- OPTION(BUILD_Examples "Build simple examples?" OFF)
- IF(BUILD_Examples)
 -OPTION(BUILD_EXAMPLES "Build cpPlugins-free examples." OFF)
 -IF(BUILD_EXAMPLES)
--  SET(
++option(BUILD_EXAMPLES "Build cpPlugins-free examples." OFF)
++if(BUILD_EXAMPLES)
++  set(
      _examples
-     RegionGrow_00
-     FastMarching_00
-     MoriRegionGrow_00
-     Skeleton_00
+     RegionGrow_Tautology
+     RegionGrow_BinaryThreshold
+     RegionGrow_Mori
+     Dijkstra_Maurer
+     #CreateMoriInputImage
+     #BronchiiInitialSegmentationWithMori
+     #BronchiiInitialSegmentationWithBinaryThresholdRegionGrow
      )
 -  OPTION(BUILD_EXAMPLE_SANDBOX "Build sandbox example." OFF)
 -  IF(BUILD_EXAMPLE_SANDBOX)
 -    LIST(APPEND _examples sandbox)
 -  ENDIF(BUILD_EXAMPLE_SANDBOX)
--  INCLUDE_DIRECTORIES(
 -    ${PROJECT_SOURCE_DIR}/libs
 -    ${PROJECT_BINARY_DIR}/libs
++  option(BUILD_EXAMPLE_SANDBOX "Build sandbox example." OFF)
++  if(BUILD_EXAMPLE_SANDBOX)
++    list(APPEND _examples sandbox)
++  endif(BUILD_EXAMPLE_SANDBOX)
++  include_directories(
 +    ${PROJECT_SOURCE_DIR}/lib
 +    ${PROJECT_BINARY_DIR}/lib
      )
-   FOREACH(_example ${_examples})
-     ADD_EXECUTABLE(fpa_example_${_example} ${_example}.cxx)
-     TARGET_LINK_LIBRARIES(fpa_example_${_example} ${ITK_LIBRARIES} ${VTK_LIBRARIES})
-   ENDFOREACH(_example)
- ENDIF(BUILD_Examples)
 -  FOREACH(_e ${_examples})
 -    ADD_EXECUTABLE(fpa_example_${_e} ${_e}.cxx)
 -    TARGET_LINK_LIBRARIES(fpa_example_${_e} ${ITK_LIBRARIES})
 -  ENDFOREACH(_e)
 -ENDIF(BUILD_EXAMPLES)
++  foreach(_e ${_examples})
++    add_executable(fpa_example_${_e} ${_e}.cxx)
++    target_link_libraries(fpa_example_${_e} ${ITK_LIBRARIES})
++  endforeach(_e)
++endif(BUILD_EXAMPLES)
  
  ## eof - $RCSfile$
index 0000000000000000000000000000000000000000,7677fe5b96f5c2fd0b43ad251d3e990c23d8f15b..bdff6aa6b40d851685cff7bb6e91326da2d80c0e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,148 +1,142 @@@
 -  if( argc < 7 + VDim )
+ #include <chrono>
+ #include <iomanip>
+ #include <itkCommand.h>
+ #include <itkImage.h>
+ #include <itkImageFileReader.h>
+ #include <itkImageFileWriter.h>
+ #include <itkBinaryThresholdImageFilter.h>
+ #include <fpa/Image/MoriRegionGrow.h>
+ // -------------------------------------------------------------------------
+ static const unsigned int VDim = 3;
+ typedef short                                             TPixel;
+ typedef itk::Image< TPixel, VDim >                        TImage;
+ typedef itk::ImageFileReader< TImage >                    TReader;
+ typedef itk::ImageFileWriter< TImage >                    TWriter;
+ typedef fpa::Image::MoriRegionGrow< TImage, TImage >      TFilter;
+ typedef itk::BinaryThresholdImageFilter< TImage, TImage > TThreshold;
+ // -------------------------------------------------------------------------
+ class ShowProgressObject
+ {
+ public:
+   ShowProgressObject( itk::ProcessObject* o )
+     {
+       this->m_Process = o;
+     }
+   void ShowProgress( )
+     {
+       std::cerr
+         << "\rProgress " << std::fixed << std::setprecision( 2 )
+         << ( this->m_Process->GetProgress( ) * 100 )
+         << " %" << std::flush;
+     }
+   itk::ProcessObject::Pointer m_Process;
+ };
+ // -------------------------------------------------------------------------
+ int main( int argc, char* argv[] )
+ {
+   // Get arguments
 -      << " input_image output_image auxiliary_image lower upper delta";
++  if( argc < 6 + VDim )
+   {
+     std::cerr
+       << "Usage: " << argv[ 0 ]
 -  std::string auxiliary_image_filename = argv[ 3 ];
 -  TPixel lower = std::atof( argv[ 4 ] );
 -  TPixel upper = std::atof( argv[ 5 ] );
 -  TPixel delta = std::atof( argv[ 6 ] );
++      << " input_image output_image lower upper delta";
+     for( unsigned int i = 0; i < VDim; ++i )
+       std::cerr << " s_" << i;
+     std::cerr << std::endl;
+     return( 1 );
+   } // fi
+   std::string input_image_filename = argv[ 1 ];
+   std::string output_image_filename = argv[ 2 ];
 -    pnt[ i ] = std::atof( argv[ i + 7 ] );
++  TPixel lower = std::atof( argv[ 3 ] );
++  TPixel upper = std::atof( argv[ 4 ] );
++  TPixel delta = std::atof( argv[ 5 ] );
+   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::PointType pnt;
+   for( int i = 0; i < VDim; ++i )
 -
 -  TWriter::Pointer aux_writer = TWriter::New( );
 -  aux_writer->SetInput( filter->GetOutput( ) );
 -  aux_writer->SetFileName( auxiliary_image_filename );
++    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 );
+   // to test ProgressReporter
+   /* 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( ) );
+   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 );
 -    aux_writer->Update( );
+   try
+   {
+     writer->Update( );
+   }
+   catch( std::exception& err )
+   {
+     std::cerr << "ERROR: " << err.what( ) << std::endl;
+     return( 1 );
+   } // 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;
+   return( 0 );
+ }
+ // eof - $RCSfile$