Commit 59a9d2d6 authored by Julien Cabieces's avatar Julien Cabieces

ENH: Add a new BandParameter to properly map to QgsProcessingParameterBand

parent f823f350
......@@ -195,8 +195,9 @@ private:
SetParameterDescription("sizey", "size along y in pixels.");
// Channelist Parameters
AddParameter(ParameterType_ListView, "cl", "Output Image channels");
AddParameter(ParameterType_Band, "cl", "Output Image channels");
SetParameterDescription("cl", "Channels to write in the output image.");
SetRasterData("cl", "in");
// Elevation
ElevationParametersHandler::AddElevationParameters(this, "elev");
......
......@@ -97,8 +97,9 @@ private:
"If no system is specified, WGS84 (EPSG: 4326) is used by default.");
MandatoryOff("mode.epsg.code");
AddParameter(ParameterType_ListView, "cl", "Channels");
AddParameter(ParameterType_Band, "cl", "Channels");
SetParameterDescription("cl", "Displayed channels");
SetRasterData("cl", "in");
MandatoryOff("cl");
AddParameter(ParameterType_String, "value", "Pixel Value");
......
......@@ -73,8 +73,9 @@ private:
AddParameter(ParameterType_OutputImage, "out", "Output Image");
SetParameterDescription("out", "The subsampled image");
AddParameter(ParameterType_ListView, "cl", "Channel List");
AddParameter(ParameterType_Band, "cl", "Channel List");
SetParameterDescription("cl", "Selected channels");
SetRasterData("cl", "in");
MandatoryOff("cl");
AddParameter(ParameterType_Int, "rox", "ROI Origin X");
......
......@@ -569,6 +569,13 @@ public:
*/
void SetVectorData(std::string const& key, std::string const& vectorData );
/**
* Set raster data name from which we choose the bands for a BandParameter
* \in key The parameter key (must be a BandParameter)
* \in rasterData raster data name
*/
void SetRasterData(std::string const& key, std::string const& rasterData );
/**
* 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 otbWrapperBandParameter_h
#define otbWrapperBandParameter_h
#include <string>
#include "otbWrapperListViewParameter.h"
namespace otb
{
namespace Wrapper
{
/** \class BandParameter
* \brief This class represents a band parameter selected from a raster file
* for the wrapper framework
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT BandParameter : public ListViewParameter
{
public:
/** Standard class typedef */
typedef BandParameter Self;
typedef ListViewParameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(BandParameter, ListViewParameter);
ParameterType GetType() const override
{
return ParameterType_Band;
}
/** Set raster data name from which we choose the fields */
void SetRasterData(const std::string& rasterData)
{
m_RasterData = rasterData;
}
/** Get raster data name from which we choose the fields */
const std::string& GetRasterData() const
{
return m_RasterData;
}
protected:
/** Constructor */
BandParameter()
{
}
/** Destructor */
~BandParameter() override
{
}
std::string m_RasterData;
private:
BandParameter(const BandParameter&) = delete;
void operator=(const BandParameter&) = delete;
}; // End class BandParameter
} // End namespace Wrapper
} // End namespace otb
#endif
......@@ -59,6 +59,7 @@ typedef enum {
ParameterType_InputProcessXML,
ParameterType_Bool,
ParameterType_Field,
ParameterType_Band,
ParameterType_MAX__
} ParameterType;
......@@ -88,6 +89,8 @@ constexpr char const* parameterTypesStrings[] = {"Int",
"InputProcessXML",
"Bool",
"Field",
"Band",
};
static_assert(std::extent<decltype(parameterTypesStrings)>::value == ParameterType_MAX__, "Wrong number of parameters in parameterTypesStrings");
}
......
......@@ -37,6 +37,7 @@
#include "otbWrapperParameterKey.h"
#include "otbWrapperBoolParameter.h"
#include "otbWrapperFieldParameter.h"
#include "otbWrapperBandParameter.h"
#include "otbWrapperAddProcessToWatchEvent.h"
#include "otbExtendedFilenameToWriterOptions.h"
......@@ -1366,6 +1367,12 @@ void Application::SetVectorData(std::string const& key, std::string const& vecto
param->SetVectorData(vectorData);
}
void Application::SetRasterData(std::string const& key, std::string const& rasterData )
{
auto param = downcast_check<BandParameter>(GetParameterByKey(key));
param->SetRasterData(rasterData);
}
void Application::ClearParameterInputImageList(std::string const& key)
{
auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key));
......
......@@ -37,6 +37,7 @@
#include "otbWrapperProxyParameter.h"
#include "otbWrapperBoolParameter.h"
#include "otbWrapperFieldParameter.h"
#include "otbWrapperBandParameter.h"
#include "otb_boost_string_header.h"
......@@ -332,6 +333,11 @@ void ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std:
newParam = FieldParameter::New();
}
break;
case ParameterType_Band:
{
newParam = BandParameter::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_Field )
type == ParameterType_StringList || type == ParameterType_ListView || type == ParameterType_Field || type == ParameterType_Band )
{
// Multiple values parameters
m_Application->SetParameterStringList(paramKey, values);
......
......@@ -22,6 +22,7 @@
#include "otbWrapperListViewParameter.h"
#include "otbWrapperBoolParameter.h"
#include "otbWrapperFieldParameter.h"
#include "otbWrapperBandParameter.h"
#include "otbWrapperApplicationRegistry.h"
#include <iostream>
......@@ -74,6 +75,7 @@ int main(int argc, char* argv[])
parameterTypeToString[ParameterType_OutputFilename] = "QgsProcessingParameterFileDestination";
parameterTypeToString[ParameterType_Directory] = "QgsProcessingParameterFile";
parameterTypeToString[ParameterType_Field] = "QgsProcessingParameterField";
parameterTypeToString[ParameterType_Band] = "QgsProcessingParameterBand";
// TODO
parameterTypeToString[ParameterType_StringList] = "QgsProcessingParameterString";
......@@ -273,6 +275,12 @@ int main(int argc, char* argv[])
dFile << "|None|" << f_param->GetVectorData()
<< "|QgsProcessingParameterField.Any|False";
}
else if (type == ParameterType_Band)
{
BandParameter *f_param = dynamic_cast<BandParameter*>(param.GetPointer());
dFile << "|None|" << f_param->GetRasterData();
}
else
{
std::cout << "ERROR: default_value is empty for '" << name << "' type='" << qgis_type << "'" << std::endl;
......@@ -303,8 +311,8 @@ int main(int argc, char* argv[])
#endif
// optionnal and default value are not in the same order than
// other QGis processing parameters
if (type == ParameterType_Field)
// other QGis processing parameters for field and band
if (type == ParameterType_Field || type == ParameterType_Band)
{
dFile << "|" << optional << "|False";
}
......
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