1 #include <cpPluginsImageFilters/SignedMaurerDistanceMapImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances/DistanceMapFilters.h>
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
7 SignedMaurerDistanceMapImageFilter( )
10 this->_AddInput( "Input" );
11 this->_AddOutput< cpPlugins::Image >( "Output" );
13 this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
14 this->m_Parameters.ConfigureAsBool( "InsideIsPositive" );
15 this->m_Parameters.ConfigureAsBool( "SquaredDistance" );
16 this->m_Parameters.ConfigureAsBool( "UseImageSpacing" );
18 std::vector< std::string > choices;
19 choices.push_back( "float" );
20 choices.push_back( "double" );
21 this->m_Parameters.ConfigureAsChoices( "OutputResolution", choices );
23 this->m_Parameters.SetReal( "BackgroundValue", 0 );
24 this->m_Parameters.SetBool( "InsideIsPositive", true );
25 this->m_Parameters.SetBool( "SquaredDistance", false );
26 this->m_Parameters.SetBool( "UseImageSpacing", true );
27 this->m_Parameters.SetSelectedChoice( "OutputResolution", "float" );
30 // -------------------------------------------------------------------------
31 cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
32 ~SignedMaurerDistanceMapImageFilter( )
36 // -------------------------------------------------------------------------
37 void cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
40 auto image = this->GetInputData< itk::DataObject >( "Input" );
41 cpPlugins_Image_Demangle_Pixel_AllScalars ( _GD0, image, 2 );
42 else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
43 else this->_Error( "No valid input image." );
46 // -------------------------------------------------------------------------
47 template< class _TImage >
48 void cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
49 _GD0( _TImage* image )
51 static const unsigned int D = _TImage::ImageDimension;
55 this->m_Parameters.GetSelectedChoice( "OutputResolution" );
56 if( out_res == "float" )
57 this->_GD1< _TImage, itk::Image< float, D > >( image );
58 else if( out_res == "double" )
59 this->_GD1< _TImage, itk::Image< double, D > >( image );
61 this->_Error( "Output resolution not supported." );
64 this->_Error( "No valid input image." );
67 // -------------------------------------------------------------------------
68 template< class _TImage, class _TDMap >
69 void cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
70 _GD1( _TImage* image )
72 typedef itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap > _F;
75 double back_value = this->m_Parameters.GetReal( "BackgroundValue" );
76 bool pos_inside = this->m_Parameters.GetBool( "InsideIsPositive" );
77 bool sqr_dist = this->m_Parameters.GetBool( "SquaredDistance" );
78 bool use_spac = this->m_Parameters.GetBool( "UseImageSpacing" );
81 _F* filter = this->_CreateITK< _F >( );
82 filter->SetInput( image );
83 filter->SetBackgroundValue( ( typename _TImage::PixelType )( back_value ) );
84 filter->SetInsideIsPositive( pos_inside );
85 filter->SetSquaredDistance( sqr_dist );
86 filter->SetUseImageSpacing( use_spac );
90 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );