2 #include <cpPlugins/Pipeline/Functor.h>
3 #include <cpInstances/DataObjects/Image.h>
5 #include <fpa/Image/Dijkstra.h>
7 // -------------------------------------------------------------------------
8 fpaPlugins_ImageAlgorithms::Dijkstra::
12 typedef cpPlugins::Pipeline::DataObject _TFunctor;
13 typedef cpInstances::DataObjects::Image _TMST;
15 this->_ConfigureInput< _TFunctor >( "VertexFunction", false, false );
16 this->_ConfigureInput< _TFunctor >( "ConversionFunction", false, false );
17 this->_ConfigureOutput< _TMST >( "MST" );
19 std::vector< std::string > choices;
20 choices.push_back( "float" );
21 choices.push_back( "double" );
22 this->m_Parameters.ConfigureAsChoices( "ResultType", choices );
23 this->m_Parameters.SetSelectedChoice( "ResultType", "float" );
26 // -------------------------------------------------------------------------
27 fpaPlugins_ImageAlgorithms::Dijkstra::
32 // -------------------------------------------------------------------------
33 void fpaPlugins_ImageAlgorithms::Dijkstra::
36 auto o = this->GetInputData( "Input" );
37 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
38 this->_Error( "Invalid input image." );
41 // -------------------------------------------------------------------------
42 template< class _TImage >
43 void fpaPlugins_ImageAlgorithms::Dijkstra::
44 _GD0( _TImage* image )
46 typedef itk::Image< float, _TImage::ImageDimension > _TFloat;
47 typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
49 auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
50 if ( rtype == "float" ) this->_GD1< _TImage, _TFloat >( image );
51 else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image );
54 // -------------------------------------------------------------------------
55 template< class _TInputImage, class _TOutputImage >
56 void fpaPlugins_ImageAlgorithms::Dijkstra::
57 _GD1( _TInputImage* image )
59 typedef cpPlugins::Pipeline::Functor _TFunctor;
60 typedef fpa::Image::Dijkstra< _TInputImage, _TOutputImage > _TFilter;
61 typedef typename _TFilter::TConversionFunction _TConversionFunction;
62 typedef typename _TFilter::TVertexFunction _TVertexFunction;
65 auto filter = this->_CreateITK< _TFilter >( );
66 std::vector< typename _TInputImage::IndexType > seeds;
67 this->_ConfigureFilter( filter, image, seeds );
69 // Instantiate functors
70 auto cost_conversion = this->GetInputData< _TFunctor >( "ConversionFunction" );
71 if( cost_conversion != NULL )
73 cost_conversion->Instantiate( filter );
74 auto cost_conversion_functor = cost_conversion->GetFunctor< _TConversionFunction >( );
75 if( cost_conversion_functor != NULL )
76 filter->SetConversionFunction( cost_conversion_functor );
80 auto vertex = this->GetInputData< _TFunctor >( "VertexFunction" );
83 vertex->Instantiate( filter );
84 auto vertex_functor = vertex->GetFunctor< _TVertexFunction >( );
85 if( vertex_functor != NULL )
86 filter->SetVertexFunction( vertex_functor );
90 // Finish filter's configuration
91 filter->ClearSeeds( );
92 for( auto seed : seeds )
93 filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) );
95 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
96 this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) );