]> Creatis software - cpPlugins.git/blob - plugins/ImageGradientFilters/GulsunTekImageFilter.cxx
b707d0067a791867518159079ca528609a3e83e1
[cpPlugins.git] / plugins / ImageGradientFilters / GulsunTekImageFilter.cxx
1 #include <plugins/ImageGradientFilters/GulsunTekImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3
4 #include <cpExtensions/Algorithms/ImageFunctionFilter.h>
5 #include <cpExtensions/Algorithms/GulsunTekMedialness.h>
6
7 #include <cpExtensions/Algorithms/ImageFunctionFilter.hxx>
8 #include <cpExtensions/Algorithms/GulsunTekMedialness.hxx>
9 #include <cpExtensions/Algorithms/GradientImageFunctionBase.hxx>
10 #include <itkImageFunction.hxx>
11
12 // -------------------------------------------------------------------------
13 cpPluginsImageGradientFilters::GulsunTekImageFilter::
14 GulsunTekImageFilter( )
15   : Superclass( )
16 {
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" );
20
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
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 );
30 }
31
32 // -------------------------------------------------------------------------
33 cpPluginsImageGradientFilters::GulsunTekImageFilter::
34 ~GulsunTekImageFilter( )
35 {
36 }
37
38 // -------------------------------------------------------------------------
39 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
40 _GenerateData( )
41 {
42   auto o = this->GetInputData( "Input" );
43   cpPlugins_Demangle_ImageCovariantVectors_Dims( o, _GD0 );
44   else this->_Error( "Invalid input image." );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class _TImage >
49 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
50 _GD0( _TImage* image )
51 {
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;
62
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 );
85 }
86
87 // -------------------------------------------------------------------------
88 template< class _TImage, class _TMask >
89 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
90 _GD1( _TImage* image, _TMask* mask )
91 {
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;
97
98   auto filter = this->_CreateITK< _TFilter >( );
99   auto function = filter->GetFunction( );
100   if( function == NULL )
101   {
102     filter->SetFunction( _TFunction::New( ) );
103     function = filter->GetFunction( );
104
105   } // fi
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 );
111   if( mask != NULL )
112     function->SetMask( mask );
113   filter->Update( );
114   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
115 }
116
117 // eof - $RCSfile$