Commit 2cdbdb5d authored by Victor Poughon's avatar Victor Poughon

Merge branch 'refactor-xml' into 'develop'

Refactor XML parameters

See merge request !487
parents 78d7f56c abde6d78
Pipeline #1411 passed with stage
in 10 minutes and 47 seconds
......@@ -25,7 +25,7 @@ import argparse
import re
import otbApplication
from otbApplication import ParameterType_Bool, ParameterType_Int, ParameterType_Radius, ParameterType_RAM, ParameterType_Float, ParameterType_String, ParameterType_StringList, ParameterType_InputFilename, ParameterType_OutputFilename, ParameterType_InputImage, ParameterType_OutputImage, ParameterType_InputVectorData, ParameterType_OutputVectorData, ParameterType_Directory, ParameterType_Choice, ParameterType_InputImageList, ParameterType_InputVectorDataList, ParameterType_InputFilenameList, ParameterType_InputProcessXML, ParameterType_OutputProcessXML, ParameterType_ListView, ParameterType_Group
from otbApplication import ParameterType_Bool, ParameterType_Int, ParameterType_Radius, ParameterType_RAM, ParameterType_Float, ParameterType_String, ParameterType_StringList, ParameterType_InputFilename, ParameterType_OutputFilename, ParameterType_InputImage, ParameterType_OutputImage, ParameterType_InputVectorData, ParameterType_OutputVectorData, ParameterType_Directory, ParameterType_Choice, ParameterType_InputImageList, ParameterType_InputVectorDataList, ParameterType_InputFilenameList, ParameterType_ListView, ParameterType_Group
from otb_warnings import application_documentation_warnings
......@@ -202,7 +202,6 @@ def rst_parameter_value(app, key):
values.update({ParameterType_InputImageList: "image1 image2..."})
values.update({ParameterType_InputVectorDataList: "vectorfile1 vectorfile2..."})
values.update({ParameterType_InputFilenameList: "filename1 filename2..."})
values.update(dict.fromkeys([ParameterType_InputProcessXML, ParameterType_OutputProcessXML], "filename.xml"))
if type in values:
return values[type]
......
......@@ -158,9 +158,6 @@ parameters:
- ``ParameterType_InputVectorDataList`` : parameter storing a list of
input vector data.
- ``ParameterType_InputProcessXML`` : parameter storing an input XML
file name.
- ``ParameterType_OutputFilename`` : parameter storing an output file
name.
......@@ -169,9 +166,6 @@ parameters:
- ``ParameterType_OutputVectorData`` : parameter storing an output
vector data.
- ``ParameterType_OutputProcessXML`` : parameter storing an output XML
file name.
- ``ParameterType_RAM`` : parameter storing the maximum amount of RAM
to be used.
......
......@@ -123,7 +123,6 @@ example based on the OrthoRectification application:
-opt.rpc <int32> RPC modeling (points per axis) (optional, off by default, default value is 10)
-opt.ram <int32> Available RAM (MB) (optional, off by default, default value is 128)
-opt.gridspacing <float> Resampling grid spacing (optional, off by default, default value is 4)
-inxml <string> Load parameters from XML (optional, off by default)
-progress <boolean> Report progress
-help <string list> Display long help (empty list), or help for given parameters keys
......@@ -145,11 +144,10 @@ Command-line examples are provided in the chapter :ref:`apprefdoc`.
Load and save parameters to XML
-------------------------------
Since OTB 3.20, OTB applications parameters can be export/import to/from
an XML file using inxml/outxml parameters. Those parameters are
available in all applications.
An example is worth a thousand words
OTB application parameters can be saved and loaded to
an XML file using the special ``-inxml`` and ``-outxml`` parameters.
Those parameters are available in all applications.
For example:
::
......@@ -177,17 +175,6 @@ time
In this case it will use as mathematical expression “(im1b1 - im2b1)”
instead of “abs(im1b1 - im2b1)”.
Finally, you can also launch applications directly from the command-line
launcher executable using the inxml parameter without having to declare
the application name. Use in this case:
::
otbApplicationLauncherCommandLine -inxml saved_applications_parameters.xml
It will retrieve the application name and related parameters from the
input XML file and launch in this case the BandMath applications.
Parallel execution with MPI
---------------------------
......
......@@ -218,11 +218,34 @@ implementation does not break it, for instance by using an internal
writer to write intermediate data. In this case, execution should
still be correct, but some intermediate data will be read or written.
Load and save parameters to XML
-------------------------------
As with a the `command line interface` you can save application parameters
to an xml file:
.. code-block:: python
# Save application parameters to XML
app = otb.Registry.CreateApplication('BandMath')
app.SetParameterStringList("il", ["image1.tif", "image2.tif"], True)
app.SetParameterString("out", out, True)
app.SetParameterString("exp", "cos(im1b1)+im2b1*im1b1", True)
app.SaveParametersToXML("parameters.xml")
And load them later for execution:
.. code-block:: python
# Load application parameters from XML
app = otb.Registry.CreateApplication("BandMath")
app.LoadParametersFromXML("parameters.xml")
app.ExecuteAndWriteOutput()
Interactions with OTB pipeline
------------------------------
[Since OTB 6.6]
The application framework has been extended in order to provide ways to
interact with the pipelines inside each application. It applies only to
applications that use input or output images. Let's check which
......
......@@ -49,12 +49,10 @@
#include "otbWrapperQtWidgetInputFilenameListParameter.h"
#include "otbWrapperQtWidgetInputImageParameter.h"
#include "otbWrapperQtWidgetInputImageListParameter.h"
#include "otbWrapperQtWidgetInputProcessXMLParameter.h"
#include "otbWrapperQtWidgetInputVectorDataParameter.h"
#include "otbWrapperQtWidgetInputVectorDataListParameter.h"
#include "otbWrapperQtWidgetOutputFilenameParameter.h"
#include "otbWrapperQtWidgetOutputImageParameter.h"
#include "otbWrapperQtWidgetOutputProcessXMLParameter.h"
#include "otbWrapperQtWidgetOutputVectorDataParameter.h"
#include "otbWrapperQtWidgetParameterFactory.h"
#include "otbWrapperQtWidgetListEditWidget.h"
......@@ -225,21 +223,6 @@ public:
inline result_type operator () ( argument_type widget ) const;
};
/**
* \class InputProcessXMLInitializer
*
* \ingroup OTBMonteverdiGUI
*
* \brief WIP.
*/
class InputProcessXMLInitializer : public std::unary_function<
otb::Wrapper::QtWidgetInputProcessXMLParameter *,
void >
{
public:
inline result_type operator () ( argument_type widget ) const;
};
/**
* \class OutputImageInitializer
*
......@@ -293,22 +276,6 @@ public:
inline result_type operator () ( argument_type widget ) const;
};
/**
* \class OutputProcessXMLInitializer
*
* \ingroup OTBMonteverdiGUI
*
* \brief WIP.
*/
class OutputProcessXMLInitializer : public std::unary_function<
otb::Wrapper::QtWidgetOutputProcessXMLParameter *,
void
>
{
public:
inline result_type operator () ( argument_type widget ) const;
};
/**
* \class ToolTipInitializer
*
......@@ -445,17 +412,6 @@ InputVectorDataListInitializer
// Drop support is done by ParameterListInitializer
}
/*****************************************************************************/
inline
InputProcessXMLInitializer::result_type
InputProcessXMLInitializer
::operator () ( argument_type widget ) const
{
assert( widget!=NULL );
SetupForFilenameDrop( widget );
}
/*****************************************************************************/
inline
ToolTipInitializer::result_type
......@@ -542,25 +498,6 @@ OutputFilenameInitializer
SetupOutputFilename( widget );
}
/*****************************************************************************/
inline
OutputProcessXMLInitializer::result_type
OutputProcessXMLInitializer
::operator () ( argument_type widget ) const
{
assert( widget!=NULL );
SetupForFilenameDrop( widget );
assert( qApp!=NULL );
assert( !qApp->arguments().empty() );
// MANTIS-1103
// {
// SetupOutputFilename( widget );
// }
}
/*****************************************************************************/
inline
ParameterListInitializer::result_type
......
......@@ -163,7 +163,6 @@ QtWidgetView
//SetupWidget( widget, InputFilenameListInitializer() );
SetupWidget( widget, InputImageInitializer() );
//SetupWidget( widget, InputImageListInitializer() );
SetupWidget( widget, InputProcessXMLInitializer() );
SetupWidget( widget, InputVectorDataInitializer() );
//SetupWidget( widget, InputVectorDataListInitializer() );
SetupWidget( widget, ParameterListInitializer() );
......@@ -172,7 +171,6 @@ QtWidgetView
#endif
SetupWidget( widget, OutputFilenameInitializer() );
SetupWidget( widget, OutputProcessXMLInitializer() );
SetupWidget(
widget,
......
......@@ -102,11 +102,8 @@ public:
/** Check if the application has been initialized */
bool IsInitialized() const;
virtual void SetHaveInXML(bool);
virtual bool GetHaveInXML() const;
virtual void SetHaveOutXML(bool);
virtual bool GetHaveOutXML() const;
void LoadParametersFromXML(const std::string& filename);
void SaveParametersToXML(const std::string& filename);
/** Update the value of parameters for which no user value has been provided */
void UpdateParameters();
......@@ -210,12 +207,6 @@ public:
/* Returns the description of a parameter */
std::vector<std::string> GetChoiceNames(std::string paramKey);
/* Is the application ready to be executed : All the mandatory
* parameters have to be set
*/
/* Set the Parameter value and Update the UserFlag. used by xml parameter
*/
/* Set an integer value
*
* Can be called for types :
......@@ -689,9 +680,6 @@ public:
*/
std::vector< std::pair<std::string, std::string> > GetOutputParametersSumUp();
/** If need to force readxml more than once in application */
void ForceInXMLParseFlag();
double GetLastExecutionTiming() const;
virtual void SetDocLink(const std::string & link);
......@@ -815,16 +803,6 @@ protected:
* by default seed initialization is based on time value*/
void AddRANDParameter(std::string paramKey, std::string paramName, unsigned int defaultValue);
void AddInXMLParameter()
{
GetParameterList()->AddInXMLParameter();
}
void AddOutXMLParameter()
{
GetParameterList()->AddOutXMLParameter();
}
/** Remove the items added to the ListWidget */
void ClearChoices(std::string key);
......@@ -913,11 +891,6 @@ private:
/** Chrono to measure execution time */
otb::Stopwatch m_Chrono;
//rashad:: controls adding of -xml parameter. set to true by default
bool m_HaveInXML;
bool m_HaveOutXML;
bool m_IsInXMLParsed;
/** Flag is true when executing DoInit, DoUpdateParameters or DoExecute */
bool m_IsInPrivateDo;
......
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbWrapperInputProcessXMLParameter_h
#define otbWrapperInputProcessXMLParameter_h
#include "otbWrapperApplication.h"
#include "otb_tinyxml.h"
#include <sstream>
#include <string>
namespace otb
{
namespace Wrapper
{
/** \class InputProcessXMLParameter
* \brief This class represent a xml filename parameter for the wrapper framework to load otb application.
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT InputProcessXMLParameter
: public Parameter
{
public:
/** Standard class typedef */
typedef InputProcessXMLParameter Self;
typedef Parameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(InputProcessXMLParameter, Parameter);
itkGetStringMacro(FileName);
bool HasValue() const override
{
if(m_FileName.empty())
return false;
else
return true;
}
virtual ParameterType GetType() const override
{
return ParameterType_InputProcessXML;
}
std::string ToString() const override
{
return GetFileName();
}
void FromString(const std::string& value) override
{
SetFileName(value);
}
// Get Value
//TODO otbGetObjectMemberMacro(StringParam, Value , std::string);
bool SetFileName(std::string value);
// Set Value
virtual void SetValue(const std::string value);
ImagePixelType GetPixelTypeFromString(std::string pixTypeAsString);
ParameterType GetParameterType(const Parameter* param) const;
const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key);
int Read(Application::Pointer application);
void otbAppLogInfo(Application::Pointer app, std::string info);
/* copied from Utilities/tinyXMLlib/tinyxml.cpp. Must have a FIX inside tinyxml.cpp */
FILE* TiXmlFOpen( const char* filename, const char* mode );
protected:
InputProcessXMLParameter();
/** Destructor */
~InputProcessXMLParameter() override;
private:
std::string m_FileName;
InputProcessXMLParameter(const InputProcessXMLParameter &) = delete;
void operator =(const InputProcessXMLParameter&) = delete;
}; // End class Parameter
} // End namespace Wrapper
} // End namespace otb
#endif
......@@ -18,58 +18,30 @@
* limitations under the License.
*/
#ifndef otbWrapperQtWidgetOutputProcessXMLParameter_h
#define otbWrapperQtWidgetOutputProcessXMLParameter_h
#include <QtWidgets>
#include "otbWrapperOutputProcessXMLParameter.h"
#include "otbWrapperQtWidgetParameterBase.h"
#ifndef otbWrapperInputXML_h
#define otbWrapperInputXML_h
#include "otbWrapperApplication.h"
#include "otb_tinyxml.h"
#include <sstream>
#include <string>
namespace otb
{
namespace Wrapper
{
/** \class QtWidgetOutputProcessXMLParameter
* \brief
*
* \ingroup OTBQtWidget
*/
class OTBQtWidget_EXPORT QtWidgetOutputProcessXMLParameter : public QtWidgetParameterBase
namespace XML
{
Q_OBJECT
public:
QtWidgetOutputProcessXMLParameter(OutputProcessXMLParameter*, QtWidgetModel*, QWidget*);
~QtWidgetOutputProcessXMLParameter() override;
const QLineEdit* GetInput() const;
QLineEdit* GetInput();
public slots:
void SetFileName( const QString& value );
protected slots:
void SelectFile();
private:
QtWidgetOutputProcessXMLParameter(const QtWidgetOutputProcessXMLParameter&) = delete;
void operator=(const QtWidgetOutputProcessXMLParameter&) = delete;
void DoCreateWidget() override;
void DoUpdateGUI() override;
OutputProcessXMLParameter::Pointer m_XMLParam;
OTBApplicationEngine_EXPORT const std::string GetChildNodeTextOf(TiXmlElement* parentElement, std::string key);
QHBoxLayout * m_HLayout;
QLineEdit* m_Input;
QPushButton * m_Button;
};
OTBApplicationEngine_EXPORT int Read(const std::string& filename, Application::Pointer application);
/* copied from Utilities/tinyXMLlib/tinyxml.cpp. Must have a FIX inside tinyxml.cpp */
OTBApplicationEngine_EXPORT FILE* TiXmlFOpen(const char* filename, const char* mode);
}
}
} // namespace XML
} // End namespace Wrapper
} // End namespace otb
#endif
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbWrapperOutputProcessXMLParameter_h
#define otbWrapperOutputProcessXMLParameter_h
#include "otbWrapperApplication.h"
#include "otb_tinyxml.h"
#include <string>
namespace otb
{
namespace Wrapper
{
/** \class OutputProcessXMLParameter
* \brief This class represent a xml filename parameter for the wrapper framework to save otb application.
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT OutputProcessXMLParameter
: public Parameter
{
public:
/** Standard class typedef */
typedef OutputProcessXMLParameter Self;
typedef Parameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(OutputProcessXMLParameter, Parameter);
itkGetStringMacro(FileName);
// Set FileName
void SetFileName(std::string value)
{
this->SetValue(value);
}
// Set Value
virtual void SetValue(const std::string value)
{
itkDebugMacro("setting member m_FileName to " << value);
this->m_FileName = value;
SetActive(true);
this->Modified();
}
bool HasValue() const override
{
if(m_FileName.empty())
return false;
else
return true;
}
void ClearValue() override
{
m_FileName = "";
}
virtual ParameterType GetType() const override
{
return ParameterType_OutputProcessXML;
}
std::string ToString() const override
{
return GetFileName();
}
void FromString(const std::string& value) override
{
SetValue(value);
}
TiXmlElement* AddChildNodeTo(TiXmlElement* parent, std::string name, std::string value="");
std::string pixelTypeToString(ImagePixelType pixType);
ParameterType GetParameterType(const Parameter* param) const;
void Write(Application::Pointer application);
TiXmlElement* ParseApplication(Application::Pointer app);
static std::string MakeCommandLine(otb::Wrapper::Application::Pointer application);
protected:
OutputProcessXMLParameter();
/** Destructor */
~OutputProcessXMLParameter() override;
private:
/** Recursive function to parse a group parameter */
void ParseGroup(const std::string& group);
std::string m_FileName;
/** Temporary storage of the XML node to fill (internal) */
TiXmlElement* m_Node;
/** Temporary pointer to the application to parse (internal) */
Application::Pointer m_Appli;
OutputProcessXMLParameter(const OutputProcessXMLParameter &) = delete;
void operator =(const OutputProcessXMLParameter&) = delete;
}; // End class Parameter
} // End namespace Wrapper
} // End namespace otb
#endif
......@@ -18,56 +18,35 @@
* limitations under the License.
*/
#ifndef otbWrapperQtWidgetInputProcessXMLParameter_h
#define otbWrapperQtWidgetInputProcessXMLParameter_h
#include <QtWidgets>
#include "otbWrapperInputProcessXMLParameter.h"
#include "otbWrapperQtWidgetParameterBase.h"
#ifndef otbWrapperOutputXML_h
#define otbWrapperOutputXML_h
#include "otbWrapperApplication.h"
#include "otb_tinyxml.h"
#include <string>
namespace otb
{
namespace Wrapper
{
/** \class QtWidgetInputProcessXMLParameter
* \brief
*
* \ingroup OTBQtWidget
*/
class OTBQtWidget_EXPORT QtWidgetInputProcessXMLParameter : public QtWidgetParameterBase
namespace XML
{
Q_OBJECT
public:
QtWidgetInputProcessXMLParameter(InputProcessXMLParameter*, QtWidgetModel*, QWidget*);
~QtWidgetInputProcessXMLParameter() override;
const QLineEdit* GetInput() const;
QLineEdit* GetInput();
protected slots:
void SetFileName( const QString& value );
void SelectFile();
private:
QtWidgetInputProcessXMLParameter(const QtWidgetInputProcessXMLParameter&) = delete;
void operator=(const QtWidgetInputProcessXMLParameter&) = delete;
void DoCreateWidget() override;
OTBApplicationEngine_EXPORT TiXmlElement* AddChildNodeTo(TiXmlElement* parent, std::string name, std::string value = "");
void DoUpdateGUI() override;
OTBApplicationEngine_EXPORT std::string pixelTypeToString(ImagePixelType pixType);
OTBApplicationEngine_EXPORT void Write(const std::string& filename, Application::Pointer application);
InputProcessXMLParameter::Pointer m_XMLParam;
OTBApplicationEngine_EXPORT TiXmlElement* ParseApplication(Application::Pointer app);
QHBoxLayout * m_HLayout;
QLineEdit* m_Input;
QPushButton * m_Button;
};
OTBApplicationEngine_EXPORT std::string MakeCommandLine(otb::Wrapper::Application::Pointer application);
/** Recursive function to parse a group parameter */