]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx
Parameters are now part of the pipeline update process
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / OtsuThresholdImageFilter.cxx
1 #include "OtsuThresholdImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <itkOtsuThresholdImageFilter.h>
5
6 // -------------------------------------------------------------------------
7 cpPlugins::BasicFilters::OtsuThresholdImageFilter::
8 OtsuThresholdImageFilter( )
9   : Superclass( )
10 {
11   this->SetNumberOfInputs( 1 );
12   this->SetNumberOfOutputs( 1 );
13   this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
14
15   this->m_Parameters->ConfigureAsUint( "NumberOfHistogramBins", 100 );
16   this->m_Parameters->ConfigureAsUint( "InsideValue", 255 );
17   this->m_Parameters->ConfigureAsUint( "OutsideValue", 0 );
18 }
19
20 // -------------------------------------------------------------------------
21 cpPlugins::BasicFilters::OtsuThresholdImageFilter::
22 ~OtsuThresholdImageFilter( )
23 {
24 }
25
26 // -------------------------------------------------------------------------
27 std::string cpPlugins::BasicFilters::OtsuThresholdImageFilter::
28 _GenerateData( )
29 {
30   cpPlugins::Interface::Image* image =
31     this->GetInput< cpPlugins::Interface::Image >( 0 );
32   if( image == NULL )
33     return( "OtsuThresholdImageFilter: 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 = "OtsuThresholdImageFilter: Input image type not supported.";
41   return( r );
42 }
43
44 // -------------------------------------------------------------------------
45 template< class I >
46 std::string cpPlugins::BasicFilters::OtsuThresholdImageFilter::
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::OtsuThresholdImageFilter::
59 _RealGD( itk::DataObject* image )
60 {
61   typedef itk::OtsuThresholdImageFilter< I, O > _F;
62   typedef typename O::PixelType _OP;
63
64   // Get parameters
65   unsigned int bins = this->m_Parameters->GetUint( "NumberOfHistogramBins" );
66   _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) );
67   _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) );
68
69   // Configure filter
70   _F* filter = this->_CreateITK< _F >( );
71   filter->SetInput( dynamic_cast< I* >( image ) );
72   filter->SetNumberOfHistogramBins( bins );
73   filter->SetInsideValue( in_val );
74   filter->SetOutsideValue( out_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( "OtsuThresholdImageFilter: output not correctly created." );
87 }
88
89 // eof - $RCSfile$