]> 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_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   cpPlugins_Demangle_Image_ScalarPixels_1( image, _GD1, _TImage::ImageDimension )
58     this->_Error( "Invalid input image pixel type." );
59 }
60
61 // -------------------------------------------------------------------------
62 template< class _TImage >
63 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
64 _GD1( _TImage* image )
65 {
66   std::string out_res =
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
74 }
75
76 // -------------------------------------------------------------------------
77 template< class _TImage, class _TScalar >
78 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
79 _GD2( _TImage* image )
80 {
81   typedef itk::Image< _TScalar, _TImage::ImageDimension >  _TDMap;
82   typedef
83     itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap >
84     _TFilter;
85
86   // Get parameters
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" );
91
92   // Configure filter
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 );
99   filter->Update( );
100
101   // Connect output
102   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
103 }
104
105 // eof - $RCSfile$