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