]> Creatis software - cpPlugins.git/blob - plugins/ImageThresholdFilters/UnaryThresholdImageFilter.cxx
97754e7aaa3879aa1cf4a56380fb10458bf68b15
[cpPlugins.git] / plugins / ImageThresholdFilters / UnaryThresholdImageFilter.cxx
1 #include <plugins/ImageThresholdFilters/UnaryThresholdImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3
4 #include <cpExtensions/Algorithms/UnaryThresholdImageFilter.h>
5 #include <cpExtensions/Algorithms/UnaryThresholdImageFilter.hxx>
6 #include <itkUnaryFunctorImageFilter.hxx>
7
8 // -------------------------------------------------------------------------
9 cpPluginsImageThresholdFilters::UnaryThresholdImageFilter::
10 UnaryThresholdImageFilter( )
11   : Superclass( )
12 {
13   this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
14   this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
15
16   this->m_Parameters.ConfigureAsReal( "Threshold" );
17   this->m_Parameters.ConfigureAsReal( "InsideValue" );
18   this->m_Parameters.ConfigureAsReal( "OutsideValue" );
19   this->m_Parameters.ConfigureAsBool( "Strict" );
20
21   this->m_Parameters.SetReal( "Threshold", 0 );
22   this->m_Parameters.SetReal( "InsideValue", 1 );
23   this->m_Parameters.SetReal( "OutsideValue", 0 );
24   this->m_Parameters.SetBool( "Strict", false );
25 }
26
27 // -------------------------------------------------------------------------
28 cpPluginsImageThresholdFilters::UnaryThresholdImageFilter::
29 ~UnaryThresholdImageFilter( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 void cpPluginsImageThresholdFilters::UnaryThresholdImageFilter::
35 _GenerateData( )
36 {
37   auto o = this->GetInputData( "Input" );
38   cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
39   else this->_Error( "Invalid input image." );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TImage >
44 void cpPluginsImageThresholdFilters::UnaryThresholdImageFilter::
45 _GD0( _TImage* image )
46 {
47   typedef
48     cpExtensions::Algorithms::UnaryThresholdImageFilter< _TImage >
49     _TFilter;
50
51   // Configure filter
52   _TFilter* filter = this->_CreateITK< _TFilter >( );
53   filter->SetInput( image );
54   filter->SetThreshold( this->m_Parameters.GetReal( "Threshold" ) );
55   filter->SetInsideValue( this->m_Parameters.GetReal( "InsideValue" ) );
56   filter->SetOutsideValue( this->m_Parameters.GetReal( "OutsideValue" ) );
57   filter->SetStrict( this->m_Parameters.GetBool( "Strict" ) );
58   filter->Update( );
59
60   // Connect output
61   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
62 }
63
64 // eof - $RCSfile$