From: Leonardo Flórez-Valencia Date: Wed, 5 Jul 2017 20:00:36 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=FrontAlgorithms.git;a=commitdiff_plain;h=479d85a44365c8aa01976ffb9c7d67d3e9e52b63 ... --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 095eff9..d1ab775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,12 @@ cmake_minimum_required(VERSION 3.0) ## == Project definition == ## ======================== -set(prj_MAJ_VERSION 0) -set(prj_MIN_VERSION 1) -set(prj_REL_VERSION 0) -set(prj_VERSION "${prj_MAJ_VERSION}.${prj_MIN_VERSION}.${prj_REL_VERSION}") -set(prj_SHORT_VERSION "${prj_MAJ_VERSION}") -project(fpa VERSION ${prj_VERSION}) +set(prj_MAJ_VER 0) +set(prj_MIN_VER 1) +set(prj_REL_VER 0) +set(prj_VER "${prj_MAJ_VER}.${prj_MIN_VER}.${prj_REL_VER}") +set(prj_SHORT_VER "${prj_MAJ_VER}") +project(fpa VERSION ${prj_VER}) ## ========================== ## == Some useful policies == @@ -22,15 +22,74 @@ foreach(_p ${_policies}) endif(POLICY ${_p}) endforeach(_p) -## =============================== -## == Some basic configurations == -## =============================== +## ========================================================= +## == If working on a MacOSX, activate the use of RPATH's == +## == Furthermore: prepare the type of executables == +## ========================================================= -include(cmake/fpaBaseConfig.cmake) +set(EXECUTABLE_TYPE "" CACHE STRING "Executable linking." FORCE) +if(APPLE) + set(EXECUTABLE_TYPE "MACOSX_BUNDLE" CACHE STRING "Executable linking." FORCE) + set(CMAKE_MACOSX_RPATH true CACHE BOOL "Use RPATH's on MacOSX." FORCE) + mark_as_advanced(CMAKE_MACOSX_RPATH) +elseif(WIN32) + set(EXECUTABLE_TYPE "WIN32" CACHE STRING "Executable linking." FORCE) +endif(APPLE) +mark_as_advanced(EXECUTABLE_TYPE) -## ========================== -## == Find needed packages == -## ========================== +## ======================================================================= +## == Force c++11 language version == +## == NOTE: It seems that by default on Visual Studio Compiler supports == +## == c++11, so it only need to be tested on other OS. == +## ======================================================================= + +if(NOT MSVC) + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11) + if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + else(COMPILER_SUPPORTS_CXX11) + check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X) + if(COMPILER_SUPPORTS_CXX0X) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + else(COMPILER_SUPPORTS_CXX0X) + message( + FATAL_ERROR + "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support." + ) + endif(COMPILER_SUPPORTS_CXX0X) + endif(COMPILER_SUPPORTS_CXX11) +endif(NOT MSVC) + +## =================================================== +## == Prepare header generator to build shared libs == +## =================================================== + +include(GenerateExportHeader) + +## ================================================== +## == Do not allow to build inside the source tree == +## ================================================== + +if(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR}) + message(FATAL_ERROR "Building in the source tree is not allowed.") +endif(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR}) + +## ================================================= +## == Where to put targets (executables and libs) == +## ================================================= + +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}) +mark_as_advanced( + CMAKE_BACKWARDS_COMPATIBILITY + EXECUTABLE_OUTPUT_PATH + LIBRARY_OUTPUT_PATH + ) + +## =========================================== +## == Find needed packages and dependencies == +## =========================================== find_package(ivq CONFIG QUIET) if(NOT ivq_FOUND) @@ -70,16 +129,14 @@ configure_package_config_file( INSTALL_DESTINATION "${config_install_dir}" ) install( - FILES - "${project_config}" - "${version_config}" - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}BaseConfig.cmake" + EXPORT "${targets_export_name}" + NAMESPACE "${namespace}" DESTINATION "${config_install_dir}" ) install( - EXPORT "${targets_export_name}" - NAMESPACE "${namespace}" + FILES "${project_config}" DESTINATION "${config_install_dir}" ) ## eof - $RCSfile$ + diff --git a/cmake/fpaBaseConfig.cmake b/cmake/fpaBaseConfig.cmake deleted file mode 100644 index 4e9cb25..0000000 --- a/cmake/fpaBaseConfig.cmake +++ /dev/null @@ -1,65 +0,0 @@ -## ========================================================= -## == If working on a MacOSX, activate the use of RPATH's == -## ========================================================= - -set(EXECUTABLE_TYPE "" CACHE STRING "Executable linking." FORCE) -if(APPLE) - set(EXECUTABLE_TYPE "MACOSX_BUNDLE" CACHE STRING "Executable linking." FORCE) - set(CMAKE_MACOSX_RPATH true CACHE BOOL "Use RPATH's on MacOSX systems." FORCE) - mark_as_advanced(CMAKE_MACOSX_RPATH) -elseif(WIN32) - set(EXECUTABLE_TYPE "WIN32" CACHE STRING "Executable linking." FORCE) -endif(APPLE) -mark_as_advanced(EXECUTABLE_TYPE) - -## ======================================================================= -## == Force c++11 language version == -## == NOTE: It seems that by default on Visual Studio Compiler supports == -## == c++11, so it only need to be tested on other OS. == -## ======================================================================= - -if(NOT MSVC) - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11) - if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - else(COMPILER_SUPPORTS_CXX11) - check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X) - if(COMPILER_SUPPORTS_CXX0X) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") - else(COMPILER_SUPPORTS_CXX0X) - message( - FATAL_ERROR - "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support." - ) - endif(COMPILER_SUPPORTS_CXX0X) - endif(COMPILER_SUPPORTS_CXX11) -endif(NOT MSVC) - -## =================================================== -## == Prepare header generator to build shared libs == -## =================================================== - -include(GenerateExportHeader) - -## ================================================== -## == Do not allow to build inside the source tree == -## ================================================== - -if(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR}) - message(FATAL_ERROR "Building in the source tree is not allowed.") -endif(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR}) - -## ================================================= -## == Where to put targets (executables and libs) == -## ================================================= - -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}) -mark_as_advanced( - CMAKE_BACKWARDS_COMPATIBILITY - EXECUTABLE_OUTPUT_PATH - LIBRARY_OUTPUT_PATH - ) - -## eof - $RCSfile$ diff --git a/cmake/fpaConfig.cmake.in b/cmake/fpaConfig.cmake.in index 26692f3..62a9a8c 100644 --- a/cmake/fpaConfig.cmake.in +++ b/cmake/fpaConfig.cmake.in @@ -1,12 +1,11 @@ @PACKAGE_INIT@ -include("${CMAKE_CURRENT_LIST_DIR}/fpaBaseConfig.cmake") include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") check_required_components("@PROJECT_NAME@") -## ============== -## == Find ITK == -## ============== +## =========================================== +## == Find needed packages and dependencies == +## =========================================== set(ITK_DIR @ITK_DIR@) diff --git a/lib/fpa/Base/Mori.h b/lib/fpa/Base/Mori.h new file mode 100644 index 0000000..430ff03 --- /dev/null +++ b/lib/fpa/Base/Mori.h @@ -0,0 +1,102 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + +#ifndef __fpa__Base__Mori__h__ +#define __fpa__Base__Mori__h__ + +#include +#include +#include +#include +#include + +namespace fpa +{ + namespace Base + { + /** + */ + template< class _TAlgorithm > + class Mori + : public _TAlgorithm + { + public: + typedef Mori Self; + typedef _TAlgorithm Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef typename _TAlgorithm::TNode TNode; + typedef typename _TAlgorithm::TNodes TNodes; + typedef typename _TAlgorithm::TInputValue TInputValue; + typedef typename _TAlgorithm::TOutputValue TOutputValue; + typedef typename _TAlgorithm::TFrontId TFrontId; + typedef typename _TAlgorithm::TVertex TVertex; + + typedef std::deque< TNode > TQueue; + typedef std::set< TInputValue > TThresholds; + typedef fpa::Base::Functors::RegionGrow::BinaryThreshold< TInputValue > TPredicate; + + public: + itkConceptMacro( + Check_TOutputValue, + ( itk::Concept::IsUnsignedInteger< TOutputValue > ) + ); + + itkGetConstMacro( InsideValue, TOutputValue ); + itkSetMacro( InsideValue, TOutputValue ); + + public: + virtual itk::ModifiedTimeType GetMTime( ) const override; + + TOutputValue GetOutsideValue( ) const; + void SetOutsideValue( const TOutputValue& v ); + + void ClearThresholds( ); + void AddThreshold( const TInputValue& thr ); + void SetThresholds( + const TInputValue& init, + const TInputValue& end, + unsigned long number_of_thresholds + ); + + protected: + Mori( ); + virtual ~Mori( ); + + virtual TOutputValue _ComputeOutputValue( const TNode& n ) override; + virtual void _QueueClear( ) override; + virtual TNode _QueuePop( ) override; + virtual void _QueuePush( const TNode& node ) override; + virtual unsigned long _QueueSize( ) const override; + virtual void _PrepareSeeds( TNodes& nodes ) override; + + private: + // Purposely not implemented. + Mori( const Self& other ); + Self& operator=( const Self& other ); + + protected: + typename TPredicate::Pointer m_Predicate; + TThresholds m_Thresholds; + TQueue m_Queues[ 2 ]; + unsigned int m_CurrentQueue; + + TOutputValue m_InsideValue; + }; + + } // ecapseman + +} // ecapseman + +/* TODO + #ifndef ITK_MANUAL_INSTANTIATION + # include + #endif // ITK_MANUAL_INSTANTIATION +*/ + +#endif // __fpa__Base__Mori__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/SingleSeedInterface.h b/lib/fpa/Base/SingleSeedInterface.h new file mode 100644 index 0000000..dc45fe9 --- /dev/null +++ b/lib/fpa/Base/SingleSeedInterface.h @@ -0,0 +1,101 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + +#ifndef __fpa__Base__SingleSeedInterface__h__ +#define __fpa__Base__SingleSeedInterface__h__ + +#include +#include +#include + +#include +#include + +namespace fpa +{ + namespace Base + { + /** + */ + template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare = std::greater< _TVertex > > + class SingleSeedInterface + { + public: + itkConceptMacro( + Check_TFrontId, + ( itk::Concept::IsUnsignedInteger< _TFrontId > ) + ); + + public: + typedef _TVertex TVertex; + typedef _TPoint TPoint; + typedef _TInputValue TInputValue; + typedef _TOutputValue TOutputValue; + typedef _TFrontId TFrontId; + typedef _TCompare TCompare; + typedef SingleSeedInterface Self; + + struct TSeed + { + TVertex Vertex; + TPoint Point; + bool IsPoint; + bool IsUnified; + TFrontId FrontId; + TSeed( ) + : IsUnified( false ), + FrontId( TFrontId( 0 ) ) + { } + }; + typedef std::vector< TSeed > TSeeds; + + struct TNode + { + TVertex Vertex; + TVertex Parent; + TFrontId FrontId; + + // Hack to hide the fact that seed values need to be initialized + mutable TOutputValue Value; + }; + struct TNodeCompare + { + bool operator()( const TNode& a, const TNode& b ) const + { + TCompare cmp; + return( cmp( a.Vertex, b.Vertex ) ); + } + }; + typedef std::set< TNode, TNodeCompare > TNodes; + + public: + const TSeeds& GetSeeds( ) const; + + virtual void SetSeed( const TVertex& seed ); + virtual void SetSeed( const TPoint& seed ); + + protected: + SingleSeedInterface( itk::ProcessObject* filter ); + virtual ~SingleSeedInterface( ); + + virtual TNodes _UnifySeeds( ) = 0; + virtual void _PrepareSeeds( TNodes& nodes ) = 0; + + protected: + TSeeds m_Seeds; + itk::ProcessObject* m_Filter; + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __fpa__Base__SingleSeedInterface__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/SingleSeedInterface.hxx b/lib/fpa/Base/SingleSeedInterface.hxx new file mode 100644 index 0000000..6db301c --- /dev/null +++ b/lib/fpa/Base/SingleSeedInterface.hxx @@ -0,0 +1,67 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + +#ifndef __fpa__Base__SingleSeedInterface__hxx__ +#define __fpa__Base__SingleSeedInterface__hxx__ + +// ------------------------------------------------------------------------- +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +const typename +fpa::Base::SingleSeedInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +TSeeds& +fpa::Base::SingleSeedInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +GetSeeds( ) const +{ + return( this->m_Seeds ); +} + +// ------------------------------------------------------------------------- +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +void +fpa::Base::SingleSeedInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +SetSeed( const TVertex& seed ) +{ + TSeed s; + s.Vertex = seed; + s.IsPoint = false; + this->m_Seeds[ 0 ] = s; + if( this->m_Filter != NULL ) + this->m_Filter->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +void +fpa::Base::SingleSeedInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +SetSeed( const TPoint& seed ) +{ + TSeed s; + s.Point = seed; + s.IsPoint = true; + this->m_Seeds[ 0 ] = s; + if( this->m_Filter != NULL ) + this->m_Filter->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +fpa::Base::SingleSeedInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +SingleSeedInterface( itk::ProcessObject* filter ) + : m_Filter( filter ) +{ + this->m_Seeds = TSeeds( 1 ); +} + +// ------------------------------------------------------------------------- +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +fpa::Base::SingleSeedInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +~SingleSeedInterface( ) +{ + this->m_Seeds.clear( ); +} + +#endif // __fpa__Base__SingleSeedInterface__hxx__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/Mori.h b/lib/fpa/Image/Mori.h new file mode 100644 index 0000000..21c1748 --- /dev/null +++ b/lib/fpa/Image/Mori.h @@ -0,0 +1,83 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + +#ifndef __fpa__Image__Mori__h__ +#define __fpa__Image__Mori__h__ + +#include +#include +#include +#include + +namespace fpa +{ + namespace Image + { + /** + */ + template< class _TInputImage, class _TOutputImage, class _TFrontId = unsigned char > + class Mori + : public fpa::Base::Mori< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterface< typename _TInputImage::IndexType >, fpa::Base::SingleSeedInterface< typename _TInputImage::IndexType, typename _TInputImage::PointType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, _TFrontId, typename _TInputImage::IndexType::LexicographicCompare > > > + { + public: + typedef _TInputImage TInputImage; + typedef _TOutputImage TOutputImage; + typedef _TFrontId TFrontId; + + typedef typename TInputImage::IndexType TVertex; + typedef typename TInputImage::PointType TPoint; + typedef typename TVertex::LexicographicCompare TVertexCompare; + typedef typename TInputImage::PixelType TInputValue; + typedef typename TOutputImage::PixelType TOutputValue; + + typedef fpa::Base::MarksInterface< TVertex > TMarksInterface; + typedef fpa::Base::SingleSeedInterface< TVertex, TPoint, TInputValue, TOutputValue, TFrontId, TVertexCompare > TSeedsInterface; + typedef fpa::Image::Algorithm< TInputImage, TOutputImage, TMarksInterface, TSeedsInterface > TAlgorithm; + + typedef Mori Self; + typedef fpa::Base::Mori< TAlgorithm > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef typename TSeedsInterface::TNode TNode; + typedef typename TSeedsInterface::TNodes TNodes; + typedef typename TAlgorithm::TMarks TMarks; + + public: + itkNewMacro( Self ); + itkTypeMacro( fpa::Image::Mori, fpa::Base::Mori ); + + public: + TMarks* GetOutputLevels( ) + { + return( this->GetMarks( ) ); + } + const TMarks* GetOutputLevels( ) const + { + return( this->GetMarks( ) ); + } + + protected: + Mori( ) + : Superclass( ) + { + } + virtual ~Mori( ) + { + } + + private: + // Purposely not implemented. + Mori( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + +} // ecapseman + +#endif // __fpa__Image__Mori__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Version.cxx.in b/lib/fpa/Version.cxx.in index 1bac65e..445f314 100644 --- a/lib/fpa/Version.cxx.in +++ b/lib/fpa/Version.cxx.in @@ -2,6 +2,6 @@ #include #include -std::string FPA_EXPORT version( ) { return( "@prj_VERSION@" ); } +std::string FPA_EXPORT version( ) { return( "@prj_VER@" ); } // eof - $RCSfile$ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dc97055..7a3c48b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,10 @@ -option(BUILD_TESTS "Build command line tests." OFF) -if(BUILD_TESTS) +option(fpa_BUILD_TESTS "Build command line tests." OFF) +if(fpa_BUILD_TESTS) include_directories( ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR}/lib ) subdirs(image) -endif(BUILD_TESTS) +endif(fpa_BUILD_TESTS) ## eof - $RCSfile$ diff --git a/tests/image/BaseFunctions.h b/tests/image/BaseFunctions.h index 21200d0..fc76be7 100644 --- a/tests/image/BaseFunctions.h +++ b/tests/image/BaseFunctions.h @@ -13,16 +13,18 @@ #include #include -#ifdef USE_ivq -# include -# include -# include -# include -# include -# include -# include -# include -#endif // USE_ivq +/* TODO + #ifdef USE_ivq + # include + # include + # include + # include + # include + # include + # include + # include + #endif // USE_ivq +*/ namespace fpa { @@ -105,203 +107,134 @@ namespace fpa } // ------------------------------------------------------------------- - template< class _TFilter > - class Viewer - { - public: - typedef _TFilter TFilter; - typedef typename _TFilter::TInputImage TInputImage; - - public: - Viewer( const TInputImage* image ) - { -#ifdef USE_ivq - this->m_VTKInputImage = TVTKInputImage::New( ); - this->m_VTKInputImage->SetInput( image ); - this->m_VTKInputImage->Update( ); - - this->m_Viewer = vtkSmartPointer< ivq::VTK::ImageViewer >::New( ); - this->m_Viewer->SetInputData( this->m_VTKInputImage->GetOutput( ) ); -#endif // USE_ivq - } - - virtual ~Viewer( ) - { - } - - void ActivateSeedWidget( ) - { -#ifdef USE_ivq - this->m_SeedWidget = - vtkSmartPointer< ivq::VTK::SeedWidgetOverImageActor >::New( ); - this->m_SeedWidget->SetActor( this->m_Viewer->GetImageActor( ) ); - this->m_SeedWidget->SetInteractor( - this->m_Viewer->GetRenderWindow( )->GetInteractor( ) - ); -#endif // USE_ivq - } - - void ActivateBrushWidget( ) - { -#ifdef USE_ivq - this->m_BrushWidget = - vtkSmartPointer< ivq::VTK::BrushWidget >::New( ); - this->m_BrushWidget->SetImageActor( this->m_Viewer->GetImageActor( ) ); - this->m_BrushWidget->SetInteractor( - this->m_Viewer->GetRenderWindow( )->GetInteractor( ) - ); -#endif // USE_ivq - } - - void Show( ) - { -#ifdef USE_ivq - this->m_Viewer->Render( ); - this->m_Viewer->ResetCamera( ); - this->m_Viewer->Initialize( ); - this->m_Viewer->Render( ); - if( this->m_SeedWidget.GetPointer( ) != NULL ) - this->m_SeedWidget->EnabledOn( ); - if( this->m_BrushWidget.GetPointer( ) != NULL ) - this->m_BrushWidget->EnabledOn( ); - this->m_Viewer->Start( ); - if( this->m_SeedWidget.GetPointer( ) != NULL ) - this->m_SeedWidget->EnabledOff( ); - if( this->m_BrushWidget.GetPointer( ) != NULL ) - this->m_BrushWidget->EnabledOff( ); -#endif // USE_ivq - } - - void AssociateSeedsTo( TFilter* filter ) - { -#ifdef USE_ivq - if( this->m_SeedWidget.GetPointer( ) != NULL ) - { - const ivq::VTK::SeedWidgetOverImageActor::TSeeds& wdg_seeds = - this->m_SeedWidget->GetSeeds( ); - ivq::VTK::SeedWidgetOverImageActor::TSeeds::const_iterator wsIt; - for( wsIt = wdg_seeds.begin( ); wsIt != wdg_seeds.end( ); ++wsIt ) - { - typename TInputImage::PointType pnt; - for( unsigned int i = 0; i < wsIt->second.size( ); i += 3 ) - { - pnt[ 0 ] = wsIt->second[ i ]; - pnt[ 1 ] = wsIt->second[ i + 1 ]; - - typename TInputImage::IndexType idx; - filter->GetInput( )->TransformPhysicalPointToIndex( pnt, idx ); - filter->AddSeed( idx ); - - } // rof - - } // rof - - } // fi -#endif // USE_ivq - } - - void AssociateLabelsTo( TFilter* filter ) - { -#ifdef USE_ivq - if( this->m_BrushWidget.GetPointer( ) != NULL ) - { - typedef typename TFilter::TLabelImage _TLabelImage; - typedef itk::VTKImageToImageFilter< _TLabelImage > TITKImage; - typename TITKImage::Pointer itk_image = TITKImage::New( ); - itk_image->SetInput( this->m_BrushWidget->GetCanvas( ) ); - itk_image->Update( ); - filter->SetLabels( itk_image->GetOutput( ) ); - - } // fi -#endif // USE_ivq - } - - void ObserveFilter( TFilter* filter ) - { -#ifdef USE_ivq - typedef fpa::Image::VisualDebugger2D< TFilter > _TDeb; - typedef typename TFilter::TEvent _TEvent; - typename _TDeb::Pointer deb = _TDeb::New( ); - deb->SetVisualization( - this->m_Viewer->GetRenderer( ), - this->m_Viewer->GetRenderWindow( )->GetInteractor( ) - ); - this->m_Observer1 = filter->AddObserver( itk::StartEvent( ), deb ); - this->m_Observer2 = filter->AddObserver( itk::EndEvent( ), deb ); - this->m_Observer3 = filter->AddObserver( _TEvent( ), deb ); - filter->VisualDebugOn( ); -#endif // USE_ivq - } - - protected: -#ifdef USE_ivq - typedef itk::ImageToVTKImageFilter< TInputImage > TVTKInputImage; - typename TVTKInputImage::Pointer m_VTKInputImage; - vtkSmartPointer< ivq::VTK::ImageViewer > m_Viewer; - vtkSmartPointer< ivq::VTK::SeedWidgetOverImageActor > m_SeedWidget; - vtkSmartPointer< ivq::VTK::BrushWidget > m_BrushWidget; - unsigned long m_Observer1; - unsigned long m_Observer2; - unsigned long m_Observer3; -#endif // USE_ivq - - - /* TODO - #ifdef USE_ivq - // VTK image - typedef itk::ImageToVTKImageFilter< TImage > TVTKImage; - TVTKImage::Pointer vtk_input; - vtkSmartPointer< ivq::VTK::ImageViewer > view; - vtkSmartPointer< ivq::VTK::SeedWidgetOverImageActor > widget; - - if( visual_debug ) - { - vtk_input = TVTKImage::New( ); - vtk_input->SetInput( input ); - vtk_input->Update( ); - - // Viewer - view = vtkSmartPointer< ivq::VTK::ImageViewer >::New( ); - view->SetInputData( vtk_input->GetOutput( ) ); - view->SetSlice( 0 ); - - // Widget - widget = vtkSmartPointer< ivq::VTK::SeedWidgetOverImageActor >::New( ); - widget->SetActor( view->GetImageActor( ) ); - widget->SetInteractor( view->GetRenderWindow( )->GetInteractor( ) ); - - // Visualize - view->Render( ); - view->ResetCamera( ); - view->Initialize( ); - view->Render( ); - widget->EnabledOn( ); - view->Start( ); - widget->EnabledOff( ); - - const ivq::VTK::SeedWidgetOverImageActor::TSeeds& wdg_seeds = - widget->GetSeeds( ); - ivq::VTK::SeedWidgetOverImageActor::TSeeds::const_iterator wsIt; - for( wsIt = wdg_seeds.begin( ); wsIt != wdg_seeds.end( ); ++wsIt ) - { - TImage::PointType pnt; - for( unsigned int i = 0; i < wsIt->second.size( ); i += 3 ) - { - pnt[ 0 ] = wsIt->second[ i ]; - pnt[ 1 ] = wsIt->second[ i + 1 ]; - - TImage::IndexType idx; - input->TransformPhysicalPointToIndex( pnt, idx ); - seeds.push_back( idx ); - - } // rof - - } // rof - - } // fi - #endif // USE_ivq - */ - }; + /* TODO + #ifdef USE_ivq + template< class _TFilter > + class Viewer + { + public: + typedef _TFilter TFilter; + typedef typename _TFilter::TInputImage TInputImage; + + public: + Viewer( const TInputImage* image ) + { + this->m_VTKInputImage = TVTKInputImage::New( ); + this->m_VTKInputImage->SetInput( image ); + this->m_VTKInputImage->Update( ); + + this->m_Viewer = vtkSmartPointer< ivq::VTK::ImageViewer >::New( ); + this->m_Viewer->SetInputData( this->m_VTKInputImage->GetOutput( ) ); + } + + virtual ~Viewer( ) + { + } + + void ActivateSeedWidget( ) + { + this->m_SeedWidget = + vtkSmartPointer< ivq::VTK::SeedWidgetOverImageActor >::New( ); + this->m_SeedWidget->SetActor( this->m_Viewer->GetImageActor( ) ); + this->m_SeedWidget->SetInteractor( + this->m_Viewer->GetRenderWindow( )->GetInteractor( ) + ); + } + + void ActivateBrushWidget( ) + { + this->m_BrushWidget = + vtkSmartPointer< ivq::VTK::BrushWidget >::New( ); + this->m_BrushWidget->SetImageActor( this->m_Viewer->GetImageActor( ) ); + this->m_BrushWidget->SetInteractor( + this->m_Viewer->GetRenderWindow( )->GetInteractor( ) + ); + } + + void Show( ) + { + this->m_Viewer->Render( ); + this->m_Viewer->ResetCamera( ); + this->m_Viewer->Initialize( ); + this->m_Viewer->Render( ); + if( this->m_SeedWidget.GetPointer( ) != NULL ) + this->m_SeedWidget->EnabledOn( ); + if( this->m_BrushWidget.GetPointer( ) != NULL ) + this->m_BrushWidget->EnabledOn( ); + this->m_Viewer->Start( ); + if( this->m_SeedWidget.GetPointer( ) != NULL ) + this->m_SeedWidget->EnabledOff( ); + if( this->m_BrushWidget.GetPointer( ) != NULL ) + this->m_BrushWidget->EnabledOff( ); + } + + void AssociateSeedsTo( TFilter* filter ) + { + if( this->m_SeedWidget.GetPointer( ) != NULL ) + { + const ivq::VTK::SeedWidgetOverImageActor::TSeeds& wdg_seeds = + this->m_SeedWidget->GetSeeds( ); + ivq::VTK::SeedWidgetOverImageActor::TSeeds::const_iterator wsIt; + for( wsIt = wdg_seeds.begin( ); wsIt != wdg_seeds.end( ); ++wsIt ) + { + typename TInputImage::PointType pnt; + for( unsigned int i = 0; i < wsIt->second.size( ); i += 3 ) + { + pnt[ 0 ] = wsIt->second[ i ]; + pnt[ 1 ] = wsIt->second[ i + 1 ]; + + typename TInputImage::IndexType idx; + filter->GetInput( )->TransformPhysicalPointToIndex( pnt, idx ); + filter->AddSeed( idx ); + + } // rof + + } // rof + + } // fi + } + + void AssociateLabelsTo( TFilter* filter ) + { + if( this->m_BrushWidget.GetPointer( ) != NULL ) + { + typedef typename TFilter::TLabelImage _TLabelImage; + typedef itk::VTKImageToImageFilter< _TLabelImage > TITKImage; + typename TITKImage::Pointer itk_image = TITKImage::New( ); + itk_image->SetInput( this->m_BrushWidget->GetCanvas( ) ); + itk_image->Update( ); + filter->SetLabels( itk_image->GetOutput( ) ); + + } // fi + } + + void ObserveFilter( TFilter* filter ) + { + typedef fpa::Image::VisualDebugger2D< TFilter > _TDeb; + typedef typename TFilter::TEvent _TEvent; + typename _TDeb::Pointer deb = _TDeb::New( ); + deb->SetVisualization( + this->m_Viewer->GetRenderer( ), + this->m_Viewer->GetRenderWindow( )->GetInteractor( ) + ); + this->m_Observer1 = filter->AddObserver( itk::StartEvent( ), deb ); + this->m_Observer2 = filter->AddObserver( itk::EndEvent( ), deb ); + this->m_Observer3 = filter->AddObserver( _TEvent( ), deb ); + filter->VisualDebugOn( ); + } + + protected: + typedef itk::ImageToVTKImageFilter< TInputImage > TVTKInputImage; + typename TVTKInputImage::Pointer m_VTKInputImage; + vtkSmartPointer< ivq::VTK::ImageViewer > m_Viewer; + vtkSmartPointer< ivq::VTK::SeedWidgetOverImageActor > m_SeedWidget; + vtkSmartPointer< ivq::VTK::BrushWidget > m_BrushWidget; + unsigned long m_Observer1; + unsigned long m_Observer2; + unsigned long m_Observer3; + }; + #endif // USE_ivq + */ } // ecapseman diff --git a/tests/image/CMakeLists.txt b/tests/image/CMakeLists.txt index c51ed18..ac3f2f6 100644 --- a/tests/image/CMakeLists.txt +++ b/tests/image/CMakeLists.txt @@ -2,19 +2,16 @@ set(_pfx test_fpa_image_) set( _examples RegionGrow_Tautology - Dijkstra_Identity - Dijkstra_Gaussian - RandomWalker - SkeletonFilter - SkeletonToPolyData + MoriSegmentation + # Dijkstra_Identity + # Dijkstra_Gaussian + # RandomWalker + # SkeletonFilter + # SkeletonToPolyData ) foreach(_e ${_examples}) add_executable(${_pfx}${_e} ${_e}.cxx) - if(ivq_FOUND) - target_link_libraries(${_pfx}${_e} fpa ivq::ivq) - else(ivq_FOUND) - target_link_libraries(${_pfx}${_e} fpa) - endif(ivq_FOUND) + target_link_libraries(${_pfx}${_e} fpa) endforeach(_e) ## eof - $RCSfile$ diff --git a/tests/image/MoriSegmentation.cxx b/tests/image/MoriSegmentation.cxx new file mode 100644 index 0000000..e02b359 --- /dev/null +++ b/tests/image/MoriSegmentation.cxx @@ -0,0 +1,64 @@ +#include "BaseFunctions.h" +#include +#include + +// ------------------------------------------------------------------------- +const unsigned int Dim = 2; +typedef unsigned char TPixel; + +typedef itk::Image< TPixel, Dim > TImage; +typedef fpa::Image::Mori< TImage, TImage > TFilter; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + // Get arguments + if( argc < 9 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " input_image output_image output_levels" + << " init_threshold end_threshold number_of_threshold seed_x seed_y" + << std::endl; + return( 1 ); + + } // fi + std::string input_image_filename = argv[ 1 ]; + std::string output_image_filename = argv[ 2 ]; + std::string output_levels_filename = argv[ 3 ]; + unsigned char init_threshold = std::atoi( argv[ 4 ] ); + unsigned char end_threshold = std::atoi( argv[ 5 ] ); + unsigned char number_of_thresholds = std::atoi( argv[ 6 ] ); + TImage::IndexType seed; + seed[ 0 ] = std::atoi( argv[ 7 ] ); + seed[ 1 ] = std::atoi( argv[ 8 ] ); + + // Create image + TImage::Pointer input_image; + std::string err0 = + fpa::tests::image::Read( input_image, input_image_filename ); + if( err0 != "" ) std::cerr << err0 << std::endl; + + // Prepare filter + TFilter::Pointer filter = TFilter::New( ); + filter->SetInput( input_image ); + filter->SetSeed( seed ); + filter->SetThresholds( init_threshold, end_threshold, number_of_thresholds ); + filter->SetInsideValue( 255 ); + filter->SetOutsideValue( 0 ); + + // Execute 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->GetOutputLevels( ), output_levels_filename ); + if( err1 != "" ) std::cerr << err1 << std::endl; + if( err2 != "" ) std::cerr << err2 << std::endl; + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/tests/image/RegionGrow_Tautology.cxx b/tests/image/RegionGrow_Tautology.cxx index 7cdffa5..d19969b 100644 --- a/tests/image/RegionGrow_Tautology.cxx +++ b/tests/image/RegionGrow_Tautology.cxx @@ -15,11 +15,11 @@ typedef fpa::Base::Functors::RegionGrow::Tautology< TPixel > TPredicate; int main( int argc, char* argv[] ) { // Get arguments - if( argc < 6 ) + if( argc < 5 ) { std::cerr << "Usage: " << argv[ 0 ] - << " output_image output_marks width height visual_debug ..." + << " output_image output_marks width height ..." << std::endl; return( 1 ); @@ -28,21 +28,11 @@ int main( int argc, char* argv[] ) 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 TImage::Pointer image; fpa::tests::image::CreateImage( image, 0, 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 predicate TPredicate::Pointer predicate = TPredicate::New( ); @@ -66,11 +56,8 @@ int main( int argc, char* argv[] ) } // fi } // rof - viewer.AssociateSeedsTo( filter ); - // Prepare visual debug and update - if( visual_debug ) - viewer.ObserveFilter( filter ); + // Execute filter filter->Update( ); // Save results