1 #include <cpPluginsImageFilters/BinaryContourImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances/DistanceMapFilters.h>
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::BinaryContourImageFilter::
7 BinaryContourImageFilter( )
10 this->_AddInput( "Input" );
11 this->_AddOutput< cpPlugins::Image >( "Output" );
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 );
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" );
27 // -------------------------------------------------------------------------
28 cpPluginsImageFilters::BinaryContourImageFilter::
29 ~BinaryContourImageFilter( )
33 // -------------------------------------------------------------------------
34 void cpPluginsImageFilters::BinaryContourImageFilter::
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." );
43 // -------------------------------------------------------------------------
44 template< class _TImage >
45 void cpPluginsImageFilters::BinaryContourImageFilter::
46 _GD0( _TImage* image )
48 static const unsigned int D = _TImage::ImageDimension;
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 );
59 this->_Error( "No valid input image." );
62 // -------------------------------------------------------------------------
63 template< class _TImage, class _TContourImage >
64 void cpPluginsImageFilters::BinaryContourImageFilter::
65 _GD1( _TImage* image )
67 typedef itk::BinaryContourImageFilter< _TImage, _TContourImage > _F;
70 bool fc = this->m_Parameters.GetBool( "FullyConnected" );
71 double bv = this->m_Parameters.GetReal( "BackgroundValue" );
72 double fv = this->m_Parameters.GetReal( "ForegroundValue" );
75 _F* filter = this->_CreateITK< _F >( );
76 filter->SetInput( image );
77 filter->SetFullyConnected( fc );
78 filter->SetBackgroundValue( bv );
79 filter->SetForegroundValue( fv );
83 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );