diff --git a/Code/Core/otbWrapperApplication.cxx b/Code/Core/otbWrapperApplication.cxx index fcc201e599a4380c4a0b64197dde0c6bab9d546e..aea3406674e5997f3fb190e328d563cdd79dcaad 100644 --- a/Code/Core/otbWrapperApplication.cxx +++ b/Code/Core/otbWrapperApplication.cxx @@ -17,13 +17,31 @@ =========================================================================*/ #include "otbWrapperApplication.h" +#include "otbWrapperChoiceParameter.h" +#include "otbWrapperDirectoryParameter.h" +#include "otbWrapperEmptyParameter.h" +#include "otbWrapperFilenameParameter.h" +#include "otbWrapperInputComplexImageParameter.h" +#include "otbWrapperInputImageParameter.h" +#include "otbWrapperInputVectorDataParameter.h" +#include "otbWrapperNumericalParameter.h" +#include "otbWrapperOutputImageParameter.h" +#include "otbWrapperOutputVectorDataParameter.h" +#include "otbWrapperRadiusParameter.h" +#include "otbWrapperStringParameter.h" + +#include "otbWrapperParameterGroup.h" + namespace otb { namespace Wrapper { -Application::Application(): m_Name(""), m_Description("") +Application::Application() + : m_Name(""), + m_Description("") { + // Don't call Init from the constructor, since it calls a virtual method ! } Application::~Application() @@ -32,9 +50,18 @@ Application::~Application() ParameterGroup* Application::GetParameterList() { + if (!m_ParameterList) + { + Init(); + } + return m_ParameterList; } +Parameter* Application::GetParameterByKey(std::string name) +{ + return GetParameterList()->GetParameterByKey(name); +} void Application::Init() { m_ParameterList = ParameterGroup::New(); @@ -51,6 +78,175 @@ void Application::Execute() this->DoExecute(); } +void Application::SetParameterInt(std::string parameter, int value) +{ + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<IntParameter*>(param)) + { + IntParameter* paramInt = dynamic_cast<IntParameter*>(param); + paramInt->SetValue(value); + } + else if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param); + paramFloat->SetValue(static_cast<float>(value)); + } + else if (dynamic_cast<RadiusParameter*>(param)) + { + RadiusParameter* paramRadius = dynamic_cast<RadiusParameter*>(param); + paramRadius->SetValue(value); + } + else if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); + paramChoice->SetValue(value); + } +} + +void Application::SetParameterFloat(std::string parameter, float value) +{ + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param); + paramFloat->SetValue(value); + } +} + +void Application::SetParameterString(std::string parameter, std::string value) +{ + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<FilenameParameter*>(param)) + { + FilenameParameter* paramDown = dynamic_cast<FilenameParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<DirectoryParameter*>(param)) + { + DirectoryParameter* paramDown = dynamic_cast<DirectoryParameter*>(param); + paramDown->SetValue(value); + } + else if (dynamic_cast<InputImageParameter*>(param)) + { + InputImageParameter* paramDown = dynamic_cast<InputImageParameter*>(param); + paramDown->SetFromFileName(value); + } + else if (dynamic_cast<InputComplexImageParameter*>(param)) + { + InputComplexImageParameter* paramDown = dynamic_cast<InputComplexImageParameter*>(param); + paramDown->SetFromFileName(value); + } + else if (dynamic_cast<InputVectorDataParameter*>(param)) + { + InputVectorDataParameter* paramDown = dynamic_cast<InputVectorDataParameter*>(param); + paramDown->SetFromFileName(value); + } + else if (dynamic_cast<OutputImageParameter*>(param)) + { + OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param); + paramDown->SetFileName(value); + } + else if (dynamic_cast<OutputVectorDataParameter*>(param)) + { + OutputVectorDataParameter* paramDown = dynamic_cast<OutputVectorDataParameter*>(param); + paramDown->SetFileName(value); + } + +} + +int Application::GetParameterInt(std::string parameter) +{ + int ret = 0; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<IntParameter*>(param)) + { + IntParameter* paramInt = dynamic_cast<IntParameter*>(param); + ret = paramInt->GetValue(); + } + else if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param); + ret = static_cast<int>(paramFloat->GetValue()); + } + else if (dynamic_cast<RadiusParameter*>(param)) + { + RadiusParameter* paramRadius = dynamic_cast<RadiusParameter*>(param); + ret = paramRadius->GetValue(); + } + else if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); + ret = paramChoice->GetValue(); + } + + //TODO: exception if not found ? + return ret; +} + +float Application::GetParameterFloat(std::string parameter) +{ + float ret = 0; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<FloatParameter*>(param)) + { + FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param); + ret = paramFloat->GetValue(); + } + + //TODO: exception if not found ? + return ret; +} + +std::string Application::GetParameterString(std::string parameter) +{ + std::string ret; + Parameter* param = GetParameterByKey(parameter); + + if (dynamic_cast<FilenameParameter*>(param)) + { + FilenameParameter* paramDown = dynamic_cast<FilenameParameter*>(param); + ret = paramDown->GetValue(); + } + else if (dynamic_cast<DirectoryParameter*>(param)) + { + DirectoryParameter* paramDown = dynamic_cast<DirectoryParameter*>(param); + ret = paramDown->GetValue(); + } + else if (dynamic_cast<InputImageParameter*>(param)) + { + InputImageParameter* paramDown = dynamic_cast<InputImageParameter*>(param); + ret = paramDown->GetFileName(); + } + else if (dynamic_cast<InputComplexImageParameter*>(param)) + { + InputComplexImageParameter* paramDown = dynamic_cast<InputComplexImageParameter*>(param); + ret = paramDown->GetFileName(); + } + else if (dynamic_cast<InputVectorDataParameter*>(param)) + { + InputVectorDataParameter* paramDown = dynamic_cast<InputVectorDataParameter*>(param); + ret = paramDown->GetFileName(); + } + else if (dynamic_cast<OutputImageParameter*>(param)) + { + OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param); + ret = paramDown->GetFileName(); + } + else if (dynamic_cast<OutputVectorDataParameter*>(param)) + { + OutputVectorDataParameter* paramDown = dynamic_cast<OutputVectorDataParameter*>(param); + ret = paramDown->GetFileName(); + } + + //TODO: exception if not found ? + return ret; +} + } } diff --git a/Code/Core/otbWrapperApplication.h b/Code/Core/otbWrapperApplication.h index feb7444bf02e87bd0fdad1a4d988b4c55cdb198d..7fc74c98ad1c595d2f2acdd8246d029530d6c0ca 100644 --- a/Code/Core/otbWrapperApplication.h +++ b/Code/Core/otbWrapperApplication.h @@ -84,12 +84,17 @@ public: ParameterGroup* GetParameterList(); - /* - void SetParameterBool(std::string parameter, bool value); + Parameter* GetParameterByKey(std::string parameter); + + //void SetParameterBool(std::string parameter, bool value); void SetParameterInt(std::string parameter, int value); void SetParameterFloat(std::string parameter, float value); void SetParameterString(std::string parameter, std::string value); - */ + + int GetParameterInt(std::string parameter); + float GetParameterFloat(std::string parameter); + std::string GetParameterString(std::string parameter); + protected: /** Constructor */ diff --git a/Code/Core/otbWrapperInputComplexImageParameter.h b/Code/Core/otbWrapperInputComplexImageParameter.h index 5b9bd578e16eec6e6ea129e8f5245b4607254dd4..791b08aee80cac2d8bb7ab791627e96affe44d85 100644 --- a/Code/Core/otbWrapperInputComplexImageParameter.h +++ b/Code/Core/otbWrapperInputComplexImageParameter.h @@ -18,7 +18,10 @@ #ifndef __otbWrapperInputComplexImageParameter_h #define __otbWrapperInputComplexImageParameter_h +#include <complex> #include "otbVectorImage.h" +#include "otbImageFileReader.h" + #include "otbWrapperParameter.h" namespace otb @@ -44,7 +47,7 @@ public: /** RTTI support */ itkTypeMacro(InputComplexImageParameter,Parameter); - typedef float PixelType; + typedef std::complex<float> PixelType; typedef otb::VectorImage<PixelType, 2> VectorImageType; /** Set the value */ @@ -53,6 +56,26 @@ public: /** Get the value */ itkGetObjectMacro(Image, VectorImageType); + /** Set value from filename */ + void SetFromFileName(const std::string& filename) + { + ImageFileReaderType::Pointer reader = ImageFileReaderType::New(); + reader->SetFileName(filename); + reader->UpdateOutputInformation(); + m_Reader = reader; + m_Image = reader->GetOutput(); + } + + std::string GetFileName() const + { + if (m_Reader) + { + return m_Reader->GetFileName(); + } + + itkExceptionMacro(<< "No value yet"); + } + protected: /** Constructor */ InputComplexImageParameter() @@ -65,7 +88,9 @@ protected: virtual ~InputComplexImageParameter() {} + typedef otb::ImageFileReader<VectorImageType> ImageFileReaderType; VectorImageType::Pointer m_Image; + ImageFileReaderType::Pointer m_Reader; private: InputComplexImageParameter(const Parameter &); //purposely not implemented diff --git a/Code/Core/otbWrapperInputImageParameter.h b/Code/Core/otbWrapperInputImageParameter.h index cc26fcbe7aa1080efdced0cbf6f7c4a6b5ad7484..01aab565e7aa661c8d56d3a21b5623c61154a9e7 100644 --- a/Code/Core/otbWrapperInputImageParameter.h +++ b/Code/Core/otbWrapperInputImageParameter.h @@ -58,14 +58,25 @@ public: /** Set value from filename */ void SetFromFileName(const std::string& filename) { - typedef otb::ImageFileReader<VectorImageType> ImageFileReaderType; ImageFileReaderType::Pointer reader = ImageFileReaderType::New(); reader->SetFileName(filename); reader->UpdateOutputInformation(); + + // everything went fine, store the object references m_Reader = reader; m_Image = reader->GetOutput(); } + std::string GetFileName() const + { + if (m_Reader) + { + return m_Reader->GetFileName(); + } + + itkExceptionMacro(<< "No value yet"); + } + /** Return any value */ virtual boost::any GetAnyValue() { @@ -85,7 +96,9 @@ protected: {} VectorImageType::Pointer m_Image; - itk::ProcessObject::Pointer m_Reader; + + typedef otb::ImageFileReader<VectorImageType> ImageFileReaderType; + ImageFileReaderType::Pointer m_Reader; private: InputImageParameter(const Parameter &); //purposely not implemented diff --git a/Code/Core/otbWrapperInputVectorDataParameter.h b/Code/Core/otbWrapperInputVectorDataParameter.h index 1baca6af1ff8cec76a2f9c5271b34701bb4c295f..f0cbe1481e4f716f58df7df4c813af16c88ce984 100644 --- a/Code/Core/otbWrapperInputVectorDataParameter.h +++ b/Code/Core/otbWrapperInputVectorDataParameter.h @@ -19,6 +19,8 @@ #define __otbWrapperInputVectorDataParameter_h #include "otbVectorData.h" +#include "otbVectorDataFileReader.h" + #include "otbWrapperParameter.h" namespace otb @@ -60,6 +62,29 @@ public: return boost::any(m_VectorData); } + /** Set value from filename */ + void SetFromFileName(const std::string& filename) + { + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + reader->SetFileName(filename); + reader->UpdateOutputInformation(); + + // everything went fine, store the object references + m_Reader = reader; + m_VectorData = reader->GetOutput(); + } + + std::string GetFileName() const + { + if (m_Reader) + { + return m_Reader->GetFileName(); + } + + itkExceptionMacro(<< "No value yet"); + } + + protected: /** Constructor */ InputVectorDataParameter() @@ -72,7 +97,9 @@ protected: virtual ~InputVectorDataParameter() {} + typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; VectorDataType::Pointer m_VectorData; + VectorDataFileReaderType::Pointer m_Reader; private: InputVectorDataParameter(const Parameter &); //purposely not implemented diff --git a/Code/Core/otbWrapperOutputVectorDataParameter.h b/Code/Core/otbWrapperOutputVectorDataParameter.h index 59b883e8217c71bb0f08f11fb604e70158c465ff..425529d947f166ae66003cd4747000ee5dd209cb 100644 --- a/Code/Core/otbWrapperOutputVectorDataParameter.h +++ b/Code/Core/otbWrapperOutputVectorDataParameter.h @@ -60,6 +60,21 @@ public: return boost::any(m_VectorData); } + /** Return any value */ + void SetValue(VectorDataType* vd) + { + m_VectorData = vd; + } + + /** Return any value */ + VectorDataType* GetValue( void ) + { + return m_VectorData; + } + + itkSetStringMacro(FileName); + itkGetStringMacro(FileName); + protected: /** Constructor */ OutputVectorDataParameter() @@ -73,6 +88,7 @@ protected: {} VectorDataType::Pointer m_VectorData; + std::string m_FileName; private: OutputVectorDataParameter(const Parameter &); //purposely not implemented diff --git a/Code/Core/otbWrapperRadiusParameter.h b/Code/Core/otbWrapperRadiusParameter.h index e0c14448baf3062a82c3724f15aa4180140435da..2b8d92169632cae6c4ca38d63f1c015294d74b1c 100644 --- a/Code/Core/otbWrapperRadiusParameter.h +++ b/Code/Core/otbWrapperRadiusParameter.h @@ -29,7 +29,7 @@ namespace Wrapper * \brief This class represent a radius parameter for the wrapper framework */ class RadiusParameter - : public NumericalParameter<int> + : public IntParameter { public: /** Standard class typedef */ diff --git a/Code/Wrappers/SWIG/otbApplication.i b/Code/Wrappers/SWIG/otbApplication.i index e8bfe0a490eff37c628f7367eb8989f4c6c63a94..1cdcebc7e7fe12b26fc3fe9dbaab151a7f280d8f 100644 --- a/Code/Wrappers/SWIG/otbApplication.i +++ b/Code/Wrappers/SWIG/otbApplication.i @@ -99,6 +99,14 @@ public: void Execute(); ParameterGroup* GetParameterList(); + void SetParameterInt(std::string parameter, int value); + void SetParameterFloat(std::string parameter, float value); + void SetParameterString(std::string parameter, std::string value); + + int GetParameterInt(std::string parameter); + float GetParameterFloat(std::string parameter); + std::string GetParameterString(std::string parameter); + protected: Application(); virtual ~Application();