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