]> 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< cpPlugins::Interface::Image >( "Input" );
36   if( image == NULL )
37     return( "BinaryThresholdImageFilter: No input image." );
38
39   itk::DataObject* itk_image = NULL;
40   std::string r = "";
41   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
42   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
43   else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
44   else r = "BinaryThresholdImageFilter: Input image type not supported.";
45   return( r );
46 }
47
48 // -------------------------------------------------------------------------
49 template< class I >
50 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
51 _GD0( itk::DataObject* image )
52 {
53   return(
54     this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
55       image
56       )
57     );
58 }
59
60 // -------------------------------------------------------------------------
61 template< class I, class O >
62 inline std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
63 _RealGD( itk::DataObject* image )
64 {
65   typedef itk::BinaryThresholdImageFilter< I, O > _F;
66   typedef typename I::PixelType _IP;
67   typedef typename O::PixelType _OP;
68
69   // Get parameters
70   //unsigned int bins =
71   //  this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
72   _IP lower_val = _IP( this->m_Parameters->GetReal( "LowerThresholdValue" ) );
73   _IP upper_val = _IP( this->m_Parameters->GetReal( "UpperThresholdValue" ) );
74   _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) );
75   _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) );
76
77   // Configure filter
78   _F* filter = this->_CreateITK< _F >( );
79   filter->SetInput( dynamic_cast< I* >( image ) );
80   filter->SetLowerThreshold( lower_val );
81   filter->SetUpperThreshold( upper_val );
82   filter->SetInsideValue( in_val );
83   filter->SetOutsideValue( out_val );
84   filter->Update( );
85
86   // Connect output
87   auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
88   if( out != NULL )
89   {
90     out->SetITK< O >( filter->GetOutput( ) );
91     return( "" );
92   }
93   else
94     return( "BinaryThresholdImageFilter: output not correctly created." );
95 }
96
97 // eof - $RCSfile$