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