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