--- /dev/null
+#include <cpPlugins/Plugins/BinaryThresholdImageFilter.h>
+#include <cpPlugins/Interface/Image.h>
+
+#include <itkBinaryThresholdImageFilter.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::Plugins::BinaryThresholdImageFilter::
+BinaryThresholdImageFilter( )
+ : Superclass( )
+{
+ this->m_ClassName = "cpPlugins::BinaryThresholdImageFilter";
+ this->m_ClassCategory = "ImageToImageFilter";
+ this->SetNumberOfInputs( 1 );
+ this->SetNumberOfOutputs( 1 );
+ this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+
+ using namespace cpPlugins::Interface;
+ this->m_DefaultParameters.Configure(Parameters::Real, "LowerThresholdValue");
+ this->m_DefaultParameters.Configure(Parameters::Real, "UpperThresholdValue");
+ this->m_DefaultParameters.Configure(Parameters::Real, "InsideValue");
+ this->m_DefaultParameters.Configure(Parameters::Real, "OutsideValue");
+
+ this->m_DefaultParameters.SetValueAsReal("LowerThresholdValue", 100);
+ this->m_DefaultParameters.SetValueAsReal("UpperThresholdValue",500);
+ this->m_DefaultParameters.SetValueAsReal("InsideValue", 255);
+ this->m_DefaultParameters.SetValueAsReal("OutsideValue", 0);
+
+ //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;
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Plugins::BinaryThresholdImageFilter::
+~BinaryThresholdImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Plugins::BinaryThresholdImageFilter::
+_GenerateData( )
+{
+ cpPlugins::Interface::Image* image =
+ this->GetInput< cpPlugins::Interface::Image >( 0 );
+ if( image == NULL )
+ return( "BinaryThresholdImageFilter: No input image." );
+
+ 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 = "BinaryThresholdImageFilter: Input image type not supported.";
+ return( r );
+}
+
+// -------------------------------------------------------------------------
+template< class I >
+std::string cpPlugins::Plugins::BinaryThresholdImageFilter::
+_DemangleOutput( itk::DataObject* image )
+{
+ return(
+ this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
+ image
+ )
+ );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+inline std::string cpPlugins::Plugins::BinaryThresholdImageFilter::
+_RealGD( itk::DataObject* image )
+{
+ typedef itk::BinaryThresholdImageFilter< I, O > _F;
+ typedef typename O::PixelType _OP;
+
+ // Get parameters
+ //unsigned int bins =
+ // this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
+ _OP lower_val = _OP(this->m_Parameters.GetValueAsReal("LowerValue"));
+ _OP upper_val = _OP(this->m_Parameters.GetValueAsReal("UpperValue"));
+ _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 )
+ {
+ this->m_RealProcessObject = _F::New( );
+ filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
+
+ } // fi
+ filter->SetInput( dynamic_cast< I* >( image ) );
+ //filter->SetNumberOfHistogramBins( bins );
+ filter->SetLowerThreshold(lower_val);
+ filter->SetUpperThreshold(upper_val);
+ filter->SetInsideValue( in_val );
+ filter->SetOutsideValue( out_val );
+ filter->Update( );
+
+ // Connect output
+ cpPlugins::Interface::Image* out =
+ this->GetOutput< cpPlugins::Interface::Image >( 0 );
+ if( out != NULL )
+ {
+ out->SetITKImage< O >( filter->GetOutput( ) );
+ return( "" );
+ }
+ else
+ return( "BinaryThresholdImageFilter: output not correctly created." );
+}
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __CPPLUGINS__PLUGINS__BINARYTHRESHOLDIMAGEFILTER__H__
+#define __CPPLUGINS__PLUGINS__BINARYTHRESHOLDIMAGEFILTER__H__
+
+#include <cpPlugins/Plugins/cpPlugins_Export.h>
+#include <cpPlugins/Interface/BaseProcessObjects.h>
+
+namespace cpPlugins
+{
+ namespace Plugins
+ {
+ /**
+ */
+ class cpPlugins_EXPORT BinaryThresholdImageFilter
+ : public cpPlugins::Interface::ImageToImageFilter
+ {
+ public:
+ typedef BinaryThresholdImageFilter Self;
+ typedef cpPlugins::Interface::ImageToImageFilter Superclass;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
+
+ public:
+ itkNewMacro( Self );
+ itkTypeMacro( BinaryThresholdImageFilter, cpPluginsInterfaceImageToImageFilter );
+
+ protected:
+ BinaryThresholdImageFilter( );
+ virtual ~BinaryThresholdImageFilter( );
+
+ virtual std::string _GenerateData( );
+
+ template< class I >
+ inline std::string _DemangleOutput( itk::DataObject* image );
+
+ template< class I, class O >
+ inline std::string _RealGD( itk::DataObject* image );
+
+ private:
+ // Purposely not implemented
+ BinaryThresholdImageFilter( const Self& );
+ Self& operator=( const Self& );
+ };
+
+ // ---------------------------------------------------------------------
+ CPPLUGINS_INHERIT_PROVIDER( BinaryThresholdImageFilter );
+
+ } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__PLUGINS__BINARYTHRESHOLDIMAGEFILTER__H__
+
+// eof - $RCSfile$