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