diff --git a/Code/Core/otbWrapperApplication.cxx b/Code/Core/otbWrapperApplication.cxx index 7fe27b876c4a57fa09e7e1f0173f531ab7137edc..5a2164d7c7e55edae636fa4c7fd9665a508911c1 100644 --- a/Code/Core/otbWrapperApplication.cxx +++ b/Code/Core/otbWrapperApplication.cxx @@ -17,6 +17,8 @@ =========================================================================*/ #include "otbWrapperApplication.h" +#include "itkImageFileWriter.h" +#include "otbStandardWriterWatcher.h" namespace otb { @@ -28,7 +30,46 @@ Application::Application(): m_Name(""), m_Description("") } Application::~Application() -{} +{ +} + +void Application::Init() +{ + m_ParameterList = ParameterGroup::New(); + this->DoCreateParameters(); +} + +void Application::UpdateParameters() +{ + this->DoUpdateParameters(); +} + +void Application::Execute() +{ + this->DoExecute(); + + ParameterGroup* params = GetParameterList(); + for (unsigned int i = 0; i < params->GetNumberOfParameters(); ++i) + { + Parameter* p = params->GetParameter( i ); + OutputImageParameter* pAsOutputImage = dynamic_cast<OutputImageParameter*>(p); + if ( pAsOutputImage != 0 ) + { + OutputImageParameter::VectorImageType* image = pAsOutputImage->GetValue(); + typedef itk::ImageFileWriter<OutputImageParameter::VectorImageType> WriterType; + + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(image); + writer->SetFileName(pAsOutputImage->GetFileName()); + + std::cout << image << std::endl; + itk::ProcessObject* source = image->GetSource(); + std::cout << source << std::endl; + otb::StandardWriterWatcher watcher(writer, source, "test"); + writer->Update(); + } + } +} } } diff --git a/Code/Core/otbWrapperApplication.h b/Code/Core/otbWrapperApplication.h index 34273f892323e3a80a6b46b1d7bd41f744784c63..455867247c28356bf0c3cadce16e207f78df57f0 100644 --- a/Code/Core/otbWrapperApplication.h +++ b/Code/Core/otbWrapperApplication.h @@ -76,21 +76,11 @@ public: /** Get the parameter description */ itkGetStringMacro(Description); - void Init() - { - m_ParameterList = ParameterGroup::New(); - this->DoCreateParameters(); - } + void Init(); - void UpdateParameters() - { - this->DoUpdateParameters(); - } + void UpdateParameters(); - void Execute() - { - this->DoExecute(); - } + void Execute(); ParameterGroup* GetParameterList() { diff --git a/Code/Core/otbWrapperChoiceParameter.h b/Code/Core/otbWrapperChoiceParameter.h index cd17d238e267a9ce693b4a4143307ac3577cb0b4..e999345ee0ef3aacdf87d216b6521daf5c9d0a25 100644 --- a/Code/Core/otbWrapperChoiceParameter.h +++ b/Code/Core/otbWrapperChoiceParameter.h @@ -19,6 +19,7 @@ #define __otbWrapperChoiceParameter_h #include "otbWrapperParameter.h" +#include "otbWrapperParameterGroup.h" namespace otb { @@ -48,19 +49,39 @@ public: itkTypeMacro(ChoiceParameter, Parameter); /** Add a value to the choice */ - void AddChoice( std::string key, Parameter::Pointer param ) + void AddChoice( std::string key, std::string name, Parameter* param ) { - m_ChoiceList.push_back(std::make_pair(key, param)); + ParameterGroup* paramAsGroup = dynamic_cast<ParameterGroup*>(param); + if ( paramAsGroup != 0 ) + { + Choice choice; + choice.m_Key = key; + choice.m_Name = name; + choice.m_AssociatedParameter = paramAsGroup; + m_ChoiceList.push_back(choice); + } + else + { + // wrap in group first + ParameterGroup::Pointer group = ParameterGroup::New(); + group->AddParameter(param); + AddChoice(key, name, group.GetPointer()); + } } std::string GetChoiceKey( int i ) { - return m_ChoiceList[i].first; + return m_ChoiceList[i].m_Key; } - Parameter::Pointer GetChoiceAssociatedParameter( int i ) + std::string GetChoiceName( int i ) { - return m_ChoiceList[i].second; + return m_ChoiceList[i].m_Name; + } + + ParameterGroup::Pointer GetChoiceAssociatedParameter( int i ) + { + return m_ChoiceList[i].m_AssociatedParameter; } unsigned int GetNbChoices( void ) @@ -73,7 +94,6 @@ public: { // Perform any cast m_CurrentChoice = v; - // Call Modified(); this->Modified(); } @@ -88,7 +108,14 @@ public: virtual void SetAnyValue(boost::any v) { // Perform any cast - m_CurrentChoice = boost::any_cast<unsigned int>(v); + unsigned int val = boost::any_cast<unsigned int>(v); + + if ( val >= GetNbChoices() ) + { + itkExceptionMacro(<< "Invalid choice value : " << val) + } + + m_CurrentChoice = val; // Call Modified(); this->Modified(); @@ -104,13 +131,21 @@ public: protected: /** Constructor */ ChoiceParameter() + : m_CurrentChoice(0) {} /** Destructor */ virtual ~ChoiceParameter() {} - typedef std::pair<std::string, Parameter::Pointer> Choice; + struct Choice + { + Choice() {} + + std::string m_Key; + std::string m_Name; + ParameterGroup::Pointer m_AssociatedParameter; + }; typedef std::vector<Choice> ChoiceList; ChoiceList m_ChoiceList; diff --git a/Code/Core/otbWrapperInputImageParameter.h b/Code/Core/otbWrapperInputImageParameter.h index b2ecd39ffb74a00c521b3cb03ad6d02e2f73bd9e..cc26fcbe7aa1080efdced0cbf6f7c4a6b5ad7484 100644 --- a/Code/Core/otbWrapperInputImageParameter.h +++ b/Code/Core/otbWrapperInputImageParameter.h @@ -62,6 +62,7 @@ public: ImageFileReaderType::Pointer reader = ImageFileReaderType::New(); reader->SetFileName(filename); reader->UpdateOutputInformation(); + m_Reader = reader; m_Image = reader->GetOutput(); } @@ -84,6 +85,7 @@ protected: {} VectorImageType::Pointer m_Image; + itk::ProcessObject::Pointer m_Reader; private: InputImageParameter(const Parameter &); //purposely not implemented diff --git a/Code/Core/otbWrapperOutputImageParameter.h b/Code/Core/otbWrapperOutputImageParameter.h index ba7096e9abbd20c13d5ff2952cae2a63985f1994..48caa96986f639fe4aff6cf912cacc22a60abd5c 100644 --- a/Code/Core/otbWrapperOutputImageParameter.h +++ b/Code/Core/otbWrapperOutputImageParameter.h @@ -59,6 +59,21 @@ public: return boost::any(m_Image); } + /** Return any value */ + void SetValue(VectorImageType* image) + { + m_Image = image; + } + + /** Return any value */ + VectorImageType* GetValue( void ) + { + return m_Image; + } + + itkSetStringMacro(FileName); + itkGetStringMacro(FileName); + protected: /** Constructor */ OutputImageParameter() @@ -72,6 +87,7 @@ protected: {} VectorImageType::Pointer m_Image; + std::string m_FileName; private: OutputImageParameter(const Parameter &); //purposely not implemented diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx index 5550f9ef51264b83e074890e3ac66e14788a64a8..8f075797442c08fcc5e7987aa1d5340aa1703e40 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx @@ -29,57 +29,56 @@ QtWidgetChoiceParameter::QtWidgetChoiceParameter(ChoiceParameter* param, QtWidge : QtWidgetParameterBase(m), m_ChoiceParam(param) { - this->CreateWidget(); } QtWidgetChoiceParameter::~QtWidgetChoiceParameter() { } -void QtWidgetChoiceParameter::CreateWidget() +void QtWidgetChoiceParameter::DoUpdateGUI() +{ + // Update the combobox value + unsigned int value = m_ChoiceParam->GetValue( ); + m_ComboBox->setCurrentIndex(value); + + // Update the choice subparameters + WidgetListIteratorType it = m_WidgetList.begin(); + for (it = m_WidgetList.begin(); it != m_WidgetList.end(); ++it) + { + (*it)->UpdateGUI(); + } +} + +void QtWidgetChoiceParameter::DoCreateWidget() { m_ComboBox = new QComboBox; m_ComboBox->setToolTip(m_ChoiceParam->GetDescription()); m_StackWidget = new QStackedWidget; - connect( m_ComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(SetValue(int)) ); - connect( m_ComboBox, SIGNAL(currentIndexChanged(int)), m_StackWidget, SLOT(setCurrentIndex(int)) ); - - for (unsigned int i = 0; i < m_ChoiceParam->GetNbChoices(); ++i) { - QString key = QString::fromStdString( m_ChoiceParam->GetChoiceKey(i) ); + QString key = QString::fromStdString( m_ChoiceParam->GetChoiceName(i) ); m_ComboBox->addItem( key, QVariant(key) ); - Parameter::Pointer param = m_ChoiceParam->GetChoiceAssociatedParameter(i); + ParameterGroup::Pointer param = m_ChoiceParam->GetChoiceAssociatedParameter(i); if (param.IsNotNull()) { - std::cout << param->GetName() << std::endl; - QWidget* label = new QtWidgetParameterLabel( param ); - QWidget* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() ); - QHBoxLayout* hbox = new QHBoxLayout; - hbox->addWidget(label); - hbox->addWidget(specificWidget); - QGroupBox* group = new QGroupBox; - group->setLayout(hbox); - m_StackWidget->addWidget(group); + QtWidgetParameterBase* widget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() ); + m_StackWidget->addWidget(widget); + m_WidgetList.push_back(widget); } } + connect( m_ComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(SetValue(int)) ); + connect( m_ComboBox, SIGNAL(currentIndexChanged(int)), m_StackWidget, SLOT(setCurrentIndex(int)) ); + m_VLayout = new QVBoxLayout; m_VLayout->addWidget(m_ComboBox); m_VLayout->addWidget(m_StackWidget); + m_VLayout->addStretch(); - m_VLayoutGroup = new QGroupBox; - m_VLayoutGroup->setLayout(m_VLayout); - m_VLayoutGroup->setFlat(true); - - m_MainHLayout = new QHBoxLayout; - m_MainHLayout->setSpacing(0); - m_MainHLayout->setContentsMargins(0,0,0,0); - m_MainHLayout->addWidget(m_VLayoutGroup); - this->setLayout(m_MainHLayout); + this->setLayout(m_VLayout); } void QtWidgetChoiceParameter::SetValue(int value) diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h index 21212ff6e48f8ac77f65084f7345372af5171043..c00e71d4b5d92db410c23aebd23de3ed38b7f4ac 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h @@ -20,6 +20,7 @@ #include <QtGui> #include "otbWrapperChoiceParameter.h" +#include "otbWrapperParameterGroup.h" #include "otbWrapperQtWidgetParameterBase.h" namespace otb @@ -40,15 +41,16 @@ public: protected slots: void SetValue( int value ); -protected: - void CreateWidget(); - - ChoiceParameter::Pointer m_ChoiceParam; - private: QtWidgetChoiceParameter(const QtWidgetChoiceParameter&); //purposely not implemented void operator=(const QtWidgetChoiceParameter&); //purposely not implemented + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + ChoiceParameter::Pointer m_ChoiceParam; + QHBoxLayout* m_MainHLayout; QComboBox* m_ComboBox; @@ -56,6 +58,10 @@ private: QVBoxLayout* m_VLayout; QGroupBox* m_VLayoutGroup; + + typedef std::vector<QtWidgetParameterBase*> WidgetListType; + typedef WidgetListType::iterator WidgetListIteratorType; + WidgetListType m_WidgetList; }; } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.cxx index 9475b6232752f82649d895dfe27b1285d477ae35..e15015f4821f4df9be9b966ac87308b6fc742c2f 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.cxx @@ -24,6 +24,19 @@ namespace Wrapper QtWidgetEmptyParameter::QtWidgetEmptyParameter(EmptyParameter* emptyParam, QtWidgetModel* m) : QtWidgetParameterBase(m) +{ +} + +QtWidgetEmptyParameter::~QtWidgetEmptyParameter() +{ +} + +void QtWidgetEmptyParameter::DoUpdateGUI() +{ + +} + +void QtWidgetEmptyParameter::DoCreateWidget() { // Set up input text edit QHBoxLayout *hLayout = new QHBoxLayout; @@ -40,9 +53,5 @@ QtWidgetEmptyParameter::QtWidgetEmptyParameter(EmptyParameter* emptyParam, QtWid this->setLayout(hLayout); } -QtWidgetEmptyParameter::~QtWidgetEmptyParameter() -{ -} - } } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.h index d34e7cb2623a3eb90f9d6a8225b0c5f45c1c88c8..3c7f5b336662f0134d7106f28ad57230c2370ad6 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetEmptyParameter.h @@ -42,6 +42,9 @@ private: QtWidgetEmptyParameter(const QtWidgetEmptyParameter&); //purposely not implemented void operator=(const QtWidgetEmptyParameter&); //purposely not implemented + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); }; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.cxx index 6d17ffd60f829db1f7d39c49b0c46bd603049014..c1191c852a95aa5d1b151a4785979623ac13e97c 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.cxx @@ -26,33 +26,42 @@ QtWidgetFloatParameter::QtWidgetFloatParameter(FloatParameter* floatParam, QtWid : QtWidgetParameterBase(m), m_FloatParam(floatParam) { - // Set up input text edit - QHBoxLayout *hLayout = new QHBoxLayout; - hLayout->setSpacing(0); - hLayout->setContentsMargins(0,0,0,0); - - QDoubleSpinBox* input = new QDoubleSpinBox; - input->setDecimals(5); - input->setRange(floatParam->GetMinimumValue(), floatParam->GetMaximumValue()); - input->setToolTip(floatParam->GetDescription()); - - connect( input, SIGNAL(valueChanged(double)), this, SLOT(SetValue(double)) ); - connect( input, SIGNAL(valueChanged(double)), GetModel(), SLOT(NotifyUpdate()) ); +} - //QString optionID(floatParam->GetName()); - hLayout->addWidget(input); - hLayout->addStretch(); +QtWidgetFloatParameter::~QtWidgetFloatParameter() +{ +} - this->setLayout(hLayout); +void QtWidgetFloatParameter::DoUpdateGUI() +{ + bool signalsBlocked = m_QDoubleSpinBox->blockSignals( true ); + m_QDoubleSpinBox->setValue(m_FloatParam->GetValue()); + m_QDoubleSpinBox->blockSignals( signalsBlocked ); } -QtWidgetFloatParameter::~QtWidgetFloatParameter() +void QtWidgetFloatParameter::DoCreateWidget() { + m_QHBoxLayout = new QHBoxLayout; + m_QHBoxLayout->setSpacing(0); + m_QHBoxLayout->setContentsMargins(0,0,0,0); + + m_QDoubleSpinBox = new QDoubleSpinBox; + m_QDoubleSpinBox->setDecimals(5); + m_QDoubleSpinBox->setRange(m_FloatParam->GetMinimumValue(), m_FloatParam->GetMaximumValue()); + m_QDoubleSpinBox->setToolTip(m_FloatParam->GetDescription()); + + connect( m_QDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(SetValue(double)) ); + connect( m_QDoubleSpinBox, SIGNAL(valueChanged(double)), GetModel(), SLOT(NotifyUpdate()) ); + + m_QHBoxLayout->addWidget(m_QDoubleSpinBox); + m_QHBoxLayout->addStretch(); + + this->setLayout(m_QHBoxLayout); + } void QtWidgetFloatParameter::SetValue(double value) { - std::cout << "QtWidgetFloatParameter::SetValue " << value << std::endl; m_FloatParam->SetValue( static_cast<float>(value) ); } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.h index f03117f3ea0d0a9e9d4f31d0a8d999b8c47f1e09..6864f017334aa2fb589a2beb745796dd3e957a1f 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetFloatParameter.h @@ -44,6 +44,13 @@ private: QtWidgetFloatParameter(const QtWidgetFloatParameter&); //purposely not implemented void operator=(const QtWidgetFloatParameter&); //purposely not implemented + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + QHBoxLayout * m_QHBoxLayout; + QDoubleSpinBox * m_QDoubleSpinBox; + FloatParameter::Pointer m_FloatParam; }; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx index 679576fcdc2640580b5ca5bd0869f123afeb8c62..8a9472e27f741f68b0f89ad91375cb1dbbdff5b7 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx @@ -26,45 +26,50 @@ QtWidgetInputImageParameter::QtWidgetInputImageParameter(InputImageParameter* pa : QtWidgetParameterBase(m), m_InputImageParam(param) { - this->CreateWidget(); } QtWidgetInputImageParameter::~QtWidgetInputImageParameter() { } -void QtWidgetInputImageParameter::CreateWidget() +void QtWidgetInputImageParameter::DoUpdateGUI() +{ + +} + +void QtWidgetInputImageParameter::DoCreateWidget() { // Set up input text edit - QHBoxLayout *hLayout = new QHBoxLayout; - hLayout->setSpacing(0); - hLayout->setContentsMargins(0,0,0,0); - QLineEdit* input = new QLineEdit; - input->setToolTip( m_InputImageParam->GetDescription() ); - connect( input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); - hLayout->addWidget(input); + m_HLayout = new QHBoxLayout; + m_HLayout->setSpacing(0); + m_HLayout->setContentsMargins(0,0,0,0); + m_Input = new QLineEdit; + m_Input->setToolTip( m_InputImageParam->GetDescription() ); + connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); + m_HLayout->addWidget(m_Input); // Set up input text edit - QPushButton *button = new QPushButton; - button->setText("..."); - button->setToolTip("Select file..."); - button->setMaximumWidth(button->width()); - connect( button, SIGNAL(clicked()), this, SLOT(SelectFile()) ); - hLayout->addWidget(button); - - this->setLayout(hLayout); + m_Button = new QPushButton; + m_Button->setText("..."); + m_Button->setToolTip("Select file..."); + m_Button->setMaximumWidth(m_Button->width()); + connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) ); + m_HLayout->addWidget(m_Button); + + this->setLayout(m_HLayout); } void QtWidgetInputImageParameter::SelectFile() { QFileDialog fileDialog; fileDialog.setConfirmOverwrite(true); - fileDialog.setFileMode(QFileDialog::AnyFile); + fileDialog.setFileMode(QFileDialog::ExistingFile); fileDialog.setNameFilter("Raster files (*)"); if (fileDialog.exec()) { - this->SetFileName(fileDialog.selectedFiles().at(0)); + //this->SetFileName(fileDialog.selectedFiles().at(0)); + m_Input->setText(fileDialog.selectedFiles().at(0)); } } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.h index bd74a6a6ec6d224b8d5e29ba96799cf338ef3a93..7b078027f2de8cbafc31a7a6b0826a5edb95d2c2 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.h @@ -42,14 +42,19 @@ protected slots: void SetFileName( const QString& value ); void SelectFile(); -protected: - void CreateWidget(); - private: QtWidgetInputImageParameter(const QtWidgetInputImageParameter&); //purposely not implemented void operator=(const QtWidgetInputImageParameter&); //purposely not implemented + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + InputImageParameter::Pointer m_InputImageParam; + + QHBoxLayout * m_HLayout; + QLineEdit* m_Input; + QPushButton * m_Button; }; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.cxx index 9193c00f0ecf298068c9a84c10c22f812de4de59..4b7c411d3e165dccc5e097af4d9f05da5c63de60 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.cxx @@ -25,32 +25,42 @@ namespace Wrapper QtWidgetIntParameter::QtWidgetIntParameter(IntParameter* param, QtWidgetModel* m) : QtWidgetParameterBase(m), m_IntParam(param) +{ +} + +QtWidgetIntParameter::~QtWidgetIntParameter() +{ +} + +void QtWidgetIntParameter::DoCreateWidget() { // Set up input text edit - QHBoxLayout *hLayout = new QHBoxLayout; - hLayout->setSpacing(0); - hLayout->setContentsMargins(0,0,0,0); + m_QHBoxLayout = new QHBoxLayout; + m_QHBoxLayout->setSpacing(0); + m_QHBoxLayout->setContentsMargins(0,0,0,0); - QSpinBox* input = new QSpinBox; - input->setRange(param->GetMinimumValue(), param->GetMaximumValue()); - input->setToolTip(param->GetDescription()); + m_QSpinBox = new QSpinBox; + m_QSpinBox->setRange(m_IntParam->GetMinimumValue(), m_IntParam->GetMaximumValue()); + m_QSpinBox->setToolTip(m_IntParam->GetDescription()); - connect( input, SIGNAL(valueChanged(int)), this, SLOT(SetValue(int)) ); - connect( input, SIGNAL(valueChanged(int)), GetModel(), SLOT(NotifyUpdate()) ); + connect( m_QSpinBox, SIGNAL(valueChanged(int)), this, SLOT(SetValue(int)) ); + connect( m_QSpinBox, SIGNAL(valueChanged(int)), GetModel(), SLOT(NotifyUpdate()) ); - hLayout->addWidget(input); - hLayout->addStretch(); + m_QHBoxLayout->addWidget(m_QSpinBox); + m_QHBoxLayout->addStretch(); - this->setLayout(hLayout); + this->setLayout(m_QHBoxLayout); } -QtWidgetIntParameter::~QtWidgetIntParameter() +void QtWidgetIntParameter::DoUpdateGUI() { + bool signalsBlocked = m_QSpinBox->blockSignals( true ); + m_QSpinBox->setValue(m_IntParam->GetValue()); + m_QSpinBox->blockSignals( signalsBlocked ); } void QtWidgetIntParameter::SetValue(int value) { - std::cout << "QtWidgetIntParameter::SetValue " << value << std::endl; m_IntParam->SetValue(value); } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.h index 5ecd2c4c1367ca18d7bc11f5ded57323c2efc3d8..b4090c4a4e61e4d2afdb13c98f4bdb1fd2ea2426 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetIntParameter.h @@ -45,6 +45,13 @@ private: QtWidgetIntParameter(const QtWidgetIntParameter&); //purposely not implemented void operator=(const QtWidgetIntParameter&); //purposely not implemented + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + QHBoxLayout * m_QHBoxLayout; + QSpinBox * m_QSpinBox; + IntParameter::Pointer m_IntParam; }; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.cxx index a7b2d01f5fdaa77d78a6c8ef883928994d20b70e..5cf37ec08912e64e36c209f12ab3dedf167acc26 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.cxx @@ -26,33 +26,37 @@ QtWidgetOutputImageParameter::QtWidgetOutputImageParameter(OutputImageParameter* : QtWidgetParameterBase(m), m_OutputImageParam(param) { - this->CreateWidget(); } QtWidgetOutputImageParameter::~QtWidgetOutputImageParameter() { } -void QtWidgetOutputImageParameter::CreateWidget() +void QtWidgetOutputImageParameter::DoUpdateGUI() +{ + +} + +void QtWidgetOutputImageParameter::DoCreateWidget() { // Set up input text edit - QHBoxLayout *hLayout = new QHBoxLayout; - hLayout->setSpacing(0); - hLayout->setContentsMargins(0,0,0,0); - QLineEdit* input = new QLineEdit; - input->setToolTip( m_OutputImageParam->GetDescription() ); - connect( input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); - hLayout->addWidget(input); + m_HLayout = new QHBoxLayout; + m_HLayout->setSpacing(0); + m_HLayout->setContentsMargins(0,0,0,0); + m_Input = new QLineEdit; + m_Input->setToolTip( m_OutputImageParam->GetDescription() ); + connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); + m_HLayout->addWidget(m_Input); // Set up input text edit - QPushButton *button = new QPushButton; - button->setText("..."); - button->setToolTip("Select output filename..."); - button->setMaximumWidth(button->width()); - connect( button, SIGNAL(clicked()), this, SLOT(SelectFile()) ); - hLayout->addWidget(button); - - this->setLayout(hLayout); + m_Button = new QPushButton; + m_Button->setText("..."); + m_Button->setToolTip("Select output filename..."); + m_Button->setMaximumWidth(m_Button->width()); + connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) ); + m_HLayout->addWidget(m_Button); + + this->setLayout(m_HLayout); } void QtWidgetOutputImageParameter::SelectFile() @@ -64,7 +68,8 @@ void QtWidgetOutputImageParameter::SelectFile() if (fileDialog.exec()) { - this->SetFileName(fileDialog.selectedFiles().at(0)); + //this->SetFileName(fileDialog.selectedFiles().at(0)); + m_Input->setText(fileDialog.selectedFiles().at(0)); } } @@ -73,6 +78,8 @@ void QtWidgetOutputImageParameter::SetFileName(const QString& value) // save value m_FileName = value.toStdString(); + m_OutputImageParam->SetFileName(m_FileName); + // notify of value change QString key( QString::fromStdString(m_OutputImageParam->GetKey()) ); emit ParameterChanged(key); diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.h index cd66231335f7d8868c641648fe65e493232aa92c..da514aeecb03c7741f0d61b212e67bcd023758b0 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputImageParameter.h @@ -42,16 +42,20 @@ protected slots: void SetFileName( const QString& value ); void SelectFile(); -protected: - void CreateWidget(); - private: QtWidgetOutputImageParameter(const QtWidgetOutputImageParameter&); //purposely not implemented void operator=(const QtWidgetOutputImageParameter&); //purposely not implemented + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + std::string m_FileName; OutputImageParameter::Pointer m_OutputImageParam; + QHBoxLayout * m_HLayout; + QLineEdit* m_Input; + QPushButton * m_Button; }; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx index 9e0fb974956fb6066e8a2617d0b7ccffae7038b6..20997b7dbaa786873380e5f132fd0ecf4795c3ab 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx @@ -31,6 +31,16 @@ QtWidgetParameterBase::~QtWidgetParameterBase() { } +void QtWidgetParameterBase::CreateWidget() +{ + this->DoCreateWidget(); +} + +void QtWidgetParameterBase::UpdateGUI() +{ + this->DoUpdateGUI(); +} + void QtWidgetParameterBase::ParameterChanged(const QString& key) { diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h index 72a62ef38926a2ccefa8be486ee79809317ddf19..e184e4895566da4d3a02466496306bfcbae48ae0 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h @@ -37,6 +37,9 @@ public: QtWidgetParameterBase(QtWidgetModel*); virtual ~QtWidgetParameterBase(); + void CreateWidget(); + void UpdateGUI(); + protected slots: void ParameterChanged(const QString& key); @@ -47,6 +50,10 @@ private: QtWidgetParameterBase(const QtWidgetParameterBase&); //purposely not implemented void operator=(const QtWidgetParameterBase&); //purposely not implemented + virtual void DoUpdateGUI() = 0; + + virtual void DoCreateWidget() = 0; + QtWidgetModel* m_Model; }; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx index 62536477b4c3092b606334be02fa63c64b157839..5512f91d842a8f844327d4ba224b9489601aab12 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx @@ -17,6 +17,11 @@ =========================================================================*/ #include "otbWrapperQtWidgetParameterFactory.h" +#include "otbWrapperParameter.h" +#include "otbWrapperQtWidgetModel.h" + +#include "otbWrapperQtWidgetParameterBase.h" + #include "otbWrapperQtWidgetEmptyParameter.h" #include "otbWrapperQtWidgetIntParameter.h" #include "otbWrapperQtWidgetFloatParameter.h" @@ -41,9 +46,9 @@ public: return dynamic_cast<TParameterType *>(param) != 0; } - static QWidget* Create( Parameter* param, QtWidgetModel* model ) + static QtWidgetParameterBase* Create( Parameter* param, QtWidgetModel* model ) { - QWidget* widget = 0; + QtWidgetParameterBase* widget = 0; TParameterType* specificParam = dynamic_cast<TParameterType *>(param); if (specificParam) @@ -62,10 +67,10 @@ QtWidgetParameterFactory::~QtWidgetParameterFactory() { } -QWidget* +QtWidgetParameterBase* QtWidgetParameterFactory::CreateQtWidget( Parameter* param, QtWidgetModel* model ) { - + QtWidgetParameterBase* widget = 0; #define CREATEWIDGET( ParameterType, WidgetType ) \ else if ( QtWidgetParameterGenericFactory<ParameterType, WidgetType>::CanCreate(param) ) \ @@ -73,8 +78,6 @@ QtWidgetParameterFactory::CreateQtWidget( Parameter* param, QtWidgetModel* model widget = QtWidgetParameterGenericFactory<ParameterType, WidgetType>::Create(param, model); \ } - QWidget* widget = 0; - if (0) {} CREATEWIDGET(EmptyParameter, QtWidgetEmptyParameter) CREATEWIDGET(IntParameter, QtWidgetIntParameter) @@ -86,9 +89,17 @@ QtWidgetParameterFactory::CreateQtWidget( Parameter* param, QtWidgetModel* model CREATEWIDGET(EmptyParameter, QtWidgetEmptyParameter) CREATEWIDGET(ParameterGroup, QtWidgetParameterGroup) +#undef CREATEWIDGET + + if (widget) + { + widget->CreateWidget(); + widget->UpdateGUI(); + } + return widget; -#undef CREATEWIDGET + } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.h index aeb39ebe97f50f57c775157b97ee9ab8a81bd909..eda9bbb3f0d1a7cdc00006c994fee7e5f5bd29a1 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.h @@ -19,14 +19,18 @@ #define __otbWrapperQtWidgetFactory_h #include <QtGui> -#include "otbWrapperParameter.h" -#include "otbWrapperQtWidgetModel.h" +#include "itkObject.h" +#include "itkObjectFactory.h" namespace otb { namespace Wrapper { +class Parameter; +class QtWidgetModel; +class QtWidgetParameterBase; + /** \class ImageIOFactory * \brief Create instances of ImageIO objects using an object factory. */ @@ -46,7 +50,7 @@ public: itkTypeMacro(QtWidgetParameterFactory, Object); /** Create the appropriate ImageIO depending on the particulars of the file. */ - static QWidget* CreateQtWidget( Parameter* param, QtWidgetModel* model ); + static QtWidgetParameterBase* CreateQtWidget( Parameter* param, QtWidgetModel* model ); protected: QtWidgetParameterFactory(); diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx index db7757d53440256e7bbc26377cadfd0562990954..34ec319fc905d87baa4d32ddcc49bed260f21a74 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx @@ -16,6 +16,7 @@ =========================================================================*/ #include "otbWrapperQtWidgetParameterGroup.h" +#include "otbWrapperQtWidgetChoiceParameter.h" #include "otbWrapperQtWidgetParameterLabel.h" #include "otbWrapperQtWidgetParameterFactory.h" @@ -28,16 +29,24 @@ QtWidgetParameterGroup::QtWidgetParameterGroup(ParameterGroup::Pointer paramList : QtWidgetParameterBase(m), m_ParamList(paramList) { - this->CreateWidget(); } QtWidgetParameterGroup::~QtWidgetParameterGroup() { } -void QtWidgetParameterGroup::CreateWidget() +void QtWidgetParameterGroup::DoUpdateGUI() { - // a GridLayout with two colums : parameter label / parameter widget + WidgetListIteratorType it = m_WidgetList.begin(); + for (it = m_WidgetList.begin(); it != m_WidgetList.end(); ++it) + { + (*it)->UpdateGUI(); + } +} + +void QtWidgetParameterGroup::DoCreateWidget() +{ + // a GridLayout with two columns : parameter label / parameter widget QGridLayout *gridLayout = new QGridLayout; gridLayout->setSpacing(1); gridLayout->setContentsMargins(0,0,0,0); @@ -46,10 +55,34 @@ void QtWidgetParameterGroup::CreateWidget() for (unsigned int i = 0; i < nbParams; ++i) { Parameter* param = m_ParamList->GetParameter(i); - QWidget* label = new QtWidgetParameterLabel( param ); - gridLayout->addWidget(label, i, 0); - QWidget* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() ); - gridLayout->addWidget(specificWidget, i, 1); + + if (param != 0) + { + ParameterGroup* paramAsGroup = dynamic_cast<ParameterGroup*>(param); + ChoiceParameter* paramAsChoice = dynamic_cast<ChoiceParameter*>(param); + + if (paramAsGroup == 0 && paramAsChoice == 0) + { + QWidget* label = new QtWidgetParameterLabel( param ); + gridLayout->addWidget(label, i, 0); + QtWidgetParameterBase* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() ); + gridLayout->addWidget(specificWidget, i, 1); + m_WidgetList.push_back(specificWidget); + } + else + { + QtWidgetParameterBase* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() ); + + QVBoxLayout* vboxLayout = new QVBoxLayout; + vboxLayout->addWidget(specificWidget); + QGroupBox* group = new QGroupBox; + group->setLayout(vboxLayout); + group->setTitle(param->GetName()); + gridLayout->addWidget(group, i, 0, 1, -1); + + m_WidgetList.push_back(specificWidget); + } + } } this->setLayout(gridLayout); diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.h index 81e4621e847c35ea1a81b49a8f7d5715178b3e14..920bd93fa8a3fdeff18f1ea35accd5721ae1148a 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.h @@ -41,10 +41,16 @@ private: QtWidgetParameterGroup(const QtWidgetParameterGroup&); //purposely not implemented void operator=(const QtWidgetParameterGroup&); //purposely not implemented - void CreateWidget(); + void DoCreateWidget(); + + virtual void DoUpdateGUI(); ParameterGroup::Pointer m_ParamList; + typedef std::vector<QtWidgetParameterBase*> WidgetListType; + typedef WidgetListType::iterator WidgetListIteratorType; + WidgetListType m_WidgetList; + }; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.cxx index ead9a072be3883121ec1230d3d4cb4621c89cff9..632a176420691e5cd40fa7e645493b75c34d22bf 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterLabel.cxx @@ -30,10 +30,10 @@ QtWidgetParameterLabel::QtWidgetParameterLabel(Parameter* param) label->setText(param->GetName()); label->setToolTip(param->GetName()); - QHBoxLayout *labelLayout = new QHBoxLayout; + QVBoxLayout *labelLayout = new QVBoxLayout; labelLayout->setSpacing(0); labelLayout->setContentsMargins(0,0,0,0); - labelLayout->addWidget(label); + labelLayout->addWidget(label, 0); this->setLayout(labelLayout); } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.cxx index 7b550d8b592deba8afa4270152442071bd165fef..e516f67a71449ca065cd0cf936590031236161b4 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.cxx @@ -26,7 +26,6 @@ QtWidgetStringParameter::QtWidgetStringParameter(StringParameter* param, QtWidge : QtWidgetParameterBase(m), m_StringParam(param) { - this->CreateWidget(); } QtWidgetStringParameter::~QtWidgetStringParameter() @@ -34,7 +33,12 @@ QtWidgetStringParameter::~QtWidgetStringParameter() } -void QtWidgetStringParameter::CreateWidget() +void QtWidgetStringParameter::DoUpdateGUI() +{ + +} + +void QtWidgetStringParameter::DoCreateWidget() { // Set up input text edit QHBoxLayout *hLayout = new QHBoxLayout; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.h index fdf69a6cb9155995ec47a2f48c998b8445b428db..1b34b0b1c91af20868063a50cc0e079075dcee2a 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.h +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetStringParameter.h @@ -44,7 +44,9 @@ private: QtWidgetStringParameter(const QtWidgetStringParameter&); //purposely not implemented void operator=(const QtWidgetStringParameter&); //purposely not implemented - void CreateWidget(); + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); StringParameter::Pointer m_StringParam; }; diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx index fe48163d920d6955c80f22fdb8aa5380f40466ed..597f8793e5af3c4c07252ed2117adc4989480da9 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx @@ -18,6 +18,7 @@ #include "otbWrapperQtWidgetView.h" #include "otbWrapperQtWidgetParameterGroup.h" +#include "otbWrapperQtWidgetParameterFactory.h" namespace otb { @@ -103,7 +104,7 @@ QWidget* QtWidgetView::CreateHeader() QWidget* QtWidgetView::CreateInputWidgets() { - QWidget* params = new QtWidgetParameterGroup( m_Model->GetApplication()->GetParameterList(), m_Model ); + QtWidgetParameterBase* params = QtWidgetParameterFactory::CreateQtWidget(m_Model->GetApplication()->GetParameterList(), m_Model); return params; } diff --git a/Example/Smoothing/otbSmoothing.cxx b/Example/Smoothing/otbSmoothing.cxx index 4dd52d447a3edd646b8aacfb36cb8790c8db2bdf..48c99e463814c02623e85de96f48c8f71a6daba9 100644 --- a/Example/Smoothing/otbSmoothing.cxx +++ b/Example/Smoothing/otbSmoothing.cxx @@ -18,6 +18,12 @@ #include "otbSmoothing.h" #include "otbWrapperNumericalParameter.h" +#include "itkMeanImageFilter.h" +#include "itkDiscreteGaussianImageFilter.h" +#include "itkGradientAnisotropicDiffusionImageFilter.h" +//#include "itkCurvatureAnisotropicDiffusionImageFilter.h" +#include "otbPerBandVectorImageFilter.h" + namespace otb { namespace Wrapper @@ -30,6 +36,22 @@ enum Smoothing_Anisotropic }; +typedef otb::Wrapper::InputImageParameter::VectorImageType VectorImageType; +typedef otb::Image<VectorImageType::InternalPixelType, 2> ImageType; + +typedef itk::MeanImageFilter<ImageType, ImageType> MeanFilterType; +typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, MeanFilterType> + PerBandMeanFilterType; + +typedef itk::DiscreteGaussianImageFilter<ImageType, ImageType> DiscreteGaussianFilterType; +typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, DiscreteGaussianFilterType> + PerBandDiscreteGaussianFilterType; + +typedef itk::GradientAnisotropicDiffusionImageFilter<ImageType, ImageType> GradientAnisotropicDiffusionFilterType; +typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, GradientAnisotropicDiffusionFilterType> + PerBandGradientAnisotropicDiffusionFilterType; + + Smoothing::Smoothing() { this->SetName("Smoothing"); @@ -50,21 +72,27 @@ void Smoothing::DoCreateParameters() smoothingType->SetKey("type"); otb::Wrapper::RadiusParameter::Pointer meanSmoothingRadius = otb::Wrapper::RadiusParameter::New(); - smoothingType->AddChoice("Mean", meanSmoothingRadius.GetPointer()); + meanSmoothingRadius->SetValue(1); + smoothingType->AddChoice("mean", "Mean", meanSmoothingRadius.GetPointer()); otb::Wrapper::RadiusParameter::Pointer gaussianSmoothingRadius = otb::Wrapper::RadiusParameter::New(); - smoothingType->AddChoice("Gaussian", gaussianSmoothingRadius.GetPointer()); + gaussianSmoothingRadius->SetValue(1); + smoothingType->AddChoice("gaussian", "Gaussian", gaussianSmoothingRadius.GetPointer()); otb::Wrapper::FloatParameter::Pointer aniDifTimeStep = otb::Wrapper::FloatParameter::New(); aniDifTimeStep->SetName("Time Step"); - aniDifTimeStep->SetKey("TimeStep"); + aniDifTimeStep->SetKey("timestep"); + aniDifTimeStep->SetValue(0.125); otb::Wrapper::IntParameter::Pointer aniDifNbIter = otb::Wrapper::IntParameter::New(); - aniDifTimeStep->SetName("Nb Iterations"); - aniDifTimeStep->SetKey("NbIter"); + aniDifNbIter->SetName("Nb Iterations"); + aniDifNbIter->SetKey("nbiter"); + aniDifNbIter->SetValue(10); otb::Wrapper::ParameterGroup::Pointer aniDifGroup = otb::Wrapper::ParameterGroup::New(); aniDifGroup->AddParameter(aniDifTimeStep.GetPointer()); aniDifGroup->AddParameter(aniDifNbIter.GetPointer()); - smoothingType->AddChoice("Anisotropic Diffusion", aniDifGroup.GetPointer()); + smoothingType->AddChoice("anidif", "Anisotropic Diffusion", aniDifGroup.GetPointer()); + + smoothingType->SetValue(2); ParameterGroup* params = GetParameterList(); params->AddParameter(inImage.GetPointer()); @@ -74,6 +102,7 @@ void Smoothing::DoCreateParameters() void Smoothing::DoUpdateParameters() { + // Nothing to do here : all parameters are independent } void Smoothing::DoExecute() @@ -81,30 +110,65 @@ void Smoothing::DoExecute() ParameterGroup* params = GetParameterList(); otb::Wrapper::InputImageParameter* inImageParam = dynamic_cast<otb::Wrapper::InputImageParameter*>(params->GetParameter(0).GetPointer()); - typedef otb::Wrapper::InputImageParameter::VectorImageType::Pointer VectorImagePointerType; - VectorImagePointerType inImage = boost::any_cast<VectorImagePointerType>(inImageParam->GetAnyValue()); + VectorImageType::Pointer inImage = boost::any_cast<VectorImageType::Pointer>(inImageParam->GetAnyValue()); -// otb::Wrapper::OutputImageParameter* outImageParam = dynamic_cast<otb::Wrapper::InputImageParameter*>(params->GetParameter(1).GetPointer()); -// otb::Wrapper::OutputImageParameter::VectorImageType outImage = boost::any_cast<float>(outImageParam->GetAnyValue()); + otb::Wrapper::OutputImageParameter* outImageParam = dynamic_cast<otb::Wrapper::OutputImageParameter*>(params->GetParameter(1).GetPointer()); otb::Wrapper::ChoiceParameter* smoothingTypeParam = dynamic_cast<otb::Wrapper::ChoiceParameter*>(params->GetParameter(2).GetPointer()); int smoothingType = smoothingTypeParam->GetValue(); + otb::Wrapper::ParameterGroup* subParam = smoothingTypeParam->GetChoiceAssociatedParameter(smoothingType); + switch (smoothingType) { case Smoothing_Mean: { + otb::Wrapper::RadiusParameter* radiusParam = dynamic_cast<otb::Wrapper::RadiusParameter*>(subParam->GetParameter(0).GetPointer()); + PerBandMeanFilterType::Pointer perBand = PerBandMeanFilterType::New(); + + perBand->SetInput(inImage); + + MeanFilterType::InputSizeType radius; + radius.Fill(radiusParam->GetValue()); + perBand->GetFilter()->SetRadius(radius); + ref = perBand; + outImageParam->SetValue( perBand->GetOutput() ); } break; case Smoothing_Gaussian: { + otb::Wrapper::RadiusParameter* radiusParam = dynamic_cast<otb::Wrapper::RadiusParameter*>(subParam->GetParameter(0).GetPointer()); + int radius = radiusParam->GetValue(); + + PerBandDiscreteGaussianFilterType::Pointer perBand = PerBandDiscreteGaussianFilterType::New(); + + perBand->SetInput(inImage); + double variance = radiusParam->GetValue() * radiusParam->GetValue(); + perBand->GetFilter()->SetVariance(variance); + ref = perBand; + outImageParam->SetValue( perBand->GetOutput() ); } break; case Smoothing_Anisotropic: { + otb::Wrapper::FloatParameter* aniDifTimeStepParam = dynamic_cast<otb::Wrapper::FloatParameter*>(subParam->GetParameter(0).GetPointer()); + otb::Wrapper::IntParameter* aniDifNbIterParam = dynamic_cast<otb::Wrapper::IntParameter*>(subParam->GetParameter(1).GetPointer()); + + float aniDifTimeStep = aniDifTimeStepParam->GetValue(); + int aniDifNbIter = aniDifNbIterParam->GetValue(); + + PerBandGradientAnisotropicDiffusionFilterType::Pointer perBand = PerBandGradientAnisotropicDiffusionFilterType::New(); + + perBand->SetInput(inImage); + perBand->GetFilter()->SetNumberOfIterations(static_cast<unsigned int>(aniDifNbIter)); + perBand->GetFilter()->SetTimeStep(static_cast<double>(aniDifTimeStep)); + // perBand->GetFilter()->SetConductanceParameter() + perBand->UpdateOutputInformation(); + ref = perBand; + outImageParam->SetValue( perBand->GetOutput() ); } break; } diff --git a/Example/Smoothing/otbSmoothing.h b/Example/Smoothing/otbSmoothing.h index c745ee6b0208b609d05db87282368d859a7614ca..c7216e6997f6be7412079da3060b8dbcbde2d8e3 100644 --- a/Example/Smoothing/otbSmoothing.h +++ b/Example/Smoothing/otbSmoothing.h @@ -50,6 +50,8 @@ private: void DoExecute(); + itk::ProcessObject::Pointer ref; + }; } diff --git a/Testing/QtWidget/otbWrapperQtWidgetParameterFactory.cxx b/Testing/QtWidget/otbWrapperQtWidgetParameterFactory.cxx index 2d0b1f7122bde4e884833fa3ac6c22e991ae8bad..99703508db471a3a30426a567d4c31044897494f 100644 --- a/Testing/QtWidget/otbWrapperQtWidgetParameterFactory.cxx +++ b/Testing/QtWidget/otbWrapperQtWidgetParameterFactory.cxx @@ -110,9 +110,9 @@ int otbWrapperQtWidgetParameterFactory(int argc, char* argv[]) choiceParam->SetName("Choice parameter"); choiceParam->SetDescription("This is a choice parameter"); choiceParam->SetKey("choice"); - choiceParam->AddChoice("choice1", 0); - choiceParam->AddChoice("choice2", 0); - choiceParam->AddChoice("choice3", 0); + choiceParam->AddChoice("choice1", "Choice 1", 0); + choiceParam->AddChoice("choice2", "Choice 2", 0); + choiceParam->AddChoice("choice3", "Choice 3", 0); QWidget * intWidget = factory->CreateQtWidget(intParam, model); QWidget * floatWidget = factory->CreateQtWidget(floatParam, model); @@ -173,9 +173,9 @@ int otbWrapperQtWidgetParameterGroup(int argc, char* argv[]) choiceParam->SetName("Choice parameter"); choiceParam->SetDescription("This is an choice parameter"); choiceParam->SetKey("choice"); - choiceParam->AddChoice("choice1", 0); - choiceParam->AddChoice("choice2", 0); - choiceParam->AddChoice("choice3", 0); + choiceParam->AddChoice("choice1", "Choice 1", 0); + choiceParam->AddChoice("choice2", "Choice 2", 0); + choiceParam->AddChoice("choice3", "Choice 3", 0); stringParam->SetName("String parameter"); stringParam->SetDescription("This is a string parameter"); @@ -217,9 +217,9 @@ int otbWrapperQtWidgetParameterGroup(int argc, char* argv[]) choiceParam2->SetName("Choice parameter"); choiceParam2->SetDescription("This is an choice parameter"); choiceParam2->SetKey("choice2"); - choiceParam2->AddChoice("choice1", 0); - choiceParam2->AddChoice("choice2", 0); - choiceParam2->AddChoice("choice3", 0); + choiceParam2->AddChoice("choice1", "Choice 1", 0); + choiceParam2->AddChoice("choice2", "Choice 2", 0); + choiceParam2->AddChoice("choice3", "Choice 3", 0); stringParam2->SetName("String parameter"); stringParam2->SetDescription("This is a string parameter");