1 #include <ImageGradientFilters/GulsunTekImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demangler.h>
6 #include <cpExtensions/Algorithms/ImageFunctionFilter.h>
7 #include <cpExtensions/Algorithms/GulsunTekMedialness.h>
9 #include <cpExtensions/Algorithms/ImageFunctionFilter.hxx>
10 #include <cpExtensions/Algorithms/GulsunTekMedialness.hxx>
11 #include <cpExtensions/Algorithms/GradientImageFunctionBase.hxx>
12 #include <itkImageFunction.hxx>
15 // -------------------------------------------------------------------------
16 cpPluginsImageGradientFilters::GulsunTekImageFilter::
17 GulsunTekImageFilter( )
20 this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
21 this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Mask", false, false );
22 this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
24 this->m_Parameters.ConfigureAsReal( "MinRadius" );
25 this->m_Parameters.ConfigureAsReal( "MaxRadius" );
26 this->m_Parameters.ConfigureAsUint( "ProfileSampling" );
27 this->m_Parameters.ConfigureAsUint( "RadialSampling" );
29 this->m_Parameters.SetReal( "MinRadius", 0 );
30 this->m_Parameters.SetReal( "MaxRadius", 1 );
31 this->m_Parameters.SetUint( "ProfileSampling", 4 );
32 this->m_Parameters.SetUint( "RadialSampling", 10 );
35 // -------------------------------------------------------------------------
36 cpPluginsImageGradientFilters::GulsunTekImageFilter::
37 ~GulsunTekImageFilter( )
41 // -------------------------------------------------------------------------
42 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
45 auto o = this->GetInputData( "Input" );
46 cpPlugins_Demangle_ImageCovariantVectors_Dims( o, _GD0 );
47 else this->_Error( "Invalid input image." );
50 // -------------------------------------------------------------------------
51 template< class _TImage >
52 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
53 _GD0( _TImage* image )
55 typedef itk::Image< char, _TImage::ImageDimension > _TChar;
56 typedef itk::Image< short, _TImage::ImageDimension > _TShort;
57 typedef itk::Image< int, _TImage::ImageDimension > _TInt;
58 typedef itk::Image< long, _TImage::ImageDimension > _TLong;
59 typedef itk::Image< float, _TImage::ImageDimension > _TFloat;
60 typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
61 typedef itk::Image< unsigned char, _TImage::ImageDimension > _TUChar;
62 typedef itk::Image< unsigned short, _TImage::ImageDimension > _TUShort;
63 typedef itk::Image< unsigned int, _TImage::ImageDimension > _TUInt;
64 typedef itk::Image< unsigned long, _TImage::ImageDimension > _TULong;
66 auto m = this->GetInput( "Mask" );
67 auto ci = m->GetITK< _TChar >( );
68 auto si = m->GetITK< _TShort >( );
69 auto ii = m->GetITK< _TInt >( );
70 auto li = m->GetITK< _TLong >( );
71 auto fi = m->GetITK< _TFloat >( );
72 auto di = m->GetITK< _TDouble >( );
73 auto uci = m->GetITK< _TUChar >( );
74 auto usi = m->GetITK< _TUShort >( );
75 auto uii = m->GetITK< _TUInt >( );
76 auto uli = m->GetITK< _TULong >( );
77 if ( ci != NULL ) this->_GD1( image, ci );
78 else if( si != NULL ) this->_GD1( image, si );
79 else if( ii != NULL ) this->_GD1( image, ii );
80 else if( li != NULL ) this->_GD1( image, li );
81 else if( fi != NULL ) this->_GD1( image, fi );
82 else if( di != NULL ) this->_GD1( image, di );
83 else if( uci != NULL ) this->_GD1( image, uci );
84 else if( usi != NULL ) this->_GD1( image, usi );
85 else if( uii != NULL ) this->_GD1( image, uii );
86 else if( uli != NULL ) this->_GD1( image, uli );
87 else this->_GD1( image, ci );
90 // -------------------------------------------------------------------------
91 template< class _TImage, class _TMask >
92 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
93 _GD1( _TImage* image, _TMask* mask )
95 typedef typename _TImage::PixelType _TGradient;
96 typedef cpExtensions::Algorithms::GulsunTekMedialness< _TImage, _TMask > _TFunction;
97 typedef typename _TFunction::TOutput _TScalar;
98 typedef itk::Image< _TScalar, _TImage::ImageDimension > _TOutputImage;
99 typedef cpExtensions::Algorithms::ImageFunctionFilter< _TImage, _TOutputImage, _TFunction > _TFilter;
101 auto filter = this->_CreateITK< _TFilter >( );
102 auto function = filter->GetFunction( );
103 if( function == NULL )
105 filter->SetFunction( _TFunction::New( ) );
106 function = filter->GetFunction( );
109 function->SetMinRadius( this->m_Parameters.GetReal( "MinRadius" ) );
110 function->SetMaxRadius( this->m_Parameters.GetReal( "MaxRadius" ) );
111 function->SetProfileSampling( this->m_Parameters.GetUint( "ProfileSampling" ) );
112 function->SetRadialSampling( this->m_Parameters.GetUint( "RadialSampling" ) );
113 filter->SetInput( image );
115 function->SetMask( mask );
117 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );