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