From 203ea510f7cc3990e606dd93a97dd0b5075d35c4 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Sun, 9 Oct 2016 19:11:34 -0500 Subject: [PATCH] ... --- CMakeLists.txt | 1 - appli/examples/CMakeLists.txt | 2 +- cmake/DetectOS.cmake | 23 --- cmake/Functions.cmake | 11 +- lib/CMakeLists.txt | 1 + lib/Instances/CMakeLists.txt | 18 +- lib/Instances/fpa_DataObjects.i | 7 +- lib/Instances/fpa_Filters.i | 2 +- lib/fpa/Base/MinimumSpanningTree.h | 15 +- lib/fpa/Base/MinimumSpanningTree.hxx | 63 ++++--- lib/fpa/Image/EndPointsFilter.hxx | 172 +++++++++--------- lib/fpa/Image/MinimumSpanningTree.h | 28 +-- lib/fpa/Image/MinimumSpanningTree.hxx | 36 +--- .../ExtractPathFromMinimumSpanningTree.cxx | 72 ++------ 14 files changed, 199 insertions(+), 252 deletions(-) delete mode 100644 cmake/DetectOS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 914bfe6..3558050 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ SET(prj_SHORT_VERSION "${prj_MAJOR_VERSION}") ## == Functions, packages and options == ## ===================================== -INCLUDE(cmake/DetectOS.cmake) INCLUDE(cmake/Restrictions.cmake) INCLUDE(cmake/Functions.cmake) INCLUDE(cmake/KitwareTools.cmake) diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index 861b670..5d570b6 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -1,4 +1,4 @@ ADD_EXECUTABLE(fpa_examples_ImageDijkstra ImageDijkstra.cxx) -TARGET_LINK_LIBRARIES(fpa_examples_ImageDijkstra ${ITK_LIBRARIES}) +TARGET_LINK_LIBRARIES(fpa_examples_ImageDijkstra ${ITK_LIBRARIES} ${VTK_LIBRARIES}) ## eof - $RCSfile$ diff --git a/cmake/DetectOS.cmake b/cmake/DetectOS.cmake deleted file mode 100644 index bba8346..0000000 --- a/cmake/DetectOS.cmake +++ /dev/null @@ -1,23 +0,0 @@ -## ===================== -## == OS-based values == -## ===================== - -SET(prj_NAME_OS "${prj_NAME}_OS_${CMAKE_SYSTEM_NAME}") -IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - SET(prj_NAME_LIB_PREFIX "lib") - SET(prj_NAME_LIB_EXT ".so") - SET(prj_NAME_ENV_SEPARATOR ":") - SET(prj_NAME_PATH_SEPARATOR "/") -ELSEIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") - SET(prj_NAME_LIB_PREFIX "lib") - SET(prj_NAME_LIB_EXT ".dylib") - SET(prj_NAME_ENV_SEPARATOR ":") - SET(prj_NAME_PATH_SEPARATOR "/") -ELSEIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") - SET(prj_NAME_LIB_PREFIX "") - SET(prj_NAME_LIB_EXT ".dll") - SET(prj_NAME_ENV_SEPARATOR ";") - SET(prj_NAME_PATH_SEPARATOR "\\") -ENDIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - -## eof - $RCSfile$ diff --git a/cmake/Functions.cmake b/cmake/Functions.cmake index f5a90f3..d3d5500 100644 --- a/cmake/Functions.cmake +++ b/cmake/Functions.cmake @@ -61,6 +61,7 @@ ENDFUNCTION() FUNCTION( CreateLib lib_name + lib_dir lib_type lib_source_files lib_header_files @@ -94,7 +95,7 @@ ENDIF(Qt4_FOUND) ## -- Ok, compile library IF(_sources) NormPaths(_cur_binary_dir ${CMAKE_CURRENT_BINARY_DIR}) - ADD_LIBRARY(${lib_name} SHARED ${_sources} ${_headers}) + ADD_LIBRARY(${lib_name} ${lib_type} ${_sources} ${_headers}) SET_TARGET_PROPERTIES( ${lib_name} PROPERTIES @@ -117,6 +118,7 @@ ENDFUNCTION() FUNCTION( LibFromDir lib_name + lib_dir lib_type lib_source_dir lib_version @@ -200,7 +202,7 @@ ENDIF(ARGN) ## -- Create library CreateLib( - ${lib_name} ${lib_type} + ${lib_name} ${lib_dir} ${lib_type} "${_sources}" "${_headers}" "${_qt_uis}" "${lib_version}" "${lib_short_version}" ) @@ -211,6 +213,7 @@ ENDFUNCTION() FUNCTION( CompileInstances out_lib_name + lib_dir def_file number_of_files prefix @@ -251,7 +254,7 @@ ADD_CUSTOM_COMMAND( ## -- Create library CreateLib( - "${_lib_name}" SHARED + "${_lib_name}" ${lib_dir} SHARED "${_all_out_code}" "${_out_header}" "" "${version}" "${short_version}" ) @@ -311,7 +314,7 @@ ENDIF(_hdr_to_wrap) ## -- Ok, build library IF(_all_src) CreateLib( - ${_lib_name} SHARED + ${_lib_name} leo SHARED "${_all_src}" "${_all_hdr}" "${_qt_ui}" "${version}" "${short_version}" ${ARGN} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f2f2463..efe40ca 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,6 +4,7 @@ LibFromDir( fpa + ${PROJECT_BINARY_DIR}/lib SHARED ${CMAKE_CURRENT_SOURCE_DIR}/fpa "${prj_VERSION}" "${prj_SHORT_VERSION}" diff --git a/lib/Instances/CMakeLists.txt b/lib/Instances/CMakeLists.txt index 31eb1f1..0c44d02 100644 --- a/lib/Instances/CMakeLists.txt +++ b/lib/Instances/CMakeLists.txt @@ -7,6 +7,7 @@ SET(_all_instances) FOREACH(_instance ${_instances}) CompileInstances( _lib_name + ${PROJECT_BINARY_DIR}/lib ${_instance} ${cpPlugins_NUMBER_OF_FILES} "" "${prj_VERSION}" "${prj_SHORT_VERSION}" ) @@ -21,8 +22,17 @@ SET( ## == Links == ## =========== -TARGET_LINK_LIBRARIES(fpa_DataObjects ${ITK_LIBRARIES} ${cpPlugins_BaseObjects_LIB} ${cpPlugins_Images_LIB}) -TARGET_LINK_LIBRARIES(fpa_Filters fpa_DataObjects ${cpPlugins_ImageFilters_LIB}) +TARGET_LINK_LIBRARIES( + fpa_DataObjects + ${ITK_LIBRARIES} ${VTK_LIBRARIES} + ${cpPlugins_BaseObjects_LIB} + ${cpPlugins_Images_LIB} ${cpPlugins_Paths_LIB} + ) +TARGET_LINK_LIBRARIES( + fpa_Filters + fpa_DataObjects + ${cpPlugins_ImageFilters_LIB} + ) ## =================================== ## == Libraries to dynamically load == @@ -30,7 +40,9 @@ TARGET_LINK_LIBRARIES(fpa_Filters fpa_DataObjects ${cpPlugins_ImageFilters_LIB}) SET(fpa_DynLibs) FOREACH(_lib ${fpa_Instances}) - LIST(APPEND fpa_DynLibs local@${_lib}) + LIST(APPEND fpa_DynLibs "${CMAKE_INSTALL_PREFIX}/bin|${_lib}") + LIST(APPEND fpa_DynLibs "${CMAKE_INSTALL_PREFIX}/lib|${_lib}") + LIST(APPEND fpa_DynLibs "${LIBRARY_OUTPUT_PATH}|${_lib}") ENDFOREACH(_lib) FILE(WRITE ${PROJECT_BINARY_DIR}/cpPlugins_Libraries.config "") FOREACH(_lib ${fpa_DynLibs}) diff --git a/lib/Instances/fpa_DataObjects.i b/lib/Instances/fpa_DataObjects.i index aee14d6..7cf6e68 100644 --- a/lib/Instances/fpa_DataObjects.i +++ b/lib/Instances/fpa_DataObjects.i @@ -1,8 +1,9 @@ +i cpPlugins_Paths.h t fpa/Image/MinimumSpanningTree t fpa/Base/MinimumSpanningTree -c fpa::Base::MinimumSpanningTree< itk::Index< #process_dims# >, itk::Image< itk::Offset< #process_dims# >, #process_dims# > > -c fpa::Image::MinimumSpanningTree< #process_dims# > +c fpa::Base::MinimumSpanningTree< itk::Index< #process_dims# >, cpExtensions::DataStructures::PolyLineParametricPath< #process_dims# >, itk::Image< itk::Offset< #process_dims# >, #process_dims# > > +* c fpa::Image::MinimumSpanningTree< #process_dims# > -** eof - $RCSfile$ \ No newline at end of file +** eof - $RCSfile$ diff --git a/lib/Instances/fpa_Filters.i b/lib/Instances/fpa_Filters.i index 70dc94d..a72f3ad 100644 --- a/lib/Instances/fpa_Filters.i +++ b/lib/Instances/fpa_Filters.i @@ -9,4 +9,4 @@ t fpa/Image/Algorithm c fpa::Base::Algorithm< itk::ImageToImageFilter< itk::Image< #i_pixels#, #process_dims# >, itk::Image< #o_pixels#, #process_dims# > >, itk::Index< #process_dims# >, #o_pixels# > c fpa::Image::Algorithm< itk::Image< #i_pixels#, #process_dims# >, itk::Image< #o_pixels#, #process_dims# > > -** eof - $RCSfile$ \ No newline at end of file +** eof - $RCSfile$ diff --git a/lib/fpa/Base/MinimumSpanningTree.h b/lib/fpa/Base/MinimumSpanningTree.h index de22019..03940f1 100644 --- a/lib/fpa/Base/MinimumSpanningTree.h +++ b/lib/fpa/Base/MinimumSpanningTree.h @@ -2,7 +2,6 @@ #define __fpa__Base__MinimumSpanningTree__h__ #include -#include #include #include #include @@ -13,7 +12,7 @@ namespace fpa { /** */ - template< class _TVertex, class _TSuperclass > + template< class _TVertex, class _TPath, class _TSuperclass > class MinimumSpanningTree : public _TSuperclass { @@ -24,7 +23,7 @@ namespace fpa typedef itk::SmartPointer< const Self > ConstPointer; typedef _TVertex TVertex; - typedef std::deque< _TVertex > TVertices; + typedef _TPath TPath; typedef std::pair< _TVertex, bool > TCollision; typedef std::vector< TCollision > TCollisionsRow; typedef std::vector< TCollisionsRow > TCollisions; @@ -46,8 +45,12 @@ namespace fpa virtual _TVertex GetParent( const _TVertex& v ) const = 0; virtual void SetParent( const _TVertex& v, const _TVertex& p ) = 0; - virtual TVertices GetPath( const _TVertex& a ) const; - virtual TVertices GetPath( const _TVertex& a, const _TVertex& b ) const; + virtual void GetPath( + typename _TPath::Pointer& path, const _TVertex& a + ) const; + virtual void GetPath( + typename _TPath::Pointer& path, const _TVertex& a, const _TVertex& b + ) const; protected: MinimumSpanningTree( ); @@ -61,7 +64,7 @@ namespace fpa protected: TCollisions m_Collisions; _TMatrix m_FrontPaths; - TVertices m_Seeds; + std::vector< _TVertex > m_Seeds; }; } // ecapseman diff --git a/lib/fpa/Base/MinimumSpanningTree.hxx b/lib/fpa/Base/MinimumSpanningTree.hxx index 8746005..4bf0135 100644 --- a/lib/fpa/Base/MinimumSpanningTree.hxx +++ b/lib/fpa/Base/MinimumSpanningTree.hxx @@ -4,17 +4,19 @@ #include // ------------------------------------------------------------------------- -template< class _TVertex, class _TSuperclass > -const typename fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: -TCollisions& fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: +template< class _TVertex, class _TPath, class _TSuperclass > +const typename +fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: +TCollisions& +fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: GetCollisions( ) const { return( this->m_Collisions ); } // ------------------------------------------------------------------------- -template< class _TVertex, class _TSuperclass > -void fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: +template< class _TVertex, class _TPath, class _TSuperclass > +void fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: SetCollisions( const TCollisions& collisions ) { static const unsigned long _inf = @@ -78,8 +80,8 @@ SetCollisions( const TCollisions& collisions ) } // ------------------------------------------------------------------------- -template< class _TVertex, class _TSuperclass > -void fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: +template< class _TVertex, class _TPath, class _TSuperclass > +void fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: ClearSeeds( ) { this->m_Seeds.clear( ); @@ -87,8 +89,8 @@ ClearSeeds( ) } // ------------------------------------------------------------------------- -template< class _TVertex, class _TSuperclass > -void fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: +template< class _TVertex, class _TPath, class _TSuperclass > +void fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: AddSeed( const _TVertex& seed ) { this->m_Seeds.push_back( seed ); @@ -96,37 +98,41 @@ AddSeed( const _TVertex& seed ) } // ------------------------------------------------------------------------- -template< class _TVertex, class _TSuperclass > -typename fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: -TVertices fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: -GetPath( const _TVertex& a ) const +template< class _TVertex, class _TPath, class _TSuperclass > +void fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: +GetPath( typename _TPath::Pointer& path, const _TVertex& a ) const { - TVertices path; + std::vector< _TVertex > vertices; _TVertex it = a; _TVertex p = this->GetParent( it ); while( it != p ) { - path.push_front( it ); + vertices.push_back( it ); it = p; p = this->GetParent( it ); } // elihw - path.push_front( it ); - return( path ); + vertices.push_back( it ); + + path = _TPath::New( ); + for( auto v = vertices.begin( ); v != vertices.end( ); ++v ) + path->AddVertex( *v ); } // ------------------------------------------------------------------------- -template< class _TVertex, class _TSuperclass > -typename fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: -TVertices fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: -GetPath( const _TVertex& a, const _TVertex& b ) const +template< class _TVertex, class _TPath, class _TSuperclass > +void fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: +GetPath( + typename _TPath::Pointer& path, const _TVertex& a, const _TVertex& b + ) const { +/* static const unsigned long _inf = std::numeric_limits< unsigned long >::max( ); - TVertices path; - TVertices pa = this->GetPath( a ); - TVertices pb = this->GetPath( b ); + _TPath path; + _TPath pa = this->GetPath( a ); + _TPath pb = this->GetPath( b ); if( pa.size( ) > 0 && pb.size( ) > 0 ) { // Find front identifiers @@ -210,19 +216,20 @@ GetPath( const _TVertex& a, const _TVertex& b ) const } // fi return( path ); +*/ } // ------------------------------------------------------------------------- -template< class _TVertex, class _TSuperclass > -fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: +template< class _TVertex, class _TPath, class _TSuperclass > +fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: MinimumSpanningTree( ) : Superclass( ) { } // ------------------------------------------------------------------------- -template< class _TVertex, class _TSuperclass > -fpa::Base::MinimumSpanningTree< _TVertex, _TSuperclass >:: +template< class _TVertex, class _TPath, class _TSuperclass > +fpa::Base::MinimumSpanningTree< _TVertex, _TPath, _TSuperclass >:: ~MinimumSpanningTree( ) { } diff --git a/lib/fpa/Image/EndPointsFilter.hxx b/lib/fpa/Image/EndPointsFilter.hxx index fe85b5a..e2be58f 100644 --- a/lib/fpa/Image/EndPointsFilter.hxx +++ b/lib/fpa/Image/EndPointsFilter.hxx @@ -29,91 +29,93 @@ template< class _TDistanceMap, class _TCostMap > void fpa::Image::EndPointsFilter< _TDistanceMap, _TCostMap >:: Compute( ) { - typedef itk::ImageRegionConstIteratorWithIndex< _TDistanceMap > _TDistMapIt; - typedef itk::ImageRegionConstIteratorWithIndex< _TCostMap > _TCostMapIt; - typedef std::multimap< double, TIndex, std::greater< double > > _TQueue; - typedef typename _TQueue::value_type _TQueueValue; - - // Create queue - _TQueue queue; - _TDistMapIt dIt( - this->m_DistanceMap, this->m_DistanceMap->GetRequestedRegion( ) - ); - _TCostMapIt cIt( - this->m_CostMap, this->m_CostMap->GetRequestedRegion( ) - ); - dIt.GoToBegin( ); - cIt.GoToBegin( ); - for( ; !dIt.IsAtEnd( ) && !cIt.IsAtEnd( ); ++dIt, ++cIt ) - { - double d = double( dIt.Get( ) ); - if( d > 0 ) - { - double v = double( cIt.Get( ) ) * d; - queue.insert( _TQueueValue( v, dIt.GetIndex( ) ) ); - - } // fi - - } // rof - - TIndices marks; - while( queue.size( ) > 0 ) - { - auto nIt = queue.begin( ); - auto n = *nIt; - queue.erase( nIt ); - - if( marks.find( n.second ) == marks.end( ) ) - { - std::cout << queue.size( ) << " " << n.first << std::endl; - marks.insert( n.second ); - this->m_EndPoints.insert( n.second ); - auto path = this->m_MST->GetPath( n.second ); - std::cout << path.size( ) << std::endl; - for( auto pIt = path.begin( ); pIt != path.end( ); ++pIt ) - { - double d = double( this->m_DistanceMap->GetPixel( *pIt ) ); - d = std::sqrt( std::fabs( d ) ); - typename _TCostMap::PointType center; - this->m_CostMap->TransformIndexToPhysicalPoint( *pIt, center ); - - std::queue< TIndex > q; - TIndices m; - q.push( *pIt ); - while( q.size( ) > 0 ) - { - TIndex idx = q.front( ); - q.pop( ); - if( m.find( idx ) != m.end( ) ) - continue; - m.insert( idx ); - marks.insert( idx ); - for( unsigned int x = 0; x < _TCostMap::ImageDimension; ++x ) - { - for( int y = -1; y <= 1; y += 2 ) - { - TIndex idx2 = idx; - idx2[ x ] += y; - typename _TCostMap::PointType c; - this->m_CostMap->TransformIndexToPhysicalPoint( idx2, c ); - if( this->m_CostMap->GetRequestedRegion( ).IsInside( idx2 ) ) - { - if( center.EuclideanDistanceTo( c ) <= ( d * 1.5 ) ) - q.push( idx2 ); - - } // fi - - } // rof - - } // rof - - } // elihw - - } // rof - - } // fi - - } // elihw + /* TODO + typedef itk::ImageRegionConstIteratorWithIndex< _TDistanceMap > _TDistMapIt; + typedef itk::ImageRegionConstIteratorWithIndex< _TCostMap > _TCostMapIt; + typedef std::multimap< double, TIndex, std::greater< double > > _TQueue; + typedef typename _TQueue::value_type _TQueueValue; + + // Create queue + _TQueue queue; + _TDistMapIt dIt( + this->m_DistanceMap, this->m_DistanceMap->GetRequestedRegion( ) + ); + _TCostMapIt cIt( + this->m_CostMap, this->m_CostMap->GetRequestedRegion( ) + ); + dIt.GoToBegin( ); + cIt.GoToBegin( ); + for( ; !dIt.IsAtEnd( ) && !cIt.IsAtEnd( ); ++dIt, ++cIt ) + { + double d = double( dIt.Get( ) ); + if( d > 0 ) + { + double v = double( cIt.Get( ) ) * d; + queue.insert( _TQueueValue( v, dIt.GetIndex( ) ) ); + + } // fi + + } // rof + + TIndices marks; + while( queue.size( ) > 0 ) + { + auto nIt = queue.begin( ); + auto n = *nIt; + queue.erase( nIt ); + + if( marks.find( n.second ) == marks.end( ) ) + { + std::cout << queue.size( ) << " " << n.first << std::endl; + marks.insert( n.second ); + this->m_EndPoints.insert( n.second ); + auto path = this->m_MST->GetPath( n.second ); + std::cout << path.size( ) << std::endl; + for( auto pIt = path.begin( ); pIt != path.end( ); ++pIt ) + { + double d = double( this->m_DistanceMap->GetPixel( *pIt ) ); + d = std::sqrt( std::fabs( d ) ); + typename _TCostMap::PointType center; + this->m_CostMap->TransformIndexToPhysicalPoint( *pIt, center ); + + std::queue< TIndex > q; + TIndices m; + q.push( *pIt ); + while( q.size( ) > 0 ) + { + TIndex idx = q.front( ); + q.pop( ); + if( m.find( idx ) != m.end( ) ) + continue; + m.insert( idx ); + marks.insert( idx ); + for( unsigned int x = 0; x < _TCostMap::ImageDimension; ++x ) + { + for( int y = -1; y <= 1; y += 2 ) + { + TIndex idx2 = idx; + idx2[ x ] += y; + typename _TCostMap::PointType c; + this->m_CostMap->TransformIndexToPhysicalPoint( idx2, c ); + if( this->m_CostMap->GetRequestedRegion( ).IsInside( idx2 ) ) + { + if( center.EuclideanDistanceTo( c ) <= ( d * 1.5 ) ) + q.push( idx2 ); + + } // fi + + } // rof + + } // rof + + } // elihw + + } // rof + + } // fi + + } // elihw + */ } // ------------------------------------------------------------------------- diff --git a/lib/fpa/Image/MinimumSpanningTree.h b/lib/fpa/Image/MinimumSpanningTree.h index 371664c..4a4e0e6 100644 --- a/lib/fpa/Image/MinimumSpanningTree.h +++ b/lib/fpa/Image/MinimumSpanningTree.h @@ -2,6 +2,7 @@ #define __fpa__Image__MinimumSpanningTree__h__ #include +#include #include namespace fpa @@ -12,20 +13,17 @@ namespace fpa */ template< unsigned int _VDim > class MinimumSpanningTree - : public fpa::Base::MinimumSpanningTree< itk::Index< _VDim >, itk::Image< itk::Offset< _VDim >, _VDim > > + : public fpa::Base::MinimumSpanningTree< itk::Index< _VDim >, cpExtensions::DataStructures::PolyLineParametricPath< _VDim >, itk::Image< itk::Offset< _VDim >, _VDim > > { public: typedef itk::Index< _VDim > TVertex; - typedef itk::Offset< _VDim > TOffset; - typedef itk::Image< TOffset, _VDim > TImage; - typedef fpa::Base::MinimumSpanningTree< TVertex, TImage > Superclass; - typedef MinimumSpanningTree Self; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef typename Superclass::TVertices TVertices; - typedef typename TImage::PointType TPoint; - typedef std::deque< TPoint > TPoints; + typedef cpExtensions::DataStructures::PolyLineParametricPath< _VDim > TPath; + typedef itk::Offset< _VDim > TOffset; + typedef itk::Image< TOffset, _VDim > TImage; + typedef fpa::Base::MinimumSpanningTree< TVertex, TPath, TImage > Superclass; + typedef MinimumSpanningTree Self; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; public: itkNewMacro( Self ); @@ -37,8 +35,12 @@ namespace fpa virtual TVertex GetParent( const TVertex& v ) const fpa_OVERRIDE; virtual void SetParent( const TVertex& v, const TVertex& p ) fpa_OVERRIDE; - TPoints GetEuclideanPath( const TVertex& a ) const; - TPoints GetEuclideanPath( const TVertex& a, const TVertex& b ) const; + virtual void GetPath( + typename TPath::Pointer& path, const TVertex& a + ) const fpa_OVERRIDE; + virtual void GetPath( + typename TPath::Pointer& path, const TVertex& a, const TVertex& b + ) const fpa_OVERRIDE; protected: MinimumSpanningTree( ); diff --git a/lib/fpa/Image/MinimumSpanningTree.hxx b/lib/fpa/Image/MinimumSpanningTree.hxx index 01c642d..162526c 100644 --- a/lib/fpa/Image/MinimumSpanningTree.hxx +++ b/lib/fpa/Image/MinimumSpanningTree.hxx @@ -21,38 +21,22 @@ SetParent( const TVertex& v, const TVertex& p ) // ------------------------------------------------------------------------- template< unsigned int _VDim > -typename fpa::Image::MinimumSpanningTree< _VDim >:: -TPoints fpa::Image::MinimumSpanningTree< _VDim >:: -GetEuclideanPath( const TVertex& a ) const +void fpa::Image::MinimumSpanningTree< _VDim >:: +GetPath( typename TPath::Pointer& path, const TVertex& a ) const { - TVertices path = this->GetPath( a ); - TPoints points; - for( auto v = path.begin( ); v != path.end( ); ++v ) - { - TPoint p; - this->TransformIndexToPhysicalPoint( *v, p ); - points.push_back( p ); - - } // rof - return( points ); + this->Superclass::GetPath( path, a ); + path->SetReferenceImage( this ); } // ------------------------------------------------------------------------- template< unsigned int _VDim > -typename fpa::Image::MinimumSpanningTree< _VDim >:: -TPoints fpa::Image::MinimumSpanningTree< _VDim >:: -GetEuclideanPath( const TVertex& a, const TVertex& b ) const +void fpa::Image::MinimumSpanningTree< _VDim >:: +GetPath( + typename TPath::Pointer& path, const TVertex& a, const TVertex& b + ) const { - TVertices path = this->GetPath( a, b ); - TPoints points; - for( auto v = path.begin( ); v != path.end( ); ++v ) - { - TPoint p; - this->TransformIndexToPhysicalPoint( *v, p ); - points.push_back( p ); - - } // rof - return( points ); + this->Superclass::GetPath( path, a, b ); + path->SetReferenceImage( this ); } // ------------------------------------------------------------------------- diff --git a/plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx b/plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx index f6b69d1..c80ffde 100644 --- a/plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx +++ b/plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx @@ -1,27 +1,21 @@ #include #include -#include +#include #include - -/* TODO - #include - #include -*/ +#include // ------------------------------------------------------------------------- fpaPlugins::ExtractPathFromMinimumSpanningTree:: ExtractPathFromMinimumSpanningTree( ) : Superclass( ) { - typedef cpPlugins::BaseObjects::DataObject _TData; - typedef cpPlugins::DataObjects::Image _TMST; - typedef cpPlugins::DataObjects::Mesh _TMesh; + typedef cpPlugins::BaseObjects::DataObject _TData; + typedef cpPlugins::DataObjects::Image _TMST; + typedef cpPlugins::DataObjects::PolyLineParametricPath _TPath; this->_ConfigureInput< _TMST >( "MST", true, false ); this->_ConfigureInput< _TData >( "Seeds", true, false ); - this->_ConfigureOutput< _TMesh >( "Paths" ); - - this->m_Parameters.ConfigureAsUintList( "Indices" ); + this->_ConfigureOutput< _TPath >( "Paths" ); } // ------------------------------------------------------------------------- @@ -50,17 +44,21 @@ void fpaPlugins::ExtractPathFromMinimumSpanningTree:: _GD0( _TMST* mst ) { typedef typename _TMST::IndexType _TIndex; + typedef typename _TMST::TPath _TPath; // Get seeds std::vector< _TIndex > seeds; auto points = this->GetInputData< vtkPolyData >( "Seeds" ); if( points != NULL ) { + if( points->GetNumberOfPoints( ) < 2 ) + this->_Error( "Not enough seeds (<2)." ); + typename _TMST::PointType pnt; typename _TMST::IndexType idx; unsigned int dim = ( _TMST::ImageDimension < 3 )? _TMST::ImageDimension: 3; - for( unsigned int i = 0; i < points->GetNumberOfPoints( ); ++i ) + for( unsigned int i = 0; i < 2; ++i ) { double buf[ 3 ]; points->GetPoint( i, buf ); @@ -74,51 +72,9 @@ _GD0( _TMST* mst ) } // fi - // Prepare result - auto mesh = this->_CreateVTK< vtkPolyData >( ); - mesh->SetPoints( vtkSmartPointer< vtkPoints >::New( ) ); - mesh->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) ); - mesh->SetLines( vtkSmartPointer< vtkCellArray >::New( ) ); - mesh->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) ); - mesh->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) ); - /* TODO - vtkSmartPointer< vtkFloatArray > data = - vtkSmartPointer< vtkFloatArray >::New( ); - data->SetNumberOfComponents( 1 ); - mesh->GetPointData( )->SetScalars( data ); - */ - - // Compute - auto indices = this->m_Parameters.GetUintList( "Indices" ); - for( unsigned int i = 0; i < indices.size( ); i += 2 ) - { - if( i < indices.size( ) - 1 ) - { - _TIndex a = seeds[ indices[ i ] ]; - _TIndex b = seeds[ indices[ i + 1 ] ]; - - auto path = mst->GetEuclideanPath( a, b ); - for( unsigned long j = 0; j < path.size( ); ++j ) - { - auto p = path[ j ]; - if( _TMST::ImageDimension == 2 ) - mesh->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 ); - else if( _TMST::ImageDimension == 3 ) - mesh->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] ); - if( j > 0 ) - { - mesh->GetLines( )->InsertNextCell( 2 ); - mesh->GetLines( )->InsertCellPoint( j - 1 ); - mesh->GetLines( )->InsertCellPoint( j ); - - } // fi - - } // rof - - } // fi - - } // rof - this->GetOutput( "Paths" )->SetVTK( mesh ); + typename _TPath::Pointer path; + mst->GetPath( path, seeds[ 0 ], seeds[ 1 ] ); + this->GetOutput( "Paths" )->SetITK( path ); } // eof - $RCSfile$ -- 2.47.1