]> Creatis software - cpPlugins.git/blob - plugins/ImageDistanceMaps/BinaryContourImageFilter.cxx
ade258036a556c3fe4dcf07f7cf0a9e3aed80a3d
[cpPlugins.git] / plugins / ImageDistanceMaps / BinaryContourImageFilter.cxx
1 #include <ImageDistanceMaps/BinaryContourImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4
5 #include <itkBinaryContourImageFilter.h>
6
7 // -------------------------------------------------------------------------
8 cpPluginsImageDistanceMaps::BinaryContourImageFilter::
9 BinaryContourImageFilter( )
10   : Superclass( )
11 {
12   typedef cpPlugins::DataObjects::Image _TImage;
13
14   this->_ConfigureInput< _TImage >( "Input", true, false );
15   this->_ConfigureOutput< _TImage >( "Output" );
16
17   this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
18   this->m_Parameters.ConfigureAsReal( "ForegroundValue" );
19   this->m_Parameters.ConfigureAsBool( "FullyConnected" );
20
21   this->m_Parameters.SetReal( "BackgroundValue", 0 );
22   this->m_Parameters.SetReal( "ForegroundValue", 1 );
23   this->m_Parameters.SetBool( "FullyConnected", false );
24 }
25
26 // -------------------------------------------------------------------------
27 cpPluginsImageDistanceMaps::BinaryContourImageFilter::
28 ~BinaryContourImageFilter( )
29 {
30 }
31
32 // -------------------------------------------------------------------------
33 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
34 _GenerateData( )
35 {
36   auto o = this->GetInputData( "Input" );
37   cpPlugins_Demangle_Image_VisualDims_1( o, _GD0 )
38     this->_Error( "Invalid input image dimension." );
39 }
40
41 // -------------------------------------------------------------------------
42 template< class _TImage >
43 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
44 _GD0( _TImage* image )
45 {
46   cpPlugins_Demangle_Image_ScalarPixels_1( image, _GD1, _TImage::ImageDimension )
47     this->_Error( "Invalid input image pixel type." );
48 }
49
50 // -------------------------------------------------------------------------
51 template< class _TImage >
52 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
53 _GD1( _TImage* image )
54 {
55   typedef
56     itk::BinaryContourImageFilter< _TImage, _TImage >
57     _TFilter;
58
59   // Get parameters
60   double b = this->m_Parameters.GetReal( "BackgroundValue" );
61   double f = this->m_Parameters.GetReal( "ForegroundValue" );
62   double c = this->m_Parameters.GetBool( "FullyConnected" );
63
64   // Configure filter
65   _TFilter* filter = this->_CreateITK< _TFilter >( );
66   filter->SetInput( image );
67   filter->SetBackgroundValue( ( typename _TImage::PixelType )( b ) );
68   filter->SetForegroundValue( ( typename _TImage::PixelType )( f ) );
69   filter->SetFullyConnected( c );
70   filter->Update( );
71
72   // Connect output
73   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
74 }
75
76 // eof - $RCSfile$