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