]> Creatis software - cpPlugins.git/blob - plugins/ImageDistanceMaps/SignedMaurerDistanceMapImageFilter.cxx
41001947368179dc1a9d1027488c5cd4a068f2ce
[cpPlugins.git] / plugins / ImageDistanceMaps / SignedMaurerDistanceMapImageFilter.cxx
1 #include <plugins/ImageDistanceMaps/SignedMaurerDistanceMapImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3
4 #include <cpPlugins_ImageIterators.h>
5 #include <itkSignedMaurerDistanceMapImageFilter.h>
6 #include <itkSignedMaurerDistanceMapImageFilter.hxx>
7 #include <itkBinaryContourImageFilter.hxx>
8 #include <itkBinaryThresholdImageFilter.hxx>
9 #include <itkUnaryFunctorImageFilter.hxx>
10
11 // -------------------------------------------------------------------------
12 cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
13 SignedMaurerDistanceMapImageFilter( )
14   : Superclass( )
15 {
16   this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
17   this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
18
19   this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
20   this->m_Parameters.ConfigureAsBool( "InsideIsPositive" );
21   this->m_Parameters.ConfigureAsBool( "SquaredDistance" );
22   this->m_Parameters.ConfigureAsBool( "UseImageSpacing" );
23
24   std::vector< std::string > choices;
25   choices.push_back( "float" );
26   choices.push_back( "double" );
27   this->m_Parameters.ConfigureAsChoices( "OutputResolution", choices );
28
29   this->m_Parameters.SetReal( "BackgroundValue", 0 );
30   this->m_Parameters.SetBool( "InsideIsPositive", true );
31   this->m_Parameters.SetBool( "SquaredDistance", false );
32   this->m_Parameters.SetBool( "UseImageSpacing", true );
33   this->m_Parameters.SetSelectedChoice( "OutputResolution", "float" );
34 }
35
36 // -------------------------------------------------------------------------
37 cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
38 ~SignedMaurerDistanceMapImageFilter( )
39 {
40 }
41
42 // -------------------------------------------------------------------------
43 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
44 _GenerateData( )
45 {
46   auto o = this->GetInputData( "Input" );
47   cpPlugins_Demangle_ImageScalars( o, _GD0, 2 );
48   else cpPlugins_Demangle_ImageScalars( o, _GD0, 3 );
49   else this->_Error( "Invalid input image." );
50 }
51
52 // -------------------------------------------------------------------------
53 template< class _TImage >
54 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
55 _GD0( _TImage* image )
56 {
57   typedef itk::Image< float, _TImage::ImageDimension >  _TFDmap;
58   typedef itk::Image< double, _TImage::ImageDimension > _TDDmap;
59
60   std::string out_res =
61     this->m_Parameters.GetSelectedChoice( "OutputResolution" );
62   if( out_res == "float" )       this->_GD1< _TImage, _TFDmap >( image );
63   else if( out_res == "double" ) this->_GD1< _TImage, _TDDmap >( image );
64   else this->_Error( "Output resolution not supported." );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class _TImage, class _TDMap >
69 void cpPluginsImageDistanceMaps::SignedMaurerDistanceMapImageFilter::
70 _GD1( _TImage* image )
71 {
72   typedef
73     itk::SignedMaurerDistanceMapImageFilter< _TImage, _TDMap >
74     _TFilter;
75
76   // Get parameters
77   double bv = this->m_Parameters.GetReal( "BackgroundValue" );
78   bool pi = this->m_Parameters.GetBool( "InsideIsPositive" );
79   bool sd = this->m_Parameters.GetBool( "SquaredDistance" );
80   bool us = this->m_Parameters.GetBool( "UseImageSpacing" );
81
82   // Configure filter
83   _TFilter* filter = this->_CreateITK< _TFilter >( );
84   filter->SetInput( image );
85   filter->SetBackgroundValue( ( typename _TImage::PixelType )( bv ) );
86   filter->SetInsideIsPositive( pi );
87   filter->SetSquaredDistance( sd );
88   filter->SetUseImageSpacing( us );
89   filter->Update( );
90
91   // Connect output
92   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
93 }
94
95 // eof - $RCSfile$