]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/BinaryThresholdImageFilter.cxx
...
[cpPlugins.git] / plugins / cpPluginsImageFilters / BinaryThresholdImageFilter.cxx
1 #include <cpPluginsImageFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances/ThresholdFilters.h>
4
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::BinaryThresholdImageFilter::
7 BinaryThresholdImageFilter( )
8   : Superclass( )
9 {
10   this->_AddInput( "Input" );
11   this->_AddOutput< cpPlugins::Image >( "Output" );
12
13   this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
14   this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
15   this->m_Parameters.ConfigureAsUint( "InsideValue" );
16   this->m_Parameters.ConfigureAsUint( "OutsideValue" );
17
18   this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
19   this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
20   this->m_Parameters.SetReal( "InsideValue", 1 );
21   this->m_Parameters.SetReal( "OutsideValue", 0 );
22   this->m_Parameters.SetSelectedChoice( "OutputResolution", "unsigned char" );
23 }
24
25 // -------------------------------------------------------------------------
26 cpPluginsImageFilters::BinaryThresholdImageFilter::
27 ~BinaryThresholdImageFilter( )
28 {
29 }
30
31 // -------------------------------------------------------------------------
32 void cpPluginsImageFilters::BinaryThresholdImageFilter::
33 _GenerateData( )
34 {
35   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
36   cpPlugins_Image_Demangle_Pixel_AllScalars     ( _GD0, image, 2 );
37   else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
38   else this->_Error( "No valid input image." );
39 }
40
41 // -------------------------------------------------------------------------
42 template< class _TImage >
43 void cpPluginsImageFilters::BinaryThresholdImageFilter::
44 _GD0( _TImage* image )
45 {
46   if( image != NULL )
47     this->_GD1< _TImage, unsigned char >( image );
48   else
49     this->_Error( "No valid input image." );
50 }
51
52 // -------------------------------------------------------------------------
53 template< class _TImage, class _TBinaryPixel >
54 void cpPluginsImageFilters::BinaryThresholdImageFilter::
55 _GD1( _TImage* image )
56 {
57   typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
58   typedef itk::BinaryThresholdImageFilter< _TImage, _TBinaryImage > _F;
59   typedef typename _TImage::PixelType _TP;
60
61   // Get parameters
62   _TP lower_val = _TP( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
63   _TP upper_val = _TP( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
64   _TBinaryPixel in_val  = _TBinaryPixel( this->m_Parameters.GetReal( "InsideValue" ) );
65   _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetReal( "OutsideValue" ) );
66
67   // Configure filter
68   _F* filter = this->_CreateITK< _F >( );
69   filter->SetInput( image );
70   filter->SetLowerThreshold( lower_val );
71   filter->SetUpperThreshold( upper_val );
72   filter->SetInsideValue( in_val );
73   filter->SetOutsideValue( out_val );
74   filter->Update( );
75
76   // Connect output
77   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
78 }
79
80 // eof - $RCSfile$