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