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