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