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