]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx
...
[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->_AddOutput< 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   auto image = this->GetInputData( "Input" );
31   itk::DataObject* itk_image = NULL;
32   std::string r = "";
33   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
34   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
35   else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
36   else r = "BinaryErodeImageFilter: Input image type not supported.";
37   return( r );
38 }
39
40 // -------------------------------------------------------------------------
41 template< class I >
42 std::string cpPlugins::BasicFilters::BinaryErodeImageFilter::
43 _GD0( itk::DataObject* image )
44 {
45   return(
46     this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
47       image
48       )
49     );
50 }
51
52 // -------------------------------------------------------------------------
53 template< class I, class O >
54 inline std::string cpPlugins::BasicFilters::BinaryErodeImageFilter::
55 _RealGD( itk::DataObject* image )
56 {
57   //typedef itk::Image<I, I::ImageDimension>    ImageType;
58   typedef itk::BinaryBallStructuringElement< typename I::PixelType, I::ImageDimension>  StructuringElementType;
59   typedef itk::BinaryErodeImageFilter< I, O, StructuringElementType > _F;
60   typedef typename _F::RadiusType _RT;
61
62   // Get parameters
63   _RT rad_val;
64   rad_val.Fill( this->m_Parameters->GetUint( "Radius" ) );
65
66   // Configure filter
67
68   StructuringElementType structuringElement;
69   structuringElement.SetRadius( rad_val );
70   structuringElement.CreateStructuringElement( );
71
72   _F* filter = this->_CreateITK< _F >( );
73   filter->SetInput( dynamic_cast< I* >( image ) );
74   filter->SetKernel( structuringElement );
75   filter->Update( );
76
77   // Connect output
78   auto out = this->GetOutputData( "Output" );
79   out->SetITK( filter->GetOutput( ) );
80   return( "" );
81 }
82
83 // eof - $RCSfile$