]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.cxx
MAC compilation issues solved... Now some tests please
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / OtsuThresholdImageFilter.cxx
index de924a67b9da78b90c68a2de89ef1984a8cf2a84..5c419ae4e1bf6e61930742365e10332ee79c1e27 100644 (file)
@@ -8,22 +8,16 @@ cpPlugins::BasicFilters::OtsuThresholdImageFilter::
 OtsuThresholdImageFilter( )
   : Superclass( )
 {
-  this->m_ClassName = "cpPlugins::BasicFilters::OtsuThresholdImageFilter";
-  this->m_ClassCategory = "ImageToImageFilter";
-  this->SetNumberOfInputs( 1 );
-  this->SetNumberOfOutputs( 1 );
-  this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+  this->_AddInput( "Input" );
+  this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
 
-  using namespace cpPlugins::Interface;
-  this->m_DefaultParameters.Configure(
-    Parameters::Uint, "NumberOfHistogramBins"
-    );
-  this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" );
-  this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" );
-  this->m_DefaultParameters.SetValueAsUint( "NumberOfHistogramBins", 100 );
-  this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 );
-  this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 );
-  this->m_Parameters = this->m_DefaultParameters;
+  this->m_Parameters->ConfigureAsUint( "NumberOfHistogramBins" );
+  this->m_Parameters->ConfigureAsUint( "InsideValue" );
+  this->m_Parameters->ConfigureAsUint( "OutsideValue" );
+
+  this->m_Parameters->SetUint( "NumberOfHistogramBins", 100 );
+  this->m_Parameters->SetUint( "InsideValue", 255 );
+  this->m_Parameters->SetUint( "OutsideValue", 0 );
 }
 
 // -------------------------------------------------------------------------
@@ -36,11 +30,7 @@ cpPlugins::BasicFilters::OtsuThresholdImageFilter::
 std::string cpPlugins::BasicFilters::OtsuThresholdImageFilter::
 _GenerateData( )
 {
-  cpPlugins::Interface::Image* image =
-    this->GetInput< cpPlugins::Interface::Image >( 0 );
-  if( image == NULL )
-    return( "OtsuThresholdImageFilter: No input image." );
-
+  auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
   itk::DataObject* itk_image = NULL;
   std::string r = "";
   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
@@ -71,29 +61,22 @@ _RealGD( itk::DataObject* image )
   typedef typename O::PixelType _OP;
 
   // Get parameters
-  unsigned int bins =
-    this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
-  _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) );
-  _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) );
+  unsigned int bins = this->m_Parameters->GetUint( "NumberOfHistogramBins" );
+  _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) );
+  _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) );
 
   // Configure filter
   _F* filter = this->_CreateITK< _F >( );
   filter->SetInput( dynamic_cast< I* >( image ) );
   filter->SetNumberOfHistogramBins( bins );
-  filter->SetInsideValue( in_val );
-  filter->SetOutsideValue( out_val );
+  filter->SetInsideValue( out_val ); // WARNING: these are inverted
+  filter->SetOutsideValue( in_val );
   filter->Update( );
 
   // Connect output
-  cpPlugins::Interface::Image* out =
-    this->GetOutput< cpPlugins::Interface::Image >( 0 );
-  if( out != NULL )
-  {
-    out->SetITK< O >( filter->GetOutput( ) );
-    return( "" );
-  }
-  else
-    return( "OtsuThresholdImageFilter: output not correctly created." );
+  auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
+  out->SetITK( filter->GetOutput( ) );
+  return( "" );
 }
 
 // eof - $RCSfile$