/**============================================================================
 * 
 * \file closing_filter.hpp
 * \brief Declarations for the ClosingFilter class.
 * 
 * \author Leblanc Christophe.
 * \date 15/04/2016
 * \email cleblancad@gmail.com
 * 
 *  * Code inspired from:
 * 'Getting Started with ITK + VTK'
 * L. Ibanez, W. Schroeder, Insight Software Consortium.
 * 
 * Source:
 * 
 * "Binary morphological closing and opening image filters", G. Lehmann, Insight Jounral 2005
 * http://www.insight-journal.com/download/pdf/979/Binary_morphological_closing_and_opening_image_filters.pdf
 * 
 *===========================================================================**/

#ifndef TOMOPROCESS_FILTER_CLOSING_FILTER_HPP
#define TOMOPROCESS_FILTER_CLOSING_FILTER_HPP

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

TOMOPROCESS_OPEN_GLOBAL_NAMESPACE
TOMOPROCESS_OPEN_FILTER_NAMESPACE

/** \class ClosingFilter.
 * \brief Computes a binary closing.
 */
template<class ImageT>
class ClosingFilter
  : public Filter<
      itk::ClosingFilter<
        typename ImageT::InputImageType,
	typename ImageT::OutputImageType,
	itk::BinaryBallStructuringElement<
	  typename ImageT::InputPixelType,
	  ImageT::InputImageType::ImageDimension
	  >
	>,
      ImageT>
{
public:
  /// \brief This type.
  typedef ClosingFilter		Self;
  
  /// \brief Image type.
  typedef ImageT 		ImageType;
  
  /// \brief Input pixel type.
  typedef typename ImageType::InputPixelType PixelType;
  
  /// \brief Structuring element type.
  typedef itk::BinaryBallStructuringElement<PixelType,
    ImageType::InputImageType::ImageDimension> StructuringElementType;
    
  /// \brief Radius type for structuring element.
  typedef typename StructuringElementType::SizeValueType RadiusType;
    
  /// \brief Parent class.
  typedef Filter<
    itk::ClosingFilter<
      typename ImageType::InputImageType,
      typename ImageType::OutputImageType,
      StructuringElementType>,
    ImageType> SuperClass;
    
  /// \brief Sets the parameters.
  /// \param[in] foreground pixel intensity value of the object to close.
  /// \param[in] radius radius of dilatation.
  virtual void SetParameters(PixelType foreground, RadiusType radius)
  {
    m_StructuringElement.SetRadius(radius);
    m_StructuringElement.CreateStructuringElement();
    
    this->m_Filter->SetForegroundValue(foreground);
    this->m_Filter->SetSafeBorder(true);
    this->m_Filter->SetKernel(m_StructuringElement);
  }
    
protected:
  /// \brief Structuring element.
  StructuringElementType m_StructuringElement;
};

TOMOPROCESS_CLOSE_FILTER_NAMESPACE
TOMOPROCESS_CLOSE_GLOBAL_NAMESPACE

#endif // TOMOPROCESS_FILTER_CLOSING_FILTER_HPP

