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

#ifndef TOMOPROCESS_FILTER_CENTROIDS_FILTER_HPP
#define TOMOPROCESS_FILTER_CENTROIDS_FILTER_HPP

#include "filter.hpp"
#include "detail/centroids_filter.hpp"

TOMOPROCESS_OPEN_GLOBAL_NAMESPACE
TOMOPROCESS_OPEN_FILTER_NAMESPACE

/** \class CentroidsFilter
 * \brief Clusters maxima into centroids.
 */
template<class ImageT, class MaximaInformationsContainerT, class ImageInformationsContainerT>
class CentroidsFilter
  : public Filter<
      itk::CentroidsFilter<
        typename ImageT::InputImageType,
	typename ImageT::OutputImageType,
	MaximaInformationsContainerT,
	ImageInformationsContainerT>,
      ImageT>
{
public:
  /// \brief This type.
  typedef CentroidsFilter 	Self;
  
  /// \brief Parent class.
  typedef Filter<
      itk::CentroidsFilter<
        typename ImageT::InputImageType,
	typename ImageT::OutputImageType,
	MaximaInformationsContainerT,
	ImageInformationsContainerT>,
      ImageT> SuperClass;
  
  /// \brief Image type.
  typedef ImageT 		ImageType;
  
  /// \brief Maxima informations container type.
  typedef typename SuperClass::ITKFilterType::MaximaInformationsContainerType
    MaximaInformationsContainerType;
    
  /// \brief Image informations container type.
  typedef typename SuperClass::ITKFilterType::ImageInformationsContainerType
    ImageInformationsContainerType;
  
  /// \brief Compute mode type for ellipsoid expansion.
  typedef typename SuperClass::ITKFilterType::ComputeModeType ComputeModeType;
  
  /// \brief Input pixel type.
  typedef typename SuperClass::ITKFilterType::InputPixelType InputPixelType;
  
  /// \brief Output pixel type.
  typedef typename SuperClass::ITKFilterType::OutputPixelType OutputPixelType;
  
  /// \brief Sets the parameters.
  /// \param[in] foreground foreground pixel.
  /// \param[in] background backgroudn pixel.
  /// \param[in] feature feature pixel.
  /// \param[in] theta angular step (in radian) for evaluating points on an ellipsoidal surface. (Longitude).
  /// \param[in] phi angular step (in radian) for evaluating points on an ellipsoidal surface. (Latitude).
  /// \param[in] minNeighbours minimum number of neighbours to cluster a maximum.
  /// \param[in] overlappingRatio minimal volume overlapping ratio between two ellipsoids (\f$\in [0, 1]\f$).
  /// \param[in] maxTrials maximum number of trial points for estimating the surface overlapping ratio between two ellipsoids.
  /// \param[in] tolerance relative tolerance in the intersecting volume estimation between two ellipsoids.
  /// \param[in] maxInfos informations on maxima.
  /// \param[in] imagesInfos informations on images.
  /// \param[in] discardBoundaries sets if the maxima on boundaries should be discarded.
  /// \param[in] draw flag for drawing (true) or not (false) to the output image.
  /// \param[in] postExpand sets if a post-expansion of the ellipsoid is done after clustering.
  /// \param[in] computeQuality flag for computing the cell-ellipsoid matching quality.
  /// \param[in] verbose sets the verbose mode on (true) or off (false).
  /// \param[in] computeMode sets the compute mode (full, fast).
  /// \param[in] os output stream for messages.
  virtual void SetParameters(OutputPixelType foreground,
			     OutputPixelType background,
			     InputPixelType feature,
			     double theta,
			     double phi,
			     unsigned int minNeighbours,
			     double overlappingRatio,
			     unsigned int maxTrials,
			     double tolerance,
			     MaximaInformationsContainerType* maxInfos,
			     const ImageInformationsContainerType* imageInfos = NULL,
			     bool discardBoundaries = false,
			     bool draw = false,
			     bool postExpand = false,
			     unsigned int computeMode = ComputeModeType::full,
			     bool computeQuality = false,
			     bool verbose = false,
			     std::ostream &os = std::cerr)
  {
    this->m_Filter->SetForeground(foreground);
    this->m_Filter->SetBackground(background);
    this->m_Filter->SetFeaturePixel(feature);
    this->m_Filter->SetDTheta(theta);
    this->m_Filter->SetDPhi(phi);
    this->m_Filter->SetMinNeighboursClustering(minNeighbours);
    this->m_Filter->SetOverlapping(overlappingRatio);
    this->m_Filter->SetMaxTrials(maxTrials);
    this->m_Filter->SetTolerance(tolerance);
    this->m_Filter->SetMaximaInformations(maxInfos);
    this->m_Filter->SetImageInformations(imageInfos);
    this->m_Filter->SetDiscardBoundaries(discardBoundaries);
    this->m_Filter->SetVerbose(verbose);
    this->m_Filter->SetDraw(draw);
    this->m_Filter->SetPostExpand(postExpand);
    this->m_Filter->SetComputeMode(computeMode);
    this->m_Filter->SetComputeQuality(computeQuality);
    this->m_Filter->SetErrorStream(os);
  }
  
  /// \brief Gets the quality matching ratio between ellipsoids and cells.
  /// \return Ratio.
  virtual double GetQualityMatchRatio() const
  { return (this->m_Filter->GetQualityMatchRatio()); }
  
  /// \brief Gets the quality mismatching ratio between ellipsoids and cells.
  /// \return Ratio.
  virtual double GetQualityMismatchRatio() const
  { return (this->m_Filter->GetQualityMismatchRatio()); }
};

TOMOPROCESS_CLOSE_FILTER_NAMESPACE
TOMOPROCESS_CLOSE_GLOBAL_NAMESPACE

#endif // TOMOPROCESS_FILTER_CENTROIDS_FILTER_HPP