]> Creatis software - cpPlugins.git/blob - plugins/ImageThresholdFilters/BinaryThresholdImageFilter.cxx
b9eb3e713550b2e6df6a566cd3162777bc46f9e9
[cpPlugins.git] / plugins / ImageThresholdFilters / BinaryThresholdImageFilter.cxx
1 #include <plugins/ImageThresholdFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3
4 #include <itkBinaryThresholdImageFilter.h>
5 #include <itkBinaryThresholdImageFilter.hxx>
6 #include <itkUnaryFunctorImageFilter.hxx>
7
8 // -------------------------------------------------------------------------
9 cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
10 BinaryThresholdImageFilter( )
11   : Superclass( )
12 {
13   this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
14   this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
15
16   this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
17   this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
18   this->m_Parameters.ConfigureAsUint( "InsideValue" );
19   this->m_Parameters.ConfigureAsUint( "OutsideValue" );
20
21   this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
22   this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
23   this->m_Parameters.SetUint( "InsideValue", 1 );
24   this->m_Parameters.SetUint( "OutsideValue", 0 );
25 }
26
27 // -------------------------------------------------------------------------
28 cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
29 ~BinaryThresholdImageFilter( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 void cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
35 _GenerateData( )
36 {
37   auto o = this->GetInputData( "Input" );
38   cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
39   else this->_Error( "Invalid input image." );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TImage >
44 void cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
45 _GD0( _TImage* image )
46 {
47   typedef unsigned char _TBin;
48   typedef itk::Image< unsigned char, _TImage::ImageDimension > _TBinImage;
49   typedef itk::BinaryThresholdImageFilter< _TImage, _TBinImage > _TFilter;
50   typedef typename _TImage::PixelType _TPixel;
51
52   // Get parameters
53   _TPixel lt = _TPixel( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
54   _TPixel ut = _TPixel( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
55   _TBin iv  = _TBin( this->m_Parameters.GetUint( "InsideValue" ) );
56   _TBin ov = _TBin( this->m_Parameters.GetUint( "OutsideValue" ) );
57
58   // Configure filter
59   _TFilter* filter = this->_CreateITK< _TFilter >( );
60   filter->SetInput( image );
61   filter->SetLowerThreshold( lt );
62   filter->SetUpperThreshold( ut );
63   filter->SetInsideValue( iv );
64   filter->SetOutsideValue( ov );
65   filter->Update( );
66
67   // Connect output
68   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
69 }
70
71 // eof - $RCSfile$