1 #include "GradientBaseImageFunctionSource.h"
2 #include <cpPlugins/Image.h>
3 #include <fpa/Image/Functors/GulsunTekMedialness.h>
4 #include <fpa/Image/Functors/FluxMedialness.h>
5 #include <fpa/Image/Functors/MFluxMedialness.h>
6 #include <cpExtensions/Algorithms/ImageFunctionFilter.h>
7 #include <fpa/Image/Functors/GulsunTekMedialness.hxx>
8 #include <fpa/Image/Functors/FluxMedialness.hxx>
9 #include <fpa/Image/Functors/MFluxMedialness.hxx>
10 #include <fpa/Image/Functors/GradientImageFunctionBase.hxx>
11 #include <cpExtensions/Algorithms/ImageFunctionFilter.hxx>
12 #include <itkImageConstIteratorWithIndex.hxx>
13 #include <itkImageIteratorWithIndex.hxx>
14 #include <itkImageToImageFilter.hxx>
15 #include <itkImageFunction.hxx>
16 #include <itkImageRegionConstIteratorWithIndex.hxx>
18 // -------------------------------------------------------------------------
19 fpaPlugins::GradientBaseImageFunctionSource::
20 GradientBaseImageFunctionSource( )
23 this->_AddInput( "Input" );
24 this->_AddOutput< cpPlugins::Image >( "Output" );
26 std::vector< std::string > choices;
27 choices.push_back( "Gulsun&Tek" );
28 choices.push_back( "Flux" );
29 choices.push_back( "MFlux" );
30 this->m_Parameters.ConfigureAsChoices( "FunctionType", choices );
31 this->m_Parameters.SetSelectedChoice( "FunctionType", "Gulsun&Tek" );
33 this->m_Parameters.ConfigureAsReal( "MinRadius" );
34 this->m_Parameters.ConfigureAsReal( "MaxRadius" );
35 this->m_Parameters.ConfigureAsUint( "ProfileSampling" );
36 this->m_Parameters.ConfigureAsUint( "RadialSampling" );
37 this->m_Parameters.SetReal( "MinRadius", 0 );
38 this->m_Parameters.SetReal( "MaxRadius", 1 );
39 this->m_Parameters.SetUint( "ProfileSampling", 4 );
40 this->m_Parameters.SetUint( "RadialSampling", 10 );
43 // -------------------------------------------------------------------------
44 fpaPlugins::GradientBaseImageFunctionSource::
45 ~GradientBaseImageFunctionSource( )
49 // -------------------------------------------------------------------------
50 std::string fpaPlugins::GradientBaseImageFunctionSource::
53 auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
54 std::string cpPlugin_Image_Demangle_VectorPixel_AllFloats( r, _GD0, image, itk::CovariantVector, 2 );
55 if( r != "" ) cpPlugin_Image_Demangle_VectorPixel_AllFloats( r, _GD0, image, itk::CovariantVector, 3 );
59 // -------------------------------------------------------------------------
60 template< class _TImage >
61 std::string fpaPlugins::GradientBaseImageFunctionSource::
62 _GD0( _TImage* image )
64 typedef fpa::Image::Functors::GulsunTekMedialness< _TImage > _TGT;
65 typedef fpa::Image::Functors::FluxMedialness< _TImage > _TFl;
66 typedef fpa::Image::Functors::MFluxMedialness< _TImage > _TMFl;
69 return( "GradientBaseImageFunctionSource: Invalid input image." );
71 auto ft = this->m_Parameters.GetSelectedChoice( "FunctionType" );
72 if ( ft == "Gulsun&Tek" ) return( this->_GD1< _TImage, _TGT >( image ) );
73 else if( ft == "Flux" ) return( this->_GD1< _TImage, _TFl >( image ) );
74 else if( ft == "MFlux" ) return( this->_GD1< _TImage, _TMFl >( image ) );
76 return( "GradientBaseImageFunctionSource: Invalid function type." );
79 // -------------------------------------------------------------------------
80 template< class _TImage, class _TFunction >
81 std::string fpaPlugins::GradientBaseImageFunctionSource::
82 _GD1( _TImage* image )
84 typedef itk::Image< typename _TFunction::TOutput, _TImage::ImageDimension > _TOutImage;
85 typedef cpExtensions::Algorithms::ImageFunctionFilter< _TImage, _TOutImage, _TFunction > _TFilter;
87 _TFilter* filter = this->_CreateITK< _TFilter >( );
88 filter->SetInput( image );
89 _TFunction* function = filter->GetFunction( );
90 if( function == NULL )
92 filter->SetFunction( _TFunction::New( ) );
93 function = filter->GetFunction( );
96 function->SetMinRadius( this->m_Parameters.GetReal( "MinRadius" ) );
97 function->SetMaxRadius( this->m_Parameters.GetReal( "MaxRadius" ) );
99 function->SetProfileSampling( this->m_Parameters.GetUint( "ProfileSampling" ) );
100 function->SetRadialSampling( this->m_Parameters.GetUint( "RadialSampling" ) );
105 // Connect output and finish
106 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );