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_VisualDims( o, _GD0, )
49 this->_Error( "Invalid input image dimension." );
52 // -------------------------------------------------------------------------
53 template< class _TImage >
54 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
55 _GD0( _TImage* image )
57 cpPlugins_Demangle_Image_ScalarPixels( image, _GD1, _TImage::ImageDimension, )
58 this->_Error( "Invalid input image pixel type." );
61 // -------------------------------------------------------------------------
62 template< class _TImage >
63 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
64 _GD1( _TImage* image )
67 this->m_Parameters.GetSelectedChoice( "OutputResolution" );
68 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
69 if( out_res == "float" ) this->_GD2< _TImage, float >( image );
70 #endif // cpPlugins_CONFIG_REAL_TYPES_float
71 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
72 if( out_res == "double" ) this->_GD2< _TImage, double >( image );
73 #endif // cpPlugins_CONFIG_REAL_TYPES_double
76 // -------------------------------------------------------------------------
77 template< class _TImage, class _TScalar >
78 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
79 _GD2( _TImage* image )
81 typedef itk::Image< _TScalar, _TImage::ImageDimension > _TDMap;
83 itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap >
87 double bv = this->m_Parameters.GetReal( "BackgroundValue" );
88 bool pi = this->m_Parameters.GetBool( "InsideIsPositive" );
89 bool sd = this->m_Parameters.GetBool( "SquaredDistance" );
90 bool us = this->m_Parameters.GetBool( "UseImageSpacing" );
93 _TFilter* filter = this->_CreateITK< _TFilter >( );
94 filter->SetInput( image );
95 filter->SetBackgroundValue( ( typename _TImage::PixelType )( bv ) );
96 filter->SetInsideIsPositive( pi );
97 filter->SetSquaredDistance( sd );
98 filter->SetUseImageSpacing( us );
102 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );