1 #include <cpPluginsImageFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_ITKInstances/ImageFilters.h>
5 #include <itkBinaryThresholdImageFilter.h>
6 #include <itkBinaryThresholdImageFilter.hxx>
7 #include <itkUnaryFunctorImageFilter.hxx>
9 // -------------------------------------------------------------------------
10 cpPluginsImageFilters::BinaryThresholdImageFilter::
11 BinaryThresholdImageFilter( )
14 this->_AddInput( "Input" );
15 this->_AddOutput< cpPlugins::Image >( "Output" );
17 this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
18 this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
19 this->m_Parameters.ConfigureAsUint( "InsideValue" );
20 this->m_Parameters.ConfigureAsUint( "OutsideValue" );
22 std::vector< std::string > choices;
23 choices.push_back( "char" );
24 choices.push_back( "short" );
25 choices.push_back( "int" );
26 choices.push_back( "long" );
27 choices.push_back( "float" );
28 choices.push_back( "double" );
29 choices.push_back( "unsigned char" );
30 choices.push_back( "unsigned short" );
31 choices.push_back( "unsigned int" );
32 choices.push_back( "unsigned long" );
33 this->m_Parameters.ConfigureAsChoices( "OutputResolution", choices );
35 this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
36 this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
37 this->m_Parameters.SetReal( "InsideValue", 1 );
38 this->m_Parameters.SetReal( "OutsideValue", 0 );
39 this->m_Parameters.SetSelectedChoice( "OutputResolution", "unsigned char" );
42 // -------------------------------------------------------------------------
43 cpPluginsImageFilters::BinaryThresholdImageFilter::
44 ~BinaryThresholdImageFilter( )
48 // -------------------------------------------------------------------------
49 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
52 auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
53 std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
54 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
55 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
56 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
60 // -------------------------------------------------------------------------
61 template< class _TImage >
62 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
63 _GD0( _TImage* image )
67 auto choice = this->m_Parameters.GetSelectedChoice( "OutputResolution" );
68 if( choice == "char" )
69 return( this->_GD1< _TImage, char >( image ) );
70 else if( choice == "short" )
71 return( this->_GD1< _TImage, short >( image ) );
72 else if( choice == "int" )
73 return( this->_GD1< _TImage, int >( image ) );
74 else if( choice == "long" )
75 return( this->_GD1< _TImage, long >( image ) );
76 else if( choice == "float" )
77 return( this->_GD1< _TImage, float >( image ) );
78 else if( choice == "double" )
79 return( this->_GD1< _TImage, double >( image ) );
80 else if( choice == "unsigned char" )
81 return( this->_GD1< _TImage, unsigned char >( image ) );
82 else if( choice == "unsigned short" )
83 return( this->_GD1< _TImage, unsigned short >( image ) );
84 else if( choice == "unsigned int" )
85 return( this->_GD1< _TImage, unsigned int >( image ) );
86 else if( choice == "unsigned long" )
87 return( this->_GD1< _TImage, unsigned long >( image ) );
88 else return( "BinaryThresholdImageFilter: no valid output type." );
92 "ImageFilters::BinaryThresholdImageFilter: No valid input image."
96 // -------------------------------------------------------------------------
97 template< class _TImage, class _TBinaryPixel >
98 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
99 _GD1( _TImage* image )
101 typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
102 typedef itk::BinaryThresholdImageFilter< _TImage, _TBinaryImage > _F;
103 typedef typename _TImage::PixelType _TP;
106 _TP lower_val = _TP( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
107 _TP upper_val = _TP( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
108 _TBinaryPixel in_val = _TBinaryPixel( this->m_Parameters.GetReal( "InsideValue" ) );
109 _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetReal( "OutsideValue" ) );
112 _F* filter = this->_CreateITK< _F >( );
113 filter->SetInput( image );
114 filter->SetLowerThreshold( lower_val );
115 filter->SetUpperThreshold( upper_val );
116 filter->SetInsideValue( in_val );
117 filter->SetOutsideValue( out_val );
121 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );