1 #include <ImageAlgorithms/FastMarching.h>
2 #include <cpInstances/DataObjects/Image.h>
4 #include <fpa/Image/FastMarching.h>
6 // -------------------------------------------------------------------------
7 fpaPluginsImageAlgorithms::FastMarching::
11 typedef cpPlugins::Pipeline::DataObject _TData;
12 typedef cpInstances::DataObjects::Image _TMST;
14 this->_ConfigureInput< _TData >( "VertexFunction", false, false );
15 this->_ConfigureInput< _TData >( "ConversionFunction", false, false );
16 this->_ConfigureOutput< _TMST >( "MST" );
18 std::vector< std::string > choices;
19 choices.push_back( "float" );
20 choices.push_back( "double" );
21 this->m_Parameters.ConfigureAsChoices( "ResultType", choices );
22 this->m_Parameters.SetSelectedChoice( "ResultType", "float" );
25 // -------------------------------------------------------------------------
26 fpaPluginsImageAlgorithms::FastMarching::
31 // -------------------------------------------------------------------------
32 void fpaPluginsImageAlgorithms::FastMarching::
35 auto o = this->GetInputData( "Input" );
36 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
37 this->_Error( "Invalid input image." );
40 // -------------------------------------------------------------------------
41 template< class _TImage >
42 void fpaPluginsImageAlgorithms::FastMarching::
43 _GD0( _TImage* image )
45 typedef itk::Image< float, _TImage::ImageDimension > _TFloat;
46 typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
48 auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
49 if ( rtype == "float" ) this->_GD1< _TImage, _TFloat >( image );
50 else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image );
53 // -------------------------------------------------------------------------
54 template< class _TInputImage, class _TOutputImage >
55 void fpaPluginsImageAlgorithms::FastMarching::
56 _GD1( _TInputImage* image )
58 typedef fpa::Image::FastMarching< _TInputImage, _TOutputImage > _TFilter;
59 typedef typename _TFilter::TConversionFunction _TConversionFunction;
60 typedef typename _TFilter::TVertexFunction _TVertexFunction;
62 auto filter = this->_CreateITK< _TFilter >( );
63 std::vector< typename _TInputImage::IndexType > seeds;
64 this->_ConfigureFilter( filter, image, seeds );
65 filter->ClearSeeds( );
66 for( auto seed : seeds )
67 filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) );
69 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
72 auto filter = this->_CreateITK< _TFilter >( );
73 this->_ConfigureFilter( filter, image );
74 auto cost = this->GetInputData< _TCost >( "Cost" );
75 auto conv = this->GetInputData< _TCostConversion >( "CostConversion" );
77 filter->SetCostFunction( cost );
79 filter->SetCostConversionFunction( conv );
81 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
82 this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) );