1 #include <plugins/ImageDistanceMaps/SignedMaurerDistanceMapImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
4 #include <cpPlugins_ImageIterators.h>
5 #include <itkSignedMaurerDistanceMapImageFilter.h>
6 #include <itkSignedMaurerDistanceMapImageFilter.hxx>
7 #include <itkBinaryContourImageFilter.hxx>
8 #include <itkBinaryThresholdImageFilter.hxx>
9 #include <itkUnaryFunctorImageFilter.hxx>
11 // -------------------------------------------------------------------------
12 cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
13 SignedMaurerDistanceMapImageFilter( )
16 this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
17 this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
19 this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
20 this->m_Parameters.ConfigureAsBool( "InsideIsPositive" );
21 this->m_Parameters.ConfigureAsBool( "SquaredDistance" );
22 this->m_Parameters.ConfigureAsBool( "UseImageSpacing" );
24 std::vector< std::string > choices;
25 choices.push_back( "float" );
26 choices.push_back( "double" );
27 this->m_Parameters.ConfigureAsChoices( "OutputResolution", choices );
29 this->m_Parameters.SetReal( "BackgroundValue", 0 );
30 this->m_Parameters.SetBool( "InsideIsPositive", true );
31 this->m_Parameters.SetBool( "SquaredDistance", false );
32 this->m_Parameters.SetBool( "UseImageSpacing", true );
33 this->m_Parameters.SetSelectedChoice( "OutputResolution", "float" );
36 // -------------------------------------------------------------------------
37 cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
38 ~SignedMaurerDistanceMapImageFilter( )
42 // -------------------------------------------------------------------------
43 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
46 auto o = this->GetInputData( "Input" );
47 cpPlugins_Demangle_ImageScalars( o, _GD0, 2 );
48 else cpPlugins_Demangle_ImageScalars( o, _GD0, 3 );
49 else this->_Error( "Invalid input image." );
52 // -------------------------------------------------------------------------
53 template< class _TImage >
54 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
55 _GD0( _TImage* image )
57 typedef itk::Image< float, _TImage::ImageDimension > _TFDmap;
58 typedef itk::Image< double, _TImage::ImageDimension > _TDDmap;
61 this->m_Parameters.GetSelectedChoice( "OutputResolution" );
62 if( out_res == "float" ) this->_GD1< _TImage, _TFDmap >( image );
63 else if( out_res == "double" ) this->_GD1< _TImage, _TDDmap >( image );
64 else this->_Error( "Output resolution not supported." );
67 // -------------------------------------------------------------------------
68 template< class _TImage, class _TDMap >
69 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
70 _GD1( _TImage* image )
73 itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap >
77 double bv = this->m_Parameters.GetReal( "BackgroundValue" );
78 bool pi = this->m_Parameters.GetBool( "InsideIsPositive" );
79 bool sd = this->m_Parameters.GetBool( "SquaredDistance" );
80 bool us = this->m_Parameters.GetBool( "UseImageSpacing" );
83 _TFilter* filter = this->_CreateITK< _TFilter >( );
84 filter->SetInput( image );
85 filter->SetBackgroundValue( ( typename _TImage::PixelType )( bv ) );
86 filter->SetInsideIsPositive( pi );
87 filter->SetSquaredDistance( sd );
88 filter->SetUseImageSpacing( us );
92 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );