From d93ab4fea6dbc791560451ecdc4bf7555d8cf11d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Tue, 7 Mar 2017 18:36:52 -0500 Subject: [PATCH] ... --- lib/fpa/Base/FastMarching.hxx | 3 +- lib/fpa/Base/RegionGrow.h | 11 ++ lib/fpa/Base/RegionGrow.hxx | 14 ++- lib/fpa/Image/Algorithm.hxx | 5 +- lib/fpa/Image/Functors/Base.h | 6 +- .../Functors/RegionGrow/BinaryThreshold.hxx | 2 +- lib/fpa/Image/RegionGrow.hxx | 4 + plugins/CMakeLists.txt | 2 + plugins/Functors/Functors.i | 6 + plugins/Functors/Inverse.cxx | 89 ++++++++++++++ plugins/Functors/Inverse.h | 32 +++++ plugins/ImageAlgorithms/BaseFilter.cxx | 6 +- plugins/ImageAlgorithms/BaseFilter.h | 21 ++-- plugins/ImageAlgorithms/Dijkstra.cxx | 58 ++++++---- plugins/ImageAlgorithms/Dijkstra.h | 12 +- .../ExtractPathFromMinimumSpanningTree.cxx | 80 +++++++++++++ .../ExtractPathFromMinimumSpanningTree.h | 29 +++++ plugins/ImageAlgorithms/FastMarching.cxx | 60 ++++++---- plugins/ImageAlgorithms/FastMarching.h | 12 +- plugins/ImageAlgorithms/MoriRegionGrow.cxx | 109 ------------------ plugins/ImageAlgorithms/MoriRegionGrow.h | 29 ----- plugins/ImageAlgorithms/RegionGrow.cxx | 47 +++++--- plugins/ImageAlgorithms/RegionGrow.h | 10 +- plugins/ImageAlgorithms/SkeletonFilter.cxx | 81 ------------- plugins/ImageAlgorithms/SkeletonFilter.h | 29 ----- plugins/ImageFunctors/BinaryThreshold.cxx | 90 +++++++++++++++ plugins/ImageFunctors/BinaryThreshold.h | 32 +++++ plugins/ImageFunctors/Tautology.cxx | 87 ++++++++++++++ plugins/ImageFunctors/Tautology.h | 32 +++++ plugins/ImageFunctors/VertexCost.cxx | 89 ++++++++++++++ plugins/ImageFunctors/VertexCost.h | 32 +++++ 31 files changed, 761 insertions(+), 358 deletions(-) create mode 100644 plugins/Functors/Functors.i create mode 100644 plugins/Functors/Inverse.cxx create mode 100644 plugins/Functors/Inverse.h create mode 100644 plugins/ImageAlgorithms/ExtractPathFromMinimumSpanningTree.cxx create mode 100644 plugins/ImageAlgorithms/ExtractPathFromMinimumSpanningTree.h delete mode 100644 plugins/ImageAlgorithms/MoriRegionGrow.cxx delete mode 100644 plugins/ImageAlgorithms/MoriRegionGrow.h delete mode 100644 plugins/ImageAlgorithms/SkeletonFilter.cxx delete mode 100644 plugins/ImageAlgorithms/SkeletonFilter.h create mode 100644 plugins/ImageFunctors/BinaryThreshold.cxx create mode 100644 plugins/ImageFunctors/BinaryThreshold.h create mode 100644 plugins/ImageFunctors/Tautology.cxx create mode 100644 plugins/ImageFunctors/Tautology.h create mode 100644 plugins/ImageFunctors/VertexCost.cxx create mode 100644 plugins/ImageFunctors/VertexCost.h diff --git a/lib/fpa/Base/FastMarching.hxx b/lib/fpa/Base/FastMarching.hxx index 61ec968..0fe1cb2 100644 --- a/lib/fpa/Base/FastMarching.hxx +++ b/lib/fpa/Base/FastMarching.hxx @@ -71,7 +71,8 @@ _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) } else { - std::cout << "-----> " << v.Vertex << " " << d << std::endl; + std::cout << std::endl << "-- FM --> " << v.Vertex << " " << d << std::endl; + std::exit( 1 ); } return( true ); } diff --git a/lib/fpa/Base/RegionGrow.h b/lib/fpa/Base/RegionGrow.h index 6a3c9e6..4790b85 100644 --- a/lib/fpa/Base/RegionGrow.h +++ b/lib/fpa/Base/RegionGrow.h @@ -48,11 +48,22 @@ namespace fpa virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) override; + virtual TOutput _GetInputValue( const _TQueueNode& v, const _TQueueNode& p ) override + { + TOutput res = this->m_InitResult; + if( this->m_GrowFunction.IsNotNull( ) ) + res = this->m_GrowFunction->Evaluate( v.Vertex, p.Vertex ); + return( res ); + } + private: // Purposely not defined RegionGrow( const Self& other ); Self& operator=( const Self& other ); + + protected: + typename TGrowFunction::Pointer m_GrowFunction; }; } // ecapseman diff --git a/lib/fpa/Base/RegionGrow.hxx b/lib/fpa/Base/RegionGrow.hxx index 6865916..c3cb9f3 100644 --- a/lib/fpa/Base/RegionGrow.hxx +++ b/lib/fpa/Base/RegionGrow.hxx @@ -9,7 +9,8 @@ typename fpa::Base::RegionGrow< _TSuperclass >:: TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >:: GetGrowFunction( ) { - return( dynamic_cast< TGrowFunction* >( this->GetVertexFunction( ) ) ); + // TODO: return( dynamic_cast< TGrowFunction* >( this->GetVertexFunction( ) ) ); + return( this->m_GrowFunction ); } // ------------------------------------------------------------------------- @@ -18,9 +19,12 @@ const typename fpa::Base::RegionGrow< _TSuperclass >:: TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >:: GetGrowFunction( ) const { - return( - dynamic_cast< const TGrowFunction* >( this->GetVertexFunction( ) ) - ); + /* TODO + return( + dynamic_cast< const TGrowFunction* >( this->GetVertexFunction( ) ) + ); + */ + return( this->m_GrowFunction ); } // ------------------------------------------------------------------------- @@ -61,7 +65,7 @@ SetGrowFunction( TGrowFunction* f ) f->SetOutsideValue( old_f->GetOutsideValue( ) ); } // fi - this->SetVertexFunction( f ); + this->m_GrowFunction = f; } // ------------------------------------------------------------------------- diff --git a/lib/fpa/Image/Algorithm.hxx b/lib/fpa/Image/Algorithm.hxx index 6e4eef1..3c33e4e 100644 --- a/lib/fpa/Image/Algorithm.hxx +++ b/lib/fpa/Image/Algorithm.hxx @@ -51,9 +51,8 @@ _BeforeGenerateData( ) dynamic_cast< TVertexFunction* >( this->GetVertexFunction( ) ); - if( vertexFunc == NULL ) - itkExceptionMacro( << "VertexFunction not well defined." ); - vertexFunc->SetImage( this->GetInput( ) ); + if( vertexFunc != NULL ) + vertexFunc->SetImage( this->GetInput( ) ); } // ------------------------------------------------------------------------- diff --git a/lib/fpa/Image/Functors/Base.h b/lib/fpa/Image/Functors/Base.h index 622cc0a..45bd846 100644 --- a/lib/fpa/Image/Functors/Base.h +++ b/lib/fpa/Image/Functors/Base.h @@ -29,8 +29,8 @@ namespace fpa public: itkTypeMacro( Base, itk::FunctionBase ); - itkGetConstObjectMacro( Image, TImageBase ); - itkSetConstObjectMacro( Image, TImageBase ); + itkGetConstObjectMacro( Image, TImage ); + itkSetConstObjectMacro( Image, TImage ); protected: Base( ) : Superclass( ) { } @@ -42,7 +42,7 @@ namespace fpa Self& operator=( const Self& other ); protected: - typename TImageBase::ConstPointer m_Image; + typename TImage::ConstPointer m_Image; }; } // ecapseman diff --git a/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx index e1853e2..7f2b9dc 100644 --- a/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx +++ b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx @@ -15,7 +15,7 @@ Evaluate( const TIndex& a, const TIndex& b ) const { TPixel v = im->GetPixel( b ); return( - ( this->m_Lower <= v && v <= this->m_Upper )? + ( this->m_Lower < v && v < this->m_Upper )? this->m_InsideValue: this->m_OutsideValue ); diff --git a/lib/fpa/Image/RegionGrow.hxx b/lib/fpa/Image/RegionGrow.hxx index 9df155a..326dc54 100644 --- a/lib/fpa/Image/RegionGrow.hxx +++ b/lib/fpa/Image/RegionGrow.hxx @@ -23,6 +23,10 @@ _BeforeGenerateData( ) { this->Superclass::_BeforeGenerateData( ); this->m_InitResult = this->GetOutsideValue( ); + TGrowFunction* grow = + dynamic_cast< TGrowFunction* >( this->GetGrowFunction( ) ); + if( grow != NULL ) + grow->SetImage( this->GetInput( ) ); } #endif // __fpa__Image__RegionGrow__hxx__ diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 383c5d6..7a565b0 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -12,6 +12,8 @@ IF(USE_cpPlugins) SET( _dirs + Functors + ImageFunctors ImageAlgorithms # RegionGrowFunctors # DijkstraFunctors diff --git a/plugins/Functors/Functors.i b/plugins/Functors/Functors.i new file mode 100644 index 0000000..c12aa36 --- /dev/null +++ b/plugins/Functors/Functors.i @@ -0,0 +1,6 @@ + +tinclude fpa/Base/Functors/Inverse:h|hxx + +instances fpa::Base::Functors::Inverse< #scalar_types#, #real_types# > + +** eof - $RCSfile$ diff --git a/plugins/Functors/Inverse.cxx b/plugins/Functors/Inverse.cxx new file mode 100644 index 0000000..1786d38 --- /dev/null +++ b/plugins/Functors/Inverse.cxx @@ -0,0 +1,89 @@ +#include "Inverse.h" + +#include + +#include +#include + +// ------------------------------------------------------------------------- +void fpaPlugins_Functors::Inverse:: +Instantiate( itk::LightObject* filter ) +{ + auto itk_filter = dynamic_cast< itk::ProcessObject* >( filter ); + if( itk_filter != NULL ) + { + auto inputs = itk_filter->GetInputs( ); + if( inputs.size( ) > 0 ) + { + cpPlugins_Demangle_Image_ScalarPixels_AllDims_2( + inputs[ 0 ].GetPointer( ), _GD0, itk_filter + ) + this->_Error( "Invalid input data." ); + } + else + this->_Error( "Not enough inputs." ); + } + else + this->_Error( "Invalid instantiation filter." ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_Functors::Inverse:: +Inverse( ) + : Superclass( ) +{ + this->_ConfigureOutput< cpPlugins::Pipeline::DataObject >( "Functor" ); + this->m_Parameters.ConfigureAsReal( "NegativeValue", -1 ); + this->GetOutput( "Functor" )->SetITK( this ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_Functors::Inverse:: +~Inverse( ) +{ +} + +// ------------------------------------------------------------------------- +void fpaPlugins_Functors::Inverse:: +_GenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TInput > +void fpaPlugins_Functors::Inverse:: +_GD0( _TInput* input, itk::ProcessObject* filter ) +{ + auto outputs = filter->GetOutputs( ); + if( outputs.size( ) > 0 ) + { + cpPlugins_Demangle_Image_RealPixels_3( + outputs[ 0 ].GetPointer( ), _GD1, _TInput::ImageDimension, input, filter + ) + this->_Error( "Invalid output data." ); + } + else + this->_Error( "Not enough outputs." ); +} + +// ------------------------------------------------------------------------- +template< class _TInput, class _TOutput > +void fpaPlugins_Functors::Inverse:: +_GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter ) +{ + typedef typename _TInput::PixelType _TIValue; + typedef typename _TOutput::PixelType _TOValue; + typedef fpa::Base::Functors::Inverse< _TIValue, _TOValue > _TFunctor; + + auto f = dynamic_cast< _TFunctor* >( this->m_Functor.GetPointer( ) ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + this->m_Functor = f; + + } // fi + f->SetNegativeValue( this->m_Parameters.GetReal( "NegativeValue" ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/Functors/Inverse.h b/plugins/Functors/Inverse.h new file mode 100644 index 0000000..634eeaf --- /dev/null +++ b/plugins/Functors/Inverse.h @@ -0,0 +1,32 @@ +#ifndef __fpaPlugins_Functors__Inverse__h__ +#define __fpaPlugins_Functors__Inverse__h__ + +#include +#include +#include + +namespace fpaPlugins_Functors +{ + /** + */ + class fpaPlugins_Functors_EXPORT Inverse + : public cpPlugins::Pipeline::Functor + { + cpPluginsObject( Inverse, cpPlugins::Pipeline::Functor, fpaFunctors ); + + public: + virtual void Instantiate( itk::LightObject* filter ) override; + + protected: + template< class _TInput > + inline void _GD0( _TInput* input, itk::ProcessObject* filter ); + + template< class _TInput, class _TOutput > + inline void _GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter ); + }; + +} // ecapseman + +#endif // __fpaPlugins_Functors__Inverse__h__ + +// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/BaseFilter.cxx b/plugins/ImageAlgorithms/BaseFilter.cxx index 3772488..00393b4 100644 --- a/plugins/ImageAlgorithms/BaseFilter.cxx +++ b/plugins/ImageAlgorithms/BaseFilter.cxx @@ -1,8 +1,8 @@ -#include +#include "BaseFilter.h" #include // ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::BaseFilter:: +fpaPlugins_ImageAlgorithms::BaseFilter:: BaseFilter( ) : Superclass( ) { @@ -19,7 +19,7 @@ BaseFilter( ) } // ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::BaseFilter:: +fpaPlugins_ImageAlgorithms::BaseFilter:: ~BaseFilter( ) { } diff --git a/plugins/ImageAlgorithms/BaseFilter.h b/plugins/ImageAlgorithms/BaseFilter.h index 0b871a5..b03abaa 100644 --- a/plugins/ImageAlgorithms/BaseFilter.h +++ b/plugins/ImageAlgorithms/BaseFilter.h @@ -1,19 +1,16 @@ -#ifndef __fpaPluginsImageAlgorithms__BaseFilter__h__ -#define __fpaPluginsImageAlgorithms__BaseFilter__h__ +#ifndef __fpaPlugins_ImageAlgorithms__BaseFilter__h__ +#define __fpaPlugins_ImageAlgorithms__BaseFilter__h__ -#include +#include #include #include -#define ITK_MANUAL_INSTANTIATION -#include - -namespace fpaPluginsImageAlgorithms +namespace fpaPlugins_ImageAlgorithms { /** */ - class fpaPluginsImageAlgorithms_EXPORT BaseFilter + class fpaPlugins_ImageAlgorithms_EXPORT BaseFilter : public cpPlugins::Pipeline::ProcessObject { public: @@ -44,9 +41,13 @@ namespace fpaPluginsImageAlgorithms } // ecapseman +// ------------------------------------------------------------------------- +#define ITK_MANUAL_INSTANTIATION +#include + // ------------------------------------------------------------------------- template< class _TFilter, class _TImage > -void fpaPluginsImageAlgorithms::BaseFilter:: +void fpaPlugins_ImageAlgorithms::BaseFilter:: _ConfigureFilter( _TFilter* filter, _TImage* image, std::vector< typename _TImage::IndexType >& seeds @@ -92,6 +93,6 @@ _ConfigureFilter( } // fi } -#endif // __fpaPluginsImageAlgorithms__BaseFilter__h__ +#endif // __fpaPlugins_ImageAlgorithms__BaseFilter__h__ // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/Dijkstra.cxx b/plugins/ImageAlgorithms/Dijkstra.cxx index c15d96f..7d4fe1e 100644 --- a/plugins/ImageAlgorithms/Dijkstra.cxx +++ b/plugins/ImageAlgorithms/Dijkstra.cxx @@ -1,18 +1,19 @@ -#include +#include "Dijkstra.h" +#include #include #include // ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::Dijkstra:: +fpaPlugins_ImageAlgorithms::Dijkstra:: Dijkstra( ) : Superclass( ) { - typedef cpPlugins::Pipeline::DataObject _TData; + typedef cpPlugins::Pipeline::DataObject _TFunctor; typedef cpInstances::DataObjects::Image _TMST; - this->_ConfigureInput< _TData >( "VertexFunction", false, false ); - this->_ConfigureInput< _TData >( "ConversionFunction", false, false ); + this->_ConfigureInput< _TFunctor >( "VertexFunction", false, false ); + this->_ConfigureInput< _TFunctor >( "ConversionFunction", false, false ); this->_ConfigureOutput< _TMST >( "MST" ); std::vector< std::string > choices; @@ -23,13 +24,13 @@ Dijkstra( ) } // ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::Dijkstra:: +fpaPlugins_ImageAlgorithms::Dijkstra:: ~Dijkstra( ) { } // ------------------------------------------------------------------------- -void fpaPluginsImageAlgorithms::Dijkstra:: +void fpaPlugins_ImageAlgorithms::Dijkstra:: _GenerateData( ) { auto o = this->GetInputData( "Input" ); @@ -39,7 +40,7 @@ _GenerateData( ) // ------------------------------------------------------------------------- template< class _TImage > -void fpaPluginsImageAlgorithms::Dijkstra:: +void fpaPlugins_ImageAlgorithms::Dijkstra:: _GD0( _TImage* image ) { typedef itk::Image< float, _TImage::ImageDimension > _TFloat; @@ -52,35 +53,46 @@ _GD0( _TImage* image ) // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > -void fpaPluginsImageAlgorithms::Dijkstra:: +void fpaPlugins_ImageAlgorithms::Dijkstra:: _GD1( _TInputImage* image ) { + typedef cpPlugins::Pipeline::Functor _TFunctor; typedef fpa::Image::Dijkstra< _TInputImage, _TOutputImage > _TFilter; typedef typename _TFilter::TConversionFunction _TConversionFunction; typedef typename _TFilter::TVertexFunction _TVertexFunction; + // Create filter auto filter = this->_CreateITK< _TFilter >( ); std::vector< typename _TInputImage::IndexType > seeds; this->_ConfigureFilter( filter, image, seeds ); + + // Instantiate functors + auto cost_conversion = this->GetInputData< _TFunctor >( "ConversionFunction" ); + if( cost_conversion != NULL ) + { + cost_conversion->Instantiate( filter ); + auto cost_conversion_functor = cost_conversion->GetFunctor< _TConversionFunction >( ); + if( cost_conversion_functor != NULL ) + filter->SetConversionFunction( cost_conversion_functor ); + + } // fi + + auto vertex = this->GetInputData< _TFunctor >( "VertexFunction" ); + if( vertex != NULL ) + { + vertex->Instantiate( filter ); + auto vertex_functor = vertex->GetFunctor< _TVertexFunction >( ); + if( vertex_functor != NULL ) + filter->SetVertexFunction( vertex_functor ); + + } // fi + + // Finish filter's configuration filter->ClearSeeds( ); for( auto seed : seeds ) filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) ); filter->Update( ); this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); - - /* TODO - auto filter = this->_CreateITK< _TFilter >( ); - this->_ConfigureFilter( filter, image ); - auto cost = this->GetInputData< _TCost >( "Cost" ); - auto conv = this->GetInputData< _TCostConversion >( "CostConversion" ); - if( cost != NULL ) - filter->SetCostFunction( cost ); - if( conv != NULL ) - filter->SetCostConversionFunction( conv ); - filter->Update( ); - this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); - this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) ); - */ } // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/Dijkstra.h b/plugins/ImageAlgorithms/Dijkstra.h index 5ac2233..5482e8d 100644 --- a/plugins/ImageAlgorithms/Dijkstra.h +++ b/plugins/ImageAlgorithms/Dijkstra.h @@ -1,13 +1,13 @@ -#ifndef __fpaPluginsImageAlgorithms__Dijkstra__h__ -#define __fpaPluginsImageAlgorithms__Dijkstra__h__ +#ifndef __fpaPlugins_ImageAlgorithms__Dijkstra__h__ +#define __fpaPlugins_ImageAlgorithms__Dijkstra__h__ #include -namespace fpaPluginsImageAlgorithms +namespace fpaPlugins_ImageAlgorithms { /** */ - class fpaPluginsImageAlgorithms_EXPORT Dijkstra + class fpaPlugins_ImageAlgorithms_EXPORT Dijkstra : public BaseFilter { cpPluginsObject( Dijkstra, BaseFilter, fpaImageAlgorithms ); @@ -16,12 +16,12 @@ namespace fpaPluginsImageAlgorithms template< class _TImage > inline void _GD0( _TImage* image ); - template< class _TInputImage, class _TOutputPixel > + template< class _TInputImage, class _TOutputImage > inline void _GD1( _TInputImage* image ); }; } // ecapseman -#endif // __fpaPluginsImageAlgorithms__Dijkstra__h__ +#endif // __fpaPlugins_ImageAlgorithms__Dijkstra__h__ // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/ExtractPathFromMinimumSpanningTree.cxx b/plugins/ImageAlgorithms/ExtractPathFromMinimumSpanningTree.cxx new file mode 100644 index 0000000..55ca96e --- /dev/null +++ b/plugins/ImageAlgorithms/ExtractPathFromMinimumSpanningTree.cxx @@ -0,0 +1,80 @@ +#include "ExtractPathFromMinimumSpanningTree.h" +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +fpaPlugins_ImageAlgorithms::ExtractPathFromMinimumSpanningTree:: +ExtractPathFromMinimumSpanningTree( ) + : Superclass( ) +{ + typedef cpPlugins::Pipeline::DataObject _TData; + typedef cpInstances::DataObjects::Image _TMST; + typedef cpInstances::DataObjects::PolyLineParametricPath _TPath; + + this->_ConfigureInput< _TMST >( "MST", true, false ); + this->_ConfigureInput< _TData >( "Seeds", true, false ); + this->_ConfigureOutput< _TPath >( "Output" ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_ImageAlgorithms::ExtractPathFromMinimumSpanningTree:: +~ExtractPathFromMinimumSpanningTree( ) +{ +} + +// ------------------------------------------------------------------------- +void fpaPlugins_ImageAlgorithms::ExtractPathFromMinimumSpanningTree:: +_GenerateData( ) +{ + typedef fpa::Image::MinimumSpanningTree< 2 > _TMST2; + typedef fpa::Image::MinimumSpanningTree< 3 > _TMST3; + + auto mst2 = this->GetInputData< _TMST2 >( "MST" ); + auto mst3 = this->GetInputData< _TMST3 >( "MST" ); + if ( mst2 != NULL ) this->_GD0( mst2 ); + else if( mst3 != NULL ) this->_GD0( mst3 ); + else this->_Error( "Invalid input spanning tree." ); +} + +// ------------------------------------------------------------------------- +template< class _TMST > +void fpaPlugins_ImageAlgorithms::ExtractPathFromMinimumSpanningTree:: +_GD0( _TMST* mst ) +{ + typedef typename _TMST::IndexType _TIndex; + typedef typename _TMST::TPath _TPath; + + // Get seeds + std::vector< _TIndex > seeds; + auto points = this->GetInputData< vtkPolyData >( "Seeds" ); + if( points != NULL ) + { + if( points->GetNumberOfPoints( ) < 2 ) + this->_Error( "Not enough seeds (<2)." ); + + typename _TMST::PointType pnt; + typename _TMST::IndexType idx; + unsigned int dim = + ( _TMST::ImageDimension < 3 )? _TMST::ImageDimension: 3; + for( unsigned int i = 0; i < 2; ++i ) + { + double buf[ 3 ]; + points->GetPoint( i, buf ); + pnt.Fill( 0 ); + for( unsigned int d = 0; d < dim; ++d ) + pnt[ d ] = buf[ d ]; + if( mst->TransformPhysicalPointToIndex( pnt, idx ) ) + seeds.push_back( idx ); + + } // rof + + } // fi + + typename _TPath::Pointer path; + mst->GetPath( path, seeds[ 0 ], seeds[ 1 ] ); + this->GetOutput( "Output" )->SetITK( path ); +} + +// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/ExtractPathFromMinimumSpanningTree.h b/plugins/ImageAlgorithms/ExtractPathFromMinimumSpanningTree.h new file mode 100644 index 0000000..a331457 --- /dev/null +++ b/plugins/ImageAlgorithms/ExtractPathFromMinimumSpanningTree.h @@ -0,0 +1,29 @@ +#ifndef __fpaPlugins_ImageAlgorithms__ExtractPathFromMinimumSpanningTree__h__ +#define __fpaPlugins_ImageAlgorithms__ExtractPathFromMinimumSpanningTree__h__ + +#include +#include + +namespace fpaPlugins_ImageAlgorithms +{ + /** + */ + class fpaPlugins_ImageAlgorithms_EXPORT ExtractPathFromMinimumSpanningTree + : public cpPlugins::Pipeline::ProcessObject + { + cpPluginsObject( + ExtractPathFromMinimumSpanningTree, + cpPlugins::Pipeline::ProcessObject, + fpaImageAlgorithms + ); + + protected: + template< class _TMST > + inline void _GD0( _TMST* mst ); + }; + +} // ecapseman + +#endif // __fpaPlugins_ImageAlgorithms__ExtractPathFromMinimumSpanningTree__h__ + +// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/FastMarching.cxx b/plugins/ImageAlgorithms/FastMarching.cxx index 5805e30..355c882 100644 --- a/plugins/ImageAlgorithms/FastMarching.cxx +++ b/plugins/ImageAlgorithms/FastMarching.cxx @@ -1,19 +1,18 @@ -#include +#include "FastMarching.h" +#include #include #include // ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::FastMarching:: +fpaPlugins_ImageAlgorithms::FastMarching:: FastMarching( ) : Superclass( ) { - typedef cpPlugins::Pipeline::DataObject _TData; - typedef cpInstances::DataObjects::Image _TMST; + typedef cpPlugins::Pipeline::DataObject _TFunctor; - this->_ConfigureInput< _TData >( "VertexFunction", false, false ); - this->_ConfigureInput< _TData >( "ConversionFunction", false, false ); - this->_ConfigureOutput< _TMST >( "MST" ); + this->_ConfigureInput< _TFunctor >( "VertexFunction", false, false ); + this->_ConfigureInput< _TFunctor >( "ConversionFunction", false, false ); std::vector< std::string > choices; choices.push_back( "float" ); @@ -23,13 +22,13 @@ FastMarching( ) } // ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::FastMarching:: +fpaPlugins_ImageAlgorithms::FastMarching:: ~FastMarching( ) { } // ------------------------------------------------------------------------- -void fpaPluginsImageAlgorithms::FastMarching:: +void fpaPlugins_ImageAlgorithms::FastMarching:: _GenerateData( ) { auto o = this->GetInputData( "Input" ); @@ -39,7 +38,7 @@ _GenerateData( ) // ------------------------------------------------------------------------- template< class _TImage > -void fpaPluginsImageAlgorithms::FastMarching:: +void fpaPlugins_ImageAlgorithms::FastMarching:: _GD0( _TImage* image ) { typedef itk::Image< float, _TImage::ImageDimension > _TFloat; @@ -52,35 +51,46 @@ _GD0( _TImage* image ) // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > -void fpaPluginsImageAlgorithms::FastMarching:: +void fpaPlugins_ImageAlgorithms::FastMarching:: _GD1( _TInputImage* image ) { + typedef cpPlugins::Pipeline::Functor _TFunctor; typedef fpa::Image::FastMarching< _TInputImage, _TOutputImage > _TFilter; typedef typename _TFilter::TConversionFunction _TConversionFunction; typedef typename _TFilter::TVertexFunction _TVertexFunction; + // Create filter auto filter = this->_CreateITK< _TFilter >( ); std::vector< typename _TInputImage::IndexType > seeds; this->_ConfigureFilter( filter, image, seeds ); + + // Instantiate functors + auto cost_conversion = this->GetInputData< _TFunctor >( "ConversionFunction" ); + if( cost_conversion != NULL ) + { + cost_conversion->Instantiate( filter ); + auto cost_conversion_functor = cost_conversion->GetFunctor< _TConversionFunction >( ); + if( cost_conversion_functor != NULL ) + filter->SetConversionFunction( cost_conversion_functor ); + + } // fi + + auto vertex = this->GetInputData< _TFunctor >( "VertexFunction" ); + if( vertex != NULL ) + { + vertex->Instantiate( filter ); + auto vertex_functor = vertex->GetFunctor< _TVertexFunction >( ); + if( vertex_functor != NULL ) + filter->SetVertexFunction( vertex_functor ); + + } // fi + + // Finish filter's configuration filter->ClearSeeds( ); for( auto seed : seeds ) filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) ); filter->Update( ); this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); - - /* TODO - auto filter = this->_CreateITK< _TFilter >( ); - this->_ConfigureFilter( filter, image ); - auto cost = this->GetInputData< _TCost >( "Cost" ); - auto conv = this->GetInputData< _TCostConversion >( "CostConversion" ); - if( cost != NULL ) - filter->SetCostFunction( cost ); - if( conv != NULL ) - filter->SetCostConversionFunction( conv ); - filter->Update( ); - this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); - this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) ); - */ } // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/FastMarching.h b/plugins/ImageAlgorithms/FastMarching.h index 3238975..2bd6207 100644 --- a/plugins/ImageAlgorithms/FastMarching.h +++ b/plugins/ImageAlgorithms/FastMarching.h @@ -1,13 +1,13 @@ -#ifndef __fpaPluginsImageAlgorithms__FastMarching__h__ -#define __fpaPluginsImageAlgorithms__FastMarching__h__ +#ifndef __fpaPlugins_ImageAlgorithms__FastMarching__h__ +#define __fpaPlugins_ImageAlgorithms__FastMarching__h__ #include -namespace fpaPluginsImageAlgorithms +namespace fpaPlugins_ImageAlgorithms { /** */ - class fpaPluginsImageAlgorithms_EXPORT FastMarching + class fpaPlugins_ImageAlgorithms_EXPORT FastMarching : public BaseFilter { cpPluginsObject( FastMarching, BaseFilter, fpaImageAlgorithms ); @@ -16,12 +16,12 @@ namespace fpaPluginsImageAlgorithms template< class _TImage > inline void _GD0( _TImage* image ); - template< class _TInputImage, class _TOutputPixel > + template< class _TInputImage, class _TOutputImage > inline void _GD1( _TInputImage* image ); }; } // ecapseman -#endif // __fpaPluginsImageAlgorithms__FastMarching__h__ +#endif // __fpaPlugins_ImageAlgorithms__FastMarching__h__ // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/MoriRegionGrow.cxx b/plugins/ImageAlgorithms/MoriRegionGrow.cxx deleted file mode 100644 index cda8979..0000000 --- a/plugins/ImageAlgorithms/MoriRegionGrow.cxx +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include - -#include - -// ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::MoriRegionGrow:: -MoriRegionGrow( ) - : Superclass( ) -{ - typedef cpPlugins::Pipeline::DataObject _TData; - typedef cpInstances::DataObjects::Image _TImage; - - this->_ConfigureInput< _TImage >( "Input", true, false ); - this->_ConfigureInput< _TData >( "Seed", true, false ); - this->_ConfigureOutput< _TImage >( "Output" ); - this->_ConfigureOutput< _TImage >( "AuxiliaryOutput" ); - - this->m_Parameters.ConfigureAsInt( "InsideValue", 1 ); - this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 ); - this->m_Parameters.ConfigureAsReal( "Step", 1 ); - this->m_Parameters.ConfigureAsReal( "Lower", 0 ); - this->m_Parameters.ConfigureAsReal( "Upper", 1 ); - this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" ); -} - -// ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::MoriRegionGrow:: -~MoriRegionGrow( ) -{ -} - -// ------------------------------------------------------------------------- -void fpaPluginsImageAlgorithms::MoriRegionGrow:: -_GenerateData( ) -{ - auto o = this->GetInputData( "Input" ); - cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) - this->_Error( "Invalid input image." ); -} - -// ------------------------------------------------------------------------- -template< class _TImage > -void fpaPluginsImageAlgorithms::MoriRegionGrow:: -_GD0( _TImage* image ) -{ - auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" ); - if( rtype == "char" ) this->_GD1< _TImage, char >( image ); - else if( rtype == "uchar" ) this->_GD1< _TImage, unsigned char >( image ); - else if( rtype == "short" ) this->_GD1< _TImage, short >( image ); - else if( rtype == "ushort" ) this->_GD1< _TImage, unsigned short >( image ); - else if( rtype == "int" ) this->_GD1< _TImage, int >( image ); - else if( rtype == "uint" ) this->_GD1< _TImage, unsigned int >( image ); - else if( rtype == "long" ) this->_GD1< _TImage, long >( image ); - else if( rtype == "ulong" ) this->_GD1< _TImage, unsigned long >( image ); - else this->_GD1< _TImage, char >( image ); -} - -// ------------------------------------------------------------------------- -template< class _TInputImage, class _TOutputPixel > -void fpaPluginsImageAlgorithms::MoriRegionGrow:: -_GD1( _TInputImage* image ) -{ - /* TODO - typedef - itk::Image< _TOutputPixel, _TInputImage::ImageDimension > - _TOutputImage; - typedef fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage > _TFilter; - - auto filter = this->_CreateITK< _TFilter >( ); - filter->SetInput( image ); - filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) ); - filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) ); - filter->SetStep( this->m_Parameters.GetReal( "Step" ) ); - filter->SetLower( this->m_Parameters.GetReal( "Lower" ) ); - filter->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); - - // Assign seed - auto seeds = this->GetInputData< vtkPolyData >( "Seed" ); - if( seeds != NULL ) - { - typename _TInputImage::PointType pnt; - typename _TInputImage::IndexType idx; - unsigned int dim = - ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3; - if( seeds->GetNumberOfPoints( ) > 0 ) - { - double buf[ 3 ]; - seeds->GetPoint( 0, buf ); - pnt.Fill( 0 ); - for( unsigned int d = 0; d < dim; ++d ) - pnt[ d ] = buf[ d ]; - - if( image->TransformPhysicalPointToIndex( pnt, idx ) ) - filter->SetSeed( idx ); - } - else - this->_Error( "No given seeds." ); - } - else - this->_Error( "No given seeds." ); - - filter->Update( ); - this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); - this->GetOutput( "AuxiliaryOutput" )->SetITK( filter->GetAuxiliaryImage( ) ); - */ -} - -// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/MoriRegionGrow.h b/plugins/ImageAlgorithms/MoriRegionGrow.h deleted file mode 100644 index f21c28b..0000000 --- a/plugins/ImageAlgorithms/MoriRegionGrow.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __fpaPluginsImageAlgorithms__MoriRegionGrow__h__ -#define __fpaPluginsImageAlgorithms__MoriRegionGrow__h__ - -#include - -namespace fpaPluginsImageAlgorithms -{ - /** - */ - class fpaPluginsImageAlgorithms_EXPORT MoriRegionGrow - : public cpPlugins::Pipeline::ProcessObject - { - cpPluginsObject( - MoriRegionGrow, cpPlugins::Pipeline::ProcessObject, fpaImageAlgorithms - ); - - protected: - template< class _TImage > - inline void _GD0( _TImage* image ); - - template< class _TInputImage, class _TOutputPixel > - inline void _GD1( _TInputImage* image ); - }; - -} // ecapseman - -#endif // __fpaPluginsImageAlgorithms__MoriRegionGrow__h__ - -// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/RegionGrow.cxx b/plugins/ImageAlgorithms/RegionGrow.cxx index e1aff3e..bd0fc74 100644 --- a/plugins/ImageAlgorithms/RegionGrow.cxx +++ b/plugins/ImageAlgorithms/RegionGrow.cxx @@ -1,29 +1,31 @@ -#include +#include "RegionGrow.h" +#include #include #include // ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::RegionGrow:: +fpaPlugins_ImageAlgorithms::RegionGrow:: RegionGrow( ) : Superclass( ) { - typedef cpPlugins::Pipeline::DataObject _TData; + typedef cpPlugins::Pipeline::DataObject _TFunctor; + typedef cpInstances::DataObjects::Image _TMST; - this->_ConfigureInput< _TData >( "GrowFunction", true, false ); + this->_ConfigureInput< _TFunctor >( "GrowFunction", true, false ); this->m_Parameters.ConfigureAsInt( "InsideValue", 1 ); this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 ); this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" ); } // ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::RegionGrow:: +fpaPlugins_ImageAlgorithms::RegionGrow:: ~RegionGrow( ) { } // ------------------------------------------------------------------------- -void fpaPluginsImageAlgorithms::RegionGrow:: +void fpaPlugins_ImageAlgorithms::RegionGrow:: _GenerateData( ) { auto o = this->GetInputData( "Input" ); @@ -33,7 +35,7 @@ _GenerateData( ) // ------------------------------------------------------------------------- template< class _TImage > -void fpaPluginsImageAlgorithms::RegionGrow:: +void fpaPlugins_ImageAlgorithms::RegionGrow:: _GD0( _TImage* image ) { auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" ); @@ -50,27 +52,34 @@ _GD0( _TImage* image ) // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputPixel > -void fpaPluginsImageAlgorithms::RegionGrow:: +void fpaPlugins_ImageAlgorithms::RegionGrow:: _GD1( _TInputImage* image ) { - typedef - itk::Image< _TOutputPixel, _TInputImage::ImageDimension > - _TOutputImage; + typedef cpPlugins::Pipeline::Functor _TFunctor; + typedef itk::Image< _TOutputPixel, _TInputImage::ImageDimension > _TOutputImage; typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > _TFilter; - typedef typename _TFilter::TGrowFunction _TGrow; - - _TOutputPixel i_val = _TOutputPixel( this->m_Parameters.GetInt( "InsideValue" ) ); - _TOutputPixel o_val = _TOutputPixel( this->m_Parameters.GetInt( "OutsideValue" ) ); + typedef typename _TFilter::TGrowFunction _TGrowFunction; + // Create filter auto filter = this->_CreateITK< _TFilter >( ); std::vector< typename _TInputImage::IndexType > seeds; this->_ConfigureFilter( filter, image, seeds ); + + // Instantiate functors + auto growfunc = this->GetInputData< _TFunctor >( "GrowFunction" ); + if( growfunc != NULL ) + { + growfunc->Instantiate( filter ); + auto growfunc_functor = growfunc->GetFunctor< _TGrowFunction >( ); + if( growfunc_functor != NULL ) + filter->SetGrowFunction( growfunc_functor ); + + } // fi + + // Finish filter's configuration filter->ClearSeeds( ); for( auto seed : seeds ) - filter->AddSeed( seed, i_val ); - filter->SetGrowFunction( this->GetInputData< _TGrow >( "GrowFunction" ) ); - filter->SetInsideValue( i_val ); - filter->SetOutsideValue( o_val ); + filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) ); filter->Update( ); this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); } diff --git a/plugins/ImageAlgorithms/RegionGrow.h b/plugins/ImageAlgorithms/RegionGrow.h index f5b49af..c9e59a7 100644 --- a/plugins/ImageAlgorithms/RegionGrow.h +++ b/plugins/ImageAlgorithms/RegionGrow.h @@ -1,13 +1,13 @@ -#ifndef __fpaPluginsImageAlgorithms__RegionGrow__h__ -#define __fpaPluginsImageAlgorithms__RegionGrow__h__ +#ifndef __fpaPlugins_ImageAlgorithms__RegionGrow__h__ +#define __fpaPlugins_ImageAlgorithms__RegionGrow__h__ #include -namespace fpaPluginsImageAlgorithms +namespace fpaPlugins_ImageAlgorithms { /** */ - class fpaPluginsImageAlgorithms_EXPORT RegionGrow + class fpaPlugins_ImageAlgorithms_EXPORT RegionGrow : public BaseFilter { cpPluginsObject( RegionGrow, BaseFilter, fpaImageAlgorithms ); @@ -22,6 +22,6 @@ namespace fpaPluginsImageAlgorithms } // ecapseman -#endif // __fpaPluginsImageAlgorithms__RegionGrow__h__ +#endif // __fpaPlugins_ImageAlgorithms__RegionGrow__h__ // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/SkeletonFilter.cxx b/plugins/ImageAlgorithms/SkeletonFilter.cxx deleted file mode 100644 index 03689aa..0000000 --- a/plugins/ImageAlgorithms/SkeletonFilter.cxx +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include - -#include - -/* TODO - #include - #include -*/ - -// ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::SkeletonFilter:: -SkeletonFilter( ) - : Superclass( ) -{ - typedef cpInstances::DataObjects::Image _TImage; - typedef cpInstances::DataObjects::Skeleton _TSkeleton; - typedef cpPlugins::Pipeline::DataObject _TData; - - this->_ConfigureInput< _TImage >( "Input", true, false ); - this->_ConfigureInput< _TData >( "Seeds", true, false ); - this->_ConfigureOutput< _TSkeleton >( "Skeleton" ); - this->_ConfigureOutput< _TImage >( "Marks" ); -} - -// ------------------------------------------------------------------------- -fpaPluginsImageAlgorithms::SkeletonFilter:: -~SkeletonFilter( ) -{ -} - -// ------------------------------------------------------------------------- -void fpaPluginsImageAlgorithms::SkeletonFilter:: -_GenerateData( ) -{ - auto o = this->GetInputData( "Input" ); - cpPlugins_Demangle_Image_RealPixels_AllDims_1( o, _GD0 ) - this->_Error( "Invalid input image." ); -} - -// ------------------------------------------------------------------------- -template< class _TImage > -void fpaPluginsImageAlgorithms::SkeletonFilter:: -_GD0( _TImage* image ) -{ - /* TODO - typedef fpa::Image::SkeletonFilter< _TImage > _TFilter; - auto filter = this->_CreateITK< _TFilter >( ); - filter->SetInput( image ); - - auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); - if( seeds != NULL ) - { - typename _TImage::PointType pnt; - typename _TImage::IndexType idx; - unsigned int dim = - ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; - - for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) - { - double buf[ 3 ]; - seeds->GetPoint( i, buf ); - pnt.Fill( 0 ); - for( unsigned int d = 0; d < dim; ++d ) - pnt[ d ] = buf[ d ]; - - if( image->TransformPhysicalPointToIndex( pnt, idx ) ) - filter->AddSeed( idx, 0 ); - - } // rof - - } // fi - - filter->Update( ); - this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) ); - this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) ); - */ -} - -// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/SkeletonFilter.h b/plugins/ImageAlgorithms/SkeletonFilter.h deleted file mode 100644 index cd3ebcf..0000000 --- a/plugins/ImageAlgorithms/SkeletonFilter.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __fpaPluginsImageAlgorithms__SkeletonFilter__h__ -#define __fpaPluginsImageAlgorithms__SkeletonFilter__h__ - -#include -#include - -namespace fpaPluginsImageAlgorithms -{ - /** - */ - class fpaPluginsImageAlgorithms_EXPORT SkeletonFilter - : public cpPlugins::Pipeline::ProcessObject - { - cpPluginsObject( - SkeletonFilter, - cpPlugins::Pipeline::ProcessObject, - fpaImageAlgorithms - ); - - protected: - template< class _TImage > - inline void _GD0( _TImage* image ); - }; - -} // ecapseman - -#endif // __fpaPluginsImageAlgorithms__SkeletonFilter__h__ - -// eof - $RCSfile$ diff --git a/plugins/ImageFunctors/BinaryThreshold.cxx b/plugins/ImageFunctors/BinaryThreshold.cxx new file mode 100644 index 0000000..4d4589e --- /dev/null +++ b/plugins/ImageFunctors/BinaryThreshold.cxx @@ -0,0 +1,90 @@ +#include "BinaryThreshold.h" + +#include + +#include +#include + +// ------------------------------------------------------------------------- +void fpaPlugins_ImageFunctors::BinaryThreshold:: +Instantiate( itk::LightObject* filter ) +{ + auto itk_filter = dynamic_cast< itk::ProcessObject* >( filter ); + if( itk_filter != NULL ) + { + auto inputs = itk_filter->GetInputs( ); + if( inputs.size( ) > 0 ) + { + cpPlugins_Demangle_Image_ScalarPixels_AllDims_2( + inputs[ 0 ].GetPointer( ), _GD0, itk_filter + ) + this->_Error( "Invalid input data." ); + } + else + this->_Error( "Not enough inputs." ); + } + else + this->_Error( "Invalid instantiation filter." ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_ImageFunctors::BinaryThreshold:: +BinaryThreshold( ) + : Superclass( ) +{ + this->_ConfigureOutput< cpPlugins::Pipeline::DataObject >( "Functor" ); + this->GetOutput( "Functor" )->SetITK( this ); + this->m_Parameters.ConfigureAsReal( "Lower", 0 ); + this->m_Parameters.ConfigureAsReal( "Upper", 1 ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_ImageFunctors::BinaryThreshold:: +~BinaryThreshold( ) +{ +} + +// ------------------------------------------------------------------------- +void fpaPlugins_ImageFunctors::BinaryThreshold:: +_GenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TInput > +void fpaPlugins_ImageFunctors::BinaryThreshold:: +_GD0( _TInput* input, itk::ProcessObject* filter ) +{ + auto outputs = filter->GetOutputs( ); + if( outputs.size( ) > 0 ) + { + cpPlugins_Demangle_Image_IntPixels_3( + outputs[ 0 ].GetPointer( ), _GD1, _TInput::ImageDimension, input, filter + ) + this->_Error( "Invalid output data." ); + } + else + this->_Error( "Not enough outputs." ); +} + +// ------------------------------------------------------------------------- +template< class _TInput, class _TOutput > +void fpaPlugins_ImageFunctors::BinaryThreshold:: +_GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter ) +{ + typedef typename _TOutput::PixelType _TValue; + typedef fpa::Image::Functors::RegionGrow::BinaryThreshold< _TInput, _TValue > _TFunctor; + + auto f = dynamic_cast< _TFunctor* >( this->m_Functor.GetPointer( ) ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + this->m_Functor = f; + + } // fi + f->SetLower( this->m_Parameters.GetReal( "Lower" ) ); + f->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/ImageFunctors/BinaryThreshold.h b/plugins/ImageFunctors/BinaryThreshold.h new file mode 100644 index 0000000..73cdad1 --- /dev/null +++ b/plugins/ImageFunctors/BinaryThreshold.h @@ -0,0 +1,32 @@ +#ifndef __fpaPlugins_ImageFunctors__BinaryThreshold__h__ +#define __fpaPlugins_ImageFunctors__BinaryThreshold__h__ + +#include +#include +#include + +namespace fpaPlugins_ImageFunctors +{ + /** + */ + class fpaPlugins_ImageFunctors_EXPORT BinaryThreshold + : public cpPlugins::Pipeline::Functor + { + cpPluginsObject( BinaryThreshold, cpPlugins::Pipeline::Functor, fpaImageFunctors ); + + public: + virtual void Instantiate( itk::LightObject* filter ) override; + + protected: + template< class _TInput > + inline void _GD0( _TInput* input, itk::ProcessObject* filter ); + + template< class _TInput, class _TOutput > + inline void _GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter ); + }; + +} // ecapseman + +#endif // __fpaPlugins_ImageFunctors__BinaryThreshold__h__ + +// eof - $RCSfile$ diff --git a/plugins/ImageFunctors/Tautology.cxx b/plugins/ImageFunctors/Tautology.cxx new file mode 100644 index 0000000..6763602 --- /dev/null +++ b/plugins/ImageFunctors/Tautology.cxx @@ -0,0 +1,87 @@ +#include "Tautology.h" + +#include + +#include +#include + +// ------------------------------------------------------------------------- +void fpaPlugins_ImageFunctors::Tautology:: +Instantiate( itk::LightObject* filter ) +{ + auto itk_filter = dynamic_cast< itk::ProcessObject* >( filter ); + if( itk_filter != NULL ) + { + auto inputs = itk_filter->GetInputs( ); + if( inputs.size( ) > 0 ) + { + cpPlugins_Demangle_Image_ScalarPixels_AllDims_2( + inputs[ 0 ].GetPointer( ), _GD0, itk_filter + ) + this->_Error( "Invalid input data." ); + } + else + this->_Error( "Not enough inputs." ); + } + else + this->_Error( "Invalid instantiation filter." ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_ImageFunctors::Tautology:: +Tautology( ) + : Superclass( ) +{ + this->_ConfigureOutput< cpPlugins::Pipeline::DataObject >( "Functor" ); + this->GetOutput( "Functor" )->SetITK( this ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_ImageFunctors::Tautology:: +~Tautology( ) +{ +} + +// ------------------------------------------------------------------------- +void fpaPlugins_ImageFunctors::Tautology:: +_GenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TInput > +void fpaPlugins_ImageFunctors::Tautology:: +_GD0( _TInput* input, itk::ProcessObject* filter ) +{ + auto outputs = filter->GetOutputs( ); + if( outputs.size( ) > 0 ) + { + cpPlugins_Demangle_Image_IntPixels_3( + outputs[ 0 ].GetPointer( ), _GD1, _TInput::ImageDimension, input, filter + ) + this->_Error( "Invalid output data." ); + } + else + this->_Error( "Not enough outputs." ); +} + +// ------------------------------------------------------------------------- +template< class _TInput, class _TOutput > +void fpaPlugins_ImageFunctors::Tautology:: +_GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter ) +{ + typedef typename _TInput::IndexType _TVertex; + typedef typename _TOutput::PixelType _TValue; + typedef fpa::Base::Functors::RegionGrow::Tautology< _TVertex, _TValue > _TFunctor; + + auto f = dynamic_cast< _TFunctor* >( this->m_Functor.GetPointer( ) ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + this->m_Functor = f; + + } // fi +} + +// eof - $RCSfile$ diff --git a/plugins/ImageFunctors/Tautology.h b/plugins/ImageFunctors/Tautology.h new file mode 100644 index 0000000..1a846c1 --- /dev/null +++ b/plugins/ImageFunctors/Tautology.h @@ -0,0 +1,32 @@ +#ifndef __fpaPlugins_ImageFunctors__Tautology__h__ +#define __fpaPlugins_ImageFunctors__Tautology__h__ + +#include +#include +#include + +namespace fpaPlugins_ImageFunctors +{ + /** + */ + class fpaPlugins_ImageFunctors_EXPORT Tautology + : public cpPlugins::Pipeline::Functor + { + cpPluginsObject( Tautology, cpPlugins::Pipeline::Functor, fpaImageFunctors ); + + public: + virtual void Instantiate( itk::LightObject* filter ) override; + + protected: + template< class _TInput > + inline void _GD0( _TInput* input, itk::ProcessObject* filter ); + + template< class _TInput, class _TOutput > + inline void _GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter ); + }; + +} // ecapseman + +#endif // __fpaPlugins_ImageFunctors__Tautology__h__ + +// eof - $RCSfile$ diff --git a/plugins/ImageFunctors/VertexCost.cxx b/plugins/ImageFunctors/VertexCost.cxx new file mode 100644 index 0000000..222cdb5 --- /dev/null +++ b/plugins/ImageFunctors/VertexCost.cxx @@ -0,0 +1,89 @@ +#include "VertexCost.h" + +#include + +#include +#include + +// ------------------------------------------------------------------------- +void fpaPlugins_ImageFunctors::VertexCost:: +Instantiate( itk::LightObject* filter ) +{ + auto itk_filter = dynamic_cast< itk::ProcessObject* >( filter ); + if( itk_filter != NULL ) + { + auto inputs = itk_filter->GetInputs( ); + if( inputs.size( ) > 0 ) + { + cpPlugins_Demangle_Image_ScalarPixels_AllDims_2( + inputs[ 0 ].GetPointer( ), _GD0, itk_filter + ) + this->_Error( "Invalid input data." ); + } + else + this->_Error( "Not enough inputs." ); + } + else + this->_Error( "Invalid instantiation filter." ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_ImageFunctors::VertexCost:: +VertexCost( ) + : Superclass( ) +{ + this->_ConfigureOutput< cpPlugins::Pipeline::DataObject >( "Functor" ); + this->m_Parameters.ConfigureAsBool( "UseImageSpacing", false ); + this->GetOutput( "Functor" )->SetITK( this ); +} + +// ------------------------------------------------------------------------- +fpaPlugins_ImageFunctors::VertexCost:: +~VertexCost( ) +{ +} + +// ------------------------------------------------------------------------- +void fpaPlugins_ImageFunctors::VertexCost:: +_GenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TInput > +void fpaPlugins_ImageFunctors::VertexCost:: +_GD0( _TInput* input, itk::ProcessObject* filter ) +{ + auto outputs = filter->GetOutputs( ); + if( outputs.size( ) > 0 ) + { + cpPlugins_Demangle_Image_ScalarPixels_3( + outputs[ 0 ].GetPointer( ), _GD1, _TInput::ImageDimension, input, filter + ) + this->_Error( "Invalid output data." ); + } + else + this->_Error( "Not enough outputs." ); +} + +// ------------------------------------------------------------------------- +template< class _TInput, class _TOutput > +void fpaPlugins_ImageFunctors::VertexCost:: +_GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter ) +{ + typedef typename _TInput::PixelType _TIValue; + typedef typename _TOutput::PixelType _TOValue; + typedef fpa::Image::Functors::VertexCost< _TInput, _TOValue > _TFunctor; + + auto f = dynamic_cast< _TFunctor* >( this->m_Functor.GetPointer( ) ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + this->m_Functor = f; + + } // fi + f->SetUseImageSpacing( this->m_Parameters.GetReal( "UseImageSpacing" ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/ImageFunctors/VertexCost.h b/plugins/ImageFunctors/VertexCost.h new file mode 100644 index 0000000..7a0bc14 --- /dev/null +++ b/plugins/ImageFunctors/VertexCost.h @@ -0,0 +1,32 @@ +#ifndef __fpaPlugins_ImageFunctors__VertexCost__h__ +#define __fpaPlugins_ImageFunctors__VertexCost__h__ + +#include +#include +#include + +namespace fpaPlugins_ImageFunctors +{ + /** + */ + class fpaPlugins_ImageFunctors_EXPORT VertexCost + : public cpPlugins::Pipeline::Functor + { + cpPluginsObject( VertexCost, cpPlugins::Pipeline::Functor, fpaImageFunctors ); + + public: + virtual void Instantiate( itk::LightObject* filter ) override; + + protected: + template< class _TInput > + inline void _GD0( _TInput* input, itk::ProcessObject* filter ); + + template< class _TInput, class _TOutput > + inline void _GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter ); + }; + +} // ecapseman + +#endif // __fpaPlugins_ImageFunctors__VertexCost__h__ + +// eof - $RCSfile$ -- 2.47.1