]> Creatis software - cpPlugins.git/blob - plugins/ImageDistanceMaps/BinaryContourImageFilter.cxx
...
[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", 0 );
18   this->m_Parameters.ConfigureAsReal( "ForegroundValue", 1 );
19   this->m_Parameters.ConfigureAsBool( "FullyConnected", false );
20 }
21
22 // -------------------------------------------------------------------------
23 cpPluginsImageDistanceMaps::BinaryContourImageFilter::
24 ~BinaryContourImageFilter( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
30 _GenerateData( )
31 {
32   auto o = this->GetInputData( "Input" );
33   cpPlugins_Demangle_Image_VisualDims_1( o, _GD0 )
34     this->_Error( "Invalid input image dimension." );
35 }
36
37 // -------------------------------------------------------------------------
38 template< class _TImage >
39 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
40 _GD0( _TImage* image )
41 {
42   cpPlugins_Demangle_Image_ScalarPixels_1( image, _GD1, _TImage::ImageDimension )
43     this->_Error( "Invalid input image pixel type." );
44 }
45
46 // -------------------------------------------------------------------------
47 template< class _TImage >
48 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
49 _GD1( _TImage* image )
50 {
51   typedef
52     itk::BinaryContourImageFilter< _TImage, _TImage >
53     _TFilter;
54
55   // Get parameters
56   double b = this->m_Parameters.GetReal( "BackgroundValue" );
57   double f = this->m_Parameters.GetReal( "ForegroundValue" );
58   double c = this->m_Parameters.GetBool( "FullyConnected" );
59
60   // Configure filter
61   _TFilter* filter = this->_CreateITK< _TFilter >( );
62   filter->SetInput( image );
63   filter->SetBackgroundValue( ( typename _TImage::PixelType )( b ) );
64   filter->SetForegroundValue( ( typename _TImage::PixelType )( f ) );
65   filter->SetFullyConnected( c );
66   filter->Update( );
67
68   // Connect output
69   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
70 }
71
72 // eof - $RCSfile$