From 75c715686349d20c7b0b143ca1442feb87a69c32 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Tue, 27 Oct 2015 18:24:53 +0100 Subject: [PATCH] ENH: add default pixel types for OutputImageParameter and ComplexOutputImageParameter --- .../include/otbWrapperApplication.h | 14 ++++++ .../otbWrapperComplexOutputImageParameter.h | 17 ++++++- .../include/otbWrapperOutputImageParameter.h | 14 ++++++ .../src/otbWrapperApplication.cxx | 23 +++++++++ .../otbWrapperComplexOutputImageParameter.cxx | 24 +++++++++- .../src/otbWrapperOutputImageParameter.cxx | 48 ++++++++++++++++++- 6 files changed, 136 insertions(+), 4 deletions(-) diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h index 9c83a78636..955a76b435 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h @@ -247,6 +247,20 @@ public: */ void SetDefaultParameterFloat(std::string parameter, float value); + /** Set a default pixel type for an output image parameter + * + * \param[in] parameter Name of the output image parameter + * \param[in] type Default pixel type + */ + void SetDefaultOutputPixelType(std::string parameter, ImagePixelType type); + + /** Set a default complex pixel type for an output complex image parameter + * + * \param[in] parameter Name of the output complex image parameter + * \param[in] type Default complex pixel type + */ + void SetDefaultOutputComplexPixelType(std::string parameter, ComplexImagePixelType type); + /* Set a minimum int value, must used in the * DoInit when setting a value by default * for the parameter diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexOutputImageParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexOutputImageParameter.h index 6500d54621..5edf833fba 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexOutputImageParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexOutputImageParameter.h @@ -61,14 +61,27 @@ public: /** Return any value */ ImageBaseType* GetValue( void ); - /** Set/Get PixelType to be used when saving */ + /** Set/Get m_ComplexPixelType to be used when saving */ itkSetMacro(ComplexPixelType, ComplexImagePixelType); itkGetMacro(ComplexPixelType, ComplexImagePixelType); + /** Set/Get m_DefaultComplexPixelType*/ + itkSetMacro(DefaultComplexPixelType, ComplexImagePixelType); + itkGetMacro(DefaultComplexPixelType, ComplexImagePixelType); + /** Set/Get available RAM value */ itkSetMacro(RAMValue, unsigned int); itkGetMacro(RAMValue, unsigned int); + /** Implement the reset method (replace pixel type by default type) */ + virtual void Reset() + { + m_ComplexPixelType = m_DefaultComplexPixelType; + } + + /** Static method to convert pixel type into string */ + static std::string ConvertPixelTypeToString(ComplexImagePixelType type); + /** Return true if a filename is set */ bool HasValue() const; @@ -106,7 +119,7 @@ protected: ImageBaseType::Pointer m_Image; std::string m_FileName; ComplexImagePixelType m_ComplexPixelType; - + ComplexImagePixelType m_DefaultComplexPixelType; typedef otb::ImageFileWriter<ComplexFloatImageType> ComplexFloatWriterType; typedef otb::ImageFileWriter<ComplexDoubleImageType> ComplexDoubleWriterType; diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h index a8dc212a7c..3313e5a8d2 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h @@ -66,10 +66,23 @@ public: itkSetMacro(PixelType, ImagePixelType); itkGetMacro(PixelType, ImagePixelType); + /** Set/Get DefaultPixelType */ + itkSetMacro(DefaultPixelType, ImagePixelType); + itkGetMacro(DefaultPixelType, ImagePixelType); + /** Set/Get available RAM value */ itkSetMacro(RAMValue, unsigned int); itkGetMacro(RAMValue, unsigned int); + /** Implement the reset method (replace pixel type by default type) */ + virtual void Reset() + { + m_PixelType = m_DefaultPixelType; + } + + /** Static method to convert pixel type into string */ + static std::string ConvertPixelTypeToString(ImagePixelType type); + /** Return true if a filename is set */ bool HasValue() const; @@ -113,6 +126,7 @@ protected: ImageBaseType::Pointer m_Image; std::string m_FileName; ImagePixelType m_PixelType; + ImagePixelType m_DefaultPixelType; typedef otb::ImageFileWriter<UInt8ImageType> UInt8WriterType; typedef otb::ImageFileWriter<Int16ImageType> Int16WriterType; diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx index 8176e2f7ff..2612a7cb97 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx @@ -657,6 +657,29 @@ void Application::SetDefaultParameterFloat(std::string parameter, float value) } } +void Application::SetDefaultOutputPixelType(std::string parameter, ImagePixelType type) +{ + Parameter* param = GetParameterByKey(parameter); + OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*>(param); + if (paramDown) + { + paramDown->SetDefaultPixelType(type); + paramDown->SetPixelType(type); + } +} + +void +Application::SetDefaultOutputComplexPixelType(std::string parameter, ComplexImagePixelType type) +{ + Parameter* param = GetParameterByKey(parameter); + ComplexOutputImageParameter* paramDown = dynamic_cast<ComplexOutputImageParameter*>(param); + if (paramDown) + { + paramDown->SetDefaultComplexPixelType(type); + paramDown->SetComplexPixelType(type); + } +} + void Application::SetMinimumParameterIntValue(std::string parameter, int value) { Parameter* param = GetParameterByKey(parameter); diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexOutputImageParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexOutputImageParameter.cxx index e87df1353b..d4f157e02e 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexOutputImageParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexOutputImageParameter.cxx @@ -26,7 +26,9 @@ namespace Wrapper { ComplexOutputImageParameter::ComplexOutputImageParameter() - : m_ComplexPixelType(ComplexImagePixelType_float), m_RAMValue(0) + : m_ComplexPixelType(ComplexImagePixelType_float), + m_DefaultComplexPixelType(ComplexImagePixelType_float), + m_RAMValue(0) { this->SetName("Complex Output Image"); this->SetKey("cout"); @@ -36,6 +38,26 @@ ComplexOutputImageParameter::~ComplexOutputImageParameter() { } +std::string +ComplexOutputImageParameter::ConvertPixelTypeToString(ComplexImagePixelType type) +{ + std::string ret; + switch(type) + { + case ComplexImagePixelType_float: + { + ret = "cfloat"; + break; + } + case ComplexImagePixelType_double: + { + ret = "cdouble"; + break; + } + } + return ret; +} + void ComplexOutputImageParameter::InitializeWriters() { m_ComplexFloatWriter = ComplexFloatWriterType::New(); diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx index 47498fa834..ec02594f47 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx @@ -25,7 +25,9 @@ namespace Wrapper { OutputImageParameter::OutputImageParameter() - : m_PixelType(ImagePixelType_float), m_RAMValue(0) + : m_PixelType(ImagePixelType_float), + m_DefaultPixelType(ImagePixelType_float), + m_RAMValue(0) { this->SetName("Output Image"); this->SetKey("out"); @@ -36,6 +38,50 @@ OutputImageParameter::~OutputImageParameter() { } +std::string OutputImageParameter::ConvertPixelTypeToString(ImagePixelType type) +{ + std::string ret; + switch(type) + { + case ImagePixelType_uint8: + { + ret = "uint8"; + break; + } + case ImagePixelType_int16: + { + ret = "int16"; + break; + } + case ImagePixelType_uint16: + { + ret = "uint16"; + break; + } + case ImagePixelType_int32: + { + ret = "int32"; + break; + } + case ImagePixelType_uint32: + { + ret = "uint32"; + break; + } + case ImagePixelType_float: + { + ret = "float"; + break; + } + case ImagePixelType_double: + { + ret = "double"; + break; + } + } + return ret; +} + void OutputImageParameter::InitializeWriters() { m_UInt8Writer = UInt8WriterType::New(); -- GitLab