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