]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/BinaryThresholdImageFilter.cxx
First dump for version 0.1.0
[cpPlugins.git] / plugins / cpPluginsImageFilters / BinaryThresholdImageFilter.cxx
1 #include <cpPluginsImageFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
3
4 #include <itkBinaryThresholdImageFilter.h>
5 #include <itkBinaryThresholdImageFilter.hxx>
6 #include <itkImageToImageFilter.hxx>
7 #include <itkInPlaceImageFilter.hxx>
8 #include <itkUnaryFunctorImageFilter.hxx>
9
10 // -------------------------------------------------------------------------
11 cpPluginsImageFilters::BinaryThresholdImageFilter::
12 BinaryThresholdImageFilter( )
13   : Superclass( )
14 {
15   this->_AddInput( "Input" );
16   this->_AddOutput< cpPlugins::Image >( "Output" );
17
18   this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
19   this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
20   this->m_Parameters.ConfigureAsUint( "InsideValue" );
21   this->m_Parameters.ConfigureAsUint( "OutsideValue" );
22
23   this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
24   this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
25   this->m_Parameters.SetUint( "InsideValue", 1 );
26   this->m_Parameters.SetUint( "OutsideValue", 0 );
27 }
28
29 // -------------------------------------------------------------------------
30 cpPluginsImageFilters::BinaryThresholdImageFilter::
31 ~BinaryThresholdImageFilter( )
32 {
33 }
34
35 // -------------------------------------------------------------------------
36 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
37 _GenerateData( )
38 {
39   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
40   std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
41   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
42   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
43   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
44   return( r );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class I >
49 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
50 _GD0( I* image )
51 {
52   if( image != NULL )
53     return(
54       this->_GD1< I, itk::Image< unsigned char, I::ImageDimension > >(
55         image
56         )
57       );
58   else
59     return(
60       "ImageFilters::BinaryThresholdImageFilter: No valid input image."
61       );
62 }
63
64 // -------------------------------------------------------------------------
65 template< class I, class O >
66 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
67 _GD1( I* image )
68 {
69   typedef itk::BinaryThresholdImageFilter< I, O > _F;
70   typedef typename I::PixelType _IP;
71   typedef typename O::PixelType _OP;
72
73   // Get parameters
74   _IP lower_val = _IP( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
75   _IP upper_val = _IP( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
76   _OP in_val    = _OP( this->m_Parameters.GetUint( "InsideValue" ) );
77   _OP out_val   = _OP( this->m_Parameters.GetUint( "OutsideValue" ) );
78
79   // Configure filter
80   _F* filter = this->_CreateITK< _F >( );
81   filter->SetInput( image );
82   filter->SetLowerThreshold( lower_val );
83   filter->SetUpperThreshold( upper_val );
84   filter->SetInsideValue( in_val );
85   filter->SetOutsideValue( out_val );
86   filter->Update( );
87
88   // Connect output
89   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
90   return( "" );
91 }
92
93 // eof - $RCSfile$