]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/OtsuThresholdImageFilter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / OtsuThresholdImageFilter.cxx
index 7988bca7bc67700168ec06765874f5ff72568153..a23bc12cce5bb739e655017d70972465a9c8bc9c 100644 (file)
@@ -48,25 +48,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 +82,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 +104,69 @@ _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." );
 }
 
+// -------------------------------------------------------------------------
+/* TODO
+   namespace cpPlugins
+   {
+   namespace Plugins
+   {
+   cpPlugins_Image_Demangle_Methods_Code_Only_Scalars(
+   OtsuThresholdImageFilter, _DemangleInput
+   );
+   }
+   }
+
+   // -------------------------------------------------------------------------
+   template< class I >
+   std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
+   _DemangleInput( itk::DataObject* image )
+   {
+   }
+
+   // -------------------------------------------------------------------------
+   template< class I, class O >
+   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" ) );
+
+   _F* filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
+   if( filter == NULL )
+   {
+   this->m_RealProcessObject = _F::New( );
+   filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
+
+   } // fi
+   filter->SetInput( dynamic_cast< I* >( image ) );
+   filter->SetNumberOfHistogramBins( bins );
+   filter->SetInsideValue( in );
+   filter->SetOutsideValue( out );
+   filter->Update( );
+   this->m_Outputs[ 0 ]->SetITKDataObject( filter->GetOutput( ) );
+
+   return( "" );
+   }
+*/
+
 // eof - $RCSfile$