]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx
Widget integration (step 5/6): generic widget controller finished and tested on linux...
[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->SetNumberOfInputs( 1 );
12   this->SetNumberOfOutputs( 1 );
13   this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
14
15   using namespace cpPlugins::Interface;
16   this->m_DefaultParameters.Configure( Parameters::Real, "LowerThresholdValue" );
17   this->m_DefaultParameters.Configure( Parameters::Real, "UpperThresholdValue" );
18   this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" );
19   this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" );
20
21   this->m_DefaultParameters.SetValueAsReal( "LowerThresholdValue", 100 );
22   this->m_DefaultParameters.SetValueAsReal( "UpperThresholdValue", 500 );
23   this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 );
24   this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 );
25
26   this->m_Parameters = this->m_DefaultParameters;
27 }
28
29 // -------------------------------------------------------------------------
30 cpPlugins::BasicFilters::BinaryThresholdImageFilter::
31 ~BinaryThresholdImageFilter( )
32 {
33 }
34
35 // -------------------------------------------------------------------------
36 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
37 _GenerateData( )
38 {
39   cpPlugins::Interface::Image* image =
40     this->GetInput< cpPlugins::Interface::Image >( 0 );
41   if( image == NULL )
42     return( "BinaryThresholdImageFilter: No input image." );
43
44   itk::DataObject* itk_image = NULL;
45   std::string r = "";
46   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
47   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
48   else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
49   else r = "BinaryThresholdImageFilter: Input image type not supported.";
50   return( r );
51 }
52
53 // -------------------------------------------------------------------------
54 template< class I >
55 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
56 _GD0( itk::DataObject* image )
57 {
58   return(
59     this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
60       image
61       )
62     );
63 }
64
65 // -------------------------------------------------------------------------
66 template< class I, class O >
67 inline std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
68 _RealGD( itk::DataObject* image )
69 {
70   typedef itk::BinaryThresholdImageFilter< I, O > _F;
71   typedef typename I::PixelType _IP;
72   typedef typename O::PixelType _OP;
73
74   // Get parameters
75   //unsigned int bins =
76   //  this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
77   _IP lower_val = _IP( this->m_Parameters.GetValueAsReal( "LowerValue" ) );
78   _IP upper_val = _IP( this->m_Parameters.GetValueAsReal( "UpperValue" ) );
79   _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) );
80   _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) );
81
82   // Configure filter
83   _F* filter = this->_CreateITK< _F >( );
84   filter->SetInput( dynamic_cast< I* >( image ) );
85   filter->SetLowerThreshold( lower_val );
86   filter->SetUpperThreshold( upper_val );
87   filter->SetInsideValue( in_val );
88   filter->SetOutsideValue( out_val );
89   filter->Update( );
90
91   // Connect output
92   cpPlugins::Interface::Image* out =
93     this->GetOutput< cpPlugins::Interface::Image >( 0 );
94   if( out != NULL )
95   {
96     out->SetITK< O >( filter->GetOutput( ) );
97     return( "" );
98   }
99   else
100     return( "BinaryThresholdImageFilter: output not correctly created." );
101 }
102
103 // eof - $RCSfile$