1 #include "SignedMaurerDistanceMapImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkSignedMaurerDistanceMapImageFilter.h>
6 // -------------------------------------------------------------------------
7 cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter::
8 SignedMaurerDistanceMapImageFilter( )
11 this->_AddInput( "Input" );
12 this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
14 this->m_Parameters->ConfigureAsReal( "BackgroundValue" );
15 this->m_Parameters->ConfigureAsBool( "InsideIsPositive" );
16 this->m_Parameters->ConfigureAsBool( "SquaredDistance" );
17 this->m_Parameters->ConfigureAsBool( "UseImageSpacing" );
19 std::vector< std::string > choices;
20 choices.push_back( "float" );
21 choices.push_back( "double" );
22 this->m_Parameters->ConfigureAsChoices( "OutputResolution", choices );
24 this->m_Parameters->SetReal( "BackgroundValue", 0 );
25 this->m_Parameters->SetBool( "InsideIsPositive", true );
26 this->m_Parameters->SetBool( "SquaredDistance", false );
27 this->m_Parameters->SetBool( "UseImageSpacing", true );
28 this->m_Parameters->SetSelectedChoice( "OutputResolution", "float" );
31 // -------------------------------------------------------------------------
32 cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter::
33 ~SignedMaurerDistanceMapImageFilter( )
37 // -------------------------------------------------------------------------
38 std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter::
41 auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
42 itk::DataObject* itk_image = NULL;
44 cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
45 else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
46 else r = "SignedMaurerDistanceMapImageFilter: Input image type not supported.";
50 // -------------------------------------------------------------------------
52 std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter::
53 _GD0( itk::DataObject* image )
56 this->m_Parameters->GetSelectedChoice( "OutputResolution" );
57 if( out_res == "float" )
59 this->_RealGD< I, itk::Image< float, I::ImageDimension > >(
63 else if( out_res == "double" )
65 this->_RealGD< I, itk::Image< double, I::ImageDimension > >(
70 return( "SignedMaurerDistanceMapImageFilter: Output resolution not supported." );
73 // -------------------------------------------------------------------------
74 template< class I, class O >
75 inline std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter::
76 _RealGD( itk::DataObject* image )
78 typedef itk::SignedMaurerDistanceMapImageFilter< I, O > _F;
81 double back_value = this->m_Parameters->GetReal( "BackgroundValue" );
82 bool pos_inside = this->m_Parameters->GetBool( "InsideIsPositive" );
83 bool sqr_dist = this->m_Parameters->GetBool( "SquaredDistance" );
84 bool use_spac = this->m_Parameters->GetBool( "UseImageSpacing" );
87 _F* filter = this->_CreateITK< _F >( );
88 filter->SetInput( dynamic_cast< I* >( image ) );
89 filter->SetBackgroundValue( ( typename I::PixelType )( back_value ) );
90 filter->SetInsideIsPositive( pos_inside );
91 filter->SetSquaredDistance( sqr_dist );
92 filter->SetUseImageSpacing( use_spac );
97 auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
98 out->SetITK( filter->GetOutput( ) );