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