/**============================================================================
 *
 * \file   adaptive_threshold_filter.hpp
 * \brief  Declarations for the AdaptiveThresholdFilter class.
 *
 * \author Leblanc Christophe.
 * \date   08/08/2013
 * \email cleblancad@gmail.com
 *
 * Code inspired from:
 * 'Getting Started with ITK + VTK'
 * L. Ibanez, W. Schroeder, Insight Software Consortium.
 *
 *
 *===========================================================================*/

#ifndef TOMOPROCESS_FILTER_ADAPTIVE_THRESHOLD_FILTER_HPP
#define TOMOPROCESS_FILTER_ADAPTIVE_THRESHOLD_FILTER_HPP

#include "filter.hpp"
#include "detail/itkAdaptiveOtsuThresholdImageFilter.h"

TOMOPROCESS_OPEN_GLOBAL_NAMESPACE
TOMOPROCESS_OPEN_FILTER_NAMESPACE

/** \class AdaptiveThresholdFilter
  * \brief Adaptive Otsu threshold.
  */
template<class ImageT>
class AdaptiveThresholdFilter
  : public Filter<
      itk::AdaptiveOtsuThresholdImageFilter<
        typename ImageT::InputImageType,
	typename ImageT::OutputImageType>,
      ImageT>
{
public:
  /// \brief This type.
  typedef AdaptiveThresholdFilter Self;
  
  /// \brief Parent class.
  typedef Filter<
    itk::AdaptiveOtsuThresholdImageFilter<
      typename ImageT::InputImageType,
      typename ImageT::OutputImageType>,
    ImageT> SuperClass;
    
  /// \brief Image type.
  typedef ImageT ImageType;
  
  /// \brief Input pixel type.
  typedef typename ImageType::InputPixelType  InputPixelType;
  
  /// \brief output pixel type.
  typedef typename ImageType::OutputPixelType OutputPixelType;
  
  /// \brief Radius type.
  typedef typename SuperClass::ITKFilterType::InputSizeType RadiusType;
  
  /** \brief Sets the parameters.
    *
    * \param[in] insideValue: pixels inside the foreground object are set to this value. Usually set as 1.
    * \param[in] outsideValue: pixels inside the foreground object are set to this value. Usually, set to 0.
    * 
    * \param[in] lowerThreshold: pixel's value lower than this threshold will be set to 'outsideValue'.
    * \param[in] upperThreshold: pixel's value upper than this threshold will be set to 'outsideValue'.
    * 
    * \param[in] numberOfControlPoints: the number of control points to be used in the base level of B-Spline
    *    approximation of the threshold surface. This depends on the number of samples being used, the
    *    topology of the intensity inhomogeneity and the nature of the fit being considered. Usually set as
    *    10 − 50.
    *
    * \param[in] numberOfLevels: the number of levels of spline reconstruction refinement to be used. Usually,
    *    set in the range 3 − 5 for large datasets.
    *
    * \param[in] numberOfSamples: the number of random samples to collect at various points in the image. A
    *    larger number increases the running time proportionately and leads to better accuracy.
    *
    * \param[in] radius: the radius of the neighborhood to compute local histograms for Otsu thresholding.
    *
    * \param[in] numberOfHistogramBins: the number of histogram bins to collect intensity data and determine
    *     the Otsu bimodal threshold. In an 8-bit image, it is usually set to the maximum of 255 bins.
    */
  virtual void SetParameters(
    OutputPixelType insideValue, OutputPixelType outsideValue,
    InputPixelType lowerThreshold, InputPixelType upperThreshold,
    unsigned int numberOfControlPoints, unsigned int numberOfLevels,
    unsigned int numberOfSamples, RadiusType radius,
    unsigned int numberOfHistogramBins)
  {
    this->m_Filter->SetInsideValue(insideValue);
    this->m_Filter->SetOutsideValue(outsideValue);
    this->m_Filter->SetLowerThreshold(lowerThreshold);
    this->m_Filter->SetUpperThreshold(upperThreshold);
    this->m_Filter->SetNumberOfControlPoints(numberOfControlPoints);
    this->m_Filter->SetNumberOfLevels(numberOfLevels);
    this->m_Filter->SetNumberOfSamples(numberOfSamples);
    this->m_Filter->SetRadius(radius);
    this->m_Filter->SetNumberOfHistogramBins(numberOfHistogramBins);
  }
};
      
TOMOPROCESS_CLOSE_FILTER_NAMESPACE
TOMOPROCESS_CLOSE_GLOBAL_NAMESPACE
      
#endif // TOMOPROCESS_FILTER_ADAPTIVE_THRESHOLD_FILTER_HPP