1 #include "FastMarching.h"
2 #include <cpPlugins/Pipeline/Functor.h>
3 #include <cpInstances/DataObjects/Image.h>
5 #include <fpa/Image/FastMarching.h>
7 // -------------------------------------------------------------------------
8 fpaPlugins_ImageAlgorithms::FastMarching::
12 typedef cpPlugins::Pipeline::DataObject _TFunctor;
14 this->_ConfigureInput< _TFunctor >( "VertexFunction", false, false );
15 this->_ConfigureInput< _TFunctor >( "ConversionFunction", false, false );
17 std::vector< std::string > choices;
18 choices.push_back( "float" );
19 choices.push_back( "double" );
20 this->m_Parameters.ConfigureAsChoices( "ResultType", choices );
21 this->m_Parameters.SetSelectedChoice( "ResultType", "float" );
24 // -------------------------------------------------------------------------
25 fpaPlugins_ImageAlgorithms::FastMarching::
30 // -------------------------------------------------------------------------
31 void fpaPlugins_ImageAlgorithms::FastMarching::
34 auto o = this->GetInputData( "Input" );
35 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
36 this->_Error( "Invalid input image." );
39 // -------------------------------------------------------------------------
40 template< class _TImage >
41 void fpaPlugins_ImageAlgorithms::FastMarching::
42 _GD0( _TImage* image )
44 typedef itk::Image< float, _TImage::ImageDimension > _TFloat;
45 typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
47 auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
48 if ( rtype == "float" ) this->_GD1< _TImage, _TFloat >( image );
49 else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image );
52 // -------------------------------------------------------------------------
53 template< class _TInputImage, class _TOutputImage >
54 void fpaPlugins_ImageAlgorithms::FastMarching::
55 _GD1( _TInputImage* image )
57 typedef cpPlugins::Pipeline::Functor _TFunctor;
58 typedef fpa::Image::FastMarching< _TInputImage, _TOutputImage > _TFilter;
59 typedef typename _TFilter::TConversionFunction _TConversionFunction;
60 typedef typename _TFilter::TVertexFunction _TVertexFunction;
63 auto filter = this->_CreateITK< _TFilter >( );
64 std::vector< typename _TInputImage::IndexType > seeds;
65 this->_ConfigureFilter( filter, image, seeds );
67 // Instantiate functors
68 auto cost_conversion = this->GetInputData< _TFunctor >( "ConversionFunction" );
69 if( cost_conversion != NULL )
71 cost_conversion->Instantiate( filter );
72 auto cost_conversion_functor = cost_conversion->GetFunctor< _TConversionFunction >( );
73 if( cost_conversion_functor != NULL )
74 filter->SetConversionFunction( cost_conversion_functor );
78 auto vertex = this->GetInputData< _TFunctor >( "VertexFunction" );
81 vertex->Instantiate( filter );
82 auto vertex_functor = vertex->GetFunctor< _TVertexFunction >( );
83 if( vertex_functor != NULL )
84 filter->SetVertexFunction( vertex_functor );
88 // Finish filter's configuration
89 filter->ClearSeeds( );
90 for( auto seed : seeds )
91 filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) );
93 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );