#include "FastMarching.h" #include #include #include // ------------------------------------------------------------------------- fpaPlugins_ImageAlgorithms::FastMarching:: FastMarching( ) : Superclass( ) { typedef cpPlugins::Pipeline::DataObject _TFunctor; this->_ConfigureInput< _TFunctor >( "VertexFunction", false, false ); this->_ConfigureInput< _TFunctor >( "ConversionFunction", false, false ); std::vector< std::string > choices; choices.push_back( "float" ); choices.push_back( "double" ); this->m_Parameters.ConfigureAsChoices( "ResultType", choices ); this->m_Parameters.SetSelectedChoice( "ResultType", "float" ); } // ------------------------------------------------------------------------- fpaPlugins_ImageAlgorithms::FastMarching:: ~FastMarching( ) { } // ------------------------------------------------------------------------- void fpaPlugins_ImageAlgorithms::FastMarching:: _GenerateData( ) { auto o = this->GetInputData( "Input" ); cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) this->_Error( "Invalid input image." ); } // ------------------------------------------------------------------------- template< class _TImage > void fpaPlugins_ImageAlgorithms::FastMarching:: _GD0( _TImage* image ) { typedef itk::Image< float, _TImage::ImageDimension > _TFloat; typedef itk::Image< double, _TImage::ImageDimension > _TDouble; auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" ); if ( rtype == "float" ) this->_GD1< _TImage, _TFloat >( image ); else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > 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( ) ); } // eof - $RCSfile$