]> Creatis software - cpPlugins.git/blob - plugins/ImageGradientFilters/MFluxImageFilter.cxx
...
[cpPlugins.git] / plugins / ImageGradientFilters / MFluxImageFilter.cxx
1 #include <ImageGradientFilters/MFluxImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4
5 #include <cpExtensions/Algorithms/ImageFunctionFilter.h>
6 #include <cpExtensions/Algorithms/MFluxMedialness.h>
7
8 // -------------------------------------------------------------------------
9 cpPluginsImageGradientFilters::MFluxImageFilter::
10 MFluxImageFilter( )
11   : Superclass( )
12 {
13   typedef cpPlugins::DataObjects::Image _TImage;
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.ConfigureAsReal( "RadiusStep", 1 );
21   this->m_Parameters.ConfigureAsUint( "RadialSampling", 4 );
22 }
23
24 // -------------------------------------------------------------------------
25 cpPluginsImageGradientFilters::MFluxImageFilter::
26 ~MFluxImageFilter( )
27 {
28 }
29
30 // -------------------------------------------------------------------------
31 void cpPluginsImageGradientFilters::MFluxImageFilter::
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::MFluxImageFilter::
42 _GD0( _TImage* image )
43 {
44   typedef typename _TImage::PixelType _TGradient;
45   typedef cpExtensions::Algorithms::MFluxMedialness< _TImage > _TFunction;
46   typedef typename _TFunction::TOutput _TScalar;
47   typedef itk::Image< _TScalar, _TImage::ImageDimension > _TOutputImage;
48   typedef cpExtensions::Algorithms::ImageFunctionFilter< _TImage, _TOutputImage, _TFunction > _TFilter;
49
50   auto filter = this->_CreateITK< _TFilter >( );
51   auto function = filter->GetFunction( );
52   if( function == NULL )
53   {
54     filter->SetFunction( _TFunction::New( ) );
55     function = filter->GetFunction( );
56
57   } // fi
58   function->SetMinRadius( this->m_Parameters.GetReal( "MinRadius" ) );
59   function->SetMaxRadius( this->m_Parameters.GetReal( "MaxRadius" ) );
60   function->SetRadiusStep( this->m_Parameters.GetReal( "RadiusStep" ) );
61   function->SetRadialSampling( this->m_Parameters.GetUint( "RadialSampling" ) );
62   filter->SetInput( image );
63   filter->Update( );
64   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
65 }
66
67 // eof - $RCSfile$