]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.cxx
Widget integration (step 5/6): generic widget controller finished and tested on linux...
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / MedianImageFilter.cxx
1 #include "MedianImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <itkMedianImageFilter.h>
5
6 // -------------------------------------------------------------------------
7 cpPlugins::BasicFilters::MedianImageFilter::
8 MedianImageFilter( )
9   : Superclass( )
10 {
11   this->SetNumberOfInputs( 1 );
12   this->SetNumberOfOutputs( 1 );
13   this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
14
15   using namespace cpPlugins::Interface;
16   this->m_DefaultParameters.Configure( Parameters::Uint, "Radius" );
17
18   this->m_DefaultParameters.SetValueAsUint( "Radius", 3 );
19
20   this->m_Parameters = this->m_DefaultParameters;
21 }
22
23 // -------------------------------------------------------------------------
24 cpPlugins::BasicFilters::MedianImageFilter::
25 ~MedianImageFilter( )
26 {
27 }
28
29 // -------------------------------------------------------------------------
30 std::string cpPlugins::BasicFilters::MedianImageFilter::
31 _GenerateData( )
32 {
33   cpPlugins::Interface::Image* image =
34     this->GetInput< cpPlugins::Interface::Image >( 0 );
35   if( image == NULL )
36     return( "MedianImageFilter: No input image." );
37
38   itk::DataObject* itk_image = NULL;
39   std::string r = "";
40   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
41   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
42   else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
43   else r = "MedianImageFilter: Input image type not supported.";
44   return( r );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class I >
49 std::string cpPlugins::BasicFilters::MedianImageFilter::
50 _GD0( itk::DataObject* image )
51 {
52   return(
53     this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
54       image
55       )
56     );
57 }
58
59 // -------------------------------------------------------------------------
60 template< class I, class O >
61 inline std::string cpPlugins::BasicFilters::MedianImageFilter::
62 _RealGD( itk::DataObject* image )
63 {
64   typedef itk::MedianImageFilter< I, O > _F;
65   typedef typename _F::RadiusType _RT;
66
67   // Get parameters
68   _RT rad_val;
69   rad_val.Fill( this->m_Parameters.GetValueAsUint( "Radius" ) );
70
71   // Configure filter
72   _F* filter = this->_CreateITK< _F >( );
73   filter->SetInput( dynamic_cast< I* >( image ) );
74   filter->SetRadius( rad_val );
75   filter->Update( );
76
77   // Connect output
78   cpPlugins::Interface::Image* out =
79     this->GetOutput< cpPlugins::Interface::Image >( 0 );
80   if( out != NULL )
81   {
82     out->SetITK< O >( filter->GetOutput( ) );
83     return( "" );
84   }
85   else
86     return( "MedianImageFilter: output not correctly created." );
87 }
88
89 // eof - $RCSfile$