1 #include <ImageDistanceMaps/SignedMaurerDistanceMapImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
5 #include <itkSignedMaurerDistanceMapImageFilter.h>
7 // -------------------------------------------------------------------------
8 cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
9 SignedMaurerDistanceMapImageFilter( )
12 typedef cpPlugins::DataObjects::Image _TImage;
14 this->_ConfigureInput< _TImage >( "Input", true, false );
15 this->_ConfigureOutput< _TImage >( "Output" );
17 this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
18 this->m_Parameters.ConfigureAsBool( "InsideIsPositive" );
19 this->m_Parameters.ConfigureAsBool( "SquaredDistance" );
20 this->m_Parameters.ConfigureAsBool( "UseImageSpacing" );
22 std::vector< std::string > choices;
23 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
24 choices.push_back( "float" );
25 #endif // cpPlugins_CONFIG_REAL_TYPES_float
26 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
27 choices.push_back( "double" );
28 #endif // cpPlugins_CONFIG_REAL_TYPES_double
29 this->m_Parameters.ConfigureAsChoices( "OutputResolution", choices );
31 this->m_Parameters.SetReal( "BackgroundValue", 0 );
32 this->m_Parameters.SetBool( "InsideIsPositive", true );
33 this->m_Parameters.SetBool( "SquaredDistance", false );
34 this->m_Parameters.SetBool( "UseImageSpacing", true );
37 // -------------------------------------------------------------------------
38 cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
39 ~SignedMaurerDistanceMapImageFilter( )
43 // -------------------------------------------------------------------------
44 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
47 auto o = this->GetInputData( "Input" );
48 cpPlugins_Demangle_Image_ScalarPixels_VisualDims_1( o, _GD0 )
49 this->_Error( "Invalid input image dimension." );
52 // -------------------------------------------------------------------------
53 template< class _TImage >
54 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
55 _GD0( _TImage* image )
58 this->m_Parameters.GetSelectedChoice( "OutputResolution" );
59 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
60 if( out_res == "float" ) this->_GD1< _TImage, float >( image );
61 #endif // cpPlugins_CONFIG_REAL_TYPES_float
62 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
63 if( out_res == "double" ) this->_GD1< _TImage, double >( image );
64 #endif // cpPlugins_CONFIG_REAL_TYPES_double
67 // -------------------------------------------------------------------------
68 template< class _TImage, class _TScalar >
69 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
70 _GD1( _TImage* image )
72 typedef itk::Image< _TScalar, _TImage::ImageDimension > _TDMap;
74 itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap >
78 double bv = this->m_Parameters.GetReal( "BackgroundValue" );
79 bool pi = this->m_Parameters.GetBool( "InsideIsPositive" );
80 bool sd = this->m_Parameters.GetBool( "SquaredDistance" );
81 bool us = this->m_Parameters.GetBool( "UseImageSpacing" );
84 _TFilter* filter = this->_CreateITK< _TFilter >( );
85 filter->SetInput( image );
86 filter->SetBackgroundValue( ( typename _TImage::PixelType )( bv ) );
87 filter->SetInsideIsPositive( pi );
88 filter->SetSquaredDistance( sd );
89 filter->SetUseImageSpacing( us );
93 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );