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

#ifndef TOMOPROCESS_FILTER_PERCOLATION_FILTER_HPP
#define TOMOPROCESS_FILTER_PERCOLATION_FILTER_HPP

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

TOMOPROCESS_OPEN_GLOBAL_NAMESPACE
TOMOPROCESS_OPEN_FILTER_NAMESPACE

/** \class PercolationFilter
 * \brief Detects and delete small isolated clusters of pixels with a given value.
 */
template< class ImageT >
class PercolationFilter
  : public Filter<
      itk::PercolationFilter<
        typename ImageT::InputImageType,
	typename ImageT::OutputImageType,
	itk::BinaryBallStructuringElement<
	  typename ImageT::InputPixelType,
	  ImageT::InputImageType::ImageDimension
	  >
	>,
      ImageT>
{
public:
  /// \brief This type.
  typedef PercolationFilter	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.
  typedef itk::BinaryBallStructuringElement< InputPixelType,
    ImageType::InputImageType::ImageDimension> StructuringElementType;
  
  /// \brief Radius type for structuring element.
  typedef typename StructuringElementType::SizeType RadiusType;
  
  /// \brief Parent class.
  typedef Filter<
    itk::PercolationFilter<
      typename ImageType::InputImageType,
      typename ImageType::OutputImageType,
      StructuringElementType>,
    ImageType> SuperClass;
  
  /// \brief Sets the parameters.
  /// \param[in] lookFor pixels' value to look for.
  /// \param[in] radius radii for the minimal cluster size (clusters of pixels smaller than that are deleted).
  /// \param[in] foregroundValue value for the selected pixels.
  /// \param[in] backgroundValue value for the deleted pixels.
  /// \param[in] useSpacing taking into account the image spacing for the computation of cluster sizes.
  virtual void SetParameters(InputPixelType lookFor, RadiusType radius,
			     OutputPixelType foregroundValue, OutputPixelType backgroundValue,
			     bool useSpacing = true)
  {
    this->m_Filter->SetLookFor(lookFor);
    this->m_Filter->SetRadius(radius);
    this->m_Filter->SetForegroundValue(foregroundValue);
    this->m_Filter->SetBackgroundValue(backgroundValue);
    this->m_Filter->SetUseImageSpacing(useSpacing);
  }
  
  /// \brief Gets the number of discarded pixels / number of foreground pixels.
  /// \return Ratio.
  virtual double GetDiscardRatio() const
  { return (this->m_Filter->GetDiscardRatio()); }
};

TOMOPROCESS_CLOSE_FILTER_NAMESPACE
TOMOPROCESS_CLOSE_GLOBAL_NAMESPACE

#endif // TOMOPROCESS_FILTER_PERCOLATION_FILTER_HPP