]> Creatis software - cpPlugins.git/blob - plugins/ImageGradientFilters/GulsunTekImageFilter.cxx
879b22c0eab7592edf8ac6481a8f6282a53e1688
[cpPlugins.git] / plugins / ImageGradientFilters / GulsunTekImageFilter.cxx
1 #include <ImageGradientFilters/GulsunTekImageFilter.h>
2 #include <cpInstances/Image.h>
3
4 #include <cpExtensions/Algorithms/ImageFunctionFilter.h>
5 #include <cpExtensions/Algorithms/GulsunTekMedialness.h>
6
7 // -------------------------------------------------------------------------
8 cpPluginsImageGradientFilters::GulsunTekImageFilter::
9 GulsunTekImageFilter( )
10   : Superclass( )
11 {
12   typedef cpInstances::Image _TImage;
13
14   this->_ConfigureInput< _TImage >( "Input", true, false );
15   this->_ConfigureInput< _TImage >( "Mask", false, false );
16   this->_ConfigureOutput< _TImage >( "Output" );
17
18   this->m_Parameters.ConfigureAsReal( "MinRadius", 0 );
19   this->m_Parameters.ConfigureAsReal( "MaxRadius", 1 );
20   this->m_Parameters.ConfigureAsUint( "ProfileSampling", 4 );
21   this->m_Parameters.ConfigureAsUint( "RadialSampling", 10 );
22 }
23
24 // -------------------------------------------------------------------------
25 cpPluginsImageGradientFilters::GulsunTekImageFilter::
26 ~GulsunTekImageFilter( )
27 {
28 }
29
30 // -------------------------------------------------------------------------
31 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
32 _GenerateData( )
33 {
34   auto o = this->GetInputData( "Input" );
35   cpPlugins_Demangle_Image_CovariantVectorPixels_AllDims_1( o, _GD0 )
36     this->_Error( "Invalid input image." );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class _TImage >
41 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
42 _GD0( _TImage* image )
43 {
44   typedef itk::Image< unsigned char, _TImage::ImageDimension > _TDummy;
45
46   auto o = this->GetInputData( "Mask" );
47   cpPlugins_Demangle_Image_ScalarPixels_2( o, _GD1, _TImage::ImageDimension, image )
48     this->_GD1< _TDummy, _TImage >( NULL, image );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class _TMask, class _TImage >
53 void cpPluginsImageGradientFilters::GulsunTekImageFilter::
54 _GD1( _TMask* mask, _TImage* image )
55 {
56   typedef typename _TImage::PixelType _TGradient;
57   typedef cpExtensions::Algorithms::GulsunTekMedialness< _TImage, _TMask > _TFunction;
58   typedef typename _TFunction::TOutput _TScalar;
59   typedef itk::Image< _TScalar, _TImage::ImageDimension > _TOutputImage;
60   typedef cpExtensions::Algorithms::ImageFunctionFilter< _TImage, _TOutputImage, _TFunction > _TFilter;
61
62   auto filter = this->_CreateITK< _TFilter >( );
63   auto function = filter->GetFunction( );
64   if( function == NULL )
65   {
66     filter->SetFunction( _TFunction::New( ) );
67     function = filter->GetFunction( );
68
69   } // fi
70   function->SetMinRadius( this->m_Parameters.GetReal( "MinRadius" ) );
71   function->SetMaxRadius( this->m_Parameters.GetReal( "MaxRadius" ) );
72   function->SetProfileSampling( this->m_Parameters.GetUint( "ProfileSampling" ) );
73   function->SetRadialSampling( this->m_Parameters.GetUint( "RadialSampling" ) );
74   filter->SetInput( image );
75   if( mask != NULL )
76     function->SetMask( mask );
77   filter->Update( );
78   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
79 }
80
81 // eof - $RCSfile$