From: Duvan Gomez Date: Tue, 9 May 2017 20:47:50 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=FrontAlgorithms.git;a=commitdiff_plain;h=f287dfe5d76525d02c37224c0a09ed6277fbbb52 ... --- f287dfe5d76525d02c37224c0a09ed6277fbbb52 diff --cc CMakeLists.txt index 4aa9686,6b7dd54..b2a6a18 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@@ -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$ diff --cc examples/CMakeLists.txt index e6d93b8,2bed4e5..4feb556 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@@ -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$ diff --cc examples/RegionGrow_Mori.cxx index 0000000,7677fe5..bdff6aa mode 000000,100644..100644 --- a/examples/RegionGrow_Mori.cxx +++ b/examples/RegionGrow_Mori.cxx @@@ -1,0 -1,148 +1,142 @@@ + #include + #include + #include + #include + #include + #include + #include + + #include + + // ------------------------------------------------------------------------- + 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 - if( argc < 7 + VDim ) ++ if( argc < 6 + VDim ) + { + std::cerr + << "Usage: " << argv[ 0 ] - << " input_image output_image auxiliary_image lower upper delta"; ++ << " 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 ]; - 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 ] ); ++ 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 ) - pnt[ i ] = std::atof( argv[ i + 7 ] ); ++ 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 ); - - TWriter::Pointer aux_writer = TWriter::New( ); - aux_writer->SetInput( filter->GetOutput( ) ); - aux_writer->SetFileName( auxiliary_image_filename ); + try + { + writer->Update( ); - aux_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$