<commit_before>/*=========================================================================

 Program:   ORFEO Toolbox
 Language:  C++
 Date:      $Date$
 Version:   $Revision$


 Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
 See OTBCopyright.txt for details.


 This software is distributed WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notices for more information.

 =========================================================================*/
#include "otbSmoothing.h"
#include "otbWrapperApplicationFactory.h"
#include "otbWrapperNumericalParameter.h"

#include "itkMeanImageFilter.h"
#include "itkDiscreteGaussianImageFilter.h"
#include "itkGradientAnisotropicDiffusionImageFilter.h"
//#include "itkCurvatureAnisotropicDiffusionImageFilter.h"
#include "otbPerBandVectorImageFilter.h"

#include "itkVersion.h"

namespace otb
{
namespace Wrapper
{

enum
{
  Smoothing_Mean,
  Smoothing_Gaussian,
  Smoothing_Anisotropic
};

typedef otb::Image<VectorImageType::InternalPixelType, 2>  ImageType;


Smoothing::Smoothing()
{
  this->SetName("Smoothing");
  this->SetDescription("Apply a smoothing filter to an image");
}

Smoothing::~Smoothing()
{
}

void Smoothing::DoCreateParameters()
{
  AddParameter(ParameterType_InputImage,  "in",   "Input Image");
  AddParameter(ParameterType_OutputImage, "out",  "Output Image");

  AddParameter(ParameterType_Choice,      "type", "Smoothing Type");

  AddChoice("type.mean",     "Mean");
  AddParameter(ParameterType_Radius, "type.mean.radius", "Radius");
  SetParameterInt("type.mean.radius", 2);

  AddChoice("type.gaussian", "Gaussian");
  AddParameter(ParameterType_Radius, "type.gaussian.radius", "Radius");
  SetParameterInt("type.gaussian.radius", 2);

  AddChoice("type.anidif",   "Anisotropic Diffusion");
  AddParameter(ParameterType_Float,  "type.anidif.timestep", "Time Step");
  AddParameter(ParameterType_Int,  "type.anidif.nbiter", "Nb Iterations");
  SetParameterFloat("type.anidif.timestep",   0.125);
  SetParameterInt("type.anidif.nbiter",     10);

  SetParameterInt("type", 2);
}

void Smoothing::DoUpdateParameters()
{
  // Nothing to do here : all parameters are independent
}

void Smoothing::DoExecute()
{
  VectorImageType::Pointer inImage = this->GetParameterImage("in");

  switch (this->GetParameterInt("type"))
    {
    case Smoothing_Mean:
      {
      typedef itk::MeanImageFilter<ImageType, ImageType>         MeanFilterType;
      typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, MeanFilterType>
        PerBandMeanFilterType;

      PerBandMeanFilterType::Pointer perBand
        = PerBandMeanFilterType::New();
      perBand->SetInput(inImage);

      MeanFilterType::InputSizeType radius;
      radius.Fill( this->GetParameterInt("type.mean.radius") );
      perBand->GetFilter()->SetRadius(radius);
      ref = perBand;
      this->SetParameterOutputImage("out", perBand->GetOutput());
      }
      break;
    case Smoothing_Gaussian:
      {
      typedef itk::DiscreteGaussianImageFilter<ImageType, ImageType>  DiscreteGaussianFilterType;
      typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, DiscreteGaussianFilterType>
        PerBandDiscreteGaussianFilterType;

      PerBandDiscreteGaussianFilterType::Pointer perBand
        = PerBandDiscreteGaussianFilterType::New();
      perBand->SetInput(inImage);

      int radius = this->GetParameterInt("type.gaussian.radius");
      double variance = static_cast<double>(radius) * radius;
      perBand->GetFilter()->SetVariance(variance);
      ref = perBand;
      this->SetParameterOutputImage("out", perBand->GetOutput());
      }
      break;
    case Smoothing_Anisotropic:
      {
      typedef itk::GradientAnisotropicDiffusionImageFilter<ImageType, ImageType>  GradientAnisotropicDiffusionFilterType;
      typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, GradientAnisotropicDiffusionFilterType>
        PerBandGradientAnisotropicDiffusionFilterType;

      PerBandGradientAnisotropicDiffusionFilterType::Pointer perBand
        = PerBandGradientAnisotropicDiffusionFilterType::New();
      perBand->SetInput(inImage);

      int aniDifNbIter = this->GetParameterInt("type.anidif.nbiter");
      perBand->GetFilter()->SetNumberOfIterations(static_cast<unsigned int>(aniDifNbIter));

      float aniDifTimeStep = this->GetParameterFloat("type.anidif.timestep");
      perBand->GetFilter()->SetTimeStep(static_cast<double>(aniDifTimeStep));
      // perBand->GetFilter()->SetConductanceParameter()
      perBand->UpdateOutputInformation();
      ref = perBand;
      this->SetParameterOutputImage("out", perBand->GetOutput());
      }
      break;
    }
}

}
}<commit_msg>ENH: put Smoothing in a single file<commit_after>/*=========================================================================

 Program:   ORFEO Toolbox
 Language:  C++
 Date:      $Date$
 Version:   $Revision$


 Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
 See OTBCopyright.txt for details.


 This software is distributed WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notices for more information.

 =========================================================================*/
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbWrapperNumericalParameter.h"

