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

#ifndef TOMOPROCESS_FILTER_EROSION_FILTER_HPP
#define TOMOPROCESS_FILTER_EROSION_FILTER_HPP

#include "filter.hpp"
#include "detail/erosion_filter.hpp"
#include "itkBinaryBallStructuringElement.h"

TOMOPROCESS_OPEN_GLOBAL_NAMESPACE
TOMOPROCESS_OPEN_FILTER_NAMESPACE

/** \class ErosionFilter
  * \brief Erodes an image.
  */
template<class ImageT>
class ErosionFilter
  : public Filter<
      itk::ErosionFilter<
        typename ImageT::InputImageType,
	typename ImageT::OutputImageType,
	itk::BinaryBallStructuringElement<
	  typename ImageT::InputPixelType,
	  ImageT::InputImageType::ImageDimension
	  >
	>,
      ImageT>
{
public:
  /// \brief This type.
  typedef ErosionFilter		Self;
  
  /// \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 Structuring element type.
  typedef itk::BinaryBallStructuringElement<InputPixelType,
    ImageType::InputImageType::ImageDimension> StructuringElementType;
    
  /// \brief Radius type for structuring element.
  typedef typename StructuringElementType::SizeValueType RadiusType;
    
  /// \brief Parent class.
  typedef Filter<
    itk::ErosionFilter<
      typename ImageType::InputImageType,
      typename ImageType::OutputImageType,
      StructuringElementType>,
    ImageType> SuperClass;
  
  /// \brief Sets the parameters.
  /// \param[in] foregroundValue pixel intensity value of the object to erode.
  /// \param[in] backgroundValue pixel intensity of the removed pixels.
  /// \param[in] radius radius of dilatation.
  virtual void SetParameters(InputPixelType foregroundValue, 
			     OutputpixelType backgroundValue,
			     RadiusType radius)
  {
    m_StructuringElement.SetRadius(radius);
    m_StructuringElement.CreateStructuringElement();
    
    this->m_Filter->SetForegroundValue(foregroundValue);
    this->m_Filter->SetBackgroundValue(backgroundValue);
    this->m_Filter->SetKernel(m_StructuringElement);
  }
  
protected:
  /// \brief Structuring element.
  StructuringElementType m_StructuringElement;
};

TOMOPROCESS_CLOSE_FILTER_NAMESPACE
TOMOPROCESS_CLOSE_GLOBAL_NAMESPACE

#endif // TOMOPROCESS_FILTER_EROSION_FILTER_HPP