]> 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< cpPlugins::Interface::Image >( "Input" );
42   if( image == NULL )
43     return( "SignedMaurerDistanceMapImageFilter: No input image." );
44
45   itk::DataObject* itk_image = NULL;
46   std::string r = "";
47   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
48   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
49   else r = "SignedMaurerDistanceMapImageFilter: Input image type not supported.";
50   return( r );
51 }
52
53 // -------------------------------------------------------------------------
54 template< class I >
55 std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter::
56 _GD0( itk::DataObject* image )
57 {
58   std::string out_res =
59     this->m_Parameters->GetSelectedChoice( "OutputResolution" );
60   if( out_res == "float" )
61     return(
62       this->_RealGD< I, itk::Image< float, I::ImageDimension > >(
63         image
64         )
65       );
66   else if( out_res == "double" )
67     return(
68       this->_RealGD< I, itk::Image< double, I::ImageDimension > >(
69         image
70         )
71       );
72   else
73     return( "SignedMaurerDistanceMapImageFilter: Output resolution not supported." );
74 }
75
76 // -------------------------------------------------------------------------
77 template< class I, class O >
78 inline std::string cpPlugins::BasicFilters::SignedMaurerDistanceMapImageFilter::
79 _RealGD( itk::DataObject* image )
80 {
81   typedef itk::SignedMaurerDistanceMapImageFilter< I, O > _F;
82
83   // Get parameters
84   double back_value = this->m_Parameters->GetReal( "BackgroundValue" );
85   bool pos_inside = this->m_Parameters->GetBool( "InsideIsPositive" );
86   bool sqr_dist = this->m_Parameters->GetBool( "SquaredDistance" );
87   bool use_spac = this->m_Parameters->GetBool( "UseImageSpacing" );
88
89   // Configure filter
90   _F* filter = this->_CreateITK< _F >( );
91   filter->SetInput( dynamic_cast< I* >( image ) );
92   filter->SetBackgroundValue( ( typename I::PixelType )( back_value ) );
93   filter->SetInsideIsPositive( pos_inside );
94   filter->SetSquaredDistance( sqr_dist );
95   filter->SetUseImageSpacing( use_spac );
96
97   filter->Update( );
98
99   // Connect output
100   auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
101   if( out != NULL )
102   {
103     out->SetITK< O >( filter->GetOutput( ) );
104     return( "" );
105   }
106   else
107     return( "SignedMaurerDistanceMapImageFilter: output not correctly created." );
108 }
109
110 // eof - $RCSfile$