From 42a30bb33696bc531b2b25103f9568fd56aa2d9e Mon Sep 17 00:00:00 2001 From: Julien Malik <julien.malik@c-s.fr> Date: Sun, 12 Jun 2011 09:32:50 +0200 Subject: [PATCH] ENH: put Smoothing in a single file --- Example/Smoothing/otbSmoothing.cxx | 222 ++++++++++++++++------------- 1 file changed, 121 insertions(+), 101 deletions(-) diff --git a/Example/Smoothing/otbSmoothing.cxx b/Example/Smoothing/otbSmoothing.cxx index 43447b3e11..f262db60f2 100644 --- a/Example/Smoothing/otbSmoothing.cxx +++ b/Example/Smoothing/otbSmoothing.cxx @@ -15,7 +15,7 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbSmoothing.h" +#include "otbWrapperApplication.h" #include "otbWrapperApplicationFactory.h" #include "otbWrapperNumericalParameter.h" @@ -41,109 +41,129 @@ enum 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() +class Smoothing : public Application { - 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: +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")) { - 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()); + 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; } - 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; - } -} + } +private: + itk::LightObject::Pointer m_FilterRef; +}; + + } } -- GitLab