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