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

#ifndef TOMOPROCESS_FILTER_BINARY_THRESHOLD_FILTER_HPP
#define TOMOPROCESS_FILTER_BINARY_THRESHOLD_FILTER_HPP

#include "filter.hpp"
#include "itkBinaryThresholdImageFilter.h"

TOMOPROCESS_OPEN_GLOBAL_NAMESPACE
TOMOPROCESS_OPEN_FILTER_NAMESPACE

/** \class BinaryThresholdFilter
 * \brief Applies a binary threhsold on a grayscale image.
 */
template<class ImageT>
class BinaryThresholdFilter
  : public Filter<
      itk::BinaryThresholdImageFilter<
        typename ImageT::InputImageType,
	typename ImageT::OutputImageType>,
      ImageT>
{
public:
  /// \brief This type.
  typedef BinaryThresholdFilter	Self;
  
  /// \brief Parent class.
  typedef Filter<
    itk::BinaryThresholdImageFilter<
      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 Sets the parameters.
  /// If the pixel value lies in interval [lowThresh, upThresh]
  ///   then pixel value set to insideValue.
  ///  else pixel value set to outsideValue.
  ///
  /// \param[in] lowThresh lower threshold.
  /// \param[in] upThresh upper threshold.
  /// \param[in] insideValue value for pixels inside the interval.
  /// \param[in] outsideValue value for pixels outside the interval.
  virtual void SetParameters(InputPixelType lowThresh, InputPixelType upThresh,
			     OutputPixelType insideValue, OutputPixelType outsideValue)
  {
    this->m_Filter->SetOutsideValue(outsideValue);
    this->m_Filter->SetInsideValue(insideValue);
    this->m_Filter->SetLowerThreshold(lowThresh);
    this->m_Filter->SetUpperThreshold(upThresh);
    
    // Sets the filter to be run in place.
    this->m_Filter->InPlaceOn();
  }
};

TOMOPROCESS_CLOSE_FILTER_NAMESPACE
TOMOPROCESS_CLOSE_GLOBAL_NAMESPACE

#endif // TOMOPROCESS_FILTER_BINARY_THRESHOLD_FILTER_HPP