]> Creatis software - cpPlugins.git/blob - plugins/ImageFilters/BinaryContourImageFilter.cxx
Code cleaning
[cpPlugins.git] / plugins / ImageFilters / BinaryContourImageFilter.cxx
1 #include <plugins/ImageFilters/BinaryContourImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances_DistanceMapFilters.h>
4
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::BinaryContourImageFilter::
7 BinaryContourImageFilter( )
8   : Superclass( )
9 {
10   this->_AddInput( "Input" );
11   this->_AddOutput< cpPlugins::Image >( "Output" );
12
13   this->m_Parameters.ConfigureAsBool( "FullyConnected" );
14   this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
15   this->m_Parameters.ConfigureAsReal( "ForegroundValue" );
16   std::vector< std::string > choices;
17   choices.push_back( "float" );
18   choices.push_back( "double" );
19   this->m_Parameters.ConfigureAsChoices( "OutputResolution", choices );
20
21   this->m_Parameters.SetBool( "FullyConnected", false );
22   this->m_Parameters.SetReal( "BackgroundValue", 0 );
23   this->m_Parameters.SetReal( "ForegroundValue", 1 );
24   this->m_Parameters.SetSelectedChoice( "OutputResolution", "float" );
25 }
26
27 // -------------------------------------------------------------------------
28 cpPluginsImageFilters::BinaryContourImageFilter::
29 ~BinaryContourImageFilter( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 void cpPluginsImageFilters::BinaryContourImageFilter::
35 _GenerateData( )
36 {
37   auto image = this->GetInputData< itk::DataObject >( "Input" );
38   cpPlugins_Image_Demangle_Pixel_AllScalars     ( _GD0, image, 2 );
39   else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
40   else this->_Error( "No valid input image." );
41 }
42
43 // -------------------------------------------------------------------------
44 template< class _TImage >
45 void cpPluginsImageFilters::BinaryContourImageFilter::
46 _GD0( _TImage* image )
47 {
48   static const unsigned int D = _TImage::ImageDimension;
49   if( image != NULL )
50   {
51     std::string out_res =
52       this->m_Parameters.GetSelectedChoice( "OutputResolution" );
53     if( out_res == "float" )
54       this->_GD1< _TImage, itk::Image< float, D > >( image );
55     else // if( out_res == "double" )
56       this->_GD1< _TImage, itk::Image< double, D > >( image );
57   }
58   else
59     this->_Error( "No valid input image." );
60 }
61
62 // -------------------------------------------------------------------------
63 template< class _TImage, class _TContourImage >
64 void cpPluginsImageFilters::BinaryContourImageFilter::
65 _GD1( _TImage* image )
66 {
67   typedef itk::BinaryContourImageFilter< _TImage, _TContourImage > _F;
68
69   // Get parameters
70   bool fc = this->m_Parameters.GetBool( "FullyConnected" );
71   double bv = this->m_Parameters.GetReal( "BackgroundValue" );
72   double fv = this->m_Parameters.GetReal( "ForegroundValue" );
73
74   // Configure filter
75   _F* filter = this->_CreateITK< _F >( );
76   filter->SetInput( image );
77   filter->SetFullyConnected( fc );
78   filter->SetBackgroundValue( bv );
79   filter->SetForegroundValue( fv );
80   filter->Update( );
81
82   // Connect output
83   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
84 }
85
86 // eof - $RCSfile$