]> Creatis software - cpPlugins.git/blob - plugins/ITKDistanceMapFilters/SignedMaurerDistanceMapImageFilter.cxx
a8f5767aab96bb31aa785f34aa6785a2ae6ca072
[cpPlugins.git] / plugins / ITKDistanceMapFilters / SignedMaurerDistanceMapImageFilter.cxx
1 #include <ITKDistanceMapFilters/SignedMaurerDistanceMapImageFilter.h>
2 #include <cpInstances/Image.h>
3
4 #include <itkSignedMaurerDistanceMapImageFilter.h>
5
6 // -------------------------------------------------------------------------
7 cpPluginsITKDistanceMapFilters::SignedMaurerDistanceMapImageFilter::
8 SignedMaurerDistanceMapImageFilter( )
9   : Superclass( )
10 {
11   typedef cpInstances::Image _TImage;
12
13   this->_ConfigureInput< _TImage >( "Input", true, false );
14   this->_ConfigureOutput< _TImage >( "Output" );
15
16   this->m_Parameters.ConfigureAsReal( "BackgroundValue", 0 );
17   this->m_Parameters.ConfigureAsBool( "InsideIsPositive", true );
18   this->m_Parameters.ConfigureAsBool( "SquaredDistance", false );
19   this->m_Parameters.ConfigureAsBool( "UseImageSpacing", true );
20
21   std::vector< std::string > choices;
22 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
23   choices.push_back( "float" );
24 #endif // cpPlugins_CONFIG_REAL_TYPES_float
25 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
26   choices.push_back( "double" );
27 #endif // cpPlugins_CONFIG_REAL_TYPES_double
28   this->m_Parameters.ConfigureAsChoices( "OutputResolution", choices );
29 }
30
31 // -------------------------------------------------------------------------
32 cpPluginsITKDistanceMapFilters::SignedMaurerDistanceMapImageFilter::
33 ~SignedMaurerDistanceMapImageFilter( )
34 {
35 }
36
37 // -------------------------------------------------------------------------
38 void cpPluginsITKDistanceMapFilters::SignedMaurerDistanceMapImageFilter::
39 _GenerateData( )
40 {
41   auto o = this->GetInputData( "Input" );
42   cpPlugins_Demangle_Image_ScalarPixels_VisualDims_1( o, _GD0 )
43     this->_Error( "Invalid input image dimension." );
44 }
45
46 // -------------------------------------------------------------------------
47 template< class _TImage >
48 void cpPluginsITKDistanceMapFilters::SignedMaurerDistanceMapImageFilter::
49 _GD0( _TImage* image )
50 {
51   std::string out_res =
52     this->m_Parameters.GetSelectedChoice( "OutputResolution" );
53 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
54   if( out_res == "float" ) this->_GD1< _TImage, float >( image );
55 #endif // cpPlugins_CONFIG_REAL_TYPES_float
56 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
57   if( out_res == "double" ) this->_GD1< _TImage, double >( image );
58 #endif // cpPlugins_CONFIG_REAL_TYPES_double
59 }
60
61 // -------------------------------------------------------------------------
62 template< class _TImage, class _TScalar >
63 void cpPluginsITKDistanceMapFilters::SignedMaurerDistanceMapImageFilter::
64 _GD1( _TImage* image )
65 {
66   typedef itk::Image< _TScalar, _TImage::ImageDimension >  _TDMap;
67   typedef
68     itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap >
69     _TFilter;
70
71   // Get parameters
72   double bv = this->m_Parameters.GetReal( "BackgroundValue" );
73   bool pi = this->m_Parameters.GetBool( "InsideIsPositive" );
74   bool sd = this->m_Parameters.GetBool( "SquaredDistance" );
75   bool us = this->m_Parameters.GetBool( "UseImageSpacing" );
76
77   // Configure filter
78   _TFilter* filter = this->_CreateITK< _TFilter >( );
79   filter->SetInput( image );
80   filter->SetBackgroundValue( ( typename _TImage::PixelType )( bv ) );
81   filter->SetInsideIsPositive( pi );
82   filter->SetSquaredDistance( sd );
83   filter->SetUseImageSpacing( us );
84   filter->Update( );
85
86   // Connect output
87   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
88 }
89
90 // eof - $RCSfile$