]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/OtsuThresholdImageFilter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / OtsuThresholdImageFilter.cxx
index 7988bca7bc67700168ec06765874f5ff72568153..efc7d6ace500028a371393bf6264314ecb833a3e 100644 (file)
@@ -1,20 +1,6 @@
 #include <cpPlugins/Plugins/OtsuThresholdImageFilter.h>
 #include <cpPlugins/Interface/Image.h>
 
-#include <complex>
-
-#define ITK_MANUAL_INSTANTIATION
-#include <itkImage.h>
-
-#include <itkCovariantVector.h>
-#include <itkDiffusionTensor3D.h>
-#include <itkPoint.h>
-#include <itkRGBPixel.h>
-#include <itkRGBAPixel.h>
-#include <itkSymmetricSecondRankTensor.h>
-#include <itkVector.h>
-
-#undef ITK_MANUAL_INSTANTIATION
 #include <itkOtsuThresholdImageFilter.h>
 
 // -------------------------------------------------------------------------
@@ -29,7 +15,9 @@ OtsuThresholdImageFilter( )
   this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
 
   using namespace cpPlugins::Interface;
-  this->m_DefaultParameters.Configure( Parameters::Uint, "NumberOfHistogramBins" );
+  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 );
@@ -48,25 +36,30 @@ cpPlugins::Plugins::OtsuThresholdImageFilter::
 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
 _GenerateData( )
 {
-  itk::DataObject* i = this->m_Inputs[ 0 ]->GetITKDataObject( );
-  return( this->_DemangleImageDimension( i ) );
-}
+  cpPlugins::Interface::Image* image =
+    this->_Input< cpPlugins::Interface::Image >( 0 );
+  if( image == NULL )
+    return( "OtsuThresholdImageFilter: No input image." );
 
-// -------------------------------------------------------------------------
-namespace cpPlugins
-{
-  namespace Plugins
-  {
-    cpPlugins_Image_Demangle_Methods_Code_Only_Scalars(
-      OtsuThresholdImageFilter, _DemangleInput
-      );
-  }
+  itk::DataObject* itk_image = NULL;
+  std::string r = "";
+  cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
+    2, image, itk_image, r, _DemangleOutput
+    );
+  else cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
+    3, image, itk_image, r, _DemangleOutput
+    );
+  else cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
+    4, image, itk_image, r, _DemangleOutput
+    );
+  else r = "OtsuThresholdImageFilter: Input image type not supported.";
+  return( r );
 }
 
 // -------------------------------------------------------------------------
 template< class I >
 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
-_DemangleInput( itk::DataObject* image )
+_DemangleOutput( itk::DataObject* image )
 {
   return(
     this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
@@ -77,16 +70,19 @@ _DemangleInput( itk::DataObject* image )
 
 // -------------------------------------------------------------------------
 template< class I, class O >
-std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
+inline std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
 _RealGD( itk::DataObject* image )
 {
   typedef itk::OtsuThresholdImageFilter< I, O > _F;
   typedef typename O::PixelType _OP;
 
-  unsigned int bins = this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
-  _OP in = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) );
-  _OP out = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) );
+  // 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" ) );
 
+  // Configure filter
   _F* filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
   if( filter == NULL )
   {
@@ -96,12 +92,20 @@ _RealGD( itk::DataObject* image )
   } // fi
   filter->SetInput( dynamic_cast< I* >( image ) );
   filter->SetNumberOfHistogramBins( bins );
-  filter->SetInsideValue( in );
-  filter->SetOutsideValue( out );
+  filter->SetInsideValue( in_val );
+  filter->SetOutsideValue( out_val );
   filter->Update( );
-  this->m_Outputs[ 0 ]->SetITKDataObject( filter->GetOutput( ) );
-  
-  return( "" );
+
+  // Connect output
+  cpPlugins::Interface::Image* out =
+    this->_Output< cpPlugins::Interface::Image >( 0 );
+  if( out != NULL )
+  {
+    out->SetITKImage< O >( filter->GetOutput( ) );
+    return( "" );
+  }
+  else
+    return( "OtsuThresholdImageFilter: output not correctly created." );
 }
 
 // eof - $RCSfile$