#include "itkMeanImageFilter.h"
#include "itkDiscreteGaussianImageFilter.h"
#include "itkGradientAnisotropicDiffusionImageFilter.h"
//#include "itkCurvatureAnisotropicDiffusionImageFilter.h"
#include "otbPerBandVectorImageFilter.h"

#include "itkVersion.h"

namespace otb
{
namespace Wrapper
{

enum
{
  Smoothing_Mean,
  Smoothing_Gaussian,
  Smoothing_Anisotropic
};

typedef otb::Image<VectorImageType::InternalPixelType, 2>  ImageType;

class Smoothing : public Application
{
public:
  /** Standard class typedefs. */
  typedef Smoothing                      Self;
  typedef Application                   Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;

  /** Standard macro */
  itkNewMacro(Self);

  itkTypeMacro(Self, otb::Application);

protected:
  Smoothing()
  {
    this->SetName("Smoothing");
    this->SetDescription("Apply a smoothing filter to an image");
  }

  virtual ~Smoothing()
  {
    std::cout << "~Smoothing" << std::endl;
  }

  void DoCreateParameters()
  {
    AddParameter(ParameterType_InputImage,  "in",   "Input Image");
    AddParameter(ParameterType_OutputImage, "out",  "Output Image");

    AddParameter(ParameterType_Choice,      "type", "Smoothing Type");

    AddChoice("type.mean",     "Mean");
    AddParameter(ParameterType_Radius, "type.mean.radius", "Radius");
    SetParameterInt("type.mean.radius", 2);

    AddChoice("type.gaussian", "Gaussian");
    AddParameter(ParameterType_Radius, "type.gaussian.radius", "Radius");
    SetParameterInt("type.gaussian.radius", 2);

    AddChoice("type.anidif",   "Anisotropic Diffusion");
    AddParameter(ParameterType_Float,  "type.anidif.timestep", "Time Step");
    AddParameter(ParameterType_Int,  "type.anidif.nbiter", "Nb Iterations");
    SetParameterFloat("type.anidif.timestep",   0.125);
    SetParameterInt("type.anidif.nbiter",     10);

    SetParameterInt("type", 2);
  }

  void DoUpdateParameters()
  {
    // Nothing to do here : all parameters are independent
  }

  void DoExecute()
  {
    VectorImageType::Pointer inImage = this->GetParameterImage("in");

    switch (this->GetParameterInt("type"))
      {
      case Smoothing_Mean:
        {
        typedef itk::MeanImageFilter<ImageType, ImageType>         MeanFilterType;
        typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, MeanFilterType>
          PerBandMeanFilterType;

        PerBandMeanFilterType::Pointer perBand
          = PerBandMeanFilterType::New();
        perBand->SetInput(inImage);

        MeanFilterType::InputSizeType radius;
        radius.Fill( this->GetParameterInt("type.mean.radius") );
        perBand->GetFilter()->SetRadius(radius);
        m_FilterRef = perBand;
        this->SetParameterOutputImage("out", perBand->GetOutput());
        }
        break;
      case Smoothing_Gaussian:
        {
        typedef itk::DiscreteGaussianImageFilter<ImageType, ImageType>  DiscreteGaussianFilterType;
        typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, DiscreteGaussianFilterType>
          PerBandDiscreteGaussianFilterType;

        PerBandDiscreteGaussianFilterType::Pointer perBand
          = PerBandDiscreteGaussianFilterType::New();
        perBand->SetInput(inImage);

        int radius = this->GetParameterInt("type.gaussian.radius");
        double variance = static_cast<double>(radius) * radius;
        perBand->GetFilter()->SetVariance(variance);
        m_FilterRef = perBand;
        this->SetParameterOutputImage("out", perBand->GetOutput());
        }
        break;
      case Smoothing_Anisotropic:
        {
        typedef itk::GradientAnisotropicDiffusionImageFilter<ImageType, ImageType>  GradientAnisotropicDiffusionFilterType;
        typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, GradientAnisotropicDiffusionFilterType>
          PerBandGradientAnisotropicDiffusionFilterType;

        PerBandGradientAnisotropicDiffusionFilterType::Pointer perBand
          = PerBandGradientAnisotropicDiffusionFilterType::New();
        perBand->SetInput(inImage);

        int aniDifNbIter = this->GetParameterInt("type.anidif.nbiter");
        perBand->GetFilter()->SetNumberOfIterations(static_cast<unsigned int>(aniDifNbIter));

        float aniDifTimeStep = this->GetParameterFloat("type.anidif.timestep");
        perBand->GetFilter()->SetTimeStep(static_cast<double>(aniDifTimeStep));
        // perBand->GetFilter()->SetConductanceParameter()
        perBand->UpdateOutputInformation();
        m_FilterRef = perBand;
        this->SetParameterOutputImage("out", perBand->GetOutput());
        }
        break;
      }
  }
private:
  itk::LightObject::Pointer m_FilterRef;
};



}
}
{'fraction_non_alphanumeric': 0.13635477582846003, 'fraction_numerical': 0.001949317738791423, 'mean_word_length': 4.463791267305644, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1537203', 'n_tokens_mistral': 3082, 'n_tokens_neox': 2909, 'n_words': 514}