]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/SignedMaurerDistanceMapImageFilter.cxx
05b9620d19591d6bcc7ba9bfa0ffcf23799bd6b8
[cpPlugins.git] / plugins / cpPluginsImageFilters / SignedMaurerDistanceMapImageFilter.cxx
1 #include <cpPluginsImageFilters/SignedMaurerDistanceMapImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances/DistanceMapFilters.h>
4
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
7 SignedMaurerDistanceMapImageFilter( )
8   : Superclass( )
9 {
10   this->_AddInput( "Input" );
11   this->_AddOutput< cpPlugins::Image >( "Output" );
12
13   this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
14   this->m_Parameters.ConfigureAsBool( "InsideIsPositive" );
15   this->m_Parameters.ConfigureAsBool( "SquaredDistance" );
16   this->m_Parameters.ConfigureAsBool( "UseImageSpacing" );
17
18   std::vector< std::string > choices;
19   choices.push_back( "float" );
20   choices.push_back( "double" );
21   this->m_Parameters.ConfigureAsChoices( "OutputResolution", choices );
22
23   this->m_Parameters.SetReal( "BackgroundValue", 0 );
24   this->m_Parameters.SetBool( "InsideIsPositive", true );
25   this->m_Parameters.SetBool( "SquaredDistance", false );
26   this->m_Parameters.SetBool( "UseImageSpacing", true );
27   this->m_Parameters.SetSelectedChoice( "OutputResolution", "float" );
28 }
29
30 // -------------------------------------------------------------------------
31 cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
32 ~SignedMaurerDistanceMapImageFilter( )
33 {
34 }
35
36 // -------------------------------------------------------------------------
37 void cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
38 _GenerateData( )
39 {
40   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
41   cpPlugins_Image_Demangle_Pixel_AllScalars     ( _GD0, image, 2 );
42   else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
43   else this->_Error( "No valid input image." );
44 }
45
46 // -------------------------------------------------------------------------
47 template< class _TImage >
48 void cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
49 _GD0( _TImage* image )
50 {
51   static const unsigned int D = _TImage::ImageDimension;
52   if( image != NULL )
53   {
54     std::string out_res =
55       this->m_Parameters.GetSelectedChoice( "OutputResolution" );
56     if( out_res == "float" )
57       this->_GD1< _TImage, itk::Image< float, D > >( image );
58     else if( out_res == "double" )
59       this->_GD1< _TImage, itk::Image< double, D > >( image );
60     else
61       this->_Error( "Output resolution not supported." );
62   }
63   else
64     this->_Error( "No valid input image." );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class _TImage, class _TDMap >
69 void cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
70 _GD1( _TImage* image )
71 {
72   typedef itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap > _F;
73
74   // Get parameters
75   double back_value = this->m_Parameters.GetReal( "BackgroundValue" );
76   bool pos_inside = this->m_Parameters.GetBool( "InsideIsPositive" );
77   bool sqr_dist = this->m_Parameters.GetBool( "SquaredDistance" );
78   bool use_spac = this->m_Parameters.GetBool( "UseImageSpacing" );
79
80   // Configure filter
81   _F* filter = this->_CreateITK< _F >( );
82   filter->SetInput( image );
83   filter->SetBackgroundValue( ( typename _TImage::PixelType )( back_value ) );
84   filter->SetInsideIsPositive( pos_inside );
85   filter->SetSquaredDistance( sqr_dist );
86   filter->SetUseImageSpacing( use_spac );
87   filter->Update( );
88
89   // Connect output
90   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
91 }
92
93 // eof - $RCSfile$