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