1 #include "GradientBaseImageFunctionSource.h"
3 #include <cpPlugins/Image.h>
4 #include <fpa_Instances/Functors.h>
6 // -------------------------------------------------------------------------
7 fpaPlugins::GradientBaseImageFunctionSource::
8 GradientBaseImageFunctionSource( )
11 this->_AddInput( "Input" );
12 this->_AddOutput< cpPlugins::Image >( "Output" );
14 std::vector< std::string > choices;
15 choices.push_back( "Gulsun&Tek" );
16 choices.push_back( "Flux" );
17 choices.push_back( "MFlux" );
18 this->m_Parameters.ConfigureAsChoices( "FunctionType", choices );
19 this->m_Parameters.SetSelectedChoice( "FunctionType", "Gulsun&Tek" );
21 this->m_Parameters.ConfigureAsReal( "MinRadius" );
22 this->m_Parameters.ConfigureAsReal( "MaxRadius" );
23 this->m_Parameters.ConfigureAsUint( "ProfileSampling" );
24 this->m_Parameters.ConfigureAsUint( "RadialSampling" );
25 this->m_Parameters.SetReal( "MinRadius", 0 );
26 this->m_Parameters.SetReal( "MaxRadius", 1 );
27 this->m_Parameters.SetUint( "ProfileSampling", 4 );
28 this->m_Parameters.SetUint( "RadialSampling", 10 );
31 // -------------------------------------------------------------------------
32 fpaPlugins::GradientBaseImageFunctionSource::
33 ~GradientBaseImageFunctionSource( )
37 // -------------------------------------------------------------------------
38 void fpaPlugins::GradientBaseImageFunctionSource::
41 auto image = this->GetInputData< itk::DataObject >( "Input" );
42 cpPlugins_Image_Demangle_VectorPixel_AllFloats ( _GD0, image, CovariantVector, 2 );
43 else cpPlugins_Image_Demangle_VectorPixel_AllFloats( _GD0, image, CovariantVector, 3 );
44 else this->_Error( "Invalid input image." );
47 // -------------------------------------------------------------------------
48 template< class _TImage >
49 void fpaPlugins::GradientBaseImageFunctionSource::
50 _GD0( _TImage* image )
52 typedef fpa::Image::Functors::GulsunTekMedialness< _TImage > _TGT;
53 typedef fpa::Image::Functors::FluxMedialness< _TImage > _TFl;
54 typedef fpa::Image::Functors::MFluxMedialness< _TImage > _TMFl;
56 auto ft = this->m_Parameters.GetSelectedChoice( "FunctionType" );
57 if ( ft == "Gulsun&Tek" ) this->_GD1< _TImage, _TGT >( image );
58 else if( ft == "Flux" ) this->_GD1< _TImage, _TFl >( image );
59 else if( ft == "MFlux" ) this->_GD1< _TImage, _TMFl >( image );
60 else this->_Error( "Invalid function type." );
63 // -------------------------------------------------------------------------
64 template< class _TImage, class _TFunction >
65 void fpaPlugins::GradientBaseImageFunctionSource::
66 _GD1( _TImage* image )
68 typedef itk::Image< typename _TFunction::TOutput, _TImage::ImageDimension > _TOutImage;
69 typedef cpExtensions::Algorithms::ImageFunctionFilter< _TImage, _TOutImage, _TFunction > _TFilter;
71 _TFilter* filter = this->_CreateITK< _TFilter >( );
72 filter->SetInput( image );
73 _TFunction* function = filter->GetFunction( );
74 if( function == NULL )
76 filter->SetFunction( _TFunction::New( ) );
77 function = filter->GetFunction( );
80 function->SetMinRadius( this->m_Parameters.GetReal( "MinRadius" ) );
81 function->SetMaxRadius( this->m_Parameters.GetReal( "MaxRadius" ) );
83 function->SetProfileSampling( this->m_Parameters.GetUint( "ProfileSampling" ) );
84 function->SetRadialSampling( this->m_Parameters.GetUint( "RadialSampling" ) );
89 // Connect output and finish
90 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );