Commit 182a1a4d authored by Julien Cabieces's avatar Julien Cabieces

ENH: Add a new FieldParameter to properly map to QgsProcessingParameterField

parent 0f4d7d57
......@@ -133,11 +133,12 @@ private:
AddParameter(ParameterType_InputImage, "ref.raster.in", "Input reference image");
SetParameterDescription("ref.raster.in", "Input image containing the ground truth labels");
AddParameter(ParameterType_InputFilename, "ref.vector.in", "Input reference vector data");
AddParameter(ParameterType_InputVectorData, "ref.vector.in", "Input reference vector data");
SetParameterDescription("ref.vector.in", "Input vector data of the ground truth");
AddParameter(ParameterType_ListView, "ref.vector.field", "Field name");
AddParameter(ParameterType_Field, "ref.vector.field", "Field name");
SetParameterDescription("ref.vector.field", "Field name containing the label values");
SetVectorData("ref.vector.field", "ref.vector.in");
SetListViewSingleSelectionMode("ref.vector.field", true);
AddParameter(ParameterType_Int, "ref.raster.nodata", "Value for nodata pixels in the reference raster");
......
......@@ -63,8 +63,9 @@ private:
AddParameter(ParameterType_OutputFilename, "outstats", "Output XML file");
SetParameterDescription("outstats", "XML file containing mean and variance of each feature.");
AddParameter(ParameterType_ListView, "feat", "Feature");
AddParameter(ParameterType_Field, "feat", "Feature");
SetParameterDescription("feat", "List of features to consider for statistics.");
SetVectorData("feat", "inshp");
// Doc example parameter settings
SetDocExampleParameterValue("inshp", "vectorData.shp");
......
......@@ -75,9 +75,9 @@ private:
AddParameter(ParameterType_OutputFilename, "insvm", "Input model filename");
SetParameterDescription("insvm", "Input model filename.");
AddParameter(ParameterType_ListView, "feat", "Features");
AddParameter(ParameterType_Field, "feat", "Features");
SetParameterDescription("feat", "Features to be calculated");
SetVectorData("feat","inshp");
AddParameter(ParameterType_String, "cfield", "Field containing the predicted class");
SetParameterDescription("cfield", "Field containing the predicted class");
......
......@@ -50,7 +50,7 @@ void VectorClassifier::DoInitSpecialization()
SetDocSeeAlso("TrainVectorClassifier");
AddDocTag(Tags::Learning);
AddParameter(ParameterType_InputFilename, "in", "Name of the input vector data");
AddParameter(ParameterType_InputVectorData, "in", "Name of the input vector data");
SetParameterDescription("in", "The input vector data file to classify.");
AddParameter(ParameterType_InputFilename, "instat", "Statistics file");
......@@ -70,10 +70,11 @@ void VectorClassifier::DoInitSpecialization()
"Caution, the 'cfield' must not exist in the input file if you are updating the file.");
SetParameterString("cfield", "predicted");
AddParameter(ParameterType_ListView, "feat", "Field names to be calculated");
AddParameter(ParameterType_Field, "feat", "Field names to be calculated");
SetParameterDescription("feat",
"List of field names in the input vector data used as features for training. "
"Put the same field names as the TrainVectorClassifier application.");
SetVectorData("feat", "in");
AddParameter(ParameterType_Bool, "confmap", "Confidence map");
SetParameterDescription("confmap",
......
......@@ -49,7 +49,7 @@ void VectorRegression::DoInitSpecialization()
SetDocSeeAlso("TrainVectorRegression");
AddDocTag(Tags::Learning);
AddParameter(ParameterType_InputFilename, "in", "Name of the input vector data");
AddParameter(ParameterType_InputVectorData, "in", "Name of the input vector data");
SetParameterDescription("in", "The input vector data file to classify.");
AddParameter(ParameterType_InputFilename, "instat", "Statistics file");
......@@ -69,10 +69,11 @@ void VectorRegression::DoInitSpecialization()
"Caution, the 'cfield' must not exist in the input file if you are updating the file.");
SetParameterString("cfield", "predicted");
AddParameter(ParameterType_ListView, "feat", "Field names to be calculated");
AddParameter(ParameterType_Field, "feat", "Field names to be calculated");
SetParameterDescription("feat",
"List of field names in the input vector data used as features for training. "
"Put the same field names as the TrainVectorRegression application.");
SetVectorData("feat", "in");
AddParameter(ParameterType_OutputFilename, "out", "Output vector data file");
MandatoryOff("out");
......
......@@ -97,8 +97,9 @@ private:
MandatoryOff("io.stats");
SetParameterDescription("io.stats", "XML file containing mean and variance of each feature.");
AddParameter(ParameterType_StringList, "feat", "Field names to be used for training");
AddParameter(ParameterType_Field, "feat", "Field names to be used for training");
SetParameterDescription("feat", "List of field names in the input vector data used as features for training.");
SetVectorData("feat", "io.vd");
Superclass::DoInit();
......
......@@ -109,8 +109,9 @@ private:
"In overwrite mode, the original features will be lost.");
MandatoryOff("out");
AddParameter(ParameterType_ListView, "feat", "Input features to use for reduction");
AddParameter(ParameterType_Field, "feat", "Input features to use for reduction");
SetParameterDescription("feat", "List of field names in the input vector data used as features for reduction.");
SetVectorData("feat", "in");
AddParameter(ParameterType_Choice, "featout", "Output feature");
SetParameterDescription("featout", "Naming of output features");
......
......@@ -562,6 +562,13 @@ public:
*/
void SetNthParameterInputImageList(std::string const& parameter, const unsigned int& id, ImageBaseType* img);
/**
* Set vector data name from which we choose the fields for a FieldParameter
* \in key The parameter key (must be a FieldParameter)
* \in vectorData vector data name
*/
void SetVectorData(std::string const& key, std::string const& vectorData );
/**
* Add a value to a parameter list as a string
*
......
/*
* Copyright (C) 2005-2020 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 otbWrapperFieldParameter_h
#define otbWrapperFieldParameter_h
#include <string>
#include "otbWrapperListViewParameter.h"
namespace otb
{
namespace Wrapper
{
/** \class FieldParameter
* \brief This class represents a field parameter selected from a vector file
* for the wrapper framework
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT FieldParameter : public ListViewParameter
{
public:
/** Standard class typedef */
typedef FieldParameter Self;
typedef ListViewParameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(FieldParameter, ListViewParameter);
ParameterType GetType() const override
{
return ParameterType_Field;
}
/** Set vector data name from which we choose the fields */
void SetVectorData(const std::string& vectorData)
{
m_VectorData = vectorData;
}
/** Get vector data name from which we choose the fields */
const std::string& GetVectorData() const
{
return m_VectorData;
}
protected:
/** Constructor */
FieldParameter()
{
}
/** Destructor */
~FieldParameter() override
{
}
std::string m_VectorData;
private:
FieldParameter(const FieldParameter&) = delete;
void operator=(const FieldParameter&) = delete;
}; // End class FieldParameter
} // End namespace Wrapper
} // End namespace otb
#endif
......@@ -58,6 +58,7 @@ typedef enum {
ParameterType_OutputProcessXML,
ParameterType_InputProcessXML,
ParameterType_Bool,
ParameterType_Field,
ParameterType_MAX__
} ParameterType;
......@@ -85,7 +86,9 @@ constexpr char const* parameterTypesStrings[] = {"Int",
"RAM",
"OutputProcessXML",
"InputProcessXML",
"Bool"};
"Bool",
"Field",
};
static_assert(std::extent<decltype(parameterTypesStrings)>::value == ParameterType_MAX__, "Wrong number of parameters in parameterTypesStrings");
}
......
......@@ -36,6 +36,7 @@
#include "otbWrapperProxyParameter.h"
#include "otbWrapperParameterKey.h"
#include "otbWrapperBoolParameter.h"
#include "otbWrapperFieldParameter.h"
#include "otbWrapperAddProcessToWatchEvent.h"
#include "otbExtendedFilenameToWriterOptions.h"
......@@ -1359,6 +1360,12 @@ void Application::SetNthParameterStringList(std::string const& key, const unsign
param->SetNthFileName(id, str);
}
void Application::SetVectorData(std::string const& key, std::string const& vectorData )
{
auto param = downcast_check<FieldParameter>(GetParameterByKey(key));
param->SetVectorData(vectorData);
}
void Application::ClearParameterInputImageList(std::string const& key)
{
auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key));
......
......@@ -36,6 +36,7 @@
#include "otbWrapperParameterKey.h"
#include "otbWrapperProxyParameter.h"
#include "otbWrapperBoolParameter.h"
#include "otbWrapperFieldParameter.h"
#include "otb_boost_string_header.h"
......@@ -326,6 +327,11 @@ void ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std:
newParam = BoolParameter::New();
}
break;
case ParameterType_Field:
{
newParam = FieldParameter::New();
}
break;
default:
break;
}
......
......@@ -426,7 +426,7 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
}
if (type == ParameterType_InputVectorDataList || type == ParameterType_InputImageList || type == ParameterType_InputFilenameList ||
type == ParameterType_StringList || type == ParameterType_ListView)
type == ParameterType_StringList || type == ParameterType_ListView || type == ParameterType_Field )
{
// Multiple values parameters
m_Application->SetParameterStringList(paramKey, values);
......
......@@ -21,6 +21,7 @@
#include "otbWrapperChoiceParameter.h"
#include "otbWrapperListViewParameter.h"
#include "otbWrapperBoolParameter.h"
#include "otbWrapperFieldParameter.h"
#include "otbWrapperApplicationRegistry.h"
#include <iostream>
......@@ -72,6 +73,7 @@ int main(int argc, char* argv[])
parameterTypeToString[ParameterType_OutputVectorData] = "QgsProcessingParameterVectorDestination";
parameterTypeToString[ParameterType_OutputFilename] = "QgsProcessingParameterFileDestination";
parameterTypeToString[ParameterType_Directory] = "QgsProcessingParameterFile";
parameterTypeToString[ParameterType_Field] = "QgsProcessingParameterField";
// TODO
parameterTypeToString[ParameterType_StringList] = "QgsProcessingParameterString";
......@@ -238,9 +240,9 @@ int main(int argc, char* argv[])
else if (type == ParameterType_ListView)
{
ListViewParameter *lv_param = dynamic_cast<ListViewParameter*>(param.GetPointer());
std::vector<std::string> key_list = appli->GetChoiceKeys(name);
std::vector<std::string> name_list = appli->GetChoiceNames(name);
std::string values = "";
for( auto k : key_list)
for( auto k : name_list)
values += k + ";";
values.pop_back();
dFile << "|" << values ;
......@@ -262,6 +264,13 @@ int main(int argc, char* argv[])
ChoiceParameter* cparam = dynamic_cast<ChoiceParameter*>(param.GetPointer());
default_value = std::to_string(cparam->GetValue());
}
else if (type == ParameterType_Field)
{
FieldParameter *f_param = dynamic_cast<FieldParameter*>(param.GetPointer());
dFile << "|None|" << f_param->GetVectorData()
<< "|QgsProcessingParameterField.Any|False";
}
else
{
std::cout << "ERROR: default_value is empty for '" << name << "' type='" << qgis_type << "'" << std::endl;
......@@ -290,7 +299,17 @@ int main(int argc, char* argv[])
std::cerr << " qgis_type=" << qgis_type;
std::cerr << " optional=" << optional << std::endl;
#endif
dFile << "|" << default_value << "|" << optional;
// optionnal and default value are not in the same order than
// other QGis processing parameters
if (type == ParameterType_Field)
{
dFile << "|" << optional << "|False";
}
else
{
dFile << "|" << default_value << "|" << optional;
}
dFile << std::endl;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment