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