]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / BinaryThresholdImageFilter.cxx
1 #include "BinaryThresholdImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <itkBinaryThresholdImageFilter.h>
5
6 // -------------------------------------------------------------------------
7 cpPlugins::BasicFilters::BinaryThresholdImageFilter::
8 BinaryThresholdImageFilter( )
9   : Superclass( )
10 {
11   this->_AddInput( "Input" );
12   this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
13
14   this->m_Parameters->ConfigureAsReal( "LowerThresholdValue" );
15   this->m_Parameters->ConfigureAsReal( "UpperThresholdValue" );
16   this->m_Parameters->ConfigureAsUint( "InsideValue" );
17   this->m_Parameters->ConfigureAsUint( "OutsideValue" );
18
19   this->m_Parameters->SetReal( "LowerThresholdValue", 0 );
20   this->m_Parameters->SetReal( "UpperThresholdValue", 10000 );
21   this->m_Parameters->SetUint( "InsideValue", 1 );
22   this->m_Parameters->SetUint( "OutsideValue", 0 );
23 }
24
25 // -------------------------------------------------------------------------
26 cpPlugins::BasicFilters::BinaryThresholdImageFilter::
27 ~BinaryThresholdImageFilter( )
28 {
29 }
30
31 // -------------------------------------------------------------------------
32 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
33 _GenerateData( )
34 {
35   auto image = this->GetInputData( "Input" );
36   itk::DataObject* itk_image = NULL;
37   std::string r = "";
38   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
39   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
40   else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
41   else r = "BinaryThresholdImageFilter: Input image type not supported.";
42   return( r );
43 }
44
45 // -------------------------------------------------------------------------
46 template< class I >
47 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
48 _GD0( itk::DataObject* image )
49 {
50   return(
51     this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
52       image
53       )
54     );
55 }
56
57 // -------------------------------------------------------------------------
58 template< class I, class O >
59 inline std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
60 _RealGD( itk::DataObject* image )
61 {
62   typedef itk::BinaryThresholdImageFilter< I, O > _F;
63   typedef typename I::PixelType _IP;
64   typedef typename O::PixelType _OP;
65
66   // Get parameters
67   //unsigned int bins =
68   //  this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
69   _IP lower_val = _IP( this->m_Parameters->GetReal( "LowerThresholdValue" ) );
70   _IP upper_val = _IP( this->m_Parameters->GetReal( "UpperThresholdValue" ) );
71   _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) );
72   _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) );
73
74   // Configure filter
75   _F* filter = this->_CreateITK< _F >( );
76   filter->SetInput( dynamic_cast< I* >( image ) );
77   filter->SetLowerThreshold( lower_val );
78   filter->SetUpperThreshold( upper_val );
79   filter->SetInsideValue( in_val );
80   filter->SetOutsideValue( out_val );
81   filter->Update( );
82
83   // Connect output
84   auto out = this->GetOutputData( "Output" );
85   out->SetITK( filter->GetOutput( ) );
86   return( "" );
87 }
88
89 // eof - $RCSfile$