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