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

#ifndef TOMOPROCESS_FILTER_DILATION_FILTER_HPP
#define TOMOPROCESS_FILTER_DILATION_FILTER_HPP

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

TOMOPROCESS_OPEN_GLOBAL_NAMESPACE
TOMOPROCESS_OPEN_FILTER_NAMESPACE

/** \class DilationFilter
  * \brief Dilates an image.
  */
template<class ImageT>
class DilationFilter
  : public Filter<
      itk::DilationFilter<
        typename ImageT::InputImageType,
	typename ImageT::OutputImageType,
	itk::BinaryBallStructuringElement<
	  typename ImageT::InputPixelType,
	  ImageT::InputImageType::ImageDimension
	  >
	>,
      ImageT>
{
public:
  /// \brief This type.
  typedef DilationFilter	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 used for dilation.
  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::DilationFilter<
      typename ImageType::InputImageType,
      typename ImageType::OutputImageType,
      StructuringElementType>,
    ImageType> SuperClass;
    
  /// \brief Sets the parameters.
  /// \param[in] foreground pixel intensity value of the object to dilate.
  /// \param[in] background pixel intensity value of the background image.
  /// \param[in] radius radius of dilatation.
  virtual void SetParameters(InputPixelType foreground, OutputPixelType background,
			     RadiusType radius)
  {
    m_StructuringElement.SetRadius(radius);
    m_StructuringElement.CreateStructuringElement();
    
    this->m_Filter->SetForegroundValue(foreground);
    this->m_Filter->SetBackgroundValue(background);
    this->m_Filter->SetKernel(m_StructuringElement);
  }
      
protected:
  /// \brief Structuring element.
  StructuringElementType m_StructuringElement;
};

TOMOPROCESS_CLOSE_FILTER_NAMESPACE
TOMOPROCESS_CLOSE_GLOBAL_NAMESPACE

#endif // TOMOPROCESS_FILTER_DILATION_FILTER_HPP