1 #include <plugins/ImageGradientFilters/GulsunTekImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
4 #include <cpExtensions/Algorithms/ImageFunctionFilter.h>
5 #include <cpExtensions/Algorithms/GulsunTekMedialness.h>
7 #include <cpExtensions/Algorithms/ImageFunctionFilter.hxx>
8 #include <cpExtensions/Algorithms/GulsunTekMedialness.hxx>
9 #include <cpExtensions/Algorithms/GradientImageFunctionBase.hxx>
10 #include <itkImageFunction.hxx>
12 // -------------------------------------------------------------------------
13 cpPluginsImageGradientFilters::GulsunTekImageFilter::
14 GulsunTekImageFilter( )
17 this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
18 this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Mask", false, false );
19 this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
21 this->m_Parameters.ConfigureAsReal( "MinRadius" );
22 this->m_Parameters.ConfigureAsReal( "MaxRadius" );
23 this->m_Parameters.ConfigureAsUint( "ProfileSampling" );
24 this->m_Parameters.ConfigureAsUint( "RadialSampling" );
26 this->m_Parameters.SetReal( "MinRadius", 0 );
27 this->m_Parameters.SetReal( "MaxRadius", 1 );
28 this->m_Parameters.SetUint( "ProfileSampling", 4 );
29 this->m_Parameters.SetUint( "RadialSampling", 10 );
32 // -------------------------------------------------------------------------
33 cpPluginsImageGradientFilters::GulsunTekImageFilter::
34 ~GulsunTekImageFilter( )
38 // -------------------------------------------------------------------------
39 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
42 auto o = this->GetInputData( "Input" );
43 cpPlugins_Demangle_ImageCovariantVectors_Dims( o, _GD0 );
44 else this->_Error( "Invalid input image." );
47 // -------------------------------------------------------------------------
48 template< class _TImage >
49 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
50 _GD0( _TImage* image )
52 typedef itk::Image< char, _TImage::ImageDimension > _TChar;
53 typedef itk::Image< short, _TImage::ImageDimension > _TShort;
54 typedef itk::Image< int, _TImage::ImageDimension > _TInt;
55 typedef itk::Image< long, _TImage::ImageDimension > _TLong;
56 typedef itk::Image< float, _TImage::ImageDimension > _TFloat;
57 typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
58 typedef itk::Image< unsigned char, _TImage::ImageDimension > _TUChar;
59 typedef itk::Image< unsigned short, _TImage::ImageDimension > _TUShort;
60 typedef itk::Image< unsigned int, _TImage::ImageDimension > _TUInt;
61 typedef itk::Image< unsigned long, _TImage::ImageDimension > _TULong;
63 auto m = this->GetInput( "Mask" );
64 auto ci = m->GetITK< _TChar >( );
65 auto si = m->GetITK< _TShort >( );
66 auto ii = m->GetITK< _TInt >( );
67 auto li = m->GetITK< _TLong >( );
68 auto fi = m->GetITK< _TFloat >( );
69 auto di = m->GetITK< _TDouble >( );
70 auto uci = m->GetITK< _TUChar >( );
71 auto usi = m->GetITK< _TUShort >( );
72 auto uii = m->GetITK< _TUInt >( );
73 auto uli = m->GetITK< _TULong >( );
74 if ( ci != NULL ) this->_GD1( image, ci );
75 else if( si != NULL ) this->_GD1( image, si );
76 else if( ii != NULL ) this->_GD1( image, ii );
77 else if( li != NULL ) this->_GD1( image, li );
78 else if( fi != NULL ) this->_GD1( image, fi );
79 else if( di != NULL ) this->_GD1( image, di );
80 else if( uci != NULL ) this->_GD1( image, uci );
81 else if( usi != NULL ) this->_GD1( image, usi );
82 else if( uii != NULL ) this->_GD1( image, uii );
83 else if( uli != NULL ) this->_GD1( image, uli );
84 else this->_GD1( image, ci );
87 // -------------------------------------------------------------------------
88 template< class _TImage, class _TMask >
89 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
90 _GD1( _TImage* image, _TMask* mask )
92 typedef typename _TImage::PixelType _TGradient;
93 typedef cpExtensions::Algorithms::GulsunTekMedialness< _TImage, _TMask > _TFunction;
94 typedef typename _TFunction::TOutput _TScalar;
95 typedef itk::Image< _TScalar, _TImage::ImageDimension > _TOutputImage;
96 typedef cpExtensions::Algorithms::ImageFunctionFilter< _TImage, _TOutputImage, _TFunction > _TFilter;
98 auto filter = this->_CreateITK< _TFilter >( );
99 auto function = filter->GetFunction( );
100 if( function == NULL )
102 filter->SetFunction( _TFunction::New( ) );
103 function = filter->GetFunction( );
106 function->SetMinRadius( this->m_Parameters.GetReal( "MinRadius" ) );
107 function->SetMaxRadius( this->m_Parameters.GetReal( "MaxRadius" ) );
108 function->SetProfileSampling( this->m_Parameters.GetUint( "ProfileSampling" ) );
109 function->SetRadialSampling( this->m_Parameters.GetUint( "RadialSampling" ) );
110 filter->SetInput( image );
112 function->SetMask( mask );
114 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );