]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.cxx
Parameters are now part of the pipeline update process
[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   this->m_Parameters->ConfigureAsReal( "LowerThresholdValue", 0 );
16   this->m_Parameters->ConfigureAsReal( "UpperThresholdValue", 0 );
17   this->m_Parameters->ConfigureAsUint( "InsideValue", 255 );
18   this->m_Parameters->ConfigureAsUint( "OutsideValue", 1 );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPlugins::BasicFilters::BinaryThresholdImageFilter::
23 ~BinaryThresholdImageFilter( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
29 _GenerateData( )
30 {
31   cpPlugins::Interface::Image* image =
32     this->GetInput< cpPlugins::Interface::Image >( 0 );
33   if( image == NULL )
34     return( "BinaryThresholdImageFilter: No input image." );
35
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( "LowerValue" ) );
70   _IP upper_val = _IP( this->m_Parameters->GetReal( "UpperValue" ) );
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   cpPlugins::Interface::Image* out =
85     this->GetOutput< cpPlugins::Interface::Image >( 0 );
86   if( out != NULL )
87   {
88     out->SetITK< O >( filter->GetOutput( ) );
89     return( "" );
90   }
91   else
92     return( "BinaryThresholdImageFilter: output not correctly created." );
93 }
94
95 // eof - $RCSfile$