]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/BinaryThresholdImageFilter.cxx
6c49a3efe12f3c47b35105a9065f72195f462b05
[cpPlugins.git] / plugins / cpPluginsImageFilters / BinaryThresholdImageFilter.cxx
1 #include <cpPluginsImageFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances/ThresholdFilters.h>
4
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::BinaryThresholdImageFilter::
7 BinaryThresholdImageFilter( )
8   : Superclass( )
9 {
10   this->_AddInput( "Input" );
11   this->_AddOutput< cpPlugins::Image >( "Output" );
12
13   this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
14   this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
15   this->m_Parameters.ConfigureAsUint( "InsideValue" );
16   this->m_Parameters.ConfigureAsUint( "OutsideValue" );
17
18   this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
19   this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
20   this->m_Parameters.SetReal( "InsideValue", 1 );
21   this->m_Parameters.SetReal( "OutsideValue", 0 );
22   this->m_Parameters.SetSelectedChoice( "OutputResolution", "unsigned char" );
23 }
24
25 // -------------------------------------------------------------------------
26 cpPluginsImageFilters::BinaryThresholdImageFilter::
27 ~BinaryThresholdImageFilter( )
28 {
29 }
30
31 // -------------------------------------------------------------------------
32 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
33 _GenerateData( )
34 {
35   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
36   std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
37   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
38   /* TODO
39      if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
40      if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
41   */
42   return( r );
43 }
44
45 // -------------------------------------------------------------------------
46 template< class _TImage >
47 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
48 _GD0( _TImage* image )
49 {
50   if( image != NULL )
51     return( this->_GD1< _TImage, unsigned char >( image ) );
52   else
53     return(
54       "ImageFilters::BinaryThresholdImageFilter: No valid input image."
55       );
56 }
57
58 // -------------------------------------------------------------------------
59 template< class _TImage, class _TBinaryPixel >
60 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
61 _GD1( _TImage* image )
62 {
63   typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
64   typedef itk::BinaryThresholdImageFilter< _TImage, _TBinaryImage > _F;
65   typedef typename _TImage::PixelType _TP;
66
67   // Get parameters
68   _TP lower_val = _TP( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
69   _TP upper_val = _TP( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
70   _TBinaryPixel in_val  = _TBinaryPixel( this->m_Parameters.GetReal( "InsideValue" ) );
71   _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetReal( "OutsideValue" ) );
72
73   // Configure filter
74   _F* filter = this->_CreateITK< _F >( );
75   filter->SetInput( 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   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
84   return( "" );
85 }
86
87 // eof - $RCSfile$