]> 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" );
18   this->m_Parameters.ConfigureAsBool( "InsideIsPositive" );
19   this->m_Parameters.ConfigureAsBool( "SquaredDistance" );
20   this->m_Parameters.ConfigureAsBool( "UseImageSpacing" );
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   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 );
35 }
36
37 // -------------------------------------------------------------------------
38 cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
39 ~SignedMaurerDistanceMapImageFilter( )
40 {
41 }
42
43 // -------------------------------------------------------------------------
44 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
45 _GenerateData( )
46 {
47   auto o = this->GetInputData( "Input" );
48   cpPlugins_Demangle_Image_ScalarPixels_VisualDims_1( o, _GD0 )
49     this->_Error( "Invalid input image dimension." );
50 }
51
52 // -------------------------------------------------------------------------
53 template< class _TImage >
54 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
55 _GD0( _TImage* image )
56 {
57   std::string out_res =
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
65 }
66
67 // -------------------------------------------------------------------------
68 template< class _TImage, class _TScalar >
69 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
70 _GD1( _TImage* image )
71 {
72   typedef itk::Image< _TScalar, _TImage::ImageDimension >  _TDMap;
73   typedef
74     itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap >
75     _TFilter;
76
77   // Get parameters
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" );
82
83   // Configure filter
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 );
90   filter->Update( );
91
92   // Connect output
93   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
94 }
95
96 // eof - $RCSfile$