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