From 8fafb83c41ab35dfc25eb637170882a612924433 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Wed, 30 Mar 2016 18:55:04 -0500 Subject: [PATCH] ... --- CMakeLists.txt | 28 +- lib/CMakeLists.txt | 71 ++-- lib/fpa/Base/Algorithm.h | 14 +- lib/fpa/Base/Algorithm.hxx | 53 +-- lib/fpa/Base/Dijkstra.h | 45 ++- lib/fpa/Base/Dijkstra.hxx | 89 ++++- .../ExtractBranchesFromMinimumSpanningTree.h | 76 ---- ...ExtractBranchesFromMinimumSpanningTree.hxx | 140 ------- ...tsAndBifurcationsFromMinimumSpanningTree.h | 84 ++++ ...AndBifurcationsFromMinimumSpanningTree.hxx | 206 ++++++++++ .../Base/ExtractPathFromMinimumSpanningTree.h | 71 ++++ .../ExtractPathFromMinimumSpanningTree.hxx | 69 ++++ lib/fpa/Base/FastMarching.h | 2 + lib/fpa/Base/Functors/InvertCostFunction.h | 22 +- lib/fpa/Base/IncrementalRegionGrow.h | 2 + lib/fpa/Base/MatrixValuesContainer.h | 80 ---- lib/fpa/Base/MinimumSpanningTree.h | 84 ++-- lib/fpa/Base/MinimumSpanningTree.hxx | 186 +++++---- lib/fpa/Base/RegionGrow.h | 2 + lib/fpa/Base/RegionGrowWithMultipleCriteria.h | 2 + lib/fpa/Base/UniqueValuesContainer.h | 74 ---- lib/fpa/Base/VectorValuesContainer.h | 66 ---- lib/fpa/Common.h | 4 +- lib/fpa/IO/MatrixValuesContainerReader.h | 63 --- lib/fpa/IO/MatrixValuesContainerReader.hxx | 103 ----- lib/fpa/IO/MatrixValuesContainerWriter.h | 61 --- lib/fpa/IO/MatrixValuesContainerWriter.hxx | 112 ------ lib/fpa/IO/MinimumSpanningTreeReader.h | 9 +- lib/fpa/IO/MinimumSpanningTreeReader.hxx | 183 ++++++--- lib/fpa/IO/MinimumSpanningTreeWriter.h | 12 +- lib/fpa/IO/MinimumSpanningTreeWriter.hxx | 169 ++++++--- lib/fpa/IO/UniqueValuesContainerReader.h | 60 --- lib/fpa/IO/UniqueValuesContainerReader.hxx | 82 ---- lib/fpa/IO/UniqueValuesContainerWriter.h | 61 --- lib/fpa/IO/UniqueValuesContainerWriter.hxx | 105 ----- lib/fpa/Image/Algorithm.h | 14 +- lib/fpa/Image/Algorithm.hxx | 11 +- lib/fpa/Image/Dijkstra.h | 24 +- lib/fpa/Image/Dijkstra.hxx | 9 + lib/fpa/Image/DijkstraWithEndPointDetection.h | 2 + ...tsAndBifurcationsFromMinimumSpanningTree.h | 105 +++++ ...AndBifurcationsFromMinimumSpanningTree.hxx | 203 ++++++++++ .../Functors/GaussianModelEstimatorFunction.h | 2 + lib/fpa/Image/IncrementalRegionGrow.h | 2 + lib/fpa/Image/MinimumSpanningTree.h | 85 +++++ lib/fpa/Image/MinimumSpanningTree.hxx | 151 ++++++++ lib/fpa/Image/RegionGrow.h | 2 + .../Image/RegionGrowWithMultipleThresholds.h | 2 + lib/fpa/VTK/Image2DObserver.h | 2 + lib/fpa/VTK/Image3DObserver.h | 2 + lib/fpa/VTK/ImageMPR.cxx | 358 ------------------ lib/fpa/VTK/ImageMPR.h | 95 ----- lib/fpa/VTK/PointPathToPolyDataFilter.h | 63 --- lib/fpa/VTK/PointPathToPolyDataFilter.hxx | 149 -------- lib/fpa/VTK/SeedWidgetCorrector.cxx | 79 ---- lib/fpa/VTK/SeedWidgetCorrector.h | 44 --- lib/fpa/VTK/UniqueVerticesToPolyDataFilter.h | 67 ---- .../VTK/UniqueVerticesToPolyDataFilter.hxx | 186 --------- .../AllPixelsImageGrowFunctionSource.cxx | 54 --- .../AllPixelsImageGrowFunctionSource.h | 48 --- lib/fpaPlugins/BaseImageFilter.cxx | 30 -- lib/fpaPlugins/BaseImageFilter.h | 59 --- lib/fpaPlugins/CMakeLists.txt | 87 ----- ...ExtractBranchesFromMinimumSpanningTree.cxx | 75 ---- .../ExtractBranchesFromMinimumSpanningTree.h | 50 --- lib/fpaPlugins/GrowFunction.cxx | 23 -- lib/fpaPlugins/GrowFunction.h | 47 --- lib/fpaPlugins/GrowFunction.hxx | 8 - lib/fpaPlugins/ImageDijkstra.cxx | 64 ---- lib/fpaPlugins/ImageRegionGrow.cxx | 77 ---- lib/fpaPlugins/MinimumSpanningTree.cxx | 23 -- lib/fpaPlugins/MinimumSpanningTree.hxx | 8 - lib/fpaPlugins/MinimumSpanningTreeToMesh.cxx | 128 ------- lib/fpaPlugins/MinimumSpanningTreeToMesh.h | 48 --- .../ThresholdImageGrowFunctionSource.cxx | 63 --- .../ThresholdImageGrowFunctionSource.h | 48 --- plugins/CMakeLists.txt | 5 + plugins/fpa/BaseImageFilter.cxx | 48 +++ plugins/fpa/BaseImageFilter.h | 68 ++++ .../fpa}/BaseImageFilter.hxx | 84 ++-- plugins/fpa/CMakeLists.txt | 103 +++++ ...AndBifurcationsFromMinimumSpanningTree.cxx | 83 ++++ ...tsAndBifurcationsFromMinimumSpanningTree.h | 50 +++ .../ExtractPathFromMinimumSpanningTree.cxx | 83 ++++ .../fpa/ExtractPathFromMinimumSpanningTree.h | 48 +++ plugins/fpa/ImageDijkstra.cxx | 77 ++++ .../fpa}/ImageDijkstra.h | 8 +- plugins/fpa/ImageRegionGrow.cxx | 78 ++++ .../fpa}/ImageRegionGrow.h | 10 +- plugins/fpa/InvertCostFunction.cxx | 63 +++ plugins/fpa/InvertCostFunction.h | 44 +++ plugins/fpa/MinimumSpanningTree.cxx | 76 ++++ .../fpa}/MinimumSpanningTree.h | 27 +- plugins/fpa/MinimumSpanningTreeReader.cxx | 75 ++++ plugins/fpa/MinimumSpanningTreeReader.h | 44 +++ plugins/fpa/MinimumSpanningTreeWriter.cxx | 67 ++++ plugins/fpa/MinimumSpanningTreeWriter.h | 44 +++ plugins/fpa/RegionGrowThresholdFunction.cxx | 64 ++++ plugins/fpa/RegionGrowThresholdFunction.h | 46 +++ 99 files changed, 2836 insertions(+), 3546 deletions(-) delete mode 100644 lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.h delete mode 100644 lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.hxx create mode 100644 lib/fpa/Base/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h create mode 100644 lib/fpa/Base/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx create mode 100644 lib/fpa/Base/ExtractPathFromMinimumSpanningTree.h create mode 100644 lib/fpa/Base/ExtractPathFromMinimumSpanningTree.hxx delete mode 100644 lib/fpa/Base/MatrixValuesContainer.h delete mode 100644 lib/fpa/Base/UniqueValuesContainer.h delete mode 100644 lib/fpa/Base/VectorValuesContainer.h delete mode 100644 lib/fpa/IO/MatrixValuesContainerReader.h delete mode 100644 lib/fpa/IO/MatrixValuesContainerReader.hxx delete mode 100644 lib/fpa/IO/MatrixValuesContainerWriter.h delete mode 100644 lib/fpa/IO/MatrixValuesContainerWriter.hxx delete mode 100644 lib/fpa/IO/UniqueValuesContainerReader.h delete mode 100644 lib/fpa/IO/UniqueValuesContainerReader.hxx delete mode 100644 lib/fpa/IO/UniqueValuesContainerWriter.h delete mode 100644 lib/fpa/IO/UniqueValuesContainerWriter.hxx create mode 100644 lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h create mode 100644 lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx create mode 100644 lib/fpa/Image/MinimumSpanningTree.h create mode 100644 lib/fpa/Image/MinimumSpanningTree.hxx delete mode 100644 lib/fpa/VTK/ImageMPR.cxx delete mode 100644 lib/fpa/VTK/ImageMPR.h delete mode 100644 lib/fpa/VTK/PointPathToPolyDataFilter.h delete mode 100644 lib/fpa/VTK/PointPathToPolyDataFilter.hxx delete mode 100644 lib/fpa/VTK/SeedWidgetCorrector.cxx delete mode 100644 lib/fpa/VTK/SeedWidgetCorrector.h delete mode 100644 lib/fpa/VTK/UniqueVerticesToPolyDataFilter.h delete mode 100644 lib/fpa/VTK/UniqueVerticesToPolyDataFilter.hxx delete mode 100644 lib/fpaPlugins/AllPixelsImageGrowFunctionSource.cxx delete mode 100644 lib/fpaPlugins/AllPixelsImageGrowFunctionSource.h delete mode 100644 lib/fpaPlugins/BaseImageFilter.cxx delete mode 100644 lib/fpaPlugins/BaseImageFilter.h delete mode 100644 lib/fpaPlugins/CMakeLists.txt delete mode 100644 lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.cxx delete mode 100644 lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.h delete mode 100644 lib/fpaPlugins/GrowFunction.cxx delete mode 100644 lib/fpaPlugins/GrowFunction.h delete mode 100644 lib/fpaPlugins/GrowFunction.hxx delete mode 100644 lib/fpaPlugins/ImageDijkstra.cxx delete mode 100644 lib/fpaPlugins/ImageRegionGrow.cxx delete mode 100644 lib/fpaPlugins/MinimumSpanningTree.cxx delete mode 100644 lib/fpaPlugins/MinimumSpanningTree.hxx delete mode 100644 lib/fpaPlugins/MinimumSpanningTreeToMesh.cxx delete mode 100644 lib/fpaPlugins/MinimumSpanningTreeToMesh.h delete mode 100644 lib/fpaPlugins/ThresholdImageGrowFunctionSource.cxx delete mode 100644 lib/fpaPlugins/ThresholdImageGrowFunctionSource.h create mode 100644 plugins/CMakeLists.txt create mode 100644 plugins/fpa/BaseImageFilter.cxx create mode 100644 plugins/fpa/BaseImageFilter.h rename {lib/fpaPlugins => plugins/fpa}/BaseImageFilter.hxx (59%) create mode 100644 plugins/fpa/CMakeLists.txt create mode 100644 plugins/fpa/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.cxx create mode 100644 plugins/fpa/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h create mode 100644 plugins/fpa/ExtractPathFromMinimumSpanningTree.cxx create mode 100644 plugins/fpa/ExtractPathFromMinimumSpanningTree.h create mode 100644 plugins/fpa/ImageDijkstra.cxx rename {lib/fpaPlugins => plugins/fpa}/ImageDijkstra.h (84%) create mode 100644 plugins/fpa/ImageRegionGrow.cxx rename {lib/fpaPlugins => plugins/fpa}/ImageRegionGrow.h (79%) create mode 100644 plugins/fpa/InvertCostFunction.cxx create mode 100644 plugins/fpa/InvertCostFunction.h create mode 100644 plugins/fpa/MinimumSpanningTree.cxx rename {lib/fpaPlugins => plugins/fpa}/MinimumSpanningTree.h (52%) create mode 100644 plugins/fpa/MinimumSpanningTreeReader.cxx create mode 100644 plugins/fpa/MinimumSpanningTreeReader.h create mode 100644 plugins/fpa/MinimumSpanningTreeWriter.cxx create mode 100644 plugins/fpa/MinimumSpanningTreeWriter.h create mode 100644 plugins/fpa/RegionGrowThresholdFunction.cxx create mode 100644 plugins/fpa/RegionGrowThresholdFunction.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a38eef5..8a9e367 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,28 +21,19 @@ ENDFOREACH(policy) ## ================ PROJECT(FrontAlgorithms) -SET(prj_MAJOR_VERSION "0") -SET(prj_MINOR_VERSION "0") -SET(prj_RELEASE_VERSION "1") -SET( - prj_VERSION - "${prj_MAJOR_VERSION}.${prj_MINOR_VERSION}.${prj_RELEASE_VERSION}" - ) +SET(prj_MAJ_VER "0") +SET(prj_MIN_VER "0") +SET(prj_REL_VER "1") +SET(prj_VER "${prj_MAJ_VER}.${prj_MIN_VER}.${prj_REL_VER}") +SET(prj_sVER "${prj_MAJ_VER}") ## =========== ## = Options = ## =========== OPTION(BUILD_EXAMPLES "Build examples" OFF) -OPTION(BUILD_SHARED_LIBS "Build shared libs" OFF) OPTION(BUILD_PLUGINS "Build plugins" OFF) -IF(BUILD_SHARED_LIBS) - SET(LIB_TYPE SHARED) -ELSE(BUILD_SHARED_LIBS) - SET(LIB_TYPE STATIC) -ENDIF(BUILD_SHARED_LIBS) - ## ============ ## = Packages = ## ============ @@ -93,8 +84,12 @@ MARK_AS_ADVANCED( ## ============================== INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR} + ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR}/lib + ${PROJECT_SOURCE_DIR}/plugins + ${PROJECT_BINARY_DIR}/plugins ) ## =========================== @@ -106,5 +101,10 @@ SUBDIRS( lib appli ) +IF(BUILD_PLUGINS) + SUBDIRS( + plugins + ) +ENDIF(BUILD_PLUGINS) ## eof - $RCSfile$ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7050253..7e4b783 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(LIB_NAME FrontAlgorithms) +SET(lib_NAME fpa) ## ================ ## = Source files = @@ -9,27 +9,27 @@ CONFIGURE_FILE( ${PROJECT_BINARY_DIR}/lib/fpa/Common.cxx ) -FILE(GLOB ${LIB_NAME}_HEADERS "fpa/*.h" "fpa/*.hxx") -FILE(GLOB ${LIB_NAME}_BASE_HEADERS "fpa/Base/*.h" "fpa/Base/*.hxx") -FILE(GLOB ${LIB_NAME}_IO_HEADERS "fpa/IO/*.h" "fpa/IO/*.hxx") -FILE(GLOB ${LIB_NAME}_IMAGE_HEADERS "fpa/Image/*.h" "fpa/Image/*.hxx") +FILE(GLOB ${lib_NAME}_HEADERS "fpa/*.h" "fpa/*.hxx") +FILE(GLOB ${lib_NAME}_BASE_HEADERS "fpa/Base/*.h" "fpa/Base/*.hxx") +FILE(GLOB ${lib_NAME}_IO_HEADERS "fpa/IO/*.h" "fpa/IO/*.hxx") +FILE(GLOB ${lib_NAME}_IMAGE_HEADERS "fpa/Image/*.h" "fpa/Image/*.hxx") -FILE(GLOB ${LIB_NAME}_SOURCES "fpa/*.cxx") -FILE(GLOB ${LIB_NAME}_BASE_SOURCES "fpa/Base/*.cxx") -FILE(GLOB ${LIB_NAME}_IO_SOURCES "fpa/IO/*.cxx") -FILE(GLOB ${LIB_NAME}_IMAGE_SOURCES "fpa/Image/*.cxx") +FILE(GLOB ${lib_NAME}_SOURCES "fpa/*.cxx") +FILE(GLOB ${lib_NAME}_BASE_SOURCES "fpa/Base/*.cxx") +FILE(GLOB ${lib_NAME}_IO_SOURCES "fpa/IO/*.cxx") +FILE(GLOB ${lib_NAME}_IMAGE_SOURCES "fpa/Image/*.cxx") -FILE(GLOB ${LIB_NAME}_VTK_HEADERS "fpa/VTK/*.h" "fpa/VTK/*.hxx") -FILE(GLOB ${LIB_NAME}_VTK_SOURCES "fpa/VTK/*.cxx") +FILE(GLOB ${lib_NAME}_VTK_HEADERS "fpa/VTK/*.h" "fpa/VTK/*.hxx") +FILE(GLOB ${lib_NAME}_VTK_SOURCES "fpa/VTK/*.cxx") SET( - ${LIB_NAME}_ALL_SOURCES + ${lib_NAME}_ALL_SOURCES ${PROJECT_BINARY_DIR}/lib/fpa/Common.cxx - ${${LIB_NAME}_SOURCES} - ${${LIB_NAME}_BASE_SOURCES} - ${${LIB_NAME}_IO_SOURCES} - ${${LIB_NAME}_IMAGE_SOURCES} - ${${LIB_NAME}_VTK_SOURCES} + ${${lib_NAME}_SOURCES} + ${${lib_NAME}_BASE_SOURCES} + ${${lib_NAME}_IO_SOURCES} + ${${lib_NAME}_IMAGE_SOURCES} + ${${lib_NAME}_VTK_SOURCES} ) ## ============= @@ -37,7 +37,7 @@ SET( ## ============= SET( - ${LIB_NAME}_LINK_LIBRARIES + ${lib_NAME}_LINK_LIBRARIES ${ITK_LIBRARIES} ${VTK_LIBRARIES} ) @@ -47,20 +47,25 @@ SET( ## ===================== ADD_LIBRARY( - ${LIB_NAME} - ${LIB_TYPE} - ${${LIB_NAME}_ALL_SOURCES} + ${lib_NAME} + SHARED + ${${lib_NAME}_ALL_SOURCES} + ) +SET_TARGET_PROPERTIES( + ${lib_NAME} PROPERTIES + VERSION "${prj_VER}" + SOVERSION "${prj_sVER}" ) GENERATE_EXPORT_HEADER( - ${LIB_NAME} - BASE_NAME ${LIB_NAME} - EXPORT_MACRO_NAME ${LIB_NAME}_EXPORT - EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/fpa/${LIB_NAME}_Export.h - STATIC_DEFINE ${LIB_NAME}_BUILT_AS_STATIC + ${lib_NAME} + BASE_NAME ${lib_NAME} + EXPORT_MACRO_NAME ${lib_NAME}_EXPORT + EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/fpa/${lib_NAME}_Export.h + STATIC_DEFINE ${lib_NAME}_BUILT_AS_STATIC ) TARGET_LINK_LIBRARIES( - ${LIB_NAME} - ${${LIB_NAME}_LINK_LIBRARIES} + ${lib_NAME} + ${${lib_NAME}_LINK_LIBRARIES} ) ## ======================== @@ -68,7 +73,7 @@ TARGET_LINK_LIBRARIES( ## ======================== INSTALL( - TARGETS ${LIB_NAME} + TARGETS ${lib_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static @@ -97,14 +102,8 @@ ENDFOREACH(dir) INSTALL( FILES - ${PROJECT_BINARY_DIR}/lib/fpa/${LIB_NAME}_Export.h + ${PROJECT_BINARY_DIR}/lib/fpa/${lib_NAME}_Export.h DESTINATION include/fpa ) -IF(BUILD_PLUGINS) - SUBDIRS( - fpaPlugins - ) -ENDIF(BUILD_PLUGINS) - ## eof - $RCSfile$ diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index 246a5e3..4d8570f 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -5,7 +5,6 @@ #include #include #include -#include namespace fpa { @@ -84,9 +83,6 @@ namespace fpa }; typedef std::map< TVertex, _TNode, TVertexCompare > _TNodes; - public: - typedef fpa::Base::MinimumSpanningTree< V, VC > TMinimumSpanningTree; - public: itkTypeMacro( Algorithm, B ); @@ -100,10 +96,6 @@ namespace fpa itkSetMacro( StopAtOneFront, bool ); public: - TMinimumSpanningTree* GetMinimumSpanningTree( ); - const TMinimumSpanningTree* GetMinimumSpanningTree( ) const; - void GraftMinimumSpanningTree( itk::DataObject* obj ); - virtual void InvokeEvent( const itk::EventObject& e ); virtual void InvokeEvent( const itk::EventObject& e ) const; @@ -149,7 +141,7 @@ namespace fpa ) const = 0; virtual void _InitResults( ) = 0; virtual const TResult& _Result( const TVertex& v ) const = 0; - virtual void _SetResult( const TVertex& v, const _TNode& n ) = 0; + virtual void _SetResult( const TVertex& v, const _TNode& n ); // Marks-related abstract methods virtual _TNode& _Node( const TVertex& v ); @@ -176,15 +168,15 @@ namespace fpa _TVertices m_SeedVertices; _TNodes m_Marks; _TCollisions m_Collisions; - - unsigned int m_MinimumSpanningTreeIndex; }; } // ecapseman } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__BASE__ALGORITHM__H__ diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx index 5629af7..3530787 100644 --- a/lib/fpa/Base/Algorithm.hxx +++ b/lib/fpa/Base/Algorithm.hxx @@ -21,46 +21,6 @@ fpa::Base::Algorithm< V, C, R, S, VC, B >::_TNode:: { } -// ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -typename fpa::Base::Algorithm< V, C, R, S, VC, B >:: -TMinimumSpanningTree* fpa::Base::Algorithm< V, C, R, S, VC, B >:: -GetMinimumSpanningTree( ) -{ - return( - dynamic_cast< TMinimumSpanningTree* >( - this->itk::ProcessObject::GetOutput( - this->m_MinimumSpanningTreeIndex - ) - ) - ); -} - -// ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -const typename fpa::Base::Algorithm< V, C, R, S, VC, B >:: -TMinimumSpanningTree* fpa::Base::Algorithm< V, C, R, S, VC, B >:: -GetMinimumSpanningTree( ) const -{ - return( - dynamic_cast< const TMinimumSpanningTree* >( - this->itk::ProcessObject::GetOutput( - this->m_MinimumSpanningTreeIndex - ) - ) - ); -} - -// ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -void fpa::Base::Algorithm< V, C, R, S, VC, B >:: -GraftMinimumSpanningTree( itk::DataObject* obj ) -{ - TMinimumSpanningTree* mst = dynamic_cast< TMinimumSpanningTree* >( obj ); - if( mst != NULL ) - this->GraftNthOutput( this->m_MinimumSpanningTreeIndex, mst ); -} - // ------------------------------------------------------------------------- template< class V, class C, class R, class S, class VC, class B > void fpa::Base::Algorithm< V, C, R, S, VC, B >:: @@ -129,11 +89,6 @@ Algorithm( ) m_ThrowEvents( false ), m_StopAtOneFront( false ) { - this->m_MinimumSpanningTreeIndex = this->GetNumberOfRequiredOutputs( ); - this->SetNumberOfRequiredOutputs( this->m_MinimumSpanningTreeIndex + 1 ); - this->itk::ProcessObject::SetNthOutput( - this->m_MinimumSpanningTreeIndex, TMinimumSpanningTree::New( ) - ); } // ------------------------------------------------------------------------- @@ -354,6 +309,14 @@ _Node( const TVertex& v ) return( vIt->second ); } +// ------------------------------------------------------------------------- +template< class V, class C, class R, class S, class VC, class B > +void fpa::Base::Algorithm< V, C, R, S, VC, B >:: +_SetResult( const TVertex& v, const _TNode& n ) +{ + // Do nothing at this hierarchy level +} + // ------------------------------------------------------------------------- template< class V, class C, class R, class S, class VC, class B > const typename fpa::Base::Algorithm< V, C, R, S, VC, B >:: diff --git a/lib/fpa/Base/Dijkstra.h b/lib/fpa/Base/Dijkstra.h index 69fe86a..e711f4f 100644 --- a/lib/fpa/Base/Dijkstra.h +++ b/lib/fpa/Base/Dijkstra.h @@ -3,6 +3,7 @@ #include #include +#include namespace fpa { @@ -11,16 +12,17 @@ namespace fpa /** * Dijkstra is a front propagation algorithm that minimizes costs * - * @param V Vertex type. - * @param C Vertex value type. - * @param R Result value type. - * @param S Space type where vertices are. - * @param VC Vertex lexicographical compare. - * @param B Base class for this algorithm. It should be any itk-based - * filter (itk::ProcessObject). + * @param V Vertex type. + * @param C Vertex value type. + * @param R Result value type. + * @param S Space type where vertices are. + * @param VC Vertex lexicographical compare. + * @param MST Minimum spanning tree type. + * @param B Base class for this algorithm. It should be any itk-based + * filter (itk::ProcessObject). * */ - template< class V, class C, class R, class S, class VC, class B > + template< class V, class C, class R, class S, class VC, class MST, class B > class Dijkstra : public Algorithm< V, C, R, S, VC, B > { @@ -30,12 +32,12 @@ namespace fpa typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef typename Superclass::TVertex TVertex; - typedef typename Superclass::TValue TValue; - typedef typename Superclass::TResult TResult; - typedef typename Superclass::TSpace TSpace; - typedef typename Superclass::TVertexCompare TVertexCompare; - typedef typename Superclass::TMinimumSpanningTree TMinimumSpanningTree; + typedef MST TMinimumSpanningTree; + typedef typename Superclass::TVertex TVertex; + typedef typename Superclass::TValue TValue; + typedef typename Superclass::TResult TResult; + typedef typename Superclass::TSpace TSpace; + typedef typename Superclass::TVertexCompare TVertexCompare; typedef typename Superclass::TStartEvent TStartEvent; typedef typename Superclass::TStartLoopEvent TStartLoopEvent; @@ -72,8 +74,16 @@ namespace fpa itkTypeMacro( Dijkstra, Algorithm ); itkBooleanMacro( LocalCosts ); + itkBooleanMacro( FillNodeQueue ); itkGetConstMacro( LocalCosts, bool ); + itkGetConstMacro( FillNodeQueue, bool ); itkSetMacro( LocalCosts, bool ); + itkSetMacro( FillNodeQueue, bool ); + + public: + TMinimumSpanningTree* GetMinimumSpanningTree( ); + const TMinimumSpanningTree* GetMinimumSpanningTree( ) const; + void GraftMinimumSpanningTree( itk::DataObject* obj ); protected: Dijkstra( ); @@ -81,10 +91,13 @@ namespace fpa virtual TResult _Cost( const TVertex& v, const TVertex& p ) const = 0; + virtual void _BeforeGenerateData( ); + // Results-related abstract methods virtual bool _ComputeNeighborResult( TResult& result, const TVertex& neighbor, const TVertex& parent ) const; + virtual void _SetResult( const TVertex& v, const _TNode& n ); // Queue-related abstract methods virtual bool _IsQueueEmpty( ) const; @@ -99,14 +112,18 @@ namespace fpa protected: bool m_LocalCosts; + bool m_FillNodeQueue; _TQueue m_Queue; + unsigned int m_MSTIdx; }; } // ecapseman } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__BASE__DIJKSTRA__H__ diff --git a/lib/fpa/Base/Dijkstra.hxx b/lib/fpa/Base/Dijkstra.hxx index 25d5650..bad348b 100644 --- a/lib/fpa/Base/Dijkstra.hxx +++ b/lib/fpa/Base/Dijkstra.hxx @@ -4,24 +4,75 @@ #include // ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -fpa::Base::Dijkstra< V, C, R, S, VC, B >:: +template< class V, class C, class R, class S, class VC, class MST, class B > +typename fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: +TMinimumSpanningTree* fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: +GetMinimumSpanningTree( ) +{ + return( + dynamic_cast< TMinimumSpanningTree* >( + this->itk::ProcessObject::GetOutput( this->m_MSTIdx ) + ) + ); +} + +// ------------------------------------------------------------------------- +template< class V, class C, class R, class S, class VC, class MST, class B > +const typename fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: +TMinimumSpanningTree* fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: +GetMinimumSpanningTree( ) const +{ + return( + dynamic_cast< const TMinimumSpanningTree* >( + this->itk::ProcessObject::GetOutput( this->m_MSTIdx ) + ) + ); +} + +// ------------------------------------------------------------------------- +template< class V, class C, class R, class S, class VC, class MST, class B > +void fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: +GraftMinimumSpanningTree( itk::DataObject* obj ) +{ + TMinimumSpanningTree* mst = dynamic_cast< TMinimumSpanningTree* >( obj ); + if( mst != NULL ) + this->GraftNthOutput( this->m_MSTIdx, mst ); +} + +// ------------------------------------------------------------------------- +template< class V, class C, class R, class S, class VC, class MST, class B > +fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: Dijkstra( ) : Superclass( ), - m_LocalCosts( false ) + m_LocalCosts( false ), + m_FillNodeQueue( false ) { + this->m_MSTIdx = this->GetNumberOfRequiredOutputs( ); + this->SetNumberOfRequiredOutputs( this->m_MSTIdx + 1 ); + this->itk::ProcessObject::SetNthOutput( + this->m_MSTIdx, TMinimumSpanningTree::New( ) + ); } // ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -fpa::Base::Dijkstra< V, C, R, S, VC, B >:: +template< class V, class C, class R, class S, class VC, class MST, class B > +fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: ~Dijkstra( ) { } // ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -bool fpa::Base::Dijkstra< V, C, R, S, VC, B >:: +template< class V, class C, class R, class S, class VC, class MST, class B > +void fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: +_BeforeGenerateData( ) +{ + this->Superclass::_BeforeGenerateData( ); + this->GetMinimumSpanningTree( )->SetFillNodeQueue( this->m_FillNodeQueue ); +} + +// ------------------------------------------------------------------------- +template< class V, class C, class R, class S, class VC, class MST, class B > +bool fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: _ComputeNeighborResult( TResult& result, const TVertex& neighbor, const TVertex& parent ) const @@ -42,16 +93,24 @@ _ComputeNeighborResult( } // ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -bool fpa::Base::Dijkstra< V, C, R, S, VC, B >:: +template< class V, class C, class R, class S, class VC, class MST, class B > +void fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: +_SetResult( const TVertex& v, const _TNode& n ) +{ + this->GetMinimumSpanningTree( )->SetNode( v, n.Parent, n.FrontId, n.Result ); +} + +// ------------------------------------------------------------------------- +template< class V, class C, class R, class S, class VC, class MST, class B > +bool fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: _IsQueueEmpty( ) const { return( this->m_Queue.empty( ) ); } // ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -void fpa::Base::Dijkstra< V, C, R, S, VC, B >:: +template< class V, class C, class R, class S, class VC, class MST, class B > +void fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: _QueuePush( const TVertex& v, const _TNode& n ) { _TQueueNode qn; @@ -62,8 +121,8 @@ _QueuePush( const TVertex& v, const _TNode& n ) } // ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -void fpa::Base::Dijkstra< V, C, R, S, VC, B >:: +template< class V, class C, class R, class S, class VC, class MST, class B > +void fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: _QueuePop( TVertex& v, _TNode& n ) { _TQueueNode qn = this->m_Queue.front( ); @@ -74,8 +133,8 @@ _QueuePop( TVertex& v, _TNode& n ) } // ------------------------------------------------------------------------- -template< class V, class C, class R, class S, class VC, class B > -void fpa::Base::Dijkstra< V, C, R, S, VC, B >:: +template< class V, class C, class R, class S, class VC, class MST, class B > +void fpa::Base::Dijkstra< V, C, R, S, VC, MST, B >:: _QueueClear( ) { this->m_Queue.clear( ); diff --git a/lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.h b/lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.h deleted file mode 100644 index cacc529..0000000 --- a/lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__H__ -#define __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__H__ - -#include -#include -#include -#include - -namespace fpa -{ - namespace Base - { - /** - */ - template< class T > - class ExtractBranchesFromMinimumSpanningTree - : public itk::ProcessObject - { - public: - typedef ExtractBranchesFromMinimumSpanningTree Self; - typedef itk::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef T TMinimumSpanningTree; - typedef typename T::TVertex TVertex; - typedef typename T::TVertexCompare TVertexCompare; - typedef itk::PolyLineParametricPath< TVertex::Dimension > TPath; - typedef std::set< TVertex, TVertexCompare > TEndPoints; - - typedef - fpa::Base::VectorValuesContainer< typename TPath::Pointer > - TBranches; - - public: - itkNewMacro( Self ); - itkTypeMacro( - ExtractBranchesFromMinimumSpanningTree, - itk::ProcessObject - ); - - public: - const T* GetInput( ) const; - void SetInput( const T* tree ); - - TPath* GetOutput( ); - - void ClearEndPoints( ); - void AddEndPoint( const TVertex& v ); - bool HasEndPoint( const TVertex& v ) const; - unsigned long GetNumberOfEndPoints( ) const; - - protected: - ExtractBranchesFromMinimumSpanningTree( ); - virtual ~ExtractBranchesFromMinimumSpanningTree( ); - - virtual void GenerateData( ); - - private: - // Purposely not implemented - ExtractBranchesFromMinimumSpanningTree( const Self& other ); - Self& operator=( const Self& other ); - - protected: - TEndPoints m_EndPoints; - }; - - } // ecapseman - -} // ecapseman - -#include - -#endif // __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.hxx b/lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.hxx deleted file mode 100644 index 5a7433f..0000000 --- a/lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.hxx +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__HXX__ -#define __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__HXX__ - -// ------------------------------------------------------------------------- -template< class T > -const T* fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -GetInput( ) const -{ - return( - dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) ) - ); -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -SetInput( const T* tree ) -{ - this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( tree ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -typename fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -TPath* fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -GetOutput( ) -{ - return( - itkDynamicCastInDebugMode< TPath* >( this->GetPrimaryOutput( ) ) - ); -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -ClearEndPoints( ) -{ - this->m_EndPoints.clear( ); - this->Modified( ); -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -AddEndPoint( const TVertex& v ) -{ - if( this->m_EndPoints.find( v ) == this->m_EndPoints.end( ) ) - { - this->m_EndPoints.insert( v ); - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -template< class T > -bool fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -HasEndPoint( const TVertex& v ) const -{ - return( this->m_EndPoints.find( v ) != this->m_EndPoints.end( ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -unsigned long fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -GetNumberOfEndPoints( ) const -{ - return( this->m_EndPoints.size( ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -ExtractBranchesFromMinimumSpanningTree( ) - : Superclass( ) -{ - this->itk::ProcessObject::SetNumberOfRequiredInputs( 1 ); - - typename TPath::Pointer out = TPath::New( ); - this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 ); - this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -~ExtractBranchesFromMinimumSpanningTree( ) -{ -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >:: -GenerateData( ) -{ - auto tree = this->GetInput( ); - auto path = this->GetOutput( ); - - // TODO: this is just a temporary code - auto v0 = *( this->m_EndPoints.begin( ) ); - auto v1 = *( this->m_EndPoints.rbegin( ) ); - auto lst = tree->GetPath( v0, v1 ); - path->Initialize( ); - for( auto i = lst.begin( ); i != lst.end( ); ++i ) - path->AddVertex( *i ); - - // Find bifurcations - /* TODO: this should be the final code - TEndPoints bifurcations, marks; - auto e0It = this->m_EndPoints.begin( ); - for( ; e0It != this->m_EndPoints.end( ); ++e0It ) - { - auto e1It = e0It; - e1It++; - for( ; e1It != this->m_EndPoints.end( ); ++e1It ) - { - auto path = tree->GetPath( *e0It, *e1It ); - std::cout << "path" << std::endl; - auto pIt = path.begin( ); - for( ; pIt != path.end( ); ++pIt ) - { - if( marks.find( *pIt ) == marks.end( ) ) - marks.insert( *pIt ); - else - bifurcations.insert( *pIt ); - - } // rof - - } // rof - - } // rof - - // Construct branches - std::cout << bifurcations.size( ) << std::endl; - */ -} - -#endif // __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Base/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h b/lib/fpa/Base/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h new file mode 100644 index 0000000..d6e97af --- /dev/null +++ b/lib/fpa/Base/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h @@ -0,0 +1,84 @@ +#ifndef __FPA__BASE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ +#define __FPA__BASE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ + +#include +#include +#include + +namespace fpa +{ + namespace Base + { + /** + */ + template< class _TMST > + class ExtractEndPointsAndBifurcationsFromMinimumSpanningTree + : public itk::ProcessObject + { + public: + typedef ExtractEndPointsAndBifurcationsFromMinimumSpanningTree Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef _TMST TMinimumSpanningTree; + typedef typename _TMST::TVertex TVertex; + + typedef itk::SimpleDataObjectDecorator< std::vector< TVertex > > TVertices; + + public: + itkTypeMacro( + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree, + itk::ProcessObject + ); + + public: + const TMinimumSpanningTree* GetMinimumSpanningTree( ); + void SetMinimumSpanningTree( TMinimumSpanningTree* mst ); + + TVertices* GetEndPoints( ); + TVertices* GetBifurcations( ); + TVertices* GetCollisions( ); + + virtual void Update( ) override + { + this->GenerateData( ); + } + + protected: + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ); + virtual ~ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ); + + virtual void GenerateData( ) override; + + virtual void _MarkSkeleton( + const TVertex& v, const unsigned long& l + ) = 0; + virtual void _MarkSphere( + const TVertex& v, + const double& r, + const unsigned long& l + ) = 0; + virtual unsigned long _Mark( const TVertex& v ) = 0; + virtual unsigned long _SkeletonMark( const TVertex& v ) = 0; + virtual double _Radius( const TVertex& v ) = 0; + + virtual void _Tmp( ) = 0; + + private: + // Purposely not implemented + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +#include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __FPA__BASE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx b/lib/fpa/Base/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx new file mode 100644 index 0000000..844d60c --- /dev/null +++ b/lib/fpa/Base/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx @@ -0,0 +1,206 @@ +#ifndef __FPA__BASE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__HXX__ +#define __FPA__BASE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__HXX__ + +#include +#include +#include + +// ------------------------------------------------------------------------- +template< class _TMST > +const typename +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +TMinimumSpanningTree* +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +GetMinimumSpanningTree( ) +{ + return( + dynamic_cast< const _TMST* >( this->itk::ProcessObject::GetInput( 0 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TMST > +void +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +SetMinimumSpanningTree( TMinimumSpanningTree* mst ) +{ + this->itk::ProcessObject::SetNthInput( 0, const_cast< _TMST* >( mst ) ); +} + +// ------------------------------------------------------------------------- +template< class _TMST > +typename +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +TVertices* +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +GetEndPoints( ) +{ + return( + dynamic_cast< TVertices* >( this->itk::ProcessObject::GetOutput( 0 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TMST > +typename +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +TVertices* +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +GetBifurcations( ) +{ + return( + dynamic_cast< TVertices* >( this->itk::ProcessObject::GetOutput( 1 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TMST > +typename +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +TVertices* +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +GetCollisions( ) +{ + return( + dynamic_cast< TVertices* >( this->itk::ProcessObject::GetOutput( 2 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TMST > +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ) + : Superclass( ) +{ + this->SetNumberOfRequiredInputs( 1 ); + this->SetNumberOfRequiredOutputs( 3 ); + typename TVertices::Pointer ep = TVertices::New( ); + typename TVertices::Pointer bf = TVertices::New( ); + typename TVertices::Pointer co = TVertices::New( ); + this->itk::ProcessObject::SetNthOutput( 0, ep.GetPointer( ) ); + this->itk::ProcessObject::SetNthOutput( 1, bf.GetPointer( ) ); + this->itk::ProcessObject::SetNthOutput( 2, co.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +template< class _TMST > +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +~ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TMST > +void +fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST >:: +GenerateData( ) +{ + typedef std::multimap< double, TVertex > _TQueue; + typedef std::pair< TVertex, TVertex > _TBranch; + typedef std::vector< _TBranch > _TBranches; + typedef typename _TQueue::value_type _TQueueValue; + + // 0. Useful objects and values + auto mst = this->GetMinimumSpanningTree( ); + auto endpoints = this->GetEndPoints( ); + auto bifurcations = this->GetBifurcations( ); + auto collisions = this->GetCollisions( ); + _TBranches branches; + endpoints->Get( ).clear( ); + bifurcations->Get( ).clear( ); + collisions->Get( ).clear( ); + + // 1. Get priority queue + auto& q = mst->GetNodeQueue( ); + + // 2. Main loop: iterate in inverse order (max-priority) + unsigned long label = 0; + for( auto qIt = q.rbegin( ); qIt != q.rend( ); ++qIt ) + { + auto gCost = qIt->first; + auto vertex = qIt->second; + + // 2.1. Check if the vertex has already been visited + if( this->_Mark( vertex ) > 0 ) + continue; + + // 2.2. Get path from front seed + auto path = mst->GetPath( vertex ); + + // 2.3. Prepare new branch data and prepare new end-point + label++; + branches.push_back( _TBranch( vertex, vertex ) ); + endpoints->Get( ).push_back( vertex ); + + // 2.4. Backtracking + auto pIt = path.begin( ); + TVertex last_collision; + bool inCollision = false; + while( pIt != path.end( ) ) + { + auto mark = this->_SkeletonMark( *pIt ); + if( mark > 0 && mark != label ) + { + // 2.4.1. A bifurcation has been reached + bifurcations->Get( ).push_back( *pIt ); + + // Reorder labels + auto coll_branch = branches[ mark ]; + branches[ mark ] = _TBranch( coll_branch.first, *pIt ); + branches[ label - 1 ] = _TBranch( qIt->second, *pIt ); + branches.push_back( _TBranch( *pIt, coll_branch.second ) ); + + // Mark skeleton (b,coll_branch_second) with the new label + label++; + while( *pIt != coll_branch.second && pIt != path.end( ) ) + { + this->_MarkSkeleton( *pIt, label ); + pIt++; + + } // elihw + + // Force inner loop termination + pIt = path.end( ); + } + else + { + if( !inCollision ) + { + mark = this->_Mark( *pIt ); + if( mark > 0 && mark != label ) + { + // 2.4.2. A collision has been reached + last_collision = *pIt; + collisions->Get( ).push_back( *pIt ); + std::cout << *pIt << std::endl; + inCollision = true; + } + else + { + // 2.4.3. Just mark sphere and skeleton + double r = this->_Radius( *pIt ); + this->_MarkSkeleton( *pIt, label ); + this->_MarkSphere( *pIt, r, label ); + branches[ label - 1 ].second = *pIt; + + // 2.4.4. Is this a seed? -> add it to endpoints + auto sIt = pIt; + sIt++; + if( sIt == path.end( ) ) + endpoints->Get( ).push_back( *pIt ); + + } // fi + + } // fi + pIt++; + + } // fi + + } // elihw + + } // rof +} + +#endif // __FPA__BASE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__HXX__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/ExtractPathFromMinimumSpanningTree.h b/lib/fpa/Base/ExtractPathFromMinimumSpanningTree.h new file mode 100644 index 0000000..9fed3bf --- /dev/null +++ b/lib/fpa/Base/ExtractPathFromMinimumSpanningTree.h @@ -0,0 +1,71 @@ +#ifndef __FPA__BASE__EXTRACTPATHFROMMINIMUMSPANNINGTREE__H__ +#define __FPA__BASE__EXTRACTPATHFROMMINIMUMSPANNINGTREE__H__ + +#include +#include +#include +#include + +namespace fpa +{ + namespace Base + { + /** + */ + template< class T > + class ExtractPathFromMinimumSpanningTree + : public itk::ProcessObject + { + public: + typedef ExtractPathFromMinimumSpanningTree Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef T TMinimumSpanningTree; + typedef typename T::TVertex TVertex; + typedef itk::PolyLineParametricPath< TVertex::Dimension > TPath; + + public: + itkNewMacro( Self ); + itkTypeMacro( ExtractPathFromMinimumSpanningTree, itk::ProcessObject ); + + itkGetConstMacro( Vertex0, TVertex ); + itkGetConstMacro( Vertex1, TVertex ); + + itkSetMacro( Vertex0, TVertex ); + itkSetMacro( Vertex1, TVertex ); + + public: + const T* GetInput( ) const; + void SetInput( const T* tree ); + + TPath* GetOutput( ); + + protected: + ExtractPathFromMinimumSpanningTree( ); + virtual ~ExtractPathFromMinimumSpanningTree( ); + + virtual void GenerateData( ); + + private: + // Purposely not implemented + ExtractPathFromMinimumSpanningTree( const Self& other ); + Self& operator=( const Self& other ); + + protected: + TVertex m_Vertex0; + TVertex m_Vertex1; + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +#include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __FPA__BASE__EXTRACTPATHFROMMINIMUMSPANNINGTREE__H__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/ExtractPathFromMinimumSpanningTree.hxx b/lib/fpa/Base/ExtractPathFromMinimumSpanningTree.hxx new file mode 100644 index 0000000..c44f41a --- /dev/null +++ b/lib/fpa/Base/ExtractPathFromMinimumSpanningTree.hxx @@ -0,0 +1,69 @@ +#ifndef __FPA__BASE__EXTRACTPATHFROMMINIMUMSPANNINGTREE__HXX__ +#define __FPA__BASE__EXTRACTPATHFROMMINIMUMSPANNINGTREE__HXX__ + +// ------------------------------------------------------------------------- +template< class T > +const T* fpa::Base::ExtractPathFromMinimumSpanningTree< T >:: +GetInput( ) const +{ + return( + dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class T > +void fpa::Base::ExtractPathFromMinimumSpanningTree< T >:: +SetInput( const T* tree ) +{ + this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( tree ) ); +} + +// ------------------------------------------------------------------------- +template< class T > +typename fpa::Base::ExtractPathFromMinimumSpanningTree< T >:: +TPath* fpa::Base::ExtractPathFromMinimumSpanningTree< T >:: +GetOutput( ) +{ + return( + itkDynamicCastInDebugMode< TPath* >( this->GetPrimaryOutput( ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class T > +fpa::Base::ExtractPathFromMinimumSpanningTree< T >:: +ExtractPathFromMinimumSpanningTree( ) + : Superclass( ) +{ + this->itk::ProcessObject::SetNumberOfRequiredInputs( 1 ); + + typename TPath::Pointer out = TPath::New( ); + this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 ); + this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +template< class T > +fpa::Base::ExtractPathFromMinimumSpanningTree< T >:: +~ExtractPathFromMinimumSpanningTree( ) +{ +} + +// ------------------------------------------------------------------------- +template< class T > +void fpa::Base::ExtractPathFromMinimumSpanningTree< T >:: +GenerateData( ) +{ + auto tree = this->GetInput( ); + auto path = this->GetOutput( ); + + auto lst = tree->GetPath( this->m_Vertex0, this->m_Vertex1 ); + path->Initialize( ); + for( auto i = lst.begin( ); i != lst.end( ); ++i ) + path->AddVertex( *i ); +} + +#endif // __FPA__BASE__EXTRACTPATHFROMMINIMUMSPANNINGTREE__HXX__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/FastMarching.h b/lib/fpa/Base/FastMarching.h index 119d0f3..b615f8e 100644 --- a/lib/fpa/Base/FastMarching.h +++ b/lib/fpa/Base/FastMarching.h @@ -69,7 +69,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__BASE__FASTMARCHING__H__ diff --git a/lib/fpa/Base/Functors/InvertCostFunction.h b/lib/fpa/Base/Functors/InvertCostFunction.h index 06315c7..d1e21f4 100644 --- a/lib/fpa/Base/Functors/InvertCostFunction.h +++ b/lib/fpa/Base/Functors/InvertCostFunction.h @@ -1,6 +1,7 @@ #ifndef __FPA__BASE__FUNCTORS__INVERTCOSTFUNCTION__H__ #define __FPA__BASE__FUNCTORS__INVERTCOSTFUNCTION__H__ +#include #include namespace fpa @@ -26,18 +27,27 @@ namespace fpa itkNewMacro( Self ); itkTypeMacro( InvertCostFunction, itkFunctionBase ); + itkGetConstMacro( Alpha, C ); + itkGetConstMacro( Beta, C ); + + itkSetMacro( Alpha, C ); + itkSetMacro( Beta, C ); + public: virtual C Evaluate( const C& input ) const { - if( input < C( 0 ) ) - return( C( -1 ) / ( C( 1 ) - C( input ) ) ); + C a = std::pow( input, this->m_Alpha ); + if( input >= C( 0 ) ) + return( std::pow( C( 1 ) / ( C( 1 ) + a ), this->m_Beta ) ); else - return( C( 1 ) / ( C( 1 ) + C( input ) ) ); + return( std::pow( C( -1 ) / ( C( 1 ) - a ), this->m_Beta ) ); } protected: InvertCostFunction( ) - : Superclass( ) + : Superclass( ), + m_Alpha( C( 1 ) ), + m_Beta( C( 1 ) ) { } virtual ~InvertCostFunction( ) { } @@ -46,6 +56,10 @@ namespace fpa // Purposely not implemented InvertCostFunction( const Self& ); void operator=( const Self& ); + + protected: + C m_Alpha; + C m_Beta; }; } // ecapseman diff --git a/lib/fpa/Base/IncrementalRegionGrow.h b/lib/fpa/Base/IncrementalRegionGrow.h index 7385f91..7104777 100644 --- a/lib/fpa/Base/IncrementalRegionGrow.h +++ b/lib/fpa/Base/IncrementalRegionGrow.h @@ -78,7 +78,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__BASE__INCREMENTALREGIONGROW__H__ diff --git a/lib/fpa/Base/MatrixValuesContainer.h b/lib/fpa/Base/MatrixValuesContainer.h deleted file mode 100644 index c5e4e41..0000000 --- a/lib/fpa/Base/MatrixValuesContainer.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef __FPA__BASE__MATRIXVALUESCONTAINER__H__ -#define __FPA__BASE__MATRIXVALUESCONTAINER__H__ - -#include -#include -#include - -namespace fpa -{ - namespace Base - { - /** - */ - template< class I, class V, class VI > - class MatrixValuesContainer - : public itk::SimpleDataObjectDecorator< std::map< I, std::map< I, V, VI >, VI > > - { - public: - typedef std::map< I, V, VI > TDecoratedRow; - typedef std::map< I, TDecoratedRow, VI > TDecorated; - typedef MatrixValuesContainer Self; - typedef itk::SimpleDataObjectDecorator< TDecorated > Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef I TIndex; - typedef V TValue; - typedef VI TIndexCompare; - - typedef typename TDecoratedRow::iterator RowIterator; - typedef typename TDecoratedRow::const_iterator ConstRowIterator; - typedef typename TDecorated::iterator Iterator; - typedef typename TDecorated::const_iterator ConstIterator; - - public: - itkNewMacro( Self ); - itkTypeMacro( MatrixValuesContainer, itkSimpleDataObjectDecorator ); - - public: - void SetValue( const I& a, const I& b, const V& v ) - { this->Get( )[ a ][ b ] = v; this->Modified( ); } - void Clear( ) - { this->Get( ).clear( ); this->Modified( ); } - Iterator Begin( ) - { return( this->Get( ).begin( ) ); } - Iterator End( ) - { return( this->Get( ).end( ) ); } - ConstIterator Begin( ) const - { return( this->Get( ).begin( ) ); } - ConstIterator End( ) const - { return( this->Get( ).end( ) ); } - RowIterator Begin( const Iterator& i ) - { return( i->second.begin( ) ); } - RowIterator End( const Iterator& i ) - { return( i->second.end( ) ); } - ConstRowIterator Begin( const ConstIterator& i ) const - { return( i->second.begin( ) ); } - ConstRowIterator End( const ConstIterator& i ) const - { return( i->second.end( ) ); } - - protected: - MatrixValuesContainer( ) - : Superclass( ) - { } - virtual ~MatrixValuesContainer( ) - { } - - private: - // Purposely not implemented - MatrixValuesContainer( const Self& other ); - Self& operator=( const Self& other ); - }; - - } // ecapseman - -} // ecapseman - -#endif // __FPA__BASE__MATRIXVALUESCONTAINER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Base/MinimumSpanningTree.h b/lib/fpa/Base/MinimumSpanningTree.h index 0c2b720..bc9ce93 100644 --- a/lib/fpa/Base/MinimumSpanningTree.h +++ b/lib/fpa/Base/MinimumSpanningTree.h @@ -2,9 +2,9 @@ #define __FPA__BASE__MINIMUMSPANNINGTREE__H__ #include -#include #include -#include +#include +#include #include namespace fpa @@ -13,62 +13,67 @@ namespace fpa { /** */ - template< class V, class B > + template< class _TSuperclass, class _TVertex > class MinimumSpanningTree - : public itk::SimpleDataObjectDecorator< std::map< V, std::pair< V, short >, B > > + : public _TSuperclass { public: - typedef std::pair< V, short > TNodeInfo; - typedef std::map< V, TNodeInfo, B > TDecorated; - typedef MinimumSpanningTree Self; - typedef itk::SimpleDataObjectDecorator< TDecorated > Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; + typedef MinimumSpanningTree Self; + typedef _TSuperclass Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; - typedef V TVertex; - typedef B TVertexCompare; + typedef _TVertex TVertex; + typedef std::vector< TVertex > TVertices; + typedef std::pair< TVertex, bool > TCollision; + typedef std::vector< TCollision > TCollisionsRow; + typedef std::vector< TCollisionsRow > TCollisions; - typedef std::vector< TVertex > TVertices; - typedef std::pair< TVertex, bool > TCollision; - typedef std::vector< TCollision > TCollisionsRow; - typedef std::vector< TCollisionsRow > TCollisions; + typedef itk::Point< double, TVertex::Dimension > TPoint; + typedef std::vector< TPoint > TPoints; + typedef std::multimap< double, TVertex > TNodeQueue; protected: typedef std::vector< unsigned long > _TRow; typedef std::vector< _TRow > _TMatrix; public: - itkNewMacro( Self ); - itkTypeMacro( MinimumSpanningTree, itkSimpleDataObjectDecorator ); + itkTypeMacro( MinimumSpanningTree, _TSuperclass ); + + itkBooleanMacro( FillNodeQueue ); + + itkGetConstReferenceMacro( Collisions, TCollisions ); + itkGetConstReferenceMacro( NodeQueue, TNodeQueue ); + itkGetConstMacro( FillNodeQueue, bool ); - itkGetConstMacro( Collisions, TCollisions ); + itkSetMacro( FillNodeQueue, bool ); public: void SetCollisions( const TCollisions& collisions ); - void SetParent( const TVertex& v, const TVertex& p, const short& fid ) - { - this->Get( )[ v ] = TNodeInfo( p, fid ); - this->Modified( ); - } - void Clear( ) - { - this->Get( ).clear( ); - this->m_Collisions.clear( ); - this->m_FrontPaths.clear( ); - } - virtual std::vector< V > GetPath( const V& a, const V& b ) const; - - template< class I > - std::vector< typename I::PointType > GetPathFromImage( - const V& a, const V& b, - const I* image, unsigned int kernel = 0 + TVertices GetPath( const TVertex& a ) const; + TVertices GetPath( const TVertex& a, const TVertex& b ) const; + + virtual TPoints GetEuclideanPath( const TVertex& a ) const; + virtual TPoints GetEuclideanPath( + const TVertex& a, const TVertex& b ) const; + virtual bool IsDefinedInEuclideanSpace( ) const; + + virtual void SetNode( + const TVertex& v, + const TVertex& p, + const short& fid, + const double& cost + ); + virtual void Clear( ); protected: MinimumSpanningTree( ); virtual ~MinimumSpanningTree( ); - virtual void _Path( std::vector< V >& path, const V& a ) const; + virtual bool _HasVertex( const TVertex& a ) const = 0; + virtual short _FrontId( const TVertex& a ) const = 0; + virtual void _Path( TVertices& path, const TVertex& a ) const = 0; private: // Purposely not implemented @@ -78,6 +83,9 @@ namespace fpa protected: TCollisions m_Collisions; _TMatrix m_FrontPaths; + TNodeQueue m_NodeQueue; + bool m_FillNodeQueue; + static const unsigned long INF_VALUE; }; @@ -85,7 +93,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__BASE__MINIMUMSPANNINGTREE__H__ diff --git a/lib/fpa/Base/MinimumSpanningTree.hxx b/lib/fpa/Base/MinimumSpanningTree.hxx index 6bf9be2..c53a071 100644 --- a/lib/fpa/Base/MinimumSpanningTree.hxx +++ b/lib/fpa/Base/MinimumSpanningTree.hxx @@ -4,22 +4,21 @@ #include // ------------------------------------------------------------------------- -template< class V, class B > -const unsigned long fpa::Base::MinimumSpanningTree< V, B >::INF_VALUE = - std::numeric_limits< unsigned long >::max( ) >> 1; - +template< class _TSuperclass, class _TVertex > +const unsigned long fpa::Base:: +MinimumSpanningTree< _TSuperclass, _TVertex >::INF_VALUE = + std::numeric_limits< unsigned long >::max( ); + // ------------------------------------------------------------------------- -template< class V, class B > -void fpa::Base::MinimumSpanningTree< V, B >:: +template< class _TSuperclass, class _TVertex > +void fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: SetCollisions( const TCollisions& collisions ) { + // Prepare a front graph this->m_Collisions = collisions; - - // Prepare fronts graph using Floyd-Warshall unsigned long nSeeds = this->m_Collisions.size( ); _TMatrix dist( nSeeds, _TRow( nSeeds, Self::INF_VALUE ) ); this->m_FrontPaths = dist; - for( unsigned long i = 0; i < nSeeds; ++i ) { for( unsigned long j = 0; j < nSeeds; ++j ) @@ -38,6 +37,8 @@ SetCollisions( const TCollisions& collisions ) this->m_FrontPaths[ i ][ i ] = i; } // rof + + // Use Floyd-Warshall to compute all possible paths for( unsigned long k = 0; k < nSeeds; ++k ) { for( unsigned long i = 0; i < nSeeds; ++i ) @@ -60,30 +61,43 @@ SetCollisions( const TCollisions& collisions ) } // ------------------------------------------------------------------------- -template< class V, class B > -std::vector< V > fpa::Base::MinimumSpanningTree< V, B >:: -GetPath( const V& a, const V& b ) const +template< class _TSuperclass, class _TVertex > +typename fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +TVertices fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +GetPath( const TVertex& a ) const { - std::vector< V > path; - typename TDecorated::const_iterator aIt = this->Get( ).find( a ); - typename TDecorated::const_iterator bIt = this->Get( ).find( b ); + TVertices path; + if( this->_HasVertex( a ) ) + this->_Path( path, a ); + return( path ); +} - if( aIt == this->Get( ).end( ) || bIt == this->Get( ).end( ) ) +// ------------------------------------------------------------------------- +template< class _TSuperclass, class _TVertex > +typename fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +TVertices fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +GetPath( const TVertex& a, const TVertex& b ) const +{ + TVertices path; + + // Check existence + if( !this->_HasVertex( a ) || !this->_HasVertex( b ) ) return( path ); - short fa = aIt->second.second; - short fb = bIt->second.second; + // Get front ids + short fa = this->_FrontId( a ); + short fb = this->_FrontId( b ); if( fa == fb ) { - std::vector< V > ap, bp; + // Get paths + TVertices ap, bp; this->_Path( ap, a ); this->_Path( bp, b ); - // Ignore common part - typename std::vector< V >::const_reverse_iterator raIt, rbIt; - raIt = ap.rbegin( ); - rbIt = bp.rbegin( ); + // Ignore common part: find common ancestor + auto raIt = ap.rbegin( ); + auto rbIt = bp.rbegin( ); while( *raIt == *rbIt && raIt != ap.rend( ) && rbIt != bp.rend( ) ) { ++raIt; @@ -94,8 +108,7 @@ GetPath( const V& a, const V& b ) const if( rbIt != bp.rbegin( ) ) --rbIt; // Add part from a - typename std::vector< V >::const_iterator iaIt = ap.begin( ); - for( ; iaIt != ap.end( ) && *iaIt != *raIt; ++iaIt ) + for( auto iaIt = ap.begin( ); iaIt != ap.end( ) && *iaIt != *raIt; ++iaIt ) path.push_back( *iaIt ); // Add part from b @@ -105,7 +118,7 @@ GetPath( const V& a, const V& b ) const else { // Use this->m_FrontPaths from Floyd-Warshall - if( this->m_FrontPaths[ fa ][ fb ] != Self::INF_VALUE ) + if( this->m_FrontPaths[ fa ][ fb ] < Self::INF_VALUE ) { // Compute front path std::vector< long > fpath; @@ -119,7 +132,7 @@ GetPath( const V& a, const V& b ) const // Continue only if both fronts are connected unsigned int N = fpath.size( ); - if( 0 < N ) + if( N > 0 ) { // First path: from start vertex to first collision path = this->GetPath( @@ -129,7 +142,7 @@ GetPath( const V& a, const V& b ) const // Intermediary paths for( unsigned int i = 1; i < N - 1; ++i ) { - std::vector< V > ipath = + TVertices ipath = this->GetPath( this->m_Collisions[ fpath[ i ] ][ fpath[ i - 1 ] ].first, this->m_Collisions[ fpath[ i ] ][ fpath[ i + 1 ] ].first @@ -139,7 +152,7 @@ GetPath( const V& a, const V& b ) const } // rof // Final path: from last collision to end point - std::vector< V > lpath = + TVertices lpath = this->GetPath( this->m_Collisions[ fpath[ N - 1 ] ][ fpath[ N - 2 ] ].first, b ); @@ -154,91 +167,68 @@ GetPath( const V& a, const V& b ) const } // ------------------------------------------------------------------------- -template< class V, class B > -template< class I > -std::vector< typename I::PointType > fpa::Base::MinimumSpanningTree< V, B >:: -GetPathFromImage( - const V& a, const V& b, - const I* image, unsigned int kernel - ) const +template< class _TSuperclass, class _TVertex > +typename fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +TPoints fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +GetEuclideanPath( const TVertex& a ) const { - typedef typename I::PointType _P; - - std::vector< _P > path; - std::vector< V > vertices = this->GetPath( a, b ); - for( unsigned int i = 0; i < vertices.size( ); ++i ) - { - _P p; - image->TransformIndexToPhysicalPoint( vertices[ i ], p ); - path.push_back( p ); - - } // rof - - // Lowpass filter - if( kernel > 0 ) - { - int k = int( kernel ) >> 1; - std::vector< _P > lowpass_path; - for( unsigned int i = 0; i < path.size( ); ++i ) - { - _P p; - p.Fill( ( typename _P::ValueType )( 0 ) ); - unsigned int c = 0; - for( int j = -k; j <= k; ++j ) - { - int l = int( i ) + j; - if( l >= 0 && l < path.size( ) ) - { - p += path[ l ].GetVectorFromOrigin( ); - c++; - - } // fi - - } // rof - if( c > 0 ) - for( unsigned int d = 0; d < _P::PointDimension; ++d ) - p[ d ] /= ( typename _P::ValueType )( c ); - lowpass_path.push_back( p ); - - } // rof - - path = lowpass_path; + TPoints points; + return( points ); +} - } // fi - return( path ); +// ------------------------------------------------------------------------- +template< class _TSuperclass, class _TVertex > +typename fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +TPoints fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +GetEuclideanPath( const TVertex& a, const TVertex& b ) const +{ + TPoints points; + return( points ); } // ------------------------------------------------------------------------- -template< class V, class B > -fpa::Base::MinimumSpanningTree< V, B >:: -MinimumSpanningTree( ) - : Superclass( ) +template< class _TSuperclass, class _TVertex > +bool fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +IsDefinedInEuclideanSpace( ) const { + return( false ); } // ------------------------------------------------------------------------- -template< class V, class B > -fpa::Base::MinimumSpanningTree< V, B >:: -~MinimumSpanningTree( ) +template< class _TSuperclass, class _TVertex > +void fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +SetNode( + const TVertex& v, const TVertex& p, + const short& fid, const double& cost + ) { + typedef typename TNodeQueue::value_type _TNodeQueueValue; + if( this->m_FillNodeQueue ) + this->m_NodeQueue.insert( _TNodeQueueValue( cost, v ) ); } // ------------------------------------------------------------------------- -template< class V, class B > -void fpa::Base::MinimumSpanningTree< V, B >:: -_Path( std::vector< V >& path, const V& a ) const +template< class _TSuperclass, class _TVertex > +void fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +Clear( ) { - typename TDecorated::const_iterator dIt = this->Get( ).find( a ); - if( dIt != this->Get( ).end( ) ) - { - do - { - path.push_back( dIt->first ); - dIt = this->Get( ).find( dIt->second.first ); + this->m_NodeQueue.clear( ); +} - } while( dIt->first != dIt->second.first && dIt != this->Get( ).end( ) ); +// ------------------------------------------------------------------------- +template< class _TSuperclass, class _TVertex > +fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +MinimumSpanningTree( ) + : Superclass( ), + m_FillNodeQueue( false ) +{ +} - } // fi +// ------------------------------------------------------------------------- +template< class _TSuperclass, class _TVertex > +fpa::Base::MinimumSpanningTree< _TSuperclass, _TVertex >:: +~MinimumSpanningTree( ) +{ } #endif // __FPA__BASE__MINIMUMSPANNINGTREE__HXX__ diff --git a/lib/fpa/Base/RegionGrow.h b/lib/fpa/Base/RegionGrow.h index b5ce46e..0a1e938 100644 --- a/lib/fpa/Base/RegionGrow.h +++ b/lib/fpa/Base/RegionGrow.h @@ -96,7 +96,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__BASE__REGIONGROW__H__ diff --git a/lib/fpa/Base/RegionGrowWithMultipleCriteria.h b/lib/fpa/Base/RegionGrowWithMultipleCriteria.h index 85d0243..cce7dbf 100644 --- a/lib/fpa/Base/RegionGrowWithMultipleCriteria.h +++ b/lib/fpa/Base/RegionGrowWithMultipleCriteria.h @@ -74,7 +74,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__BASE__REGIONGROWWITHMULTIPLECRITERIA__H__ diff --git a/lib/fpa/Base/UniqueValuesContainer.h b/lib/fpa/Base/UniqueValuesContainer.h deleted file mode 100644 index eb554bb..0000000 --- a/lib/fpa/Base/UniqueValuesContainer.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef __FPA__BASE__UNIQUEVALUESCONTAINER__H__ -#define __FPA__BASE__UNIQUEVALUESCONTAINER__H__ - -#include -#include -#include - -namespace fpa -{ - namespace Base - { - /** - */ - template< class V, class VC > - class UniqueValuesContainer - : public itk::SimpleDataObjectDecorator< std::set< V, VC > > - { - public: - typedef std::set< V, VC > TDecorated; - typedef UniqueValuesContainer Self; - typedef itk::SimpleDataObjectDecorator< TDecorated > Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef V TValue; - typedef VC TValueCompare; - - typedef typename TDecorated::iterator Iterator; - typedef typename TDecorated::const_iterator ConstIterator; - - public: - itkNewMacro( Self ); - itkTypeMacro( UniqueValuesContainer, itkSimpleDataObjectDecorator ); - - public: - void Insert( const V& v ) - { this->Get( ).insert( v ); this->Modified( ); } - void Erase( const V& v ) - { this->Get( ).erase( v ); this->Modified( ); } - void Clear( ) - { this->Get( ).clear( ); this->Modified( ); } - bool Find( const V& v ) const - { return( this->Get( ).find( v ) != this->Get( ).end( ) ); } - Iterator Begin( ) - { return( this->Get( ).begin( ) ); } - Iterator End( ) - { return( this->Get( ).end( ) ); } - ConstIterator Begin( ) const - { return( this->Get( ).begin( ) ); } - ConstIterator End( ) const - { return( this->Get( ).end( ) ); } - unsigned long Size( ) const - { return( this->Get( ).size( ) ); } - - protected: - UniqueValuesContainer( ) - : Superclass( ) - { } - virtual ~UniqueValuesContainer( ) - { } - - private: - // Purposely not implemented - UniqueValuesContainer( const Self& other ); - Self& operator=( const Self& other ); - }; - - } // ecapseman - -} // ecapseman - -#endif // __FPA__BASE__UNIQUEVALUESCONTAINER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Base/VectorValuesContainer.h b/lib/fpa/Base/VectorValuesContainer.h deleted file mode 100644 index 9358c33..0000000 --- a/lib/fpa/Base/VectorValuesContainer.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef __FPA__BASE__VECTORVALUESCONTAINER__H__ -#define __FPA__BASE__VECTORVALUESCONTAINER__H__ - -#include -#include -#include - -namespace fpa -{ - namespace Base - { - /** - */ - template< class T > - class VectorValuesContainer - : public itk::SimpleDataObjectDecorator< std::vector< T > > - { - public: - typedef std::vector< T > TDecorated; - typedef VectorValuesContainer Self; - typedef itk::SimpleDataObjectDecorator< TDecorated > Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef T TValue; - typedef typename TDecorated::iterator Iterator; - typedef typename TDecorated::const_iterator ConstIterator; - - public: - itkNewMacro( Self ); - itkTypeMacro( VectorValuesContainer, itkSimpleDataObjectDecorator ); - - public: - void PushBack( const T& v ) - { this->Get( ).push_back( v ); this->Modified( ); } - void PopBack( const T& v ) - { this->Get( ).pop_back( ); this->Modified( ); } - Iterator Begin( ) - { return( this->Get( ).begin( ) ); } - Iterator End( ) - { return( this->Get( ).end( ) ); } - ConstIterator Begin( ) const - { return( this->Get( ).begin( ) ); } - ConstIterator End( ) const - { return( this->Get( ).end( ) ); } - - protected: - VectorValuesContainer( ) - : Superclass( ) - { } - virtual ~VectorValuesContainer( ) - { } - - private: - // Purposely not implemented - VectorValuesContainer( const Self& other ); - Self& operator=( const Self& other ); - }; - - } // ecapseman - -} // ecapseman - -#endif // __FPA__BASE__VECTORVALUESCONTAINER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Common.h b/lib/fpa/Common.h index c5bf168..c46ae57 100644 --- a/lib/fpa/Common.h +++ b/lib/fpa/Common.h @@ -2,11 +2,11 @@ #define __FPA__COMMON__H__ #include -#include +#include namespace fpa { - std::string FrontAlgorithms_EXPORT GetVersion( ); + std::string fpa_EXPORT GetVersion( ); } // ecapseman diff --git a/lib/fpa/IO/MatrixValuesContainerReader.h b/lib/fpa/IO/MatrixValuesContainerReader.h deleted file mode 100644 index 8d65074..0000000 --- a/lib/fpa/IO/MatrixValuesContainerReader.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __FPA__IO__MATRIXVALUESCONTAINERREADER__H__ -#define __FPA__IO__MATRIXVALUESCONTAINERREADER__H__ - -#include -#include - -namespace fpa -{ - namespace IO - { - /** - */ - template< class T > - class MatrixValuesContainerReader - : public itk::ProcessObject - { - public: - typedef MatrixValuesContainerReader Self; - typedef itk::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef T TTree; - - public: - itkNewMacro( Self ); - itkTypeMacro( MatrixValuesContainerReader, itkProcessObject ); - - itkGetConstMacro( FileName, std::string ); - itkGetConstMacro( NumberOfLabels, unsigned int ); - - itkSetMacro( FileName, std::string ); - - public: - T* GetOutput( ); - - virtual void Update( ); - - protected: - MatrixValuesContainerReader( ); - virtual ~MatrixValuesContainerReader( ); - - virtual void GenerateData( ); - - private: - // Purposely not implemented - MatrixValuesContainerReader( const Self& other ); - Self& operator=( const Self& other ); - - protected: - std::string m_FileName; - unsigned int m_NumberOfLabels; - }; - - } // ecapseman - -} // ecapseman - -#include - -#endif // __FPA__IO__MATRIXVALUESCONTAINERREADER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/IO/MatrixValuesContainerReader.hxx b/lib/fpa/IO/MatrixValuesContainerReader.hxx deleted file mode 100644 index 902462b..0000000 --- a/lib/fpa/IO/MatrixValuesContainerReader.hxx +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef __FPA__IO__MATRIXVALUESCONTAINERREADER__HXX__ -#define __FPA__IO__MATRIXVALUESCONTAINERREADER__HXX__ - -#include - -// ------------------------------------------------------------------------- -template< class T > -T* fpa::IO::MatrixValuesContainerReader< T >:: -GetOutput( ) -{ - return( itkDynamicCastInDebugMode< T* >( this->GetPrimaryOutput( ) ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MatrixValuesContainerReader< T >:: -Update( ) -{ - this->GenerateData( ); -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::IO::MatrixValuesContainerReader< T >:: -MatrixValuesContainerReader( ) - : Superclass( ), - m_FileName( "" ) -{ - this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 ); - this->itk::ProcessObject::SetNthOutput( 0, T::New( ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::IO::MatrixValuesContainerReader< T >:: -~MatrixValuesContainerReader( ) -{ -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MatrixValuesContainerReader< T >:: -GenerateData( ) -{ - T* output = this->GetOutput( ); - output->Clear( ); - - std::ifstream in( this->m_FileName.c_str( ) ); - if( !in ) - { - itkExceptionMacro( - << "Error opening file to read a minimum spanning tree: \"" - << this->m_FileName - << "\"" - ); - return; - - } // fi - - unsigned int dim; - unsigned long nTuples; - in >> dim >> nTuples; - this->m_NumberOfLabels = 0; - for( unsigned long tId = 0; tId < nTuples; ++tId ) - { - unsigned long nCouples; - in >> nCouples; - typename T::TIndex v0; - for( unsigned int d = 0; d < dim; ++d ) - { - long val; - in >> val; - if( d < T::TIndex::Dimension ) - v0[ d ] = val; - - } // rof - - for( unsigned long cId = 0; cId < nCouples; ++cId ) - { - typename T::TIndex v1; - for( unsigned int d = 0; d < dim; ++d ) - { - long val; - in >> val; - if( d < T::TIndex::Dimension ) - v1[ d ] = val; - - } // rof - typename T::TValue val; - in >> val; - output->SetValue( v0, v1, val ); - if( val > this->m_NumberOfLabels ) - this->m_NumberOfLabels = val; - - } // rof - - } // rof - in.close( ); -} - -#endif // __FPA__IO__MATRIXVALUESCONTAINERREADER__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpa/IO/MatrixValuesContainerWriter.h b/lib/fpa/IO/MatrixValuesContainerWriter.h deleted file mode 100644 index 456716e..0000000 --- a/lib/fpa/IO/MatrixValuesContainerWriter.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef __FPA__IO__MATRIXVALUESCONTAINERWRITER__H__ -#define __FPA__IO__MATRIXVALUESCONTAINERWRITER__H__ - -#include -#include - -namespace fpa -{ - namespace IO - { - /** - */ - template< class T > - class MatrixValuesContainerWriter - : public itk::ProcessObject - { - public: - typedef MatrixValuesContainerWriter Self; - typedef itk::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef T TTree; - - public: - itkNewMacro( Self ); - itkTypeMacro( MatrixValuesContainerWriter, itkProcessObject ); - - itkGetConstMacro( FileName, std::string ); - itkSetMacro( FileName, std::string ); - - public: - void SetInput( const T* input ); - T* GetInput( ); - const T* GetInput( ) const; - virtual void Update( ); - - protected: - MatrixValuesContainerWriter( ); - virtual ~MatrixValuesContainerWriter( ); - - virtual void GenerateData( ); - - private: - // Purposely not implemented - MatrixValuesContainerWriter( const Self& other ); - Self& operator=( const Self& other ); - - protected: - std::string m_FileName; - }; - - } // ecapseman - -} // ecapseman - -#include - -#endif // __FPA__IO__MATRIXVALUESCONTAINERWRITER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/IO/MatrixValuesContainerWriter.hxx b/lib/fpa/IO/MatrixValuesContainerWriter.hxx deleted file mode 100644 index dedc587..0000000 --- a/lib/fpa/IO/MatrixValuesContainerWriter.hxx +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef __FPA__IO__MATRIXVALUESCONTAINERWRITER__HXX__ -#define __FPA__IO__MATRIXVALUESCONTAINERWRITER__HXX__ - -#include -#include - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MatrixValuesContainerWriter< T >:: -SetInput( const T* input ) -{ - this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( input ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -T* fpa::IO::MatrixValuesContainerWriter< T >:: -GetInput( ) -{ - return( dynamic_cast< T* >( this->itk::ProcessObject::GetInput( 0 ) ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -const T* fpa::IO::MatrixValuesContainerWriter< T >:: -GetInput( ) const -{ - return( - dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) ) - ); -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MatrixValuesContainerWriter< T >:: -Update( ) -{ - T* input = this->GetInput( ); - if( input != NULL ) - { - input->UpdateOutputInformation( ); - input->UpdateOutputData( ); - this->GenerateData( ); - this->ReleaseInputs( ); - - } // fi -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::IO::MatrixValuesContainerWriter< T >:: -MatrixValuesContainerWriter( ) - : Superclass( ), - m_FileName( "" ) -{ - this->SetNumberOfRequiredInputs( 1 ); -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::IO::MatrixValuesContainerWriter< T >:: -~MatrixValuesContainerWriter( ) -{ -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MatrixValuesContainerWriter< T >:: -GenerateData( ) -{ - const T* input = this->GetInput( ); - - std::ofstream out( this->m_FileName.c_str( ) ); - if( !out ) - { - itkExceptionMacro( - << "Error opening file to write a minimum spanning tree: \"" - << this->m_FileName - << "\"" - ); - return; - - } // fi - - out << T::TIndex::Dimension << std::endl; - - const typename T::TDecorated& real_input = input->Get( ); - out << real_input.size( ) << std::endl; - typename T::TDecorated::const_iterator cIt = real_input.begin( ); - for( ; cIt != real_input.end( ); ++cIt ) - { - out << cIt->second.size( ) << " "; - for( unsigned int d = 0; d < T::TIndex::Dimension; ++d ) - out << ( cIt->first )[ d ] << " "; - - typename T::TDecorated::value_type::second_type::const_iterator rIt = - cIt->second.begin( ); - for( ; rIt != cIt->second.end( ); ++rIt ) - { - for( unsigned int d = 0; d < T::TIndex::Dimension; ++d ) - out << ( rIt->first )[ d ] << " "; - out << rIt->second << std::endl; - - } // rof - - } // rof - out.close( ); -} - -#endif // __FPA__IO__MATRIXVALUESCONTAINERWRITER__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpa/IO/MinimumSpanningTreeReader.h b/lib/fpa/IO/MinimumSpanningTreeReader.h index 40bf102..d0cbef3 100644 --- a/lib/fpa/IO/MinimumSpanningTreeReader.h +++ b/lib/fpa/IO/MinimumSpanningTreeReader.h @@ -10,7 +10,7 @@ namespace fpa { /** */ - template< class T > + template< class _TTree > class MinimumSpanningTreeReader : public itk::ProcessObject { @@ -20,7 +20,7 @@ namespace fpa typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef T TTree; + typedef _TTree TTree; public: itkNewMacro( Self ); @@ -30,8 +30,7 @@ namespace fpa itkSetMacro( FileName, std::string ); public: - T* GetOutput( ); - + _TTree* GetOutput( ); virtual void Update( ); protected: @@ -53,7 +52,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IO__MINIMUMSPANNINGTREEREADER__H__ diff --git a/lib/fpa/IO/MinimumSpanningTreeReader.hxx b/lib/fpa/IO/MinimumSpanningTreeReader.hxx index 9a41db5..72eecc2 100644 --- a/lib/fpa/IO/MinimumSpanningTreeReader.hxx +++ b/lib/fpa/IO/MinimumSpanningTreeReader.hxx @@ -2,51 +2,61 @@ #define __FPA__IO__MINIMUMSPANNINGTREEREADER__HXX__ #include +#include +#include +#include // ------------------------------------------------------------------------- -template< class T > -T* fpa::IO::MinimumSpanningTreeReader< T >:: +template< class _TTree > +_TTree* fpa::IO::MinimumSpanningTreeReader< _TTree >:: GetOutput( ) { - return( itkDynamicCastInDebugMode< T* >( this->GetPrimaryOutput( ) ) ); + return( + dynamic_cast< _TTree* >( this->itk::ProcessObject::GetOutput( 0 ) ) + ); } // ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MinimumSpanningTreeReader< T >:: +template< class _TTree > +void fpa::IO::MinimumSpanningTreeReader< _TTree >:: Update( ) { this->GenerateData( ); } // ------------------------------------------------------------------------- -template< class T > -fpa::IO::MinimumSpanningTreeReader< T >:: +template< class _TTree > +fpa::IO::MinimumSpanningTreeReader< _TTree >:: MinimumSpanningTreeReader( ) : Superclass( ), m_FileName( "" ) { - this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 ); - this->itk::ProcessObject::SetNthOutput( 0, T::New( ) ); + this->SetNumberOfRequiredInputs( 0 ); + this->SetNumberOfRequiredOutputs( 0 ); + typename _TTree::Pointer out = _TTree::New( ); + this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) ); } // ------------------------------------------------------------------------- -template< class T > -fpa::IO::MinimumSpanningTreeReader< T >:: +template< class _TTree > +fpa::IO::MinimumSpanningTreeReader< _TTree >:: ~MinimumSpanningTreeReader( ) { } // ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MinimumSpanningTreeReader< T >:: +template< class _TTree > +void fpa::IO::MinimumSpanningTreeReader< _TTree >:: GenerateData( ) { - T* output = this->GetOutput( ); - output->Clear( ); - - std::ifstream in( this->m_FileName.c_str( ) ); - if( !in ) + _TTree* tree = this->GetOutput( ); + + char* buff = NULL; + std::ifstream file( + this->m_FileName.c_str( ), + std::ios::in | std::ios::binary | std::ios::ate + ); + if( !file ) { itkExceptionMacro( << "Error opening file to read a minimum spanning tree: \"" @@ -57,56 +67,119 @@ GenerateData( ) } // fi - unsigned int dim; - unsigned long nSeeds, nVertices; - in >> dim >> nSeeds; + // Put all file into a memory buffer + auto size = file.tellg( ); + buff = new char[ size ]; + file.seekg( 0, std::ios::beg ); + file.read ( buff, size ); + file.close( ); + std::istringstream in( buff ); + + // Read basic data + unsigned int dim, fill_queue; + in >> dim >> fill_queue; + tree->SetFillNodeQueue( fill_queue == 1 ); + + // Read regions + typename _TTree::IndexType li, ri, bi; + typename _TTree::SizeType ls, rs, bs; + li.Fill( 0 ); + ri = bi = li; + ls.Fill( 0 ); + rs = bs = ls; + for( unsigned int d = 0; d < dim; ++d ) + if( d < _TTree::ImageDimension ) + in >> li[ d ] >> ls[ d ]; + for( unsigned int d = 0; d < dim; ++d ) + if( d < _TTree::ImageDimension ) + in >> ri[ d ] >> rs[ d ]; + for( unsigned int d = 0; d < dim; ++d ) + if( d < _TTree::ImageDimension ) + in >> bi[ d ] >> bs[ d ]; + typename _TTree::RegionType lr, rr, br; + lr.SetIndex( li ); lr.SetSize( ls ); + rr.SetIndex( ri ); rr.SetSize( rs ); + br.SetIndex( bi ); br.SetSize( bs ); + + // Read spatial information + typename _TTree::SpacingType spc; + typename _TTree::PointType ori; + typename _TTree::DirectionType dir; + for( unsigned int d = 0; d < dim; ++d ) + if( d < _TTree::ImageDimension ) + in >> ori[ d ]; + for( unsigned int d = 0; d < dim; ++d ) + if( d < _TTree::ImageDimension ) + in >> spc[ d ]; + for( unsigned int d = 0; d < dim; ++d ) + { + if( d < _TTree::ImageDimension ) + { + for( unsigned int e = 0; e < dim; ++e ) + if( e < _TTree::ImageDimension ) + in >> dir[ d ][ e ]; - typedef typename T::TCollisions _TCollisions; - typedef typename _TCollisions::value_type _TCollisionsRow; - typedef typename _TCollisionsRow::value_type _TCollision; - typedef typename T::TVertex _TVertex; + } // fi - _TCollisions - collisions( nSeeds, _TCollisionsRow( nSeeds, _TCollision( _TVertex( ), false ) ) ); - for( unsigned long i = 0; i < nSeeds; ++i ) + } // rof + + // Allocate memory and prepare it + tree->SetLargestPossibleRegion( lr ); + tree->SetRequestedRegion( rr ); + tree->SetBufferedRegion( br ); + tree->SetOrigin( ori ); + tree->SetSpacing( spc ); + tree->SetDirection( dir ); + tree->Allocate( ); + tree->Clear( ); + + // Read collisions + typedef typename _TTree::TCollision _TCollision; + typedef typename _TTree::TCollisionsRow _TCollisionsRow; + typename _TTree::TCollisions coll; + unsigned long coll_size; + in >> coll_size; + for( unsigned long i = 0; i < coll_size; ++i ) { - for( unsigned long j = 0; j < nSeeds; ++j ) - { - int val; - in >> val; - collisions[ i ][ j ].second = ( val == 1 ); + coll.push_back( _TCollisionsRow( ) ); + unsigned long row_size; + in >> row_size; + for( unsigned long j = 0; j < row_size; ++j ) + { + typename _TTree::IndexType v; + for( unsigned int d = 0; d < dim; ++d ) + if( d < _TTree::ImageDimension ) + in >> v[ d ]; + unsigned int b; + in >> b; + coll[ i ].push_back( _TCollision( v, b == 1 ) ); + } // rof } // rof + tree->SetCollisions( coll ); - in >> nVertices; - for( unsigned long vId = 0; vId < nVertices; ++vId ) + // Read vertices + while( !in.eof( ) ) { - typename T::TVertex v0, v1; + short fid; + double cost; + typename _TTree::IndexType v; + typename _TTree::IndexType::OffsetType p; + in >> fid >> cost; for( unsigned int d = 0; d < dim; ++d ) - { - long val; - in >> val; - if( d < T::TVertex::Dimension ) - v0[ d ] = val; - - } // rof + if( d < _TTree::ImageDimension ) + in >> v[ d ]; for( unsigned int d = 0; d < dim; ++d ) - { - long val; - in >> val; - if( d < T::TVertex::Dimension ) - v1[ d ] = val; + if( d < _TTree::ImageDimension ) + in >> p[ d ]; + tree->SetNode( v, v + p, fid, cost ); - } // rof - short fId; - in >> fId; - output->SetParent( v0, v1, fId ); + } // elihw - } // rof - output->SetCollisions( collisions ); - in.close( ); + // Free buffer + delete [] buff; } #endif // __FPA__IO__MINIMUMSPANNINGTREEREADER__HXX__ diff --git a/lib/fpa/IO/MinimumSpanningTreeWriter.h b/lib/fpa/IO/MinimumSpanningTreeWriter.h index 3c3e9d1..c3465fa 100644 --- a/lib/fpa/IO/MinimumSpanningTreeWriter.h +++ b/lib/fpa/IO/MinimumSpanningTreeWriter.h @@ -10,7 +10,7 @@ namespace fpa { /** */ - template< class T > + template< class _TTree > class MinimumSpanningTreeWriter : public itk::ProcessObject { @@ -20,7 +20,7 @@ namespace fpa typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef T TTree; + typedef _TTree TTree; public: itkNewMacro( Self ); @@ -30,9 +30,9 @@ namespace fpa itkSetMacro( FileName, std::string ); public: - void SetInput( const T* input ); - T* GetInput( ); - const T* GetInput( ) const; + void SetInput( const _TTree* input ); + _TTree* GetInput( ); + const _TTree* GetInput( ) const; virtual void Update( ); protected: @@ -54,7 +54,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IO__MINIMUMSPANNINGTREEWRITER__H__ diff --git a/lib/fpa/IO/MinimumSpanningTreeWriter.hxx b/lib/fpa/IO/MinimumSpanningTreeWriter.hxx index f9b8533..d4b1f12 100644 --- a/lib/fpa/IO/MinimumSpanningTreeWriter.hxx +++ b/lib/fpa/IO/MinimumSpanningTreeWriter.hxx @@ -2,40 +2,45 @@ #define __FPA__IO__MINIMUMSPANNINGTREEWRITER__HXX__ #include +#include #include +#include +#include // ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MinimumSpanningTreeWriter< T >:: -SetInput( const T* input ) +template< class _TTree > +void fpa::IO::MinimumSpanningTreeWriter< _TTree >:: +SetInput( const _TTree* input ) { - this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( input ) ); + this->itk::ProcessObject::SetNthInput( 0, const_cast< _TTree* >( input ) ); } // ------------------------------------------------------------------------- -template< class T > -T* fpa::IO::MinimumSpanningTreeWriter< T >:: +template< class _TTree > +_TTree* fpa::IO::MinimumSpanningTreeWriter< _TTree >:: GetInput( ) { - return( dynamic_cast< T* >( this->itk::ProcessObject::GetInput( 0 ) ) ); + return( + dynamic_cast< _TTree* >( this->itk::ProcessObject::GetInput( 0 ) ) + ); } // ------------------------------------------------------------------------- -template< class T > -const T* fpa::IO::MinimumSpanningTreeWriter< T >:: +template< class _TTree > +const _TTree* fpa::IO::MinimumSpanningTreeWriter< _TTree >:: GetInput( ) const { return( - dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) ) + dynamic_cast< const _TTree* >( this->itk::ProcessObject::GetInput( 0 ) ) ); } // ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MinimumSpanningTreeWriter< T >:: +template< class _TTree > +void fpa::IO::MinimumSpanningTreeWriter< _TTree >:: Update( ) { - T* input = this->GetInput( ); + _TTree* input = this->GetInput( ); if( input != NULL ) { input->UpdateOutputInformation( ); @@ -47,8 +52,8 @@ Update( ) } // ------------------------------------------------------------------------- -template< class T > -fpa::IO::MinimumSpanningTreeWriter< T >:: +template< class _TTree > +fpa::IO::MinimumSpanningTreeWriter< _TTree >:: MinimumSpanningTreeWriter( ) : Superclass( ), m_FileName( "" ) @@ -57,60 +62,120 @@ MinimumSpanningTreeWriter( ) } // ------------------------------------------------------------------------- -template< class T > -fpa::IO::MinimumSpanningTreeWriter< T >:: +template< class _TTree > +fpa::IO::MinimumSpanningTreeWriter< _TTree >:: ~MinimumSpanningTreeWriter( ) { } // ------------------------------------------------------------------------- -template< class T > -void fpa::IO::MinimumSpanningTreeWriter< T >:: +template< class _TTree > +void fpa::IO::MinimumSpanningTreeWriter< _TTree >:: GenerateData( ) { - const T* input = this->GetInput( ); - - std::ofstream out( this->m_FileName.c_str( ) ); - if( !out ) + typedef itk::Offset< _TTree::ImageDimension > _TOffset; + _TOffset zero_off; + zero_off.Fill( 0 ); + const _TTree* input = this->GetInput( ); + + // Create buffer + std::stringstream out; + + // Get tree properties + unsigned int dim = _TTree::ImageDimension; + auto lr = input->GetLargestPossibleRegion( ); + auto rr = input->GetRequestedRegion( ); + auto br = input->GetBufferedRegion( ); + auto ori = input->GetOrigin( ); + auto spc = input->GetSpacing( ); + auto dir = input->GetDirection( ); + + // Write tree dimension + out << dim << std::endl; + out << ( ( input->GetFillNodeQueue( ) )? 1: 0 ) << std::endl; + + // Write tree regions + out << lr.GetIndex( )[ 0 ] << " " << lr.GetSize( )[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + out << " " << lr.GetIndex( )[ d ] << " " << lr.GetSize( )[ d ]; + out << std::endl; + out << rr.GetIndex( )[ 0 ] << " " << rr.GetSize( )[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + out << " " << rr.GetIndex( )[ d ] << " " << rr.GetSize( )[ d ]; + out << std::endl; + out << br.GetIndex( )[ 0 ] << " " << br.GetSize( )[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + out << " " << br.GetIndex( )[ d ] << " " << br.GetSize( )[ d ]; + out << std::endl; + + // Write spatial properties + out << ori[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + out << " " << ori[ d ]; + out << std::endl; + out << spc[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + out << " " << spc[ d ]; + out << std::endl; + out << dir[ 0 ][ 0 ]; + for( unsigned int d = 0; d < dim; ++d ) + for( unsigned int e = 0; e < dim; ++e ) + if( d != 0 || e != 0 ) + out << " " << dir[ d ][ e ]; + out << std::endl; + + // Write collisions + auto& coll = input->GetCollisions( ); + out << coll.size( ) << std::endl; + for( unsigned long i = 0; i < coll.size( ); ++i ) { - itkExceptionMacro( - << "Error opening file to write a minimum spanning tree: \"" - << this->m_FileName - << "\"" - ); - return; + out << coll[ i ].size( ); + for( unsigned long j = 0; j < coll[ i ].size( ); ++j ) + { + for( unsigned int d = 0; d < dim; ++d ) + out << " " << coll[ i ][ j ].first[ d ]; + out << " " << coll[ i ][ j ].second << std::endl; - } // fi + } // rof - out << T::TVertex::Dimension << std::endl; + } // rof - const typename T::TCollisions& collisions = input->GetCollisions( ); - unsigned long nSeeds = collisions.size( ); - out << nSeeds << std::endl; - for( unsigned long i = 0; i < nSeeds; ++i ) + // Write vertices + itk::ImageRegionConstIteratorWithIndex< _TTree > vIt( input, rr ); + for( vIt.GoToBegin( ); !vIt.IsAtEnd( ); ++vIt ) { - for( unsigned long j = 0; j < nSeeds; ++j ) - out << collisions[ i ][ j ].second << " "; - out << std::endl; + if( + vIt.Get( ).Parent != zero_off || + vIt.Get( ).GlobalCost > double( 0 ) + ) + { + out << vIt.Get( ).FrontId << " " << vIt.Get( ).GlobalCost; + for( unsigned int d = 0; d < dim; ++d ) + out << " " << vIt.GetIndex( )[ d ]; + for( unsigned int d = 0; d < dim; ++d ) + out << " " << vIt.Get( ).Parent[ d ]; + out << std::endl; + + } // fi } // rof - const typename T::TDecorated& real_input = input->Get( ); - out << real_input.size( ) << std::endl; - for( - typename T::TDecorated::const_iterator iIt = real_input.begin( ); - iIt != real_input.end( ); - ++iIt - ) + // Real file write + std::ofstream file( + this->m_FileName.c_str( ), std::ios::binary | std::ios::trunc + ); + if( !file ) { - for( unsigned int d = 0; d < T::TVertex::Dimension; ++d ) - out << iIt->first[ d ] << " "; - for( unsigned int d = 0; d < T::TVertex::Dimension; ++d ) - out << iIt->second.first[ d ] << " "; - out << iIt->second.second << std::endl; + itkExceptionMacro( + << "Error opening file to write a minimum spanning tree: \"" + << this->m_FileName + << "\"" + ); + return; - } // rof - out.close( ); + } // fi + file.write( out.str( ).c_str( ), out.str( ).size( ) ); + file.close( ); } #endif // __FPA__IO__MINIMUMSPANNINGTREEWRITER__HXX__ diff --git a/lib/fpa/IO/UniqueValuesContainerReader.h b/lib/fpa/IO/UniqueValuesContainerReader.h deleted file mode 100644 index 5dc895b..0000000 --- a/lib/fpa/IO/UniqueValuesContainerReader.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __FPA__IO__UNIQUEVALUESCONTAINERREADER__H__ -#define __FPA__IO__UNIQUEVALUESCONTAINERREADER__H__ - -#include -#include - -namespace fpa -{ - namespace IO - { - /** - */ - template< class T > - class UniqueValuesContainerReader - : public itk::ProcessObject - { - public: - typedef UniqueValuesContainerReader Self; - typedef itk::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef T TTree; - - public: - itkNewMacro( Self ); - itkTypeMacro( UniqueValuesContainerReader, itkProcessObject ); - - itkGetConstMacro( FileName, std::string ); - itkSetMacro( FileName, std::string ); - - public: - T* GetOutput( ); - - virtual void Update( ); - - protected: - UniqueValuesContainerReader( ); - virtual ~UniqueValuesContainerReader( ); - - virtual void GenerateData( ); - - private: - // Purposely not implemented - UniqueValuesContainerReader( const Self& other ); - Self& operator=( const Self& other ); - - protected: - std::string m_FileName; - }; - - } // ecapseman - -} // ecapseman - -#include - -#endif // __FPA__IO__UNIQUEVALUESCONTAINERREADER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/IO/UniqueValuesContainerReader.hxx b/lib/fpa/IO/UniqueValuesContainerReader.hxx deleted file mode 100644 index 16719f2..0000000 --- a/lib/fpa/IO/UniqueValuesContainerReader.hxx +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__ -#define __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__ - -#include - -// ------------------------------------------------------------------------- -template< class T > -T* fpa::IO::UniqueValuesContainerReader< T >:: -GetOutput( ) -{ - return( itkDynamicCastInDebugMode< T* >( this->GetPrimaryOutput( ) ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::UniqueValuesContainerReader< T >:: -Update( ) -{ - this->GenerateData( ); -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::IO::UniqueValuesContainerReader< T >:: -UniqueValuesContainerReader( ) - : Superclass( ), - m_FileName( "" ) -{ - this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 ); - this->itk::ProcessObject::SetNthOutput( 0, T::New( ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::IO::UniqueValuesContainerReader< T >:: -~UniqueValuesContainerReader( ) -{ -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::UniqueValuesContainerReader< T >:: -GenerateData( ) -{ - T* output = this->GetOutput( ); - output->Clear( ); - - std::ifstream in( this->m_FileName.c_str( ) ); - if( !in ) - { - itkExceptionMacro( - << "Error opening file to read a minimum spanning tree: \"" - << this->m_FileName - << "\"" - ); - return; - - } // fi - - unsigned int dim; - unsigned long nVertices; - in >> dim >> nVertices; - for( unsigned long vId = 0; vId < nVertices; ++vId ) - { - typename T::TValue v; - for( unsigned int d = 0; d < dim; ++d ) - { - long val; - in >> val; - if( d < T::TValue::Dimension ) - v[ d ] = val; - - } // rof - output->Insert( v ); - - } // rof - in.close( ); -} - -#endif // __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpa/IO/UniqueValuesContainerWriter.h b/lib/fpa/IO/UniqueValuesContainerWriter.h deleted file mode 100644 index fc27012..0000000 --- a/lib/fpa/IO/UniqueValuesContainerWriter.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef __FPA__IO__UNIQUEVALUESCONTAINERWRITER__H__ -#define __FPA__IO__UNIQUEVALUESCONTAINERWRITER__H__ - -#include -#include - -namespace fpa -{ - namespace IO - { - /** - */ - template< class T > - class UniqueValuesContainerWriter - : public itk::ProcessObject - { - public: - typedef UniqueValuesContainerWriter Self; - typedef itk::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef T TTree; - - public: - itkNewMacro( Self ); - itkTypeMacro( UniqueValuesContainerWriter, itkProcessObject ); - - itkGetConstMacro( FileName, std::string ); - itkSetMacro( FileName, std::string ); - - public: - void SetInput( const T* input ); - T* GetInput( ); - const T* GetInput( ) const; - virtual void Update( ); - - protected: - UniqueValuesContainerWriter( ); - virtual ~UniqueValuesContainerWriter( ); - - virtual void GenerateData( ); - - private: - // Purposely not implemented - UniqueValuesContainerWriter( const Self& other ); - Self& operator=( const Self& other ); - - protected: - std::string m_FileName; - }; - - } // ecapseman - -} // ecapseman - -#include - -#endif // __FPA__IO__UNIQUEVALUESCONTAINERWRITER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/IO/UniqueValuesContainerWriter.hxx b/lib/fpa/IO/UniqueValuesContainerWriter.hxx deleted file mode 100644 index 17eb1d1..0000000 --- a/lib/fpa/IO/UniqueValuesContainerWriter.hxx +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef __FPA__IO__UNIQUEVALUESCONTAINERWRITER__HXX__ -#define __FPA__IO__UNIQUEVALUESCONTAINERWRITER__HXX__ - -#include -#include - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::UniqueValuesContainerWriter< T >:: -SetInput( const T* input ) -{ - this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( input ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -T* fpa::IO::UniqueValuesContainerWriter< T >:: -GetInput( ) -{ - return( dynamic_cast< T* >( this->itk::ProcessObject::GetInput( 0 ) ) ); -} - -// ------------------------------------------------------------------------- -template< class T > -const T* fpa::IO::UniqueValuesContainerWriter< T >:: -GetInput( ) const -{ - return( - dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) ) - ); -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::UniqueValuesContainerWriter< T >:: -Update( ) -{ - T* input = this->GetInput( ); - if( input != NULL ) - { - input->UpdateOutputInformation( ); - input->UpdateOutputData( ); - this->GenerateData( ); - this->ReleaseInputs( ); - - } // fi -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::IO::UniqueValuesContainerWriter< T >:: -UniqueValuesContainerWriter( ) - : Superclass( ), - m_FileName( "" ) -{ - this->SetNumberOfRequiredInputs( 1 ); -} - -// ------------------------------------------------------------------------- -template< class T > -fpa::IO::UniqueValuesContainerWriter< T >:: -~UniqueValuesContainerWriter( ) -{ -} - -// ------------------------------------------------------------------------- -template< class T > -void fpa::IO::UniqueValuesContainerWriter< T >:: -GenerateData( ) -{ - const T* input = this->GetInput( ); - - std::ofstream out( this->m_FileName.c_str( ) ); - if( !out ) - { - itkExceptionMacro( - << "Error opening file to write a minimum spanning tree: \"" - << this->m_FileName - << "\"" - ); - return; - - } // fi - - out << T::TValue::Dimension << std::endl; - - const typename T::TDecorated& real_input = input->Get( ); - out << real_input.size( ) << std::endl; - for( - typename T::TDecorated::const_iterator iIt = real_input.begin( ); - iIt != real_input.end( ); - ++iIt - ) - { - for( unsigned int d = 0; d < T::TValue::Dimension; ++d ) - out << ( *iIt )[ d ] << " "; - out << std::endl; - - } // rof - out.close( ); -} - -#endif // __FPA__IO__UNIQUEVALUESCONTAINERWRITER__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Image/Algorithm.h b/lib/fpa/Image/Algorithm.h index 9a44146..dce2d25 100644 --- a/lib/fpa/Image/Algorithm.h +++ b/lib/fpa/Image/Algorithm.h @@ -29,12 +29,11 @@ namespace fpa typedef I TInputImage; typedef O TOutputImage; - typedef typename Superclass::TVertex TVertex; - typedef typename Superclass::TValue TValue; - typedef typename Superclass::TResult TResult; - typedef typename Superclass::TSpace TSpace; - typedef typename Superclass::TVertexCompare TVertexCompare; - typedef typename Superclass::TMinimumSpanningTree TMinimumSpanningTree; + typedef typename Superclass::TVertex TVertex; + typedef typename Superclass::TValue TValue; + typedef typename Superclass::TResult TResult; + typedef typename Superclass::TSpace TSpace; + typedef typename Superclass::TVertexCompare TVertexCompare; protected: typedef typename Superclass::_TVertices _TVertices; @@ -56,7 +55,6 @@ namespace fpa virtual ~Algorithm( ); virtual void _BeforeGenerateData( ); - virtual void _AfterGenerateData( ); // Graph-related abstract methods virtual unsigned long _NumberOfVertices( ) const; @@ -87,7 +85,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IMAGE__ALGORITHM__H__ diff --git a/lib/fpa/Image/Algorithm.hxx b/lib/fpa/Image/Algorithm.hxx index 5e8605d..2eda502 100644 --- a/lib/fpa/Image/Algorithm.hxx +++ b/lib/fpa/Image/Algorithm.hxx @@ -29,15 +29,6 @@ _BeforeGenerateData( ) this->AllocateOutputs( ); } -// ------------------------------------------------------------------------- -template< class I, class O, class A > -void fpa::Image::Algorithm< I, O, A >:: -_AfterGenerateData( ) -{ - this->Superclass::_AfterGenerateData( ); - this->GetMinimumSpanningTree( )->SetCollisions( this->m_Collisions ); -} - // ------------------------------------------------------------------------- template< class I, class O, class A > unsigned long fpa::Image::Algorithm< I, O, A >:: @@ -145,8 +136,8 @@ template< class I, class O, class A > void fpa::Image::Algorithm< I, O, A >:: _SetResult( const TVertex& v, const _TNode& n ) { + this->Superclass::_SetResult( v, n ); this->GetOutput( )->SetPixel( v, n.Result ); - this->GetMinimumSpanningTree( )->SetParent( v, n.Parent, n.FrontId ); } #endif // __FPA__IMAGE__ALGORITHM__HXX__ diff --git a/lib/fpa/Image/Dijkstra.h b/lib/fpa/Image/Dijkstra.h index 45759cb..7ff5908 100644 --- a/lib/fpa/Image/Dijkstra.h +++ b/lib/fpa/Image/Dijkstra.h @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace fpa @@ -17,23 +18,21 @@ namespace fpa */ template< class I, class O = I > class Dijkstra - : public Algorithm< I, O, fpa::Base::Dijkstra< typename I::IndexType, typename I::PixelType, typename O::PixelType, I, itk::Functor::IndexLexicographicCompare< I::ImageDimension >, itk::ImageToImageFilter< I, O > > > + : public Algorithm< I, O, fpa::Base::Dijkstra< typename I::IndexType, typename I::PixelType, typename O::PixelType, I, itk::Functor::IndexLexicographicCompare< I::ImageDimension >, fpa::Image::MinimumSpanningTree< I::ImageDimension >, itk::ImageToImageFilter< I, O > > > { public: - typedef fpa::Base::Dijkstra< typename I::IndexType, typename I::PixelType, typename O::PixelType, I, itk::Functor::IndexLexicographicCompare< I::ImageDimension >, itk::ImageToImageFilter< I, O > > TBaseAlgorithm; - + typedef fpa::Base::Dijkstra< typename I::IndexType, typename I::PixelType, typename O::PixelType, I, itk::Functor::IndexLexicographicCompare< I::ImageDimension >, fpa::Image::MinimumSpanningTree< I::ImageDimension >, itk::ImageToImageFilter< I, O > > TBaseAlgorithm; typedef Dijkstra Self; typedef Algorithm< I, O, TBaseAlgorithm > Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef typename Superclass::TInputImage TInputImage; - typedef typename Superclass::TOutputImage TOutputImage; - typedef typename Superclass::TVertex TVertex; - typedef typename Superclass::TValue TValue; - typedef typename Superclass::TResult TResult; - typedef typename Superclass::TSpace TSpace; - typedef typename Superclass::TMinimumSpanningTree TMinimumSpanningTree; + typedef typename Superclass::TInputImage TInputImage; + typedef typename Superclass::TOutputImage TOutputImage; + typedef typename Superclass::TVertex TVertex; + typedef typename Superclass::TValue TValue; + typedef typename Superclass::TResult TResult; + typedef typename Superclass::TSpace TSpace; typedef typename Superclass::TStartEvent TStartEvent; typedef typename Superclass::TStartLoopEvent TStartLoopEvent; @@ -47,6 +46,8 @@ namespace fpa typedef typename Superclass::TEndBacktrackingEvent TEndBacktrackingEvent; typedef typename Superclass::TBacktrackingEvent TBacktrackingEvent; + typedef typename TBaseAlgorithm::TMinimumSpanningTree TMinimumSpanningTree; + typedef fpa::Image::Functors::ImageCostFunction< TInputImage, TResult > TCostFunction; typedef itk::FunctionBase< TResult, TResult > TConversionFunction; @@ -78,6 +79,7 @@ namespace fpa virtual TResult _Cost( const TVertex& v, const TVertex& p ) const; virtual void _BeforeGenerateData( ); + virtual void _AfterGenerateData( ); virtual void _InitResults( ); private: @@ -94,7 +96,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IMAGE__DIJKSTRA__H__ diff --git a/lib/fpa/Image/Dijkstra.hxx b/lib/fpa/Image/Dijkstra.hxx index 4f7b60b..76df258 100644 --- a/lib/fpa/Image/Dijkstra.hxx +++ b/lib/fpa/Image/Dijkstra.hxx @@ -45,6 +45,15 @@ _BeforeGenerateData( ) this->m_CostFunction->SetInputImage( this->GetInput( ) ); } +// ------------------------------------------------------------------------- +template< class I, class O > +void fpa::Image::Dijkstra< I, O >:: +_AfterGenerateData( ) +{ + this->Superclass::_AfterGenerateData( ); + this->GetMinimumSpanningTree( )->SetCollisions( this->m_Collisions ); +} + // ------------------------------------------------------------------------- template< class I, class O > void fpa::Image::Dijkstra< I, O >:: diff --git a/lib/fpa/Image/DijkstraWithEndPointDetection.h b/lib/fpa/Image/DijkstraWithEndPointDetection.h index 13da729..2158f16 100644 --- a/lib/fpa/Image/DijkstraWithEndPointDetection.h +++ b/lib/fpa/Image/DijkstraWithEndPointDetection.h @@ -151,7 +151,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IMAGE__DIJKSTRAWITHENDPOINTDETECTION__H__ diff --git a/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h b/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h new file mode 100644 index 0000000..4ad643a --- /dev/null +++ b/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h @@ -0,0 +1,105 @@ +#ifndef __FPA__IMAGE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ +#define __FPA__IMAGE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ + +#include + +#include +#include +#include + +namespace fpa +{ + namespace Image + { + /** + */ + template< class _TImage, class _TMST > + class ExtractEndPointsAndBifurcationsFromMinimumSpanningTree + : public fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST > + { + public: + typedef + fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TMST > + Superclass; + typedef ExtractEndPointsAndBifurcationsFromMinimumSpanningTree Self; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef _TImage TImage; + typedef typename Superclass::TMinimumSpanningTree TMinimumSpanningTree; + typedef typename Superclass::TVertex TVertex; + + typedef itk::Image< unsigned short, TImage::ImageDimension > TMarkImage; + + public: + itkNewMacro( Self ); + itkTypeMacro( + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree, + fpa::Base::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree + ); + + itkBooleanMacro( SquaredDistanceMap ); + itkGetConstMacro( SquaredDistanceMap, bool ); + itkSetMacro( SquaredDistanceMap, bool ); + + public: + const TImage* GetCostsImage( ); + const TImage* GetDistanceMap( ); + void SetCostsImage( TImage* image ); + void SetDistanceMap( TImage* image ); + + protected: + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ); + virtual ~ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ); + + virtual void GenerateData( ) override; + + virtual void _MarkSkeleton( + const TVertex& v, const unsigned long& l + ) override; + virtual void _MarkSphere( + const TVertex& v, + const double& r, + const unsigned long& l + ) override; + virtual unsigned long _Mark( const TVertex& v ) override; + virtual unsigned long _SkeletonMark( const TVertex& v ) override; + virtual double _Radius( const TVertex& v ) override; + + virtual void _Tmp( ) override + { + /* TODO + static unsigned int i = 0; + std::stringstream s; + s << "marks_" << i << ".mhd"; + i++; + typename itk::ImageFileWriter< TMarkImage >::Pointer w = + itk::ImageFileWriter< TMarkImage >::New( ); + w->SetInput( this->m_MarkImage ); + w->SetFileName( s.str( ) ); + w->Update( ); + */ + } + + private: + // Purposely not implemented + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( const Self& other ); + Self& operator=( const Self& other ); + + protected: + typename TMarkImage::Pointer m_MarkImage; + typename TMarkImage::Pointer m_SkeletonImage; + bool m_SquaredDistanceMap; + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +#include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __FPA__IMAGE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx b/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx new file mode 100644 index 0000000..0a33ee9 --- /dev/null +++ b/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx @@ -0,0 +1,203 @@ +#ifndef __FPA__IMAGE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__HXX__ +#define __FPA__IMAGE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__HXX__ + +#include +#include + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +const typename +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +TImage* +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +GetCostsImage( ) +{ + return( + dynamic_cast< const _TImage* >( this->itk::ProcessObject::GetInput( 1 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +const typename +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +TImage* +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +GetDistanceMap( ) +{ + return( + dynamic_cast< const _TImage* >( this->itk::ProcessObject::GetInput( 2 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +void +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +SetCostsImage( TImage* image ) +{ + this->itk::ProcessObject::SetNthInput( 1, const_cast< _TImage* >( image ) ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +void +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +SetDistanceMap( TImage* image ) +{ + this->itk::ProcessObject::SetNthInput( 2, const_cast< _TImage* >( image ) ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ) + : Superclass( ), + m_SquaredDistanceMap( false ) +{ + this->SetNumberOfRequiredInputs( 3 ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +~ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +void +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +GenerateData( ) +{ + auto image = this->GetCostsImage( ); + + this->m_MarkImage = TMarkImage::New( ); + this->m_MarkImage->SetLargestPossibleRegion( image->GetLargestPossibleRegion( ) ); + this->m_MarkImage->SetRequestedRegion( image->GetRequestedRegion( ) ); + this->m_MarkImage->SetBufferedRegion( image->GetBufferedRegion( ) ); + this->m_MarkImage->SetDirection( image->GetDirection( ) ); + this->m_MarkImage->SetOrigin( image->GetOrigin( ) ); + this->m_MarkImage->SetSpacing( image->GetSpacing( ) ); + this->m_MarkImage->Allocate( ); + this->m_MarkImage->FillBuffer( 0 ); + + this->m_SkeletonImage = TMarkImage::New( ); + this->m_SkeletonImage->SetLargestPossibleRegion( image->GetLargestPossibleRegion( ) ); + this->m_SkeletonImage->SetRequestedRegion( image->GetRequestedRegion( ) ); + this->m_SkeletonImage->SetBufferedRegion( image->GetBufferedRegion( ) ); + this->m_SkeletonImage->SetDirection( image->GetDirection( ) ); + this->m_SkeletonImage->SetOrigin( image->GetOrigin( ) ); + this->m_SkeletonImage->SetSpacing( image->GetSpacing( ) ); + this->m_SkeletonImage->Allocate( ); + this->m_SkeletonImage->FillBuffer( 0 ); + + this->Superclass::GenerateData( ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +void +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +_MarkSkeleton( const TVertex& v, const unsigned long& l ) +{ + if( this->m_SkeletonImage->GetRequestedRegion( ).IsInside( v ) ) + this->m_SkeletonImage->SetPixel( v, l ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +void +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +_MarkSphere( + const TVertex& v, + const double& r, + const unsigned long& l + ) +{ + // Get marking region + auto rreg = this->m_MarkImage->GetRequestedRegion( ); + auto spac = this->m_MarkImage->GetSpacing( ); + TVertex ireg = rreg.GetIndex( ); + TVertex jreg = ireg + rreg.GetSize( ); + TVertex idx, jdx; + typename _TImage::SizeType size; + bool all = false; + for( unsigned int d = 0; d < _TImage::ImageDimension; ++d ) + { + unsigned long s = std::ceil( r / double( spac[ d ] ) ); + if( s < 3 ) + { + s = 3; + all = true; + + } // fi + s += 3; + idx[ d ] = v[ d ] - s; + jdx[ d ] = v[ d ] + s; + + jreg[ d ]--; + if( idx[ d ] < ireg[ d ] ) idx[ d ] = ireg[ d ]; + if( idx[ d ] > jreg[ d ] ) idx[ d ] = jreg[ d ]; + if( jdx[ d ] < ireg[ d ] ) jdx[ d ] = ireg[ d ]; + if( jdx[ d ] > jreg[ d ] ) jdx[ d ] = jreg[ d ]; + size[ d ] = jdx[ d ] - idx[ d ] + 1; + + } // rof + typename _TImage::RegionType region; + region.SetIndex( idx ); + region.SetSize( size ); + + // Mark region + typename _TImage::PointType c; + this->m_MarkImage->TransformIndexToPhysicalPoint( v, c ); + itk::ImageRegionIteratorWithIndex< TMarkImage > + spIt( this->m_MarkImage, region ); + for( spIt.GoToBegin( ); !spIt.IsAtEnd( ); ++spIt ) + { + typename _TImage::PointType pnt; + this->m_MarkImage->TransformIndexToPhysicalPoint( spIt.GetIndex( ), pnt ); + // TODO: if( double( pnt.EuclideanDistanceTo( c ) ) <= r || all ) + // TODO: if( spIt.Get( ) == 0 ) + spIt.Set( l ); + + } // rof +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +unsigned long +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +_Mark( const TVertex& v ) +{ + return( this->m_MarkImage->GetPixel( v ) ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +unsigned long fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +_SkeletonMark( const TVertex& v ) +{ + return( this->m_SkeletonImage->GetPixel( v ) ); +} + +// ------------------------------------------------------------------------- +template< class _TImage, class _TMST > +double +fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST >:: +_Radius( const TVertex& v ) +{ + double d = double( this->GetDistanceMap( )->GetPixel( v ) ); + double s = std::fabs( d ); + if( s > double( 0 ) ) + s /= d; + if( this->m_SquaredDistanceMap ) + return( s * std::sqrt( std::fabs( d ) ) ); + else + return( d ); +} + +#endif // __FPA__IMAGE__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__HXX__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h b/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h index e3cabfe..0b7727d 100644 --- a/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h +++ b/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h @@ -65,7 +65,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__H__ diff --git a/lib/fpa/Image/IncrementalRegionGrow.h b/lib/fpa/Image/IncrementalRegionGrow.h index a2a1156..70d13c8 100644 --- a/lib/fpa/Image/IncrementalRegionGrow.h +++ b/lib/fpa/Image/IncrementalRegionGrow.h @@ -62,7 +62,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IMAGE__INCREMENTALREGIONGROW__H__ diff --git a/lib/fpa/Image/MinimumSpanningTree.h b/lib/fpa/Image/MinimumSpanningTree.h new file mode 100644 index 0000000..0d26c20 --- /dev/null +++ b/lib/fpa/Image/MinimumSpanningTree.h @@ -0,0 +1,85 @@ +#ifndef __FPA__IMAGE__MINIMUMSPANNINGTREE__H__ +#define __FPA__IMAGE__MINIMUMSPANNINGTREE__H__ + +#include +#include +#include + +namespace fpa +{ + namespace Image + { + template< unsigned int _NDim > + struct MinimumSpanningTreeData + { + typedef itk::Offset< _NDim > TOffset; + TOffset Parent; + short FrontId; + double GlobalCost; + }; + + /** + */ + template< unsigned int _NDim > + class MinimumSpanningTree + : public fpa::Base::MinimumSpanningTree< itk::Image< MinimumSpanningTreeData< _NDim >, _NDim >, itk::Index< _NDim > > + { + public: + typedef MinimumSpanningTreeData< _NDim > TInfo; + typedef itk::Image< TInfo, _NDim > TBase; + typedef itk::Index< _NDim > TVertex; + typedef fpa::Base::MinimumSpanningTree< TBase, TVertex > Superclass; + typedef MinimumSpanningTree Self; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef typename Superclass::TVertices TVertices; + typedef typename Superclass::TPoint TPoint; + typedef typename Superclass::TPoints TPoints; + itkStaticConstMacro( Dimension, unsigned int, _NDim ); + + public: + itkNewMacro( Self ); + itkTypeMacro( MinimumSpanningTree, _TSuperclass ); + + public: + void CopyMetaData( itk::ImageBase< _NDim >* infoImage ); + virtual void SetNode( + const TVertex& v, + const TVertex& p, + const short& fid, + const double& cost + ) override; + virtual void Clear( ) override; + + virtual TPoints GetEuclideanPath( const TVertex& a ) const override; + virtual TPoints GetEuclideanPath( + const TVertex& a, const TVertex& b + ) const override; + virtual bool IsDefinedInEuclideanSpace( ) const override; + + protected: + MinimumSpanningTree( ); + virtual ~MinimumSpanningTree( ); + + virtual bool _HasVertex( const TVertex& a ) const override; + virtual short _FrontId( const TVertex& a ) const override; + virtual void _Path( TVertices& path, const TVertex& a ) const override; + + private: + // Purposely not implemented + MinimumSpanningTree( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +#include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __FPA__IMAGE__MINIMUMSPANNINGTREE__H__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/MinimumSpanningTree.hxx b/lib/fpa/Image/MinimumSpanningTree.hxx new file mode 100644 index 0000000..a4dc47e --- /dev/null +++ b/lib/fpa/Image/MinimumSpanningTree.hxx @@ -0,0 +1,151 @@ +#ifndef __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__ +#define __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__ + +#include + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +void fpa::Image::MinimumSpanningTree< _NDim >:: +CopyMetaData( itk::ImageBase< _NDim >* infoImage ) +{ + this->SetLargestPossibleRegion( infoImage->GetLargestPossibleRegion( ) ); + this->SetRequestedRegion( infoImage->GetRequestedRegion( ) ); + this->SetBufferedRegion( infoImage->GetBufferedRegion( ) ); + this->SetDirection( infoImage->GetDirection( ) ); + this->SetOrigin( infoImage->GetOrigin( ) ); + this->SetSpacing( infoImage->GetSpacing( ) ); + this->Allocate( ); + this->Clear( ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +void fpa::Image::MinimumSpanningTree< _NDim >:: +SetNode( + const TVertex& v, const TVertex& p, + const short& fid, const double& cost + ) +{ + this->Superclass::SetNode( v, p, fid, cost ); + TInfo info; + info.Parent = p - v; + info.FrontId = fid; + info.GlobalCost = cost; + this->SetPixel( v, info ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +void fpa::Image::MinimumSpanningTree< _NDim >:: +Clear( ) +{ + this->Superclass::Clear( ); + TInfo info; + info.Parent.Fill( 0 ); + info.FrontId = std::numeric_limits< short >::max( ); + info.GlobalCost = double( 0 ); + this->FillBuffer( info ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +typename fpa::Image::MinimumSpanningTree< _NDim >:: +TPoints fpa::Image::MinimumSpanningTree< _NDim >:: +GetEuclideanPath( const TVertex& a ) const +{ + TPoints path; + auto vertices = this->GetPath( a ); + for( auto vIt = vertices.begin( ); vIt != vertices.end( ); ++vIt ) + { + TPoint pnt; + this->TransformIndexToPhysicalPoint( *vIt, pnt ); + path.push_back( pnt ); + + } // rof + return( path ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +typename fpa::Image::MinimumSpanningTree< _NDim >:: +TPoints fpa::Image::MinimumSpanningTree< _NDim >:: +GetEuclideanPath( const TVertex& a, const TVertex& b ) const +{ + TPoints path; + auto vertices = this->GetPath( a, b ); + for( auto vIt = vertices.begin( ); vIt != vertices.end( ); ++vIt ) + { + TPoint pnt; + this->TransformIndexToPhysicalPoint( *vIt, pnt ); + path.push_back( pnt ); + + } // rof + return( path ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +bool fpa::Image::MinimumSpanningTree< _NDim >:: +IsDefinedInEuclideanSpace( ) const +{ + return( true ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +fpa::Image::MinimumSpanningTree< _NDim >:: +MinimumSpanningTree( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +fpa::Image::MinimumSpanningTree< _NDim >:: +~MinimumSpanningTree( ) +{ +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +bool fpa::Image::MinimumSpanningTree< _NDim >:: +_HasVertex( const TVertex& a ) const +{ + return( this->_FrontId( a ) < std::numeric_limits< short >::max( ) ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +short fpa::Image::MinimumSpanningTree< _NDim >:: +_FrontId( const TVertex& a ) const +{ + static const short MAX_ID = std::numeric_limits< short >::max( ); + if( this->GetRequestedRegion( ).IsInside( a ) ) + return( this->GetPixel( a ).FrontId ); + else + return( MAX_ID ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +void fpa::Image::MinimumSpanningTree< _NDim >:: +_Path( TVertices& path, const TVertex& a ) const +{ + if( this->_HasVertex( a ) ) + { + typename TVertex::OffsetType zero; + zero.Fill( 0 ); + auto it = a; + do + { + path.push_back( it ); + it += this->GetPixel( it ).Parent; + + } while( this->GetPixel( it ).Parent != zero ); + + } // fi +} + +#endif // __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/RegionGrow.h b/lib/fpa/Image/RegionGrow.h index b814798..14d2f1c 100644 --- a/lib/fpa/Image/RegionGrow.h +++ b/lib/fpa/Image/RegionGrow.h @@ -63,7 +63,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IMAGE__REGIONGROW__H__ diff --git a/lib/fpa/Image/RegionGrowWithMultipleThresholds.h b/lib/fpa/Image/RegionGrowWithMultipleThresholds.h index 3bcc7db..f538e7b 100644 --- a/lib/fpa/Image/RegionGrowWithMultipleThresholds.h +++ b/lib/fpa/Image/RegionGrowWithMultipleThresholds.h @@ -87,7 +87,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__H__ diff --git a/lib/fpa/VTK/Image2DObserver.h b/lib/fpa/VTK/Image2DObserver.h index bd5eea9..0d95658 100644 --- a/lib/fpa/VTK/Image2DObserver.h +++ b/lib/fpa/VTK/Image2DObserver.h @@ -75,7 +75,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__VTK__IMAGE2DOBSERVER__H__ diff --git a/lib/fpa/VTK/Image3DObserver.h b/lib/fpa/VTK/Image3DObserver.h index d5ec4e8..f9c123b 100644 --- a/lib/fpa/VTK/Image3DObserver.h +++ b/lib/fpa/VTK/Image3DObserver.h @@ -73,7 +73,9 @@ namespace fpa } // ecapseman +#ifndef ITK_MANUAL_INSTANTIATION #include +#endif // ITK_MANUAL_INSTANTIATION #endif // __FPA__VTK__IMAGE3DOBSERVER__H__ diff --git a/lib/fpa/VTK/ImageMPR.cxx b/lib/fpa/VTK/ImageMPR.cxx deleted file mode 100644 index b565689..0000000 --- a/lib/fpa/VTK/ImageMPR.cxx +++ /dev/null @@ -1,358 +0,0 @@ -#include - -#include -#include - -#include - -/** - */ -class fpa_VTK_InteractionModeCallback - : public vtkCommand -{ -public: - static fpa_VTK_InteractionModeCallback* New( ) - { - return( new fpa_VTK_InteractionModeCallback ); - } - virtual void Execute( - vtkObject* caller, unsigned long eventId, void* arguments ) - { - if( eventId == vtkCommand::KeyPressEvent ) - { - vtkRenderWindowInteractor* iren = - static_cast< vtkRenderWindowInteractor* >( caller ); - if( caller == NULL ) - return; - - switch( iren->GetKeyCode( ) ) - { - case 'x': - case 'X': - { - bool eSeed = ( this->SeedWidget->GetProcessEvents( ) == 1 ); - if( eSeed ) - { - this->SeedWidget->ProcessEventsOff( ); - this->WidgetX->InteractionOn( ); - this->WidgetY->InteractionOn( ); - this->WidgetZ->InteractionOn( ); - } - else - { - this->SeedWidget->ProcessEventsOn( ); - this->WidgetX->InteractionOff( ); - this->WidgetY->InteractionOff( ); - this->WidgetZ->InteractionOff( ); - - } // fi - } - break; - case 'z': - case 'Z': - { - this->SeedWidget->ProcessEventsOff( ); - this->WidgetX->InteractionOff( ); - this->WidgetY->InteractionOff( ); - this->WidgetZ->InteractionOff( ); - } - break; - default: - break; - - } // hctiws - - } // fi - } - -public: - vtkImagePlaneWidget* WidgetX; - vtkImagePlaneWidget* WidgetY; - vtkImagePlaneWidget* WidgetZ; - vtkSeedWidget* SeedWidget; -}; - -// ------------------------------------------------------------------------- -fpa::VTK::ImageMPR:: -ImageMPR( ) -{ - this->m_Outline = vtkSmartPointer< vtkOutlineSource >::New( ); - this->m_OutlineMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->m_OutlineActor = vtkSmartPointer< vtkActor >::New( ); - this->m_Picker = vtkSmartPointer< vtkCellPicker >::New( ); - this->m_WidgetX = vtkSmartPointer< vtkImagePlaneWidget >::New( ); - this->m_WidgetY = vtkSmartPointer< vtkImagePlaneWidget >::New( ); - this->m_WidgetZ = vtkSmartPointer< vtkImagePlaneWidget >::New( ); - this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( ); - this->m_Window = vtkSmartPointer< vtkRenderWindow >::New( ); - this->m_Interactor = vtkSmartPointer< vtkRenderWindowInteractor >::New( ); - this->m_SeedHandleRepresentation = - vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); - this->m_SeedRepresentation = - vtkSmartPointer< vtkSeedRepresentation >::New( ); - this->m_SeedWidget = vtkSmartPointer::New(); - - this->m_SeedHandleRepresentation->GetProperty()->SetColor( 1, 0, 1 ); - this->m_SeedRepresentation-> - SetHandleRepresentation( this->m_SeedHandleRepresentation ); - this->m_SeedWidget->SetRepresentation( this->m_SeedRepresentation ); - - this->m_WidgetX->KeyPressActivationOff( ); - this->m_WidgetY->KeyPressActivationOff( ); - this->m_WidgetZ->KeyPressActivationOff( ); - this->m_SeedWidget->KeyPressActivationOff( ); - - vtkSmartPointer< fpa_VTK_InteractionModeCallback > int_cb = - vtkSmartPointer< fpa_VTK_InteractionModeCallback >::New( ); - int_cb->WidgetX = this->m_WidgetX; - int_cb->WidgetY = this->m_WidgetY; - int_cb->WidgetZ = this->m_WidgetZ; - int_cb->SeedWidget = this->m_SeedWidget; - this->m_Interactor->AddObserver( vtkCommand::KeyPressEvent, int_cb ); - - vtkSmartPointer< fpa::VTK::SeedWidgetCorrector > corr_cb = - vtkSmartPointer< fpa::VTK::SeedWidgetCorrector >::New( ); - corr_cb->Configure( this->m_Picker ); - this->m_SeedWidget->AddObserver( vtkCommand::PlacePointEvent, corr_cb ); -} - -// ------------------------------------------------------------------------- -fpa::VTK::ImageMPR:: -~ImageMPR( ) -{ -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -SetImage( vtkImageData* image ) -{ - this->m_Image = image; - - // Outline - this->m_Outline->SetBounds( this->m_Image->GetBounds( ) ); - this->m_OutlineMapper-> - SetInputConnection( this->m_Outline->GetOutputPort( ) ); - this->m_OutlineActor->SetMapper( this->m_OutlineMapper ); - this->m_OutlineActor->GetProperty( )->SetColor( 1, 1, 1 ); - - // Local picker - this->m_Picker->SetTolerance( 0.005 ); - - // Image planes - this->m_WidgetX->DisplayTextOn( ); - this->m_WidgetX->SetInputData( this->m_Image ); - this->m_WidgetX->SetPlaneOrientationToXAxes( ); - this->m_WidgetX->SetSliceIndex( this->m_Image->GetExtent( )[ 0 ] ); - this->m_WidgetX->SetPicker( this->m_Picker ); - this->m_WidgetX->SetKeyPressActivationValue( 'x' ); - this->m_WidgetX->GetPlaneProperty( )->SetLineWidth( 3 ); - this->m_WidgetX->GetPlaneProperty( )->SetColor( 0, 1, 1 ); - - this->m_WidgetY->DisplayTextOn( ); - this->m_WidgetY->SetInputData( this->m_Image ); - this->m_WidgetY->SetPlaneOrientationToYAxes( ); - this->m_WidgetY->SetSliceIndex( this->m_Image->GetExtent( )[ 2 ] ); - this->m_WidgetY->SetPicker( this->m_Picker ); - this->m_WidgetY->SetKeyPressActivationValue( 'y' ); - this->m_WidgetY->GetPlaneProperty( )->SetColor( 1, 0, 1 ); - this->m_WidgetY->GetPlaneProperty( )->SetLineWidth( 3 ); - this->m_WidgetY->SetLookupTable( this->m_WidgetX->GetLookupTable( ) ); - - this->m_WidgetZ->DisplayTextOn( ); - this->m_WidgetZ->SetInputData( this->m_Image ); - this->m_WidgetZ->SetPlaneOrientationToZAxes( ); - this->m_WidgetZ->SetSliceIndex( this->m_Image->GetExtent( )[ 4 ] ); - this->m_WidgetZ->SetPicker( this->m_Picker ); - this->m_WidgetZ->SetKeyPressActivationValue( 'z' ); - this->m_WidgetZ->GetPlaneProperty( )->SetColor( 1, 1, 0 ); - this->m_WidgetZ->GetPlaneProperty( )->SetLineWidth( 3 ); - this->m_WidgetZ->SetLookupTable( this->m_WidgetX->GetLookupTable( ) ); - - // Rendering stuff - this->m_Window->AddRenderer( this->m_Renderer ); - this->m_Interactor->SetRenderWindow( this->m_Window ); - - // Command - double spac[ 3 ]; - this->m_Image->GetSpacing( spac ); - double min_spacing = spac[ 0 ]; - for( unsigned int d = 1; d < 3; d++ ) - min_spacing = ( spac[ d ] < min_spacing )? spac[ d ]: min_spacing; - - vtkInteractorStyleSwitch* iswitch = - dynamic_cast< vtkInteractorStyleSwitch* >( - this->m_Interactor->GetInteractorStyle( ) - ); - if( iswitch != NULL ) - iswitch->SetCurrentStyleToTrackballCamera( ); - - // Add actors - this->m_Renderer->AddActor( this->m_OutlineActor ); - - // Prepare widgets - this->m_WidgetX->SetInteractor( this->m_Interactor ); - this->m_WidgetY->SetInteractor( this->m_Interactor ); - this->m_WidgetZ->SetInteractor( this->m_Interactor ); - this->m_SeedWidget->SetInteractor( this->m_Interactor ); - - this->m_WidgetX->On( ); - this->m_WidgetY->On( ); - this->m_WidgetZ->On( ); - this->m_SeedWidget->On( ); - this->m_SeedWidget->ProcessEventsOff( ); - this->m_Interactor->SetPicker( this->m_Picker ); - /* - this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker ); - this->m_Interactor->GetPickingManager( )->EnabledOn( ); - */ -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -SetBackground( double r, double g, double b ) -{ - this->m_Renderer->SetBackground( r, g, b ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -SetSize( unsigned int w, unsigned int h ) -{ - this->m_Window->SetSize( w, h ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -SetWindowLevel( double w, double l ) -{ - this->m_WidgetX->SetWindowLevel( w, l ); - this->m_WidgetY->SetWindowLevel( w, l ); - this->m_WidgetZ->SetWindowLevel( w, l ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -AddPolyData( vtkPolyData* pd, double opacity ) -{ - unsigned int i = this->m_PolyDatas.size( ); - - this->m_PolyDatas.push_back( pd ); - this->m_Mappers.push_back( vtkSmartPointer< vtkPolyDataMapper >::New( ) ); - this->m_Actors.push_back( vtkSmartPointer< vtkActor >::New( ) ); - - this->m_Mappers[ i ]->SetInputData( pd ); - this->m_Actors[ i ]->SetMapper( this->m_Mappers[ i ] ); - this->m_Actors[ i ]->GetProperty( )->SetOpacity( opacity ); - this->m_Actors[ i ]->GetProperty( )->SetLineWidth( 3 ); - this->m_Actors[ i ]->GetProperty( )->SetPointSize( 5 ); - this->m_Renderer->AddActor( this->m_Actors[ i ] ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -AddPolyData( vtkPolyData* pd, double r, double g, double b, double opacity ) -{ - unsigned int i = this->m_PolyDatas.size( ); - - this->m_PolyDatas.push_back( pd ); - this->m_Mappers.push_back( vtkSmartPointer< vtkPolyDataMapper >::New( ) ); - this->m_Actors.push_back( vtkSmartPointer< vtkActor >::New( ) ); - - this->m_Mappers[ i ]->SetInputData( pd ); - this->m_Mappers[ i ]->ScalarVisibilityOff( ); - this->m_Actors[ i ]->SetMapper( this->m_Mappers[ i ] ); - this->m_Actors[ i ]->GetProperty( )->SetColor( r, g, b ); - this->m_Actors[ i ]->GetProperty( )->SetOpacity( opacity ); - this->m_Actors[ i ]->GetProperty( )->SetLineWidth( 3 ); - this->m_Actors[ i ]->GetProperty( )->SetPointSize( 5 ); - this->m_Renderer->AddActor( this->m_Actors[ i ] ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -AddPolyData( vtkPolyData* pd, vtkLookupTable* lut, double opacity ) -{ - unsigned int i = this->m_PolyDatas.size( ); - - this->m_PolyDatas.push_back( pd ); - this->m_Mappers.push_back( vtkSmartPointer< vtkPolyDataMapper >::New( ) ); - this->m_Actors.push_back( vtkSmartPointer< vtkActor >::New( ) ); - - this->m_Mappers[ i ]->SetInputData( pd ); - this->m_Mappers[ i ]->SetLookupTable( lut ); - this->m_Actors[ i ]->SetMapper( this->m_Mappers[ i ] ); - this->m_Actors[ i ]->GetProperty( )->SetOpacity( opacity ); - this->m_Renderer->AddActor( this->m_Actors[ i ] ); -} - -// ------------------------------------------------------------------------- -unsigned int fpa::VTK::ImageMPR:: -GetNumberOfSeeds( ) const -{ - return( this->m_SeedRepresentation->GetNumberOfSeeds( ) ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -GetSeed( int n, double* s ) const -{ - vtkHandleWidget* hWdg = this->m_SeedWidget->GetSeed( n ); - if( hWdg == NULL ) - return; - vtkHandleRepresentation* hRep = - dynamic_cast< vtkHandleRepresentation* >( hWdg->GetRepresentation( ) ); - if( hRep == NULL ) - return; - hRep->GetWorldPosition( s ); -} - -// ------------------------------------------------------------------------- -unsigned int fpa::VTK::ImageMPR:: -AddSeed( const double& x, const double& y, const double& z ) const -{ - double pos[ 3 ] = { x, y, z }; - - int hnd_id = this->m_SeedRepresentation->CreateHandle( pos ); - vtkHandleWidget* hnd = this->m_SeedWidget->CreateNewHandle( ); - vtkHandleWidget::ComputeWorldToDisplay( this->m_Renderer, x, y, z, pos ); - this->m_SeedRepresentation->SetSeedDisplayPosition( hnd_id, pos ); - hnd->SetEnabled( 1 ); - - return( this->GetNumberOfSeeds( ) - 1 ); -} - -// ------------------------------------------------------------------------- -vtkRenderWindow* fpa::VTK::ImageMPR:: -GetWindow( ) const -{ - return( this->m_Window ); -} - -// ------------------------------------------------------------------------- -vtkRenderer* fpa::VTK::ImageMPR:: -GetRenderer( ) const -{ - return( this->m_Renderer ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -Start( ) -{ - this->m_WidgetX->On( ); - this->m_WidgetY->On( ); - this->m_WidgetZ->On( ); - - this->m_Renderer->ResetCamera( ); - this->m_Interactor->Initialize( ); - this->m_Interactor->Start( ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::ImageMPR:: -Render( ) -{ - this->m_Window->Render( ); -} - -// eof - $RCSfile$ diff --git a/lib/fpa/VTK/ImageMPR.h b/lib/fpa/VTK/ImageMPR.h deleted file mode 100644 index 978738a..0000000 --- a/lib/fpa/VTK/ImageMPR.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef __FPA__VTK__IMAGEMPR__H__ -#define __FPA__VTK__IMAGEMPR__H__ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace fpa -{ - namespace VTK - { - /** - */ - class FrontAlgorithms_EXPORT ImageMPR - { - public: - ImageMPR( ); - virtual ~ImageMPR( ); - - void SetImage( vtkImageData* image ); - void SetBackground( double r, double g, double b ); - void SetSize( unsigned int w, unsigned int h ); - void SetWindowLevel( double w, double l ); - - void AddPolyData( vtkPolyData* pd, double opacity = double( 1 ) ); - void AddPolyData( - vtkPolyData* pd, - double r, double g, double b, double opacity = double( 1 ) - ); - void AddPolyData( - vtkPolyData* pd, - vtkLookupTable* lut, - double opacity = double( 1 ) - ); - - unsigned int GetNumberOfSeeds( ) const; - void GetSeed( int n, double* s ) const; - unsigned int AddSeed( - const double& x, const double& y, const double& z - ) const; - - vtkRenderWindow* GetWindow( ) const; - vtkRenderer* GetRenderer( ) const; - - void Start( ); - void Render( ); - - protected: - vtkSmartPointer< vtkImageData > m_Image; - vtkSmartPointer< vtkOutlineSource > m_Outline; - vtkSmartPointer< vtkPolyDataMapper > m_OutlineMapper; - vtkSmartPointer< vtkActor > m_OutlineActor; - vtkSmartPointer< vtkCellPicker > m_Picker; - vtkSmartPointer< vtkImagePlaneWidget > m_WidgetX; - vtkSmartPointer< vtkImagePlaneWidget > m_WidgetY; - vtkSmartPointer< vtkImagePlaneWidget > m_WidgetZ; - vtkSmartPointer< vtkRenderer > m_Renderer; - vtkSmartPointer< vtkRenderWindow > m_Window; - vtkSmartPointer< vtkRenderWindowInteractor > m_Interactor; - - std::vector< vtkSmartPointer< vtkPolyData > > m_PolyDatas; - std::vector< vtkSmartPointer< vtkPolyDataMapper > > m_Mappers; - std::vector< vtkSmartPointer< vtkActor > > m_Actors; - - // Create the widget and its representation - vtkSmartPointer< vtkPointHandleRepresentation3D > - m_SeedHandleRepresentation; - vtkSmartPointer< vtkSeedRepresentation > m_SeedRepresentation; - vtkSmartPointer< vtkSeedWidget > m_SeedWidget; - }; - - } // ecapseman - -} // ecapseman - -#endif // __FPA__VTK__IMAGEMPR__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/VTK/PointPathToPolyDataFilter.h b/lib/fpa/VTK/PointPathToPolyDataFilter.h deleted file mode 100644 index 1184129..0000000 --- a/lib/fpa/VTK/PointPathToPolyDataFilter.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __FPA__VTK__POINTPATHTOPOLYDATAFILTER__H__ -#define __FPA__VTK__POINTPATHTOPOLYDATAFILTER__H__ - -#include - -namespace fpa -{ - namespace VTK - { - /** - */ - template< class C > - class PointPathToPolyDataFilter - : public vtkPolyDataAlgorithm - { - public: - typedef PointPathToPolyDataFilter Self; - - typedef C TContainer; - typedef typename C::value_type TPoint; - - public: - vtkTypeMacro( PointPathToPolyDataFilter, vtkPolyDataAlgorithm ); - - public: - static Self* New( ); - - const C* GetInput( ) const; - void SetInput( const C* c ); - - protected: - PointPathToPolyDataFilter( ); - virtual ~PointPathToPolyDataFilter( ); - - int RequestData( - vtkInformation* information, - vtkInformationVector** input, - vtkInformationVector* output - ); - int RequestInformation( - vtkInformation* information, - vtkInformationVector** input, - vtkInformationVector* output - ); - - private: - // Purposely not implemented - PointPathToPolyDataFilter( const Self& ); - void operator=( const Self& ); - - protected: - const C* m_Container; - }; - - } // ecapseman - -} // ecapseman - -#include - -#endif // __FPA__VTK__POINTPATHTOPOLYDATAFILTER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/VTK/PointPathToPolyDataFilter.hxx b/lib/fpa/VTK/PointPathToPolyDataFilter.hxx deleted file mode 100644 index a79c763..0000000 --- a/lib/fpa/VTK/PointPathToPolyDataFilter.hxx +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef __FPA__VTK__POINTPATHTOPOLYDATAFILTER__HXX__ -#define __FPA__VTK__POINTPATHTOPOLYDATAFILTER__HXX__ - -#include -#include - -// ------------------------------------------------------------------------- -template< class C > -typename fpa::VTK::PointPathToPolyDataFilter< C >:: -Self* fpa::VTK::PointPathToPolyDataFilter< C >:: -New( ) -{ - return( new Self( ) ); -} - -// ------------------------------------------------------------------------- -template< class C > -const C* fpa::VTK::PointPathToPolyDataFilter< C >:: -GetInput( ) const -{ - return( this->m_Container ); -} - -// ------------------------------------------------------------------------- -template< class C > -void fpa::VTK::PointPathToPolyDataFilter< C >:: -SetInput( const C* c ) -{ - if( this->m_Container != c ) - { - this->m_Container = c; - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -template< class C > -fpa::VTK::PointPathToPolyDataFilter< C >:: -PointPathToPolyDataFilter( ) - : vtkPolyDataAlgorithm( ), - m_Container( NULL ) -{ - this->SetNumberOfInputPorts( 0 ); -} - -// ------------------------------------------------------------------------- -template< class C > -fpa::VTK::PointPathToPolyDataFilter< C >:: -~PointPathToPolyDataFilter( ) -{ -} - -// ------------------------------------------------------------------------- -template< class C > -int fpa::VTK::PointPathToPolyDataFilter< C >:: -RequestData( - vtkInformation* information, - vtkInformationVector** input, - vtkInformationVector* output - ) -{ - if( this->m_Container == NULL ) - return( 0 ); - - // Get output - vtkInformation* info = output->GetInformationObject( 0 ); - vtkPolyData* out = vtkPolyData::SafeDownCast( - info->Get( vtkDataObject::DATA_OBJECT( ) ) - ); - - // Prepare points - vtkPoints* points = out->GetPoints( ); - if( points == NULL ) - { - points = vtkPoints::New( ); - out->SetPoints( points ); - points->Delete( ); - - } // fi - points->SetNumberOfPoints( this->m_Container->size( ) ); - - // Prepare cells - vtkSmartPointer< vtkCellArray > cells = - vtkSmartPointer< vtkCellArray >::New( ); - - unsigned int pId = 0; - for( - typename C::const_iterator it = this->m_Container->begin( ); - it != this->m_Container->end( ); - ++it, ++pId - ) - { - TPoint pnt = *it; - if( TPoint::Dimension == 1 ) - points->SetPoint( pId, pnt[ 0 ], 0, 0 ); - else if( TPoint::Dimension == 2 ) - points->SetPoint( pId, pnt[ 0 ], pnt[ 1 ], 0 ); - else - points->SetPoint( pId, pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] ); - - cells->InsertNextCell( 1 ); - cells->InsertCellPoint( pId ); - - } // rof - out->SetPoints( points ); - out->SetVerts( cells ); - return( 1 ); -} - -// ------------------------------------------------------------------------- -template< class C > -int fpa::VTK::PointPathToPolyDataFilter< C >:: -RequestInformation( - vtkInformation* information, - vtkInformationVector** input, - vtkInformationVector* output - ) -{ - vtkInformation* info = output->GetInformationObject( 0 ); - /* TODO - info->Set( - vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1 - ); - */ - - if( this->m_Container != NULL ) - { - /* TODO - typename C::TScalar len = this->m_RGC->GetTotalLength( ); - typename C::TScalar s0 = this->m_RGC->Gets0( ); - typename C::TPoint p0 = this->m_RGC->Axis( s0 ); - typename C::TPoint p1 = this->m_RGC->Axis( s0 + len ); - - info->Set( - vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ), - double( p0[ 0 ] ), double( p1[ 0 ] ), - double( p0[ 1 ] ), double( p1[ 1 ] ), - double( p0[ 2 ] ), double( p1[ 2 ] ) - ); - */ - - } // fi - return( 1 ); -} - -#endif // __FPA__VTK__POINTPATHTOPOLYDATAFILTER__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpa/VTK/SeedWidgetCorrector.cxx b/lib/fpa/VTK/SeedWidgetCorrector.cxx deleted file mode 100644 index 93f32a1..0000000 --- a/lib/fpa/VTK/SeedWidgetCorrector.cxx +++ /dev/null @@ -1,79 +0,0 @@ -#include - -#include -#include - -#include -#include -#include - -// ------------------------------------------------------------------------- -fpa::VTK::SeedWidgetCorrector* -fpa::VTK::SeedWidgetCorrector:: -New( ) -{ - return( new fpa::VTK::SeedWidgetCorrector ); -} - -// ------------------------------------------------------------------------- -void fpa::VTK::SeedWidgetCorrector:: -Configure( vtkCellPicker* picker ) -{ - this->m_Picker = picker; -} - -// ------------------------------------------------------------------------- -void fpa::VTK::SeedWidgetCorrector:: -Execute( vtkObject* caller, unsigned long eventId, void* arguments ) -{ - vtkSeedWidget* wdg = dynamic_cast< vtkSeedWidget* >( caller ); - if( wdg == NULL || this->m_Picker == NULL ) - return; - - if( eventId == vtkCommand::PlacePointEvent ) - { - // Get newly added handle and its associated objects - int hId = *( reinterpret_cast< int* >( arguments ) ); - vtkHandleWidget* hWdg = wdg->GetSeed( hId ); - if( hWdg == NULL ) - return; - vtkHandleRepresentation* hRep = - dynamic_cast< vtkHandleRepresentation* >( hWdg->GetRepresentation( ) ); - if( hRep == NULL ) - return; - - // Get clicked point and 3D scene - double p[ 3 ]; - hRep->GetDisplayPosition( p ); - vtkRenderWindowInteractor* iren = wdg->GetInteractor( ); - if( iren == NULL ) - return; - vtkRenderer* ren = - iren->FindPokedRenderer( int( p[ 0 ] ), int( p[ 1 ] ) ); - if( ren == NULL ) - return; - - // Correct point with given picker - double q[ 3 ]; - this->m_Picker->Pick( p[ 0 ], p[ 1 ], p[ 2 ], ren ); - this->m_Picker->GetPickPosition( q ); - hRep->SetWorldPosition( q ); - - } // fi -} - -// ------------------------------------------------------------------------- -fpa::VTK::SeedWidgetCorrector:: -SeedWidgetCorrector( ) - : vtkCommand( ), - m_Picker( NULL ) -{ -} - -// ------------------------------------------------------------------------- -fpa::VTK::SeedWidgetCorrector:: -~SeedWidgetCorrector( ) -{ -} - -// eof - $RCSfile$ diff --git a/lib/fpa/VTK/SeedWidgetCorrector.h b/lib/fpa/VTK/SeedWidgetCorrector.h deleted file mode 100644 index 426a75a..0000000 --- a/lib/fpa/VTK/SeedWidgetCorrector.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __FPA__VTK__SEEDWIDGETCORRECTOR__H__ -#define __FPA__VTK__SEEDWIDGETCORRECTOR__H__ - -#include -#include - -class vtkCellPicker; -class vtkSeedWidget; - -namespace fpa -{ - namespace VTK - { - /** - */ - class FrontAlgorithms_EXPORT SeedWidgetCorrector - : public vtkCommand - { - public: - static SeedWidgetCorrector* New( ); - - void Configure( vtkCellPicker* picker ); - - virtual void Execute( - vtkObject* caller, - unsigned long eventId, - void* arguments - ); - - protected: - SeedWidgetCorrector( ); - virtual ~SeedWidgetCorrector( ); - - protected: - vtkCellPicker* m_Picker; - }; - - } // ecapseman - -} // ecapseman - -#endif // __FPA__VTK__SEEDWIDGETCORRECTOR__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/VTK/UniqueVerticesToPolyDataFilter.h b/lib/fpa/VTK/UniqueVerticesToPolyDataFilter.h deleted file mode 100644 index 96d66ca..0000000 --- a/lib/fpa/VTK/UniqueVerticesToPolyDataFilter.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__H__ -#define __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__H__ - -#include - -namespace fpa -{ - namespace VTK - { - /** - */ - template< class U, class I > - class UniqueVerticesToPolyDataFilter - : public vtkPolyDataAlgorithm - { - public: - typedef UniqueVerticesToPolyDataFilter Self; - - public: - vtkTypeMacro( UniqueVerticesToPolyDataFilter, vtkPolyDataAlgorithm ); - - public: - static Self* New( ); - - const U* GetInput( ) const; - void SetInput( const U* c ); - - const I* GetImage( ) const; - void SetImage( const I* i ); - - virtual unsigned long GetMTime( ); - - protected: - UniqueVerticesToPolyDataFilter( ); - virtual ~UniqueVerticesToPolyDataFilter( ); - - int RequestData( - vtkInformation* information, - vtkInformationVector** input, - vtkInformationVector* output - ); - int RequestInformation( - vtkInformation* information, - vtkInformationVector** input, - vtkInformationVector* output - ); - - private: - // Purposely not implemented - UniqueVerticesToPolyDataFilter( const Self& ); - void operator=( const Self& ); - - protected: - typename U::ConstPointer m_Container; - typename I::ConstPointer m_Image; - unsigned long m_LastContainerModifiedTime; - }; - - } // ecapseman - -} // ecapseman - -#include - -#endif // __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpa/VTK/UniqueVerticesToPolyDataFilter.hxx b/lib/fpa/VTK/UniqueVerticesToPolyDataFilter.hxx deleted file mode 100644 index c2d2629..0000000 --- a/lib/fpa/VTK/UniqueVerticesToPolyDataFilter.hxx +++ /dev/null @@ -1,186 +0,0 @@ -#ifndef __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__HXX__ -#define __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__HXX__ - -#include -#include - -// ------------------------------------------------------------------------- -template< class U, class I > -typename fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -Self* fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -New( ) -{ - return( new Self( ) ); -} - -// ------------------------------------------------------------------------- -template< class U, class I > -const U* fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -GetInput( ) const -{ - return( this->m_Container ); -} - -// ------------------------------------------------------------------------- -template< class U, class I > -void fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -SetInput( const U* c ) -{ - if( this->m_Container.GetPointer( ) != c ) - { - this->m_Container = c; - this->m_LastContainerModifiedTime = this->m_Container->GetMTime( ); - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -template< class U, class I > -const I* fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -GetImage( ) const -{ - return( this->m_Image ); -} - -// ------------------------------------------------------------------------- -template< class U, class I > -void fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -SetImage( const I* i ) -{ - if( this->m_Image.GetPointer( ) != i ) - { - this->m_Image = i; - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -template< class U, class I > -unsigned long fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -GetMTime( ) -{ - unsigned long ctime = this->m_Container->GetMTime( ); - if( ctime > this->m_LastContainerModifiedTime ) - { - this->m_LastContainerModifiedTime = ctime; - this->Modified( ); - - } // fi - return( this->Superclass::GetMTime( ) ); -} - -// ------------------------------------------------------------------------- -template< class U, class I > -fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -UniqueVerticesToPolyDataFilter( ) - : vtkPolyDataAlgorithm( ) -{ - this->SetNumberOfInputPorts( 0 ); -} - -// ------------------------------------------------------------------------- -template< class U, class I > -fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -~UniqueVerticesToPolyDataFilter( ) -{ -} - -// ------------------------------------------------------------------------- -template< class U, class I > -int fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -RequestData( - vtkInformation* information, - vtkInformationVector** input, - vtkInformationVector* output - ) -{ - if( this->m_Container.IsNull( ) || this->m_Image.IsNull( ) ) - return( 0 ); - - // Get output - vtkInformation* info = output->GetInformationObject( 0 ); - vtkPolyData* out = vtkPolyData::SafeDownCast( - info->Get( vtkDataObject::DATA_OBJECT( ) ) - ); - - // Prepare points - vtkPoints* points = out->GetPoints( ); - if( points == NULL ) - { - points = vtkPoints::New( ); - out->SetPoints( points ); - points->Delete( ); - - } // fi - points->SetNumberOfPoints( this->m_Container->Size( ) ); - - // Prepare cells - vtkSmartPointer< vtkCellArray > cells = - vtkSmartPointer< vtkCellArray >::New( ); - - unsigned int pId = 0; - for( - typename U::ConstIterator it = this->m_Container->Begin( ); - it != this->m_Container->End( ); - ++it, ++pId - ) - { - typename I::PointType pnt; - this->m_Image->TransformIndexToPhysicalPoint( *it, pnt ); - if( I::ImageDimension == 1 ) - points->SetPoint( pId, pnt[ 0 ], 0, 0 ); - else if( I::ImageDimension == 2 ) - points->SetPoint( pId, pnt[ 0 ], pnt[ 1 ], 0 ); - else - points->SetPoint( pId, pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] ); - - cells->InsertNextCell( 1 ); - cells->InsertCellPoint( pId ); - - } // rof - out->SetPoints( points ); - out->SetVerts( cells ); - return( 1 ); -} - -// ------------------------------------------------------------------------- -template< class U, class I > -int fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >:: -RequestInformation( - vtkInformation* information, - vtkInformationVector** input, - vtkInformationVector* output - ) -{ - vtkInformation* info = output->GetInformationObject( 0 ); - /* TODO - info->Set( - vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1 - ); - */ - - if( this->m_Container.IsNotNull( ) && this->m_Image.IsNotNull( ) ) - { - /* TODO - typename C::TScalar len = this->m_RGC->GetTotalLength( ); - typename C::TScalar s0 = this->m_RGC->Gets0( ); - typename C::TPoint p0 = this->m_RGC->Axis( s0 ); - typename C::TPoint p1 = this->m_RGC->Axis( s0 + len ); - - info->Set( - vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ), - double( p0[ 0 ] ), double( p1[ 0 ] ), - double( p0[ 1 ] ), double( p1[ 1 ] ), - double( p0[ 2 ] ), double( p1[ 2 ] ) - ); - */ - - } // fi - return( 1 ); -} - -#endif // __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/AllPixelsImageGrowFunctionSource.cxx b/lib/fpaPlugins/AllPixelsImageGrowFunctionSource.cxx deleted file mode 100644 index 6071ab4..0000000 --- a/lib/fpaPlugins/AllPixelsImageGrowFunctionSource.cxx +++ /dev/null @@ -1,54 +0,0 @@ -#include "AllPixelsImageGrowFunctionSource.h" - -#include -#include -#include -#include - -// ------------------------------------------------------------------------- -fpaPlugins::AllPixelsImageGrowFunctionSource:: -AllPixelsImageGrowFunctionSource( ) - : Superclass( ) -{ - this->_AddInput( "ReferenceImage" ); - this->_AddOutput< GrowFunction >( "Output" ); -} - -// ------------------------------------------------------------------------- -fpaPlugins::AllPixelsImageGrowFunctionSource:: -~AllPixelsImageGrowFunctionSource( ) -{ -} - -// ------------------------------------------------------------------------- -std::string fpaPlugins::AllPixelsImageGrowFunctionSource:: -_GenerateData( ) -{ - auto image = this->GetInputData( "ReferenceImage" ); - itk::DataObject* itk_image = NULL; - std::string r = ""; - cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); - else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 ); - else r = "fpaPlugins::AllPixelsImageGrowFunctionSource: no valid reference image."; - return( r ); -} - -// ------------------------------------------------------------------------- -template< class I > -std::string fpaPlugins::AllPixelsImageGrowFunctionSource:: -_GD0( itk::DataObject* data ) -{ - typedef fpa::Image::Functors::RegionGrowAllBelongsFunction< I > _F; - auto out = this->GetOutputData( "Output" ); - auto f = out->GetITK< _F >( ); - if( f == NULL ) - { - typename _F::Pointer ptr_f = _F::New( ); - f = ptr_f.GetPointer( ); - out->SetITK( f ); - - } // fi - return( "" ); -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/AllPixelsImageGrowFunctionSource.h b/lib/fpaPlugins/AllPixelsImageGrowFunctionSource.h deleted file mode 100644 index de2b56f..0000000 --- a/lib/fpaPlugins/AllPixelsImageGrowFunctionSource.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __FPAPLUGINS__ALLPIXELSIMAGEGROWFUNCTIONSOURCE__H__ -#define __FPAPLUGINS__ALLPIXELSIMAGEGROWFUNCTIONSOURCE__H__ - -#include -#include - -namespace fpaPlugins -{ - /** - */ - class fpaPlugins_EXPORT AllPixelsImageGrowFunctionSource - : public cpPlugins::Interface::ProcessObject - { - public: - typedef AllPixelsImageGrowFunctionSource Self; - typedef cpPlugins::Interface::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( - AllPixelsImageGrowFunctionSource, cpPlugins::Interface::ProcessObject - ); - cpPlugins_Id_Macro( - AllPixelsImageGrowFunctionSource, FrontPropagationFunctors - ); - - protected: - AllPixelsImageGrowFunctionSource( ); - virtual ~AllPixelsImageGrowFunctionSource( ); - - virtual std::string _GenerateData( ); - - template< class I > - std::string _GD0( itk::DataObject* data ); - - private: - // Purposely not implemented. - AllPixelsImageGrowFunctionSource( const Self& other ); - Self& operator=( const Self& other ); - }; - -} // ecapseman - -#endif // __FPAPLUGINS__ALLPIXELSIMAGEGROWFUNCTIONSOURCE__H__ - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/BaseImageFilter.cxx b/lib/fpaPlugins/BaseImageFilter.cxx deleted file mode 100644 index 19a1533..0000000 --- a/lib/fpaPlugins/BaseImageFilter.cxx +++ /dev/null @@ -1,30 +0,0 @@ -#include "BaseImageFilter.h" - -// ------------------------------------------------------------------------- -fpaPlugins::BaseImageFilter:: -BaseImageFilter( ) - : Superclass( ) -{ - this->_AddInput( "Input" ); - this->_AddInput( "Seeds" ); - this->_AddOutput< cpPlugins::Interface::Image >( "Output" ); - - this->m_Parameters->ConfigureAsBool( "VisualDebug" ); - this->m_Parameters->ConfigureAsBool( "StopAtOneFront" ); - this->m_Parameters->SetBool( "VisualDebug", false ); - this->m_Parameters->SetBool( "StopAtOneFront", false ); - - std::vector< std::string > orders; - orders.push_back( "1" ); - orders.push_back( "2" ); - this->m_Parameters->ConfigureAsChoices( "NeighborhoodOrder", orders ); - this->m_Parameters->SetSelectedChoice( "NeighborhoodOrder", "1" ); -} - -// ------------------------------------------------------------------------- -fpaPlugins::BaseImageFilter:: -~BaseImageFilter( ) -{ -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/BaseImageFilter.h b/lib/fpaPlugins/BaseImageFilter.h deleted file mode 100644 index 2deeb5b..0000000 --- a/lib/fpaPlugins/BaseImageFilter.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __FPAPLUGINS__BASEIMAGEFILTER__H__ -#define __FPAPLUGINS__BASEIMAGEFILTER__H__ - -#include -#include - -namespace fpaPlugins -{ - /** - */ - class fpaPlugins_EXPORT BaseImageFilter - : public cpPlugins::Interface::ImageToImageFilter - { - public: - typedef BaseImageFilter Self; - typedef cpPlugins::Interface::ImageToImageFilter Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkTypeMacro( - BaseImageFilter, cpPlugins::Interface::ImageToImageFilter - ); - cpPlugins_Id_Macro( - BaseImageFilter, FrontPropagationImageAlgorithm - ); - - protected: - BaseImageFilter( ); - virtual ~BaseImageFilter( ); - - template< class F > - inline F* _ConfigureFilter( ); - - template< class F > - inline void _ExecuteFilter( F* filter ); - - template< class F > - inline void _ConfigureDebugger( F* filter ); - - template< class F > - inline void _DeconfigureDebugger( F* filter ); - - private: - // Purposely not implemented. - BaseImageFilter( const Self& other ); - Self& operator=( const Self& other ); - - protected: - std::set< unsigned long > m_Observers; - }; - -} // ecapseman - -#include - -#endif // __FPAPLUGINS__BASEIMAGEFILTER__H__ - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/CMakeLists.txt b/lib/fpaPlugins/CMakeLists.txt deleted file mode 100644 index 773b4ff..0000000 --- a/lib/fpaPlugins/CMakeLists.txt +++ /dev/null @@ -1,87 +0,0 @@ -SET(LIBRARY_NAME fpaPlugins) - -## =============== -## = Source code = -## =============== - -SET( - data_LIB_HEADERS - BaseImageFilter.h - GrowFunction.h - GrowFunction.hxx - MinimumSpanningTree.h - MinimumSpanningTree.cxx - ) -SET( - filters_LIB_HEADERS - MinimumSpanningTreeToMesh.h - ExtractBranchesFromMinimumSpanningTree.h - AllPixelsImageGrowFunctionSource.h - ThresholdImageGrowFunctionSource.h - ImageRegionGrow.h - ImageDijkstra.h - ) -SET( - data_LIB_SOURCES - BaseImageFilter.cxx - GrowFunction.cxx - MinimumSpanningTree.cxx - ) -SET( - filters_LIB_SOURCES - MinimumSpanningTreeToMesh.cxx - ExtractBranchesFromMinimumSpanningTree.cxx - AllPixelsImageGrowFunctionSource.cxx - ThresholdImageGrowFunctionSource.cxx - ImageRegionGrow.cxx - ImageDijkstra.cxx - ) -INCLUDE_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/lib/fpaPlugins - ${PROJECT_BINARY_DIR}/lib/fpaPlugins - ) - -## ===================== -## = Compilation rules = -## ===================== - -ADD_CUSTOM_COMMAND( - OUTPUT ${LIBRARY_NAME}_Host.cxx - DEPENDS ${cpPlugins_createHost_APP} ${filters_LIB_HEADERS} - COMMAND ${cpPlugins_createHost_APP} ${LIBRARY_NAME}_Host.cxx fpaPlugins ${filters_LIB_HEADERS} - ) - -ADD_LIBRARY( - ${LIBRARY_NAME} - SHARED - ${LIBRARY_NAME}_Host.cxx - ${data_LIB_SOURCES} - ${filters_LIB_SOURCES} - ) -GENERATE_EXPORT_HEADER( - ${LIBRARY_NAME} - BASE_NAME ${LIBRARY_NAME} - EXPORT_MACRO_NAME ${LIBRARY_NAME}_EXPORT - EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/fpaPlugins/${LIBRARY_NAME}_Export.h - STATIC_DEFINE ${LIBRARY_NAME}_BUILT_AS_STATIC - ) -TARGET_LINK_LIBRARIES( - ${LIBRARY_NAME} - ${ITK_LIBRARIES} - ${VTK_LIBRARIES} - ${cpPlugins_Pluma_LIBRARY} - ${cpPlugins_Interface_LIBRARY} - ) - -## ======================== -## -- Installation rules -- -## ======================== - -INSTALL( - TARGETS ${LIBRARY_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib/static - ) - -## eof - $RCSfile$ diff --git a/lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.cxx b/lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.cxx deleted file mode 100644 index 33980a2..0000000 --- a/lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.cxx +++ /dev/null @@ -1,75 +0,0 @@ -#include "ExtractBranchesFromMinimumSpanningTree.h" - -#include - -#include -#include -#include -#include - -#include -#include - -// ------------------------------------------------------------------------- -fpaPlugins::ExtractBranchesFromMinimumSpanningTree:: -ExtractBranchesFromMinimumSpanningTree( ) - : Superclass( ) -{ - this->_AddInput( "MinimumSpanningTree" ); - this->_AddInput( "EndPoints" ); - this->_AddOutput< cpPlugins::Interface::PolyLineParametricPath >( "Output" ); -} - -// ------------------------------------------------------------------------- -fpaPlugins::ExtractBranchesFromMinimumSpanningTree:: -~ExtractBranchesFromMinimumSpanningTree( ) -{ -} - -// ------------------------------------------------------------------------- -std::string fpaPlugins::ExtractBranchesFromMinimumSpanningTree:: -_GenerateData( ) -{ - std::string err = this->_GD0< 2 >( ); - if( err != "" ) - err = this->_GD0< 3 >( ); - if( err != "" ) - err = this->_GD0< 4 >( ); - return( err ); -} - -// ------------------------------------------------------------------------- -template< unsigned int D > -std::string fpaPlugins::ExtractBranchesFromMinimumSpanningTree:: -_GD0( ) -{ - typedef itk::Index< D > _V; - typedef itk::Functor::IndexLexicographicCompare< D > _VC; - typedef fpa::Base::MinimumSpanningTree< _V, _VC > _MST; - typedef fpa::Base::ExtractBranchesFromMinimumSpanningTree< _MST > _Filter; - typedef cpExtensions::DataStructures::VectorValuesContainer< _V > _CIdx; - - // Get inputs - auto tree = this->GetInputData( "MinimumSpanningTree" )->GetITK< _MST >( ); - if( tree == NULL ) - return( "fpaPlugins::ExtractBranchesFromMinimumSpanningTree: Input MST type not supported." ); - auto endpoints = this->GetInputData( "EndPoints" )->GetITK< _CIdx >( ); - if( endpoints == NULL ) - return( "fpaPlugins::ExtractBranchesFromMinimumSpanningTree: No end-points." ); - if( endpoints->Get( ).size( ) < 2 ) - return( "fpaPlugins::ExtractBranchesFromMinimumSpanningTree: Not enough end-points (<2)." ); - - // Create filter and connect input - _Filter* filter = this->_CreateITK< _Filter >( ); - filter->SetInput( tree ); - for( auto iIt = endpoints->Begin( ); iIt != endpoints->End( ); ++iIt ) - filter->AddEndPoint( *iIt ); - filter->Update( ); - - // Connect output and finish - auto out = this->GetOutputData( "Output" ); - out->SetITK( filter->GetOutput( ) ); - return( "" ); -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.h b/lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.h deleted file mode 100644 index 66f50e4..0000000 --- a/lib/fpaPlugins/ExtractBranchesFromMinimumSpanningTree.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef __FPAPLUGINS__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__H__ -#define __FPAPLUGINS__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__H__ - -#include -#include - -namespace fpaPlugins -{ - /** - */ - class fpaPlugins_EXPORT ExtractBranchesFromMinimumSpanningTree - : public cpPlugins::Interface::ProcessObject - { - public: - typedef ExtractBranchesFromMinimumSpanningTree Self; - typedef cpPlugins::Interface::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( - ExtractBranchesFromMinimumSpanningTree, - cpPlugins::Interface::ProcessObject - ); - cpPlugins_Id_Macro( - ExtractBranchesFromMinimumSpanningTree, - FrontPropagationImageAlgorithm - ); - - protected: - ExtractBranchesFromMinimumSpanningTree( ); - virtual ~ExtractBranchesFromMinimumSpanningTree( ); - - virtual std::string _GenerateData( ); - - template< unsigned int D > - inline std::string _GD0( ); - - private: - // Purposely not implemented. - ExtractBranchesFromMinimumSpanningTree( const Self& other ); - Self& operator=( const Self& other ); - }; - -} // ecapseman - -#endif // __FPAPLUGINS__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__H__ - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/GrowFunction.cxx b/lib/fpaPlugins/GrowFunction.cxx deleted file mode 100644 index 8cc392f..0000000 --- a/lib/fpaPlugins/GrowFunction.cxx +++ /dev/null @@ -1,23 +0,0 @@ -#include - -// ------------------------------------------------------------------------- -void fpaPlugins::GrowFunction:: -SetVTK( vtkObjectBase* o ) -{ - // Do nothing: this has only sense in ITK -} - -// ------------------------------------------------------------------------- -fpaPlugins::GrowFunction:: -GrowFunction( ) - : Superclass( ) -{ -} - -// ------------------------------------------------------------------------- -fpaPlugins::GrowFunction:: -~GrowFunction( ) -{ -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/GrowFunction.h b/lib/fpaPlugins/GrowFunction.h deleted file mode 100644 index 9bcd887..0000000 --- a/lib/fpaPlugins/GrowFunction.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __FPAPLUGINS__GROWFUNCTION__H__ -#define __FPAPLUGINS__GROWFUNCTION__H__ - -#include -#include - -#include - -// ------------------------------------------------------------------------- -namespace fpaPlugins -{ - /** - */ - class fpaPlugins_EXPORT GrowFunction - : public cpPlugins::Interface::DataObject - { - public: - typedef GrowFunction Self; - typedef cpPlugins::Interface::DataObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( GrowFunction, cpPlugins::Interface::DataObject ); - cpPlugins_Id_Macro( GrowFunction, GrowFunction ); - - public: - virtual void SetVTK( vtkObjectBase* o ); - - protected: - GrowFunction( ); - virtual ~GrowFunction( ); - - private: - // Purposely not implemented - GrowFunction( const Self& ); - Self& operator=( const Self& ); - }; - -} // ecapseman - -#include - -#endif // __FPAPLUGINS__GROWFUNCTION__H__ - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/GrowFunction.hxx b/lib/fpaPlugins/GrowFunction.hxx deleted file mode 100644 index a8e84b7..0000000 --- a/lib/fpaPlugins/GrowFunction.hxx +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __FPAPLUGINS__GROWFUNCTION__HXX__ -#define __FPAPLUGINS__GROWFUNCTION__HXX__ - -// TODO: erase this file - -#endif // __FPAPLUGINS__GROWFUNCTION__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/ImageDijkstra.cxx b/lib/fpaPlugins/ImageDijkstra.cxx deleted file mode 100644 index 46ff8d3..0000000 --- a/lib/fpaPlugins/ImageDijkstra.cxx +++ /dev/null @@ -1,64 +0,0 @@ -#include "ImageDijkstra.h" - -#include -#include - -#include -#include - -// ------------------------------------------------------------------------- -fpaPlugins::ImageDijkstra:: -ImageDijkstra( ) - : Superclass( ) -{ - this->_AddOutput< fpaPlugins::MinimumSpanningTree >( "MinimumSpanningTree" ); -} - -// ------------------------------------------------------------------------- -fpaPlugins::ImageDijkstra:: -~ImageDijkstra( ) -{ -} - -// ------------------------------------------------------------------------- -std::string fpaPlugins::ImageDijkstra:: -_GenerateData( ) -{ - auto input = this->GetInputData( "Input" ); - itk::DataObject* image = NULL; - std::string r = ""; - cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 ); - else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 ); - else r = "fpaPlugins::ImageDijkstra: Input image type not supported."; - return( r ); -} - -// ------------------------------------------------------------------------- -template< class I > -std::string fpaPlugins::ImageDijkstra:: -_GD0( itk::DataObject* data ) -{ - typedef typename I::PixelType _TOutPixel; - typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut; - typedef fpa::Image::Dijkstra< I, _TOut > _TFilter; - typedef typename _TFilter::TResult _TCost; - typedef fpa::Base::Functors::InvertCostFunction< _TCost > _TCostFunctor; - typedef typename _TFilter::TMinimumSpanningTree _TMST; - - // Create filter - _TFilter* filter = this->_ConfigureFilter< _TFilter >( ); - - // Connect cost functor - typename _TCostFunctor::Pointer functor = _TCostFunctor::New( ); - filter->SetConversionFunction( functor ); - - // Go!!! - this->_ExecuteFilter( filter ); - - // Connect remaining output - auto mst = this->GetOutputData( "MinimumSpanningTree" ); - mst->SetITK( filter->GetMinimumSpanningTree( ) ); - return( "" ); -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/ImageRegionGrow.cxx b/lib/fpaPlugins/ImageRegionGrow.cxx deleted file mode 100644 index 04b0503..0000000 --- a/lib/fpaPlugins/ImageRegionGrow.cxx +++ /dev/null @@ -1,77 +0,0 @@ -#include "ImageRegionGrow.h" - -#include -#include -#include -#include - -// ------------------------------------------------------------------------- -fpaPlugins::ImageRegionGrow:: -ImageRegionGrow( ) - : Superclass( ) -{ - this->_AddInput( "GrowFunction", false ); - - this->m_Parameters->ConfigureAsReal( "InsideValue" ); - this->m_Parameters->ConfigureAsReal( "OutsideValue" ); - - this->m_Parameters->SetReal( "InsideValue", 1 ); - this->m_Parameters->SetReal( "OutsideValue", 0 ); -} - -// ------------------------------------------------------------------------- -fpaPlugins::ImageRegionGrow:: -~ImageRegionGrow( ) -{ -} - -// ------------------------------------------------------------------------- -std::string fpaPlugins::ImageRegionGrow:: -_GenerateData( ) -{ - auto input = this->GetInputData( "Input" ); - itk::DataObject* image = NULL; - std::string r = ""; - cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 ); - else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 ); - else r = "fpaPlugins::ImageRegionGrow: Input image type not supported."; - return( r ); -} - -// ------------------------------------------------------------------------- -template< class I > -std::string fpaPlugins::ImageRegionGrow:: -_GD0( itk::DataObject* data ) -{ - typedef unsigned char _TOutPixel; - typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut; - typedef fpa::Image::RegionGrow< I, _TOut > _TFilter; - typedef typename _TFilter::TGrowingFunction _TFunctor; - - // Create filter - _TFilter* filter = this->_ConfigureFilter< _TFilter >( ); - - // Connect grow functor (or create a tautology) - typename _TFunctor::Pointer functor; - auto functor_wrapper = this->GetInputData( "GrowFunction" ); - if( functor_wrapper != NULL ) - functor = functor_wrapper->GetITK< _TFunctor >( ); - if( functor.IsNull( ) ) - functor = - fpa::Image::Functors::RegionGrowAllBelongsFunction< I >::New( ); - filter->SetGrowingFunction( functor ); - - // Set numeric parameters - filter->SetInsideValue( - _TOutPixel( this->m_Parameters->GetReal( "InsideValue" ) ) - ); - filter->SetOutsideValue( - _TOutPixel( this->m_Parameters->GetReal( "OutsideValue" ) ) - ); - - // Go!!! - this->_ExecuteFilter( filter ); - return( "" ); -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/MinimumSpanningTree.cxx b/lib/fpaPlugins/MinimumSpanningTree.cxx deleted file mode 100644 index ad561e8..0000000 --- a/lib/fpaPlugins/MinimumSpanningTree.cxx +++ /dev/null @@ -1,23 +0,0 @@ -#include - -// ------------------------------------------------------------------------- -void fpaPlugins::MinimumSpanningTree:: -SetVTK( vtkObjectBase* o ) -{ - // Do nothing: this only has sense in ITK -} - -// ------------------------------------------------------------------------- -fpaPlugins::MinimumSpanningTree:: -MinimumSpanningTree( ) - : Superclass( ) -{ -} - -// ------------------------------------------------------------------------- -fpaPlugins::MinimumSpanningTree:: -~MinimumSpanningTree( ) -{ -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/MinimumSpanningTree.hxx b/lib/fpaPlugins/MinimumSpanningTree.hxx deleted file mode 100644 index ccbda26..0000000 --- a/lib/fpaPlugins/MinimumSpanningTree.hxx +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __FPAPLUGINS__MINIMUMSPANNINGTREE__HXX__ -#define __FPAPLUGINS__MINIMUMSPANNINGTREE__HXX__ - -// TODO: delete this file - -#endif // __FPAPLUGINS__MINIMUMSPANNINGTREE__HXX__ - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/MinimumSpanningTreeToMesh.cxx b/lib/fpaPlugins/MinimumSpanningTreeToMesh.cxx deleted file mode 100644 index 8596bc5..0000000 --- a/lib/fpaPlugins/MinimumSpanningTreeToMesh.cxx +++ /dev/null @@ -1,128 +0,0 @@ -#include "MinimumSpanningTreeToMesh.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -// ------------------------------------------------------------------------- -fpaPlugins::MinimumSpanningTreeToMesh:: -MinimumSpanningTreeToMesh( ) - : Superclass( ) -{ - this->_AddInput( "Input" ); - this->_AddInput( "Seeds" ); - this->_AddInput( "ReferenceImage" ); - this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" ); - - this->m_Parameters->ConfigureAsUint( "Kernel" ); - this->m_Parameters->SetUint( "Kernel", 0 ); -} - -// ------------------------------------------------------------------------- -fpaPlugins::MinimumSpanningTreeToMesh:: -~MinimumSpanningTreeToMesh( ) -{ -} - -// ------------------------------------------------------------------------- -std::string fpaPlugins::MinimumSpanningTreeToMesh:: -_GenerateData( ) -{ - typedef itk::ImageBase< 2 > _2D; - typedef itk::ImageBase< 3 > _3D; - - auto input = this->GetInputData( "ReferenceImage" ); - _2D* im2d = input->GetITK< _2D >( ); - _3D* im3d = input->GetITK< _3D >( ); - if( im2d != NULL ) - return( this->_GD0( im2d ) ); - else if( im3d != NULL ) - return( this->_GD0( im3d ) ); - else - return( "fpaPlugins::MinimumSpanningTreeToMesh: Reference image type not supported." ); -} - -// ------------------------------------------------------------------------- -template< class I > -std::string fpaPlugins::MinimumSpanningTreeToMesh:: -_GD0( I* image ) -{ - /* TODO - typedef typename I::IndexType _V; - typedef typename I::PointType _P; - typedef itk::Functor::IndexLexicographicCompare< I::ImageDimension > _VC; - typedef fpa::Base::MinimumSpanningTree< _V, _VC > _MST; - - // Get inputs - auto mst_wrapper = this->GetInputData( "Input" ); - _MST* mst = mst_wrapper->GetITK< _MST >( ); - if( mst == NULL ) - return( "fpaPlugins::MinimumSpanningTreeToMesh: Input MST type not supported." ); - auto seeds = dynamic_cast< cpPlugins::Interface::PointList* >( - this->GetInputData( "Seeds" ) - ); - if( seeds == NULL ) - return( "fpaPlugins::MinimumSpanningTreeToMesh: Not valid seeds." ); - if( seeds->GetNumberOfPoints( ) < 2 ) - return( "fpaPlugins::MinimumSpanningTreeToMesh: Not enough seeds (<2)." ); - - // Get output - auto out = this->GetOutputData( "Output" ); - vtkSmartPointer< vtkPolyData > pd = out->GetVTK< vtkPolyData >( ); - if( pd.GetPointer( ) == NULL ) - { - pd = vtkPolyData::New( ); - out->SetVTK( pd ); - - } // fi - - _P pa = seeds->GetPoint< _P >( 0 ); - _P pb = seeds->GetPoint< _P >( 1 ); - _V va, vb; - image->TransformPhysicalPointToIndex( pa, va ); - image->TransformPhysicalPointToIndex( pb, vb ); - - std::vector< _P > path = - mst->GetPathFromImage( - va, vb, image, - this->m_Parameters->GetUint( "Kernel" ) - ); - - vtkSmartPointer< vtkPoints > points = - vtkSmartPointer< vtkPoints >::New( ); - vtkSmartPointer< vtkCellArray > array = - vtkSmartPointer< vtkCellArray >::New( ); - for( unsigned int i = 0; i < path.size( ); ++i ) - { - if( I::ImageDimension == 2 ) - points->InsertNextPoint( path[ i ][ 0 ], path[ i ][ 1 ], 0 ); - else if( I::ImageDimension == 3 ) - points->InsertNextPoint( - path[ i ][ 0 ], path[ i ][ 1 ], path[ i ][ 2 ] - ); - else - points->InsertNextPoint( 0, 0, 0 ); - if( i > 0 ) - { - array->InsertNextCell( 2 ); - array->InsertCellPoint( i - 1 ); - array->InsertCellPoint( i ); - - } // fi - - } // rof - pd->SetPoints( points ); - pd->SetLines( array ); - - return( "" ); - */ - return( "Not yet implemented." ); -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/MinimumSpanningTreeToMesh.h b/lib/fpaPlugins/MinimumSpanningTreeToMesh.h deleted file mode 100644 index 28ed24e..0000000 --- a/lib/fpaPlugins/MinimumSpanningTreeToMesh.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __FPAPLUGINS__MINIMUMSPANNINGTREETOMESH__H__ -#define __FPAPLUGINS__MINIMUMSPANNINGTREETOMESH__H__ - -#include -#include - -namespace fpaPlugins -{ - /** - */ - class fpaPlugins_EXPORT MinimumSpanningTreeToMesh - : public cpPlugins::Interface::MeshSource - { - public: - typedef MinimumSpanningTreeToMesh Self; - typedef cpPlugins::Interface::MeshSource Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( - MinimumSpanningTreeToMesh, cpPlugins::Interface::MeshSource - ); - cpPlugins_Id_Macro( - MinimumSpanningTreeToMesh, FrontPropagationImageAlgorithm - ); - - protected: - MinimumSpanningTreeToMesh( ); - virtual ~MinimumSpanningTreeToMesh( ); - - virtual std::string _GenerateData( ); - - template< class I > - std::string _GD0( I* data ); - - private: - // Purposely not implemented. - MinimumSpanningTreeToMesh( const Self& other ); - Self& operator=( const Self& other ); - }; - -} // ecapseman - -#endif // __FPAPLUGINS__MINIMUMSPANNINGTREETOMESH__H__ - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/ThresholdImageGrowFunctionSource.cxx b/lib/fpaPlugins/ThresholdImageGrowFunctionSource.cxx deleted file mode 100644 index e518b6b..0000000 --- a/lib/fpaPlugins/ThresholdImageGrowFunctionSource.cxx +++ /dev/null @@ -1,63 +0,0 @@ -#include "ThresholdImageGrowFunctionSource.h" - -#include -#include -#include -#include - -// ------------------------------------------------------------------------- -fpaPlugins::ThresholdImageGrowFunctionSource:: -ThresholdImageGrowFunctionSource( ) - : Superclass( ) -{ - this->_AddInput( "ReferenceImage" ); - this->_AddOutput< GrowFunction >( "Output" ); - - this->m_Parameters->ConfigureAsReal( "LowerThreshold" ); - this->m_Parameters->ConfigureAsReal( "UpperThreshold" ); - - this->m_Parameters->SetReal( "LowerThreshold", 0 ); - this->m_Parameters->SetReal( "UpperThreshold", 1 ); -} - -// ------------------------------------------------------------------------- -fpaPlugins::ThresholdImageGrowFunctionSource:: -~ThresholdImageGrowFunctionSource( ) -{ -} - -// ------------------------------------------------------------------------- -std::string fpaPlugins::ThresholdImageGrowFunctionSource:: -_GenerateData( ) -{ - auto image = this->GetInputData( "ReferenceImage" ); - itk::DataObject* itk_image = NULL; - std::string r = ""; - cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); - else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 ); - else r = "fpaPlugins::ThresholdImageGrowFunctionSource: no valid reference image."; - return( r ); -} - -// ------------------------------------------------------------------------- -template< class I > -std::string fpaPlugins::ThresholdImageGrowFunctionSource:: -_GD0( itk::DataObject* data ) -{ - typedef fpa::Image::Functors::RegionGrowThresholdFunction< I > _F; - - auto out = this->GetOutputData( "Output" ); - auto f = out->GetITK< _F >( ); - if( f == NULL ) - { - typename _F::Pointer ptr_f = _F::New( ); - f = ptr_f.GetPointer( ); - out->SetITK( f ); - - } // fi - f->SetLowerThreshold( this->m_Parameters->GetReal( "LowerThreshold" ) ); - f->SetUpperThreshold( this->m_Parameters->GetReal( "UpperThreshold" ) ); - return( "" ); -} - -// eof - $RCSfile$ diff --git a/lib/fpaPlugins/ThresholdImageGrowFunctionSource.h b/lib/fpaPlugins/ThresholdImageGrowFunctionSource.h deleted file mode 100644 index 5874127..0000000 --- a/lib/fpaPlugins/ThresholdImageGrowFunctionSource.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __FPAPLUGINS__THRESHOLDIMAGEGROWFUNCTIONSOURCE__H__ -#define __FPAPLUGINS__THRESHOLDIMAGEGROWFUNCTIONSOURCE__H__ - -#include -#include - -namespace fpaPlugins -{ - /** - */ - class fpaPlugins_EXPORT ThresholdImageGrowFunctionSource - : public cpPlugins::Interface::ProcessObject - { - public: - typedef ThresholdImageGrowFunctionSource Self; - typedef cpPlugins::Interface::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( - ThresholdImageGrowFunctionSource, cpPlugins::Interface::ProcessObject - ); - cpPlugins_Id_Macro( - ThresholdImageGrowFunctionSource, FrontPropagationFunctors - ); - - protected: - ThresholdImageGrowFunctionSource( ); - virtual ~ThresholdImageGrowFunctionSource( ); - - virtual std::string _GenerateData( ); - - template< class I > - std::string _GD0( itk::DataObject* data ); - - private: - // Purposely not implemented. - ThresholdImageGrowFunctionSource( const Self& other ); - Self& operator=( const Self& other ); - }; - -} // ecapseman - -#endif // __FPAPLUGINS__THRESHOLDIMAGEGROWFUNCTIONSOURCE__H__ - -// eof - $RCSfile$ diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 0000000..df80a25 --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,5 @@ +SUBDIRS( + fpa + ) + +## eof - $RCSfile$ diff --git a/plugins/fpa/BaseImageFilter.cxx b/plugins/fpa/BaseImageFilter.cxx new file mode 100644 index 0000000..d56c894 --- /dev/null +++ b/plugins/fpa/BaseImageFilter.cxx @@ -0,0 +1,48 @@ +#include "BaseImageFilter.h" + +// ------------------------------------------------------------------------- +bool fpaPlugins::BaseImageFilter:: +IsInteractive( ) +{ + return( true ); +} + +// ------------------------------------------------------------------------- +void fpaPlugins::BaseImageFilter:: +SetInteractionObjects( const std::vector< void* >& objs ) +{ + if( objs.size( ) > 0 ) + this->m_SingleInteractor = + reinterpret_cast< vtkRenderWindowInteractor* >( objs[ 0 ] ); + if( objs.size( ) > 1 ) + this->m_MPRViewer = reinterpret_cast< TMPRWidget* >( objs[ 1 ] ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::BaseImageFilter:: +BaseImageFilter( ) + : Superclass( ) +{ + this->_AddInput( "Input" ); + this->_AddInput( "Seeds" ); + this->_AddOutput< cpPlugins::Image >( "Output" ); + + this->m_Parameters.ConfigureAsBool( "VisualDebug" ); + this->m_Parameters.ConfigureAsBool( "StopAtOneFront" ); + this->m_Parameters.SetBool( "VisualDebug", false ); + this->m_Parameters.SetBool( "StopAtOneFront", false ); + + std::vector< std::string > orders; + orders.push_back( "1" ); + orders.push_back( "2" ); + this->m_Parameters.ConfigureAsChoices( "NeighborhoodOrder", orders ); + this->m_Parameters.SetSelectedChoice( "NeighborhoodOrder", "1" ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::BaseImageFilter:: +~BaseImageFilter( ) +{ +} + +// eof - $RCSfile$ diff --git a/plugins/fpa/BaseImageFilter.h b/plugins/fpa/BaseImageFilter.h new file mode 100644 index 0000000..2b7e6a3 --- /dev/null +++ b/plugins/fpa/BaseImageFilter.h @@ -0,0 +1,68 @@ +#ifndef __FPAPLUGINS__BASEIMAGEFILTER__H__ +#define __FPAPLUGINS__BASEIMAGEFILTER__H__ + +#include +#include + +#include +#include + +namespace fpaPlugins +{ + /** + */ + class fpaPlugins_EXPORT BaseImageFilter + : public cpPlugins::ProcessObject + { + public: + typedef BaseImageFilter Self; + typedef cpPlugins::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef cpExtensions::QT::SimpleMPRWidget TMPRWidget; + + public: + itkTypeMacro( BaseImageFilter, cpPlugins::ProcessObject ); + cpPlugins_Id_Macro( BaseImageFilter, fpaImageAlgorithm ); + + public: + virtual bool IsInteractive( ) override; + virtual void SetInteractionObjects( + const std::vector< void* >& objs + ) override; + + protected: + BaseImageFilter( ); + virtual ~BaseImageFilter( ); + + template< class _TFilter > + inline _TFilter* _ConfigureFilter( ); + + template< class _TFilter > + inline void _ExecuteFilter( _TFilter* filter ); + + template< class _TFilter > + inline void _ConfigureDebugger( _TFilter* filter ); + + template< class _TFilter > + inline void _DeconfigureDebugger( _TFilter* filter ); + + private: + // Purposely not implemented. + BaseImageFilter( const Self& other ); + Self& operator=( const Self& other ); + + protected: + TMPRWidget* m_MPRViewer; + vtkRenderWindowInteractor* m_SingleInteractor; + std::set< unsigned long > m_Observers; + }; + +} // ecapseman + +#include "BaseImageFilter.hxx" + +#endif // __FPAPLUGINS__BASEIMAGEFILTER__H__ + +// eof - $RCSfile$ diff --git a/lib/fpaPlugins/BaseImageFilter.hxx b/plugins/fpa/BaseImageFilter.hxx similarity index 59% rename from lib/fpaPlugins/BaseImageFilter.hxx rename to plugins/fpa/BaseImageFilter.hxx index 4c27afd..9d99f47 100644 --- a/lib/fpaPlugins/BaseImageFilter.hxx +++ b/plugins/fpa/BaseImageFilter.hxx @@ -1,58 +1,64 @@ #ifndef __FPAPLUGINS__BASEIMAGEFILTER__HXX__ #define __FPAPLUGINS__BASEIMAGEFILTER__HXX__ -#include -#include -#include -#include - +#include #include #include - #include +#include +#include + // ------------------------------------------------------------------------- -template< class F > -F* fpaPlugins::BaseImageFilter:: +template< class _TFilter > +_TFilter* fpaPlugins::BaseImageFilter:: _ConfigureFilter( ) { - typedef typename F::TInputImage _I; - typedef itk::Point< double, _I::ImageDimension > _Pnt; - typedef typename _I::IndexType _Idx; - typedef cpExtensions::DataStructures::VectorValuesContainer< _Pnt > _CPnt; - typedef cpExtensions::DataStructures::VectorValuesContainer< _Idx > _CIdx; - - auto image = this->GetInputData( "Input" )->GetITK< _I >( ); - auto seeds = this->GetInputData( "Seeds" ); - auto p_seeds = seeds->GetITK< _CPnt >( ); - auto i_seeds = seeds->GetITK< _CIdx >( ); + typedef typename _TFilter::TInputImage _TImage; + typedef typename _TImage::IndexType _TIndex; + typedef itk::Point< double, _TImage::ImageDimension > _TPoint; + typedef itk::SimpleDataObjectDecorator< std::vector< _TPoint > > _TPoints; + typedef itk::SimpleDataObjectDecorator< std::vector< _TIndex > > _TIndexes; + + auto image = this->GetInputData( "Input" )->GetITK< _TImage >( ); + if( image == NULL ) + return( NULL ); + auto points = this->GetInputData( "Seeds" )->GetITK< _TPoints >( ); + auto indexes = this->GetInputData( "Seeds" )->GetITK< _TIndexes >( ); // Create filter and connect input - F* filter = this->_CreateITK< F >( ); + auto filter = this->_CreateITK< _TFilter >( ); filter->SetInput( image ); // Set numeric parameters - Superclass::TParameters* params = this->m_Parameters; filter->SetNeighborhoodOrder( - params->GetSelectedChoice( "NeighborhoodOrder" )[ 0 ] - '0' + this->m_Parameters.GetSelectedChoice( "NeighborhoodOrder" )[ 0 ] - '0' ); - filter->SetStopAtOneFront( params->GetBool( "StopAtOneFront" ) ); + filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) ); // Assign seeds filter->ClearSeeds( ); - if( p_seeds != NULL ) + if( points != NULL ) { - for( auto pIt = p_seeds->Begin( ); pIt != p_seeds->End( ); ++pIt ) + for( + auto pIt = points->Get( ).begin( ); + pIt != points->Get( ).end( ); + ++pIt + ) { - _Idx idx; + _TIndex idx; if( image->TransformPhysicalPointToIndex( *pIt, idx ) ) filter->AddSeed( idx, 0 ); } // rof } - else if( i_seeds != NULL ) + else if( indexes != NULL ) { - for( auto iIt = i_seeds->Begin( ); iIt != i_seeds->End( ); ++iIt ) + for( + auto iIt = indexes->Get( ).begin( ); + iIt != indexes->Get( ).end( ); + ++iIt + ) filter->AddSeed( *iIt, 0 ); } // fi @@ -62,9 +68,9 @@ _ConfigureFilter( ) } // ------------------------------------------------------------------------- -template< class F > +template< class _TFilter > void fpaPlugins::BaseImageFilter:: -_ExecuteFilter( F* filter ) +_ExecuteFilter( _TFilter* filter ) { // Go!!! this->_ConfigureDebugger( filter ); @@ -77,20 +83,20 @@ _ExecuteFilter( F* filter ) } // ------------------------------------------------------------------------- -template< class F > +template< class _TFilter > void fpaPlugins::BaseImageFilter:: -_ConfigureDebugger( F* filter ) +_ConfigureDebugger( _TFilter* filter ) { - typedef typename F::TInputImage _I; - typedef fpa::VTK::Image2DObserver< F, vtkRenderWindow > _2D; - typedef fpa::VTK::Image3DObserver< F, vtkRenderWindow > _3D; + typedef typename _TFilter::TInputImage _TImage; + typedef fpa::VTK::Image2DObserver< _TFilter, vtkRenderWindow > _2D; + typedef fpa::VTK::Image3DObserver< _TFilter, vtkRenderWindow > _3D; this->m_Observers.clear( ); - if( this->m_Parameters->GetBool( "VisualDebug" ) ) + if( this->m_Parameters.GetBool( "VisualDebug" ) ) { if( this->m_MPRViewer != NULL ) { - if( _I::ImageDimension == 2 ) + if( _TImage::ImageDimension == 2 ) { auto iren = this->m_MPRViewer->GetInteractor( 2 ); if( iren != NULL ) @@ -105,7 +111,7 @@ _ConfigureDebugger( F* filter ) } // fi } - else if( _I::ImageDimension == 3 ) + else if( _TImage::ImageDimension == 3 ) { auto iren = this->m_MPRViewer->GetInteractor( 3 ); if( iren != NULL ) @@ -126,10 +132,10 @@ _ConfigureDebugger( F* filter ) if( this->m_SingleInteractor != NULL ) { - if( _I::ImageDimension == 2 ) + if( _TImage::ImageDimension == 2 ) { } - else if( _I::ImageDimension == 3 ) + else if( _TImage::ImageDimension == 3 ) { } // fi diff --git a/plugins/fpa/CMakeLists.txt b/plugins/fpa/CMakeLists.txt new file mode 100644 index 0000000..9196099 --- /dev/null +++ b/plugins/fpa/CMakeLists.txt @@ -0,0 +1,103 @@ +SET(lib_NAME fpaPlugins) +SET(lib_DIR fpa) + +## =============== +## = Source code = +## =============== + +SET( + base_HEADERS_H + ${CMAKE_CURRENT_SOURCE_DIR}/BaseImageFilter.h + ${CMAKE_CURRENT_SOURCE_DIR}/MinimumSpanningTree.h + ) + +SET( + filters_HEADERS_H + ${CMAKE_CURRENT_SOURCE_DIR}/MinimumSpanningTreeReader.h + ${CMAKE_CURRENT_SOURCE_DIR}/MinimumSpanningTreeWriter.h + ${CMAKE_CURRENT_SOURCE_DIR}/ImageRegionGrow.h + ${CMAKE_CURRENT_SOURCE_DIR}/ImageDijkstra.h + ${CMAKE_CURRENT_SOURCE_DIR}/ExtractPathFromMinimumSpanningTree.h + ${CMAKE_CURRENT_SOURCE_DIR}/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h + ${CMAKE_CURRENT_SOURCE_DIR}/RegionGrowThresholdFunction.h + ${CMAKE_CURRENT_SOURCE_DIR}/InvertCostFunction.h + ) + +SET( + base_HEADERS_HXX + ${CMAKE_CURRENT_SOURCE_DIR}/BaseImageFilter.hxx + ) + +SET( + base_SOURCES_CXX + ${CMAKE_CURRENT_SOURCE_DIR}/BaseImageFilter.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/MinimumSpanningTree.cxx + ) + +SET( + filters_SOURCES_CXX + ${CMAKE_CURRENT_SOURCE_DIR}/MinimumSpanningTreeReader.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/MinimumSpanningTreeWriter.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/ImageRegionGrow.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/ImageDijkstra.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/ExtractPathFromMinimumSpanningTree.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/RegionGrowThresholdFunction.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/InvertCostFunction.cxx + ) + +SET( + target_LIBRARIES + ${cpExtensions_LIBRARY} + ${cpPlugins_LIBRARY} + cpPlugins_ITKInstances_Base + cpPlugins_ITKInstances_Image + cpPlugins_ITKInstances_ImageIterators + cpPlugins_ITKInstances_ImageFilters + cpPlugins_ITKInstances_Mesh + cpPlugins_ITKInstances_Paths + ${ITK_LIBRARIES} + ) + +## ===================== +## = Compilation rules = +## ===================== + +ADD_CUSTOM_COMMAND( + OUTPUT ${lib_NAME}_Host.cxx + DEPENDS ${cpPlugins_HostCreator_APP} ${filters_HEADERS_H} + COMMAND ${cpPlugins_HostCreator_APP} ${lib_NAME}_Host.cxx ${filters_HEADERS_H} + ) +ADD_LIBRARY( + ${lib_NAME} + SHARED + ${lib_NAME}_Host.cxx + ${base_SOURCES_CXX} + ${filters_SOURCES_CXX} + ) +SET_TARGET_PROPERTIES( + ${lib_NAME} PROPERTIES + VERSION "${prj_VER}" + SOVERSION "${prj_sVER}" + ) +GENERATE_EXPORT_HEADER( + ${lib_NAME} + BASE_NAME ${lib_NAME} + EXPORT_MACRO_NAME ${lib_NAME}_EXPORT + EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/plugins/${lib_DIR}/${lib_NAME}_Export.h + STATIC_DEFINE ${lib_NAME}_BUILT_AS_STATIC + ) +TARGET_LINK_LIBRARIES(${lib_NAME} ${target_LIBRARIES}) + +## ======================== +## -- Installation rules -- +## ======================== + +INSTALL( + TARGETS ${lib_NAME} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static + ) + +## eof - $RCSfile$ diff --git a/plugins/fpa/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.cxx b/plugins/fpa/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.cxx new file mode 100644 index 0000000..997fa49 --- /dev/null +++ b/plugins/fpa/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.cxx @@ -0,0 +1,83 @@ +#include "ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h" +#include "MinimumSpanningTree.h" + +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree:: +ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ) + : Superclass( ) +{ + this->_AddInput( "CostsImage" ); + this->_AddInput( "DistanceMap" ); + this->_AddInput( "MST" ); + this->_AddOutput< cpPlugins::DataObject >( "EndPoints" ); + this->_AddOutput< cpPlugins::DataObject >( "Bifurcations" ); + this->_AddOutput< cpPlugins::DataObject >( "Collisions" ); + + this->m_Parameters.ConfigureAsBool( "SquaredDistanceMap" ); + this->m_Parameters.SetBool( "SquaredDistanceMap", false ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree:: +~ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ) +{ +} + +// ------------------------------------------------------------------------- +std::string fpaPlugins::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree:: +_GenerateData( ) +{ + auto image = this->GetInputData( "CostsImage" )->GetITK< itk::DataObject >( ); + std::string r = cpPlugin_Image_Demangle_Pixel_Dim( _GD0, image, float, 2 ); + if( r != "" ) r = cpPlugin_Image_Demangle_Pixel_Dim( _GD0, image, double, 2 ); + if( r != "" ) r = cpPlugin_Image_Demangle_Pixel_Dim( _GD0, image, float, 3 ); + if( r != "" ) r = cpPlugin_Image_Demangle_Pixel_Dim( _GD0, image, double, 3 ); + return( r ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +std::string fpaPlugins::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree:: +_GD0( _TImage* image ) +{ + typedef fpa::Image::MinimumSpanningTree< _TImage::ImageDimension > _TMST; + typedef fpa::Image::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree< _TImage, _TMST > _TFilter; + + // Check input objects' integrity + if( image == NULL ) + return( + "fpaPlugins::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree: No valid input costs image." + ); + auto dmap = this->GetInputData( "DistanceMap" )->GetITK< _TImage >( ); + if( dmap == NULL ) + return( + "fpaPlugins::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree: Distance map does not have the same type as the costs image." + ); + auto mst = this->GetInputData( "MST" )->GetITK< _TMST >( ); + if( mst == NULL ) + return( + "fpaPlugins::ExtractEndPointsAndBifurcationsFromMinimumSpanningTree: No valid input tree." + ); + + // Create filter and connect inputs + _TFilter* filter = this->_CreateITK< _TFilter >( ); + filter->SetCostsImage( image ); + filter->SetDistanceMap( dmap ); + filter->SetMinimumSpanningTree( mst ); + filter->SetSquaredDistanceMap( + this->m_Parameters.GetBool( "SquaredDistanceMap" ) + ); + filter->Update( ); + + this->GetOutputData( "EndPoints" )->SetITK( filter->GetEndPoints( ) ); + this->GetOutputData( "Bifurcations" )->SetITK( filter->GetBifurcations( ) ); + this->GetOutputData( "Collisions" )->SetITK( filter->GetCollisions( ) ); + return( "" ); +} + +// eof - $RCSfile$ diff --git a/plugins/fpa/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h b/plugins/fpa/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h new file mode 100644 index 0000000..8e32467 --- /dev/null +++ b/plugins/fpa/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.h @@ -0,0 +1,50 @@ +#ifndef __FPAPLUGINS__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ +#define __FPAPLUGINS__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ + +#include +#include + +namespace fpaPlugins +{ + /** + */ + class fpaPlugins_EXPORT ExtractEndPointsAndBifurcationsFromMinimumSpanningTree + : public cpPlugins::ProcessObject + { + public: + typedef ExtractEndPointsAndBifurcationsFromMinimumSpanningTree Self; + typedef cpPlugins::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree, + cpPlugins::ProcessObject + ); + cpPlugins_Id_Macro( + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree, + fpaImageAlgorithm + ); + + protected: + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ); + virtual ~ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( ); + + virtual std::string _GenerateData( ); + + template< class _TImage > + inline std::string _GD0( _TImage* image ); + + private: + // Purposely not implemented. + ExtractEndPointsAndBifurcationsFromMinimumSpanningTree( const Self& other ); + Self& operator=( const Self& other ); + }; + +} // ecapseman + +#endif // __FPAPLUGINS__EXTRACTENDPOINTSANDBIFURCATIONSFROMMINIMUMSPANNINGTREE__H__ + +// eof - $RCSfile$ diff --git a/plugins/fpa/ExtractPathFromMinimumSpanningTree.cxx b/plugins/fpa/ExtractPathFromMinimumSpanningTree.cxx new file mode 100644 index 0000000..6a2aef5 --- /dev/null +++ b/plugins/fpa/ExtractPathFromMinimumSpanningTree.cxx @@ -0,0 +1,83 @@ +#include "ExtractPathFromMinimumSpanningTree.h" +#include "MinimumSpanningTree.h" + +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins::ExtractPathFromMinimumSpanningTree:: +ExtractPathFromMinimumSpanningTree( ) + : Superclass( ) +{ + this->_AddInput( "MST" ); + this->_AddInput( "Seeds" ); + this->_AddOutput< cpPlugins::DataObject >( "Output" ); + + this->m_Parameters.ConfigureAsUint( "Vertex0" ); + this->m_Parameters.ConfigureAsUint( "Vertex1" ); + this->m_Parameters.SetUint( "Vertex0", 0 ); + this->m_Parameters.SetUint( "Vertex1", 1 ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::ExtractPathFromMinimumSpanningTree:: +~ExtractPathFromMinimumSpanningTree( ) +{ +} + +// ------------------------------------------------------------------------- +std::string fpaPlugins::ExtractPathFromMinimumSpanningTree:: +_GenerateData( ) +{ + typedef fpa::Image::MinimumSpanningTree< 2 > _2DMST; + typedef fpa::Image::MinimumSpanningTree< 3 > _3DMST; + + auto mst = this->GetInputData( "MST" )->GetITK< itk::DataObject >( ); + auto mst2 = dynamic_cast< _2DMST* >( mst ); + auto mst3 = dynamic_cast< _3DMST* >( mst ); + std::string r = this->_GD0( mst2 ); + if( r != "" ) r = this->_GD0( mst3 ); + return( r ); +} + +// ------------------------------------------------------------------------- +template< class _TMST > +std::string fpaPlugins::ExtractPathFromMinimumSpanningTree:: +_GD0( _TMST* mst ) +{ + typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST > _TFilter; + typedef typename _TMST::TVertex _TVertex; + typedef itk::SimpleDataObjectDecorator< std::vector< _TVertex > > _TVertices; + if( mst == NULL ) + return( + "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid input tree." + ); + auto vertices = this->GetInputData( "Seeds" )->GetITK< _TVertices >( ); + if( vertices == NULL ) + return( + "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid vertices." + ); + if( vertices->Get( ).size( ) < 2 ) + return( + "fpaPlugins::ExtractPathFromMinimumSpanningTree: Not enough vertices." + ); + auto v0 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex0" ) ]; + auto v1 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex1" ) ]; + + // Create filter and connect input + _TFilter* filter = this->_CreateITK< _TFilter >( ); + filter->SetInput( mst ); + filter->SetVertex0( v0 ); + filter->SetVertex1( v1 ); + filter->Update( ); + + // Connect output and finish + this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) ); + return( "" ); +} + +// eof - $RCSfile$ diff --git a/plugins/fpa/ExtractPathFromMinimumSpanningTree.h b/plugins/fpa/ExtractPathFromMinimumSpanningTree.h new file mode 100644 index 0000000..313f67e --- /dev/null +++ b/plugins/fpa/ExtractPathFromMinimumSpanningTree.h @@ -0,0 +1,48 @@ +#ifndef __FPAPLUGINS__EXTRACTPATHFROMMINIMUMSPANNINGTREE__H__ +#define __FPAPLUGINS__EXTRACTPATHFROMMINIMUMSPANNINGTREE__H__ + +#include +#include + +namespace fpaPlugins +{ + /** + */ + class fpaPlugins_EXPORT ExtractPathFromMinimumSpanningTree + : public cpPlugins::ProcessObject + { + public: + typedef ExtractPathFromMinimumSpanningTree Self; + typedef cpPlugins::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( + ExtractPathFromMinimumSpanningTree, cpPlugins::ProcessObject + ); + cpPlugins_Id_Macro( + ExtractPathFromMinimumSpanningTree, fpaBaseAlgorithm + ); + + protected: + ExtractPathFromMinimumSpanningTree( ); + virtual ~ExtractPathFromMinimumSpanningTree( ); + + virtual std::string _GenerateData( ); + + template< class _TMST > + inline std::string _GD0( _TMST* mst ); + + private: + // Purposely not implemented. + ExtractPathFromMinimumSpanningTree( const Self& other ); + Self& operator=( const Self& other ); + }; + +} // ecapseman + +#endif // __FPAPLUGINS__EXTRACTPATHFROMMINIMUMSPANNINGTREE__H__ + +// eof - $RCSfile$ diff --git a/plugins/fpa/ImageDijkstra.cxx b/plugins/fpa/ImageDijkstra.cxx new file mode 100644 index 0000000..44f5822 --- /dev/null +++ b/plugins/fpa/ImageDijkstra.cxx @@ -0,0 +1,77 @@ +#include "ImageDijkstra.h" +#include "MinimumSpanningTree.h" + +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins::ImageDijkstra:: +ImageDijkstra( ) + : Superclass( ) +{ + this->_AddInput( "CostFunctor", false ); + this->_AddOutput< fpaPlugins::MinimumSpanningTree >( "MST" ); + this->m_Parameters.ConfigureAsBool( "FillNodeQueue" ); + this->m_Parameters.SetBool( "FillNodeQueue", false ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::ImageDijkstra:: +~ImageDijkstra( ) +{ +} + +// ------------------------------------------------------------------------- +std::string fpaPlugins::ImageDijkstra:: +_GenerateData( ) +{ + auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( ); + std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 ); + if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 ); + return( r ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +std::string fpaPlugins::ImageDijkstra:: +_GD0( _TImage* image ) +{ + typedef fpa::Image::Dijkstra< _TImage, _TImage > _TFilter; + typedef typename _TFilter::TResult _TCost; + typedef itk::FunctionBase< _TCost, _TCost > _TCostFunctor; + typedef typename _TFilter::TMinimumSpanningTree _TMST; + + if( image == NULL ) + return( "fpaPlugins::ImageDijkstra: Invalid image type." ); + + auto base_functor = + this->GetInputData( "CostFunctor" )->GetITK< itk::LightObject >( ); + _TCostFunctor* functor = NULL; + if( base_functor != NULL ) + { + functor = dynamic_cast< _TCostFunctor* >( base_functor ); + if( functor == NULL ) + return( "fpaPlugins::ImageDijkstra: Given cost functor is invalid." ); + + } // fi + + // Create filter + _TFilter* filter = this->_ConfigureFilter< _TFilter >( ); + filter->SetFillNodeQueue( this->m_Parameters.GetBool( "FillNodeQueue" ) ); + filter->SetConversionFunction( functor ); + + // Go!!! + this->_ExecuteFilter( filter ); + + // Connect remaining output + this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) ); + this->GetOutputData( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) ); + return( "" ); +} + +// eof - $RCSfile$ diff --git a/lib/fpaPlugins/ImageDijkstra.h b/plugins/fpa/ImageDijkstra.h similarity index 84% rename from lib/fpaPlugins/ImageDijkstra.h rename to plugins/fpa/ImageDijkstra.h index 845b8f4..bc34724 100644 --- a/lib/fpaPlugins/ImageDijkstra.h +++ b/plugins/fpa/ImageDijkstra.h @@ -19,9 +19,7 @@ namespace fpaPlugins public: itkNewMacro( Self ); itkTypeMacro( ImageDijkstra, BaseImageFilter ); - cpPlugins_Id_Macro( - ImageDijkstra, FrontPropagationImageAlgorithm - ); + cpPlugins_Id_Macro( ImageDijkstra, fpaImageAlgorithm ); protected: ImageDijkstra( ); @@ -29,8 +27,8 @@ namespace fpaPlugins virtual std::string _GenerateData( ); - template< class I > - std::string _GD0( itk::DataObject* data ); + template< class _TImage > + std::string _GD0( _TImage* image ); private: // Purposely not implemented. diff --git a/plugins/fpa/ImageRegionGrow.cxx b/plugins/fpa/ImageRegionGrow.cxx new file mode 100644 index 0000000..a988c63 --- /dev/null +++ b/plugins/fpa/ImageRegionGrow.cxx @@ -0,0 +1,78 @@ +#include "ImageRegionGrow.h" + +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins::ImageRegionGrow:: +ImageRegionGrow( ) + : Superclass( ) +{ + this->_AddInput( "GrowFunctor", false ); + this->m_Parameters.ConfigureAsUint( "InsideValue" ); + this->m_Parameters.ConfigureAsUint( "OutsideValue" ); + this->m_Parameters.SetUint( "InsideValue", 1 ); + this->m_Parameters.SetUint( "OutsideValue", 0 ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::ImageRegionGrow:: +~ImageRegionGrow( ) +{ +} + +// ------------------------------------------------------------------------- +std::string fpaPlugins::ImageRegionGrow:: +_GenerateData( ) +{ + auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( ); + std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 ); + if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 ); + return( r ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +std::string fpaPlugins::ImageRegionGrow:: +_GD0( _TImage* image ) +{ + typedef fpa::Image::RegionGrow< _TImage, _TImage > _TFilter; + typedef typename _TFilter::TGrowingFunction _TGrowFunctor; + typedef typename _TFilter::TResult _TResult; + + if( image == NULL ) + return( "fpaPlugins::ImageRegionGrow: Invalid image type." ); + + // Get functor (if any) + typename _TGrowFunctor::Pointer functor; + auto wrap_functor = this->GetInputData( "GrowFunctor" ); + if( wrap_functor != NULL ) + functor = wrap_functor->GetITK< _TGrowFunctor >( ); + if( functor.IsNull( ) ) + functor = + fpa::Image::Functors::RegionGrowAllBelongsFunction< _TImage >::New( ); + + // Create filter + _TFilter* filter = this->_ConfigureFilter< _TFilter >( ); + filter->SetGrowingFunction( functor ); + filter->SetInsideValue( + _TResult( this->m_Parameters.GetUint( "InsideValue" ) ) + ); + filter->SetOutsideValue( + _TResult( this->m_Parameters.GetUint( "OutsideValue" ) ) + ); + + // Go!!! + this->_ExecuteFilter( filter ); + + // Connect remaining output + this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) ); + return( "" ); +} + +// eof - $RCSfile$ diff --git a/lib/fpaPlugins/ImageRegionGrow.h b/plugins/fpa/ImageRegionGrow.h similarity index 79% rename from lib/fpaPlugins/ImageRegionGrow.h rename to plugins/fpa/ImageRegionGrow.h index 46fa592..6c680fb 100644 --- a/lib/fpaPlugins/ImageRegionGrow.h +++ b/plugins/fpa/ImageRegionGrow.h @@ -11,7 +11,7 @@ namespace fpaPlugins : public BaseImageFilter { public: - typedef ImageRegionGrow Self; + typedef ImageRegionGrow Self; typedef BaseImageFilter Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; @@ -19,9 +19,7 @@ namespace fpaPlugins public: itkNewMacro( Self ); itkTypeMacro( ImageRegionGrow, BaseImageFilter ); - cpPlugins_Id_Macro( - ImageRegionGrow, FrontPropagationImageAlgorithm - ); + cpPlugins_Id_Macro( ImageRegionGrow, fpaImageAlgorithm ); protected: ImageRegionGrow( ); @@ -29,8 +27,8 @@ namespace fpaPlugins virtual std::string _GenerateData( ); - template< class I > - std::string _GD0( itk::DataObject* data ); + template< class _TImage > + std::string _GD0( _TImage* image ); private: // Purposely not implemented. diff --git a/plugins/fpa/InvertCostFunction.cxx b/plugins/fpa/InvertCostFunction.cxx new file mode 100644 index 0000000..82631ef --- /dev/null +++ b/plugins/fpa/InvertCostFunction.cxx @@ -0,0 +1,63 @@ +#include "InvertCostFunction.h" + +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins::InvertCostFunction:: +InvertCostFunction( ) + : Superclass( ) +{ + this->_AddOutput< cpPlugins::DataObject >( "Output" ); + + this->m_Parameters.ConfigureAsReal( "Alpha" ); + this->m_Parameters.ConfigureAsReal( "Beta" ); + + std::vector< std::string > choices; + choices.push_back( "float" ); + choices.push_back( "double" ); + this->m_Parameters.ConfigureAsChoices( "ScalarType", choices ); + + this->m_Parameters.SetReal( "Alpha", 1 ); + this->m_Parameters.SetReal( "Beta", 1 ); + this->m_Parameters.SetSelectedChoice( "ScalarType", "float" ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::InvertCostFunction:: +~InvertCostFunction( ) +{ +} + +// ------------------------------------------------------------------------- +std::string fpaPlugins::InvertCostFunction:: +_GenerateData( ) +{ + auto choice = this->m_Parameters.GetSelectedChoice( "ScalarType" ); + if ( choice == "float" ) return( this->_GD0< float >( ) ); + else if( choice == "double" ) return( this->_GD0< double >( ) ); + else + return( "fpaPlugins::InvertCostFunction: invalid scalar type." ); +} + +// ------------------------------------------------------------------------- +template< class _TScalar > +std::string fpaPlugins::InvertCostFunction:: +_GD0( ) +{ + typedef fpa::Base::Functors::InvertCostFunction< _TScalar > _TFunctor; + auto out = this->GetOutputData( "Output" ); + auto f = out->GetITK< _TFunctor >( ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + out->SetITK( f ); + + } // fi + f->SetAlpha( this->m_Parameters.GetReal( "Alpha" ) ); + f->SetBeta( this->m_Parameters.GetReal( "Beta" ) ); + return( "" ); +} + +// eof - $RCSfile$ diff --git a/plugins/fpa/InvertCostFunction.h b/plugins/fpa/InvertCostFunction.h new file mode 100644 index 0000000..a0a9c90 --- /dev/null +++ b/plugins/fpa/InvertCostFunction.h @@ -0,0 +1,44 @@ +#ifndef __FPAPLUGINS__INVERTCOSTFUNCTION__H__ +#define __FPAPLUGINS__INVERTCOSTFUNCTION__H__ + +#include +#include + +namespace fpaPlugins +{ + /** + */ + class fpaPlugins_EXPORT InvertCostFunction + : public cpPlugins::ProcessObject + { + public: + typedef InvertCostFunction Self; + typedef cpPlugins::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( InvertCostFunction, cpPlugins::ProcessObject ); + cpPlugins_Id_Macro( InvertCostFunction, fpaImageAlgorithmFunctors ); + + protected: + InvertCostFunction( ); + virtual ~InvertCostFunction( ); + + virtual std::string _GenerateData( ); + + template< class _TScalar > + std::string _GD0( ); + + private: + // Purposely not implemented. + InvertCostFunction( const Self& other ); + Self& operator=( const Self& other ); + }; + +} // ecapseman + +#endif // __FPAPLUGINS__INVERTCOSTFUNCTION__H__ + +// eof - $RCSfile$ diff --git a/plugins/fpa/MinimumSpanningTree.cxx b/plugins/fpa/MinimumSpanningTree.cxx new file mode 100644 index 0000000..4ad07f3 --- /dev/null +++ b/plugins/fpa/MinimumSpanningTree.cxx @@ -0,0 +1,76 @@ +#include + +// ------------------------------------------------------------------------- +void fpaPlugins::MinimumSpanningTree:: +SetITK( itk::LightObject* o ) +{ + typedef fpa::Image::MinimumSpanningTree< 2 > _I2; + typedef fpa::Image::MinimumSpanningTree< 3 > _I3; + + bool r = this->_SetITK< _I2 >( o ); + if( !r ) r = this->_SetITK< _I3 >( o ); + if( !r ) + this->Superclass::SetITK( NULL ); +} + +// ------------------------------------------------------------------------- +void fpaPlugins::MinimumSpanningTree:: +SetVTK( vtkObjectBase* o ) +{ + // Do nothing: this only has sense in ITK +} + +// ------------------------------------------------------------------------- +fpaPlugins::MinimumSpanningTree:: +MinimumSpanningTree( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +fpaPlugins::MinimumSpanningTree:: +~MinimumSpanningTree( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TMST > +bool fpaPlugins::MinimumSpanningTree:: +_SetITK( itk::LightObject* o ) +{ + _TMST* mst = dynamic_cast< _TMST* >( o ); + if( mst != NULL ) + { + this->Superclass::SetITK( o ); + return( true ); + } + else + { + this->Superclass::SetITK( NULL ); + this->Superclass::SetVTK( NULL ); + return( false ); + + } // fi +} + +// ------------------------------------------------------------------------- +// Explicit instances +// ------------------------------------------------------------------------- + +#include +#include +#include +#include +#include +#include + +#define fpa_Explicit_MST( D ) \ + template class fpaPlugins_EXPORT fpa::Base::MinimumSpanningTree< itk::Image< fpa::Image::MinimumSpanningTreeData< D >, D >, itk::Index< D > >; \ + template class fpaPlugins_EXPORT fpa::Image::MinimumSpanningTree< D >; \ + template class fpaPlugins_EXPORT itk::ImageConstIteratorWithIndex< fpa::Image::MinimumSpanningTree< D > >; \ + template class fpaPlugins_EXPORT itk::ImageRegionConstIteratorWithIndex< fpa::Image::MinimumSpanningTree< D > > + +fpa_Explicit_MST( 2 ); +fpa_Explicit_MST( 3 ); + +// eof - $RCSfile$ diff --git a/lib/fpaPlugins/MinimumSpanningTree.h b/plugins/fpa/MinimumSpanningTree.h similarity index 52% rename from lib/fpaPlugins/MinimumSpanningTree.h rename to plugins/fpa/MinimumSpanningTree.h index 557583c..26e0262 100644 --- a/lib/fpaPlugins/MinimumSpanningTree.h +++ b/plugins/fpa/MinimumSpanningTree.h @@ -1,10 +1,9 @@ #ifndef __FPAPLUGINS__MINIMUMSPANNINGTREE__H__ #define __FPAPLUGINS__MINIMUMSPANNINGTREE__H__ -#include -#include - -#include +#include +#include +#include // ------------------------------------------------------------------------- namespace fpaPlugins @@ -12,26 +11,30 @@ namespace fpaPlugins /** */ class fpaPlugins_EXPORT MinimumSpanningTree - : public cpPlugins::Interface::DataObject + : public cpPlugins::DataObject { public: - typedef MinimumSpanningTree Self; - typedef cpPlugins::Interface::DataObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; + typedef MinimumSpanningTree Self; + typedef cpPlugins::DataObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; public: itkNewMacro( Self ); - itkTypeMacro( MinimumSpanningTree, cpPlugins::Interface::DataObject ); + itkTypeMacro( MinimumSpanningTree, cpPlugins::DataObject ); cpPlugins_Id_Macro( MinimumSpanningTree, MinimumSpanningTree ); public: - void SetVTK( vtkObjectBase* o ); + virtual void SetITK( itk::LightObject* o ) override; + virtual void SetVTK( vtkObjectBase* o ) override; protected: MinimumSpanningTree( ); virtual ~MinimumSpanningTree( ); + template< class _TMST > + bool _SetITK( itk::LightObject* o ); + private: // Purposely not implemented MinimumSpanningTree( const Self& ); @@ -40,8 +43,6 @@ namespace fpaPlugins } // ecapseman -#include - #endif // __FPAPLUGINS__MINIMUMSPANNINGTREE__H__ // eof - $RCSfile$ diff --git a/plugins/fpa/MinimumSpanningTreeReader.cxx b/plugins/fpa/MinimumSpanningTreeReader.cxx new file mode 100644 index 0000000..98ef989 --- /dev/null +++ b/plugins/fpa/MinimumSpanningTreeReader.cxx @@ -0,0 +1,75 @@ +#include "MinimumSpanningTreeReader.h" +#include "MinimumSpanningTree.h" + +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins::MinimumSpanningTreeReader:: +MinimumSpanningTreeReader( ) + : Superclass( ) +{ + this->_AddOutput< fpaPlugins::MinimumSpanningTree >( "Output" ); + this->m_Parameters.Clear( ); + this->m_Parameters.ConfigureAsOpenFileName( "FileName" ); + this->m_Parameters.SetAcceptedFileExtensions( + "FileName", + "Minimum spanning tree files (*.mst)" + ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::MinimumSpanningTreeReader:: +~MinimumSpanningTreeReader( ) +{ +} + +// ------------------------------------------------------------------------- +std::string fpaPlugins::MinimumSpanningTreeReader:: +_GenerateData( ) +{ + // Infere MST dimensions + auto fname = this->m_Parameters.GetOpenFileName( "FileName" ); + std::ifstream input( fname.c_str( ) ); + if( !input ) + return( + std::string( "MinimumSpanningTreeReader: Error opening file \"" ) + + fname + + std::string( "\"" ) + ); + unsigned int dim; + input >> dim; + + // Real execution + if ( dim == 2 ) return( this->_GD0< 2 >( fname ) ); + else if( dim == 3 ) return( this->_GD0< 3 >( fname ) ); + else + return( "MinimumSpanningTreeReader: invalid dimensions." ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +std::string fpaPlugins::MinimumSpanningTreeReader:: +_GD0( const std::string& fname ) +{ + typedef fpa::Image::MinimumSpanningTree< _NDim > _TTree; + typedef fpa::IO::MinimumSpanningTreeReader< _TTree > _TFilter; + + _TFilter* reader = this->_CreateITK< _TFilter >( ); + reader->SetFileName( this->m_Parameters.GetOpenFileName( "FileName" ) ); + try + { + reader->Update( ); + } + catch( itk::ExceptionObject& err ) + { + return( + "MinimumSpanningTreeReader: " + std::string( err.GetDescription( ) ) + ); + + } // yrt + this->GetOutputData( "Output" )->SetITK( reader->GetOutput( ) ); + return( "" ); +} + +// eof - $RCSfile$ diff --git a/plugins/fpa/MinimumSpanningTreeReader.h b/plugins/fpa/MinimumSpanningTreeReader.h new file mode 100644 index 0000000..8e81c4d --- /dev/null +++ b/plugins/fpa/MinimumSpanningTreeReader.h @@ -0,0 +1,44 @@ +#ifndef __FPAPLUGINS__MINIMUMSPANNINGTREEREADER__H__ +#define __FPAPLUGINS__MINIMUMSPANNINGTREEREADER__H__ + +#include +#include + +namespace fpaPlugins +{ + /** + */ + class fpaPlugins_EXPORT MinimumSpanningTreeReader + : public cpPlugins::ProcessObject + { + public: + typedef MinimumSpanningTreeReader Self; + typedef cpPlugins::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( MinimumSpanningTreeReader, cpPlugins::ProcessObject ); + cpPlugins_Id_Macro( MinimumSpanningTreeReader, fpaIO ); + + protected: + MinimumSpanningTreeReader( ); + virtual ~MinimumSpanningTreeReader( ); + + virtual std::string _GenerateData( ); + + template< unsigned int _NDim > + inline std::string _GD0( const std::string& fname ); + + private: + // Purposely not implemented. + MinimumSpanningTreeReader( const Self& other ); + Self& operator=( const Self& other ); + }; + +} // ecapseman + +#endif // __FPAPLUGINS__MINIMUMSPANNINGTREEREADER__H__ + +// eof - $RCSfile$ diff --git a/plugins/fpa/MinimumSpanningTreeWriter.cxx b/plugins/fpa/MinimumSpanningTreeWriter.cxx new file mode 100644 index 0000000..90fd428 --- /dev/null +++ b/plugins/fpa/MinimumSpanningTreeWriter.cxx @@ -0,0 +1,67 @@ +#include "MinimumSpanningTreeWriter.h" +#include "MinimumSpanningTree.h" + +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins::MinimumSpanningTreeWriter:: +MinimumSpanningTreeWriter( ) + : Superclass( ) +{ + this->_AddInput( "Input" ); + this->m_Parameters.Clear( ); + this->m_Parameters.ConfigureAsSaveFileName( "FileName" ); + this->m_Parameters.SetAcceptedFileExtensions( + "FileName", + "Minimum spanning tree files (*.mst)" + ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::MinimumSpanningTreeWriter:: +~MinimumSpanningTreeWriter( ) +{ +} + +// ------------------------------------------------------------------------- +std::string fpaPlugins::MinimumSpanningTreeWriter:: +_GenerateData( ) +{ + typedef fpa::Image::MinimumSpanningTree< 2 > _2D; + typedef fpa::Image::MinimumSpanningTree< 3 > _3D; + + auto _2d = this->GetInputData( "Input" )->GetITK< _2D >( ); + auto _3d = this->GetInputData( "Input" )->GetITK< _3D >( ); + + if ( _2d != NULL ) return( this->_GD0( _2d ) ); + else if( _3d != NULL ) return( this->_GD0( _3d ) ); + else + return( "MinimumSpanningTreeWriter: Not a valid MST." ); +} + +// ------------------------------------------------------------------------- +template< class _TTree > +std::string fpaPlugins::MinimumSpanningTreeWriter:: +_GD0( _TTree* tree ) +{ + typedef fpa::IO::MinimumSpanningTreeWriter< _TTree > _TFilter; + + _TFilter* writer = this->_CreateITK< _TFilter >( ); + writer->SetInput( tree ); + writer->SetFileName( this->m_Parameters.GetSaveFileName( "FileName" ) ); + try + { + writer->Update( ); + } + catch( itk::ExceptionObject& err ) + { + return( + "MinimumSpanningTreeWriter: " + std::string( err.GetDescription( ) ) + ); + + } // yrt + return( "" ); +} + +// eof - $RCSfile$ diff --git a/plugins/fpa/MinimumSpanningTreeWriter.h b/plugins/fpa/MinimumSpanningTreeWriter.h new file mode 100644 index 0000000..60600e6 --- /dev/null +++ b/plugins/fpa/MinimumSpanningTreeWriter.h @@ -0,0 +1,44 @@ +#ifndef __FPAPLUGINS__MINIMUMSPANNINGTREEWRITER__H__ +#define __FPAPLUGINS__MINIMUMSPANNINGTREEWRITER__H__ + +#include +#include + +namespace fpaPlugins +{ + /** + */ + class fpaPlugins_EXPORT MinimumSpanningTreeWriter + : public cpPlugins::ProcessObject + { + public: + typedef MinimumSpanningTreeWriter Self; + typedef cpPlugins::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( MinimumSpanningTreeWriter, cpPlugins::ProcessObject ); + cpPlugins_Id_Macro( MinimumSpanningTreeWriter, fpaIO ); + + protected: + MinimumSpanningTreeWriter( ); + virtual ~MinimumSpanningTreeWriter( ); + + virtual std::string _GenerateData( ); + + template< class _TTree > + inline std::string _GD0( _TTree* tree ); + + private: + // Purposely not implemented. + MinimumSpanningTreeWriter( const Self& other ); + Self& operator=( const Self& other ); + }; + +} // ecapseman + +#endif // __FPAPLUGINS__MINIMUMSPANNINGTREEWRITER__H__ + +// eof - $RCSfile$ diff --git a/plugins/fpa/RegionGrowThresholdFunction.cxx b/plugins/fpa/RegionGrowThresholdFunction.cxx new file mode 100644 index 0000000..1c27fe5 --- /dev/null +++ b/plugins/fpa/RegionGrowThresholdFunction.cxx @@ -0,0 +1,64 @@ +#include "RegionGrowThresholdFunction.h" + +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins::RegionGrowThresholdFunction:: +RegionGrowThresholdFunction( ) + : Superclass( ) +{ + this->_AddInput( "ReferenceImage" ); + this->_AddOutput< cpPlugins::DataObject >( "Output" ); + + this->m_Parameters.ConfigureAsReal( "LowerThreshold" ); + this->m_Parameters.ConfigureAsReal( "UpperThreshold" ); + + this->m_Parameters.SetReal( "LowerThreshold", 0 ); + this->m_Parameters.SetReal( "UpperThreshold", 1 ); +} + +// ------------------------------------------------------------------------- +fpaPlugins::RegionGrowThresholdFunction:: +~RegionGrowThresholdFunction( ) +{ +} + +// ------------------------------------------------------------------------- +std::string fpaPlugins::RegionGrowThresholdFunction:: +_GenerateData( ) +{ + auto image = + this->GetInputData( "ReferenceImage" )->GetITK< itk::DataObject >( ); + std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 ); + if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 ); + return( r ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +std::string fpaPlugins::RegionGrowThresholdFunction:: +_GD0( _TImage* image ) +{ + typedef + fpa::Image::Functors::RegionGrowThresholdFunction< _TImage > + _TFunctor; + + if( image == NULL ) + return( "fpaPlugins::RegionGrowThresholdFunction: invalid image type." ); + + auto out = this->GetOutputData( "Output" ); + auto f = out->GetITK< _TFunctor >( ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + out->SetITK( f ); + + } // fi + f->SetLowerThreshold( this->m_Parameters.GetReal( "LowerThreshold" ) ); + f->SetUpperThreshold( this->m_Parameters.GetReal( "UpperThreshold" ) ); + return( "" ); +} + +// eof - $RCSfile$ diff --git a/plugins/fpa/RegionGrowThresholdFunction.h b/plugins/fpa/RegionGrowThresholdFunction.h new file mode 100644 index 0000000..2f9694a --- /dev/null +++ b/plugins/fpa/RegionGrowThresholdFunction.h @@ -0,0 +1,46 @@ +#ifndef __FPAPLUGINS__REGIONGROWTHRESHOLDFUNCTION__H__ +#define __FPAPLUGINS__REGIONGROWTHRESHOLDFUNCTION__H__ + +#include +#include + +namespace fpaPlugins +{ + /** + */ + class fpaPlugins_EXPORT RegionGrowThresholdFunction + : public cpPlugins::ProcessObject + { + public: + typedef RegionGrowThresholdFunction Self; + typedef cpPlugins::ProcessObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( RegionGrowThresholdFunction, cpPlugins::ProcessObject ); + cpPlugins_Id_Macro( + RegionGrowThresholdFunction, fpaImageAlgorithmFunctors + ); + + protected: + RegionGrowThresholdFunction( ); + virtual ~RegionGrowThresholdFunction( ); + + virtual std::string _GenerateData( ); + + template< class _TImage > + std::string _GD0( _TImage* image ); + + private: + // Purposely not implemented. + RegionGrowThresholdFunction( const Self& other ); + Self& operator=( const Self& other ); + }; + +} // ecapseman + +#endif // __FPAPLUGINS__REGIONGROWTHRESHOLDFUNCTION__H__ + +// eof - $RCSfile$ -- 2.45.1