]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/SignedMaurerDistanceMapImageFilter.cxx
a0f29d84b2e9e4e700cc94f7f161f4638aca0d0a
[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 std::string cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
38 _GenerateData( )
39 {
40   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
41   std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
42   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
43   return( r );
44 }
45
46 // -------------------------------------------------------------------------
47 template< class _TImage >
48 std::string cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
49 _GD0( _TImage* image )
50 {
51   if( image != NULL )
52   {
53     std::string out_res =
54       this->m_Parameters.GetSelectedChoice( "OutputResolution" );
55     if( out_res == "float" )
56       return(
57         this->_GD1< _TImage, itk::Image< float, _TImage::ImageDimension > >( image )
58         );
59   else if( out_res == "double" )
60     return(
61       this->_GD1< _TImage, itk::Image< double, _TImage::ImageDimension > >( image )
62       );
63   else
64     return( "ImageFilters::SignedMaurerDistanceMapImageFilter: Output resolution not supported." );
65   }
66   else
67     return(
68       "ImageFilters::SignedMaurerDistanceMapImageFilter: No valid input image."
69       );
70 }
71
72 // -------------------------------------------------------------------------
73 template< class _TImage, class _TDMap >
74 std::string cpPluginsImageFilters::SignedMaurerDistanceMapImageFilter::
75 _GD1( _TImage* image )
76 {
77   typedef itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap > _F;
78
79   // Get parameters
80   double back_value = this->m_Parameters.GetReal( "BackgroundValue" );
81   bool pos_inside = this->m_Parameters.GetBool( "InsideIsPositive" );
82   bool sqr_dist = this->m_Parameters.GetBool( "SquaredDistance" );
83   bool use_spac = this->m_Parameters.GetBool( "UseImageSpacing" );
84
85   // Configure filter
86   _F* filter = this->_CreateITK< _F >( );
87   filter->SetInput( image );
88   filter->SetBackgroundValue( ( typename _TImage::PixelType )( back_value ) );
89   filter->SetInsideIsPositive( pos_inside );
90   filter->SetSquaredDistance( sqr_dist );
91   filter->SetUseImageSpacing( use_spac );
92   filter->Update( );
93
94   // Connect output
95   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
96   return( "" );
97 }
98
99 // eof - $RCSfile$