Commit b47f546e authored by Carole AMIOT's avatar Carole AMIOT

Merge branch 'develop' into fast_nlmeans_filter

parents e1112737 0d4fae35
......@@ -104,9 +104,12 @@ private:
/** Normalize a list sample using the statistic file given */
typename ListSampleType::Pointer NormalizeListSample(ListSampleType::Pointer input);
/** Create the output DataSource, in update mode the input layer is buffered and the input
* data source is re opened in update mode. */
otb::ogr::DataSource::Pointer CreateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer& layer, bool updateMode);
/** Update the output DataSource : the input layer is buffered and the input data source is re opened in update mode. */
otb::ogr::DataSource::Pointer ReopenDataSourceInUpdateMode(ogr::DataSource::Pointer source, ogr::Layer& layer,
ogr::DataSource::Pointer buffer);
/** Create the output DataSource. */
otb::ogr::DataSource::Pointer CreateOutputDataSource(ogr::DataSource::Pointer source, ogr::Layer& layer);
/** Add a prediction field in the output layer if it does not exist.
* If computeConfidenceMap evaluates to true a confidence field will be
......
......@@ -147,41 +147,39 @@ typename VectorPrediction<RegressionMode>::ListSampleType::Pointer VectorPredict
template <bool RegressionMode>
otb::ogr::DataSource::Pointer VectorPrediction<RegressionMode>::CreateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer& layer,
bool updateMode)
otb::ogr::DataSource::Pointer VectorPrediction<RegressionMode>::ReopenDataSourceInUpdateMode(ogr::DataSource::Pointer source, ogr::Layer& layer,
ogr::DataSource::Pointer buffer)
{
ogr::DataSource::Pointer output;
ogr::DataSource::Pointer buffer = ogr::DataSource::New();
if (updateMode)
{
// Update mode
otbAppLogINFO("Update input vector data.");
// fill temporary buffer for the transfer
otb::ogr::Layer inputLayer = layer;
layer = buffer->CopyLayer(inputLayer, std::string("Buffer"));
// close input data source
source->Clear();
// Re-open input data source in update mode
output = otb::ogr::DataSource::New(GetParameterString("in"), otb::ogr::DataSource::Modes::Update_LayerUpdate);
}
else
// Update mode
otbAppLogINFO("Update input vector data.");
// fill temporary buffer for the transfer
otb::ogr::Layer inputLayer = layer;
layer = buffer->CopyLayer(inputLayer, std::string("Buffer"));
// close input data source
source->Clear();
// Re-open input data source in update mode
output = otb::ogr::DataSource::New(GetParameterString("in"), otb::ogr::DataSource::Modes::Update_LayerUpdate);
return output;
}
template <bool RegressionMode>
otb::ogr::DataSource::Pointer VectorPrediction<RegressionMode>::CreateOutputDataSource(ogr::DataSource::Pointer source, ogr::Layer& layer)
{
ogr::DataSource::Pointer output;
// Create new OGRDataSource
output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Overwrite);
otb::ogr::Layer newLayer = output->CreateLayer(GetParameterString("out"), const_cast<OGRSpatialReference*>(layer.GetSpatialRef()), layer.GetGeomType());
// Copy existing fields
OGRFeatureDefn& inLayerDefn = layer.GetLayerDefn();
for (int k = 0; k < inLayerDefn.GetFieldCount(); k++)
{
// Create new OGRDataSource
output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Overwrite);
otb::ogr::Layer newLayer = output->CreateLayer(GetParameterString("out"), const_cast<OGRSpatialReference*>(layer.GetSpatialRef()), layer.GetGeomType());
// Copy existing fields
OGRFeatureDefn& inLayerDefn = layer.GetLayerDefn();
for (int k = 0; k < inLayerDefn.GetFieldCount(); k++)
{
OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k));
newLayer.CreateField(fieldDefn);
}
OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k));
newLayer.CreateField(fieldDefn);
}
return output;
}
template <bool RegressionMode>
void VectorPrediction<RegressionMode>::AddPredictionField(otb::ogr::Layer& outLayer, otb::ogr::Layer const& layer, bool computeConfidenceMap)
{
......@@ -306,7 +304,21 @@ void VectorPrediction<RegressionMode>::DoExecute()
const bool updateMode = !(IsParameterEnabled("out") && HasValue("out"));
auto output = CreateOutputDataSource(source, layer, updateMode);
ogr::DataSource::Pointer buffer;
ogr::DataSource::Pointer output;
if (updateMode)
{
// in update mode, output is added to input data source.
// buffer needs to be allocated here, as its life-cycle is bound to "layer"
buffer = ogr::DataSource::New();
output = ReopenDataSourceInUpdateMode(source, layer, buffer);
}
else
{
output = CreateOutputDataSource(source, layer);
}
otb::ogr::Layer outLayer = output->GetLayer(0);
OGRErr errStart = outLayer.ogr().StartTransaction();
......
......@@ -143,7 +143,7 @@ otb_test_application(NAME apTvUtTileFusion
-rows 2
-out ${TEMP}/apTvUtTileFusion.png uint8
VALID --compare-image ${NOTOL}
${INPUTDATA}/Scene.png
${INPUTDATA}/scene.png
${TEMP}/apTvUtTileFusion.png)
......@@ -203,6 +203,20 @@ otb_test_application(NAME apTvUtQuicklookROI1Channel
${TEMP}/apTvUtQuicklookROI1Channel.tif
)
otb_test_application(NAME apTvUtQuicklookWithGCP
APP Quicklook
OPTIONS -in ${INPUTDATA}/spot5SubWithGcps.tif
-out ${TEMP}/apTvUtQuicklookWithGCP.tif uint8
-sr 4
-rox 100
-roy 100
-rsx 200
-rsy 200
VALID --compare-metadata ${NOTOL}
${BASELINE}/apTvUtQuicklookWithGCP.tif
${TEMP}/apTvUtQuicklookWithGCP.tif
)
otb_test_application(NAME apTvUtQuicklookSpot5
APP Quicklook
OPTIONS -in LARGEINPUT{SPOT5/TEHERAN/IMAGERY.TIF}
......
......@@ -30,8 +30,6 @@
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otb_boost_string_header.h"
int otbExtractROITestMetaData(int itkNotUsed(argc), char* argv[])
{
typedef float PixelType;
......@@ -100,17 +98,20 @@ int otbExtractROITestMetaData(int itkNotUsed(argc), char* argv[])
reader00->SetFileName(argv[2]);
reader00->GenerateOutputInformation();
if (reader00->GetOutput()->GetProjectionRef() != "" || boost::algorithm::istarts_with(reader00->GetOutput()->GetProjectionRef(), "LOCAL_CS"))
// The input image should have a sensor model and GCP, but the output images
// should only have the sensor model (priority over GCP). This behaviour
// must be consistent regardless of the ROI.
if (reader00->GetOutput()->GetProjectionRef().size())
{
std::cout << "The read generated extract from index (0, 0) must NOT contain a ProjectionReference." << std::endl;
std::cout << "Found ProjectionReference: " << reader00->GetOutput()->GetProjectionRef() << std::endl;
return EXIT_FAILURE;
}
if (reader00->GetOutput()->GetGCPCount() == 0)
if (reader00->GetOutput()->GetGCPCount())
{
std::cout << "The read generated extract from index (0, 0) must contain a list a GCPs.." << std::endl;
std::cout << "The read generated extract from index (0, 0) must NOT contain a list a GCPs.." << std::endl;
return EXIT_FAILURE;
}
......@@ -118,14 +119,14 @@ int otbExtractROITestMetaData(int itkNotUsed(argc), char* argv[])
reader57->SetFileName(argv[3]);
reader57->GenerateOutputInformation();
if (reader57->GetOutput()->GetProjectionRef() != "" || boost::algorithm::istarts_with(reader57->GetOutput()->GetProjectionRef(), "LOCAL_CS"))
if (reader57->GetOutput()->GetProjectionRef().size())
{
std::cout << "The read generated extract from index (x, y) must NOT contain a ProjectionReference." << std::endl;
std::cout << "Found ProjectionReference: " << reader57->GetOutput()->GetProjectionRef() << std::endl;
return EXIT_FAILURE;
}
if (reader57->GetOutput()->GetGCPCount() != 0)
if (reader57->GetOutput()->GetGCPCount())
{
std::cout << "The read generated extract from index (x, y) must NOT contain a list a GCPs.." << std::endl;
return EXIT_FAILURE;
......
......@@ -34,9 +34,7 @@ namespace otb
void bands::Eval(mup::ptr_val_type& ret, const mup::ptr_val_type* a_pArg, int a_iArgc)
{
if (a_iArgc != 2)
return;
assert (a_iArgc == 2);
assert(a_pArg[0]->GetType() == 'm');
assert(a_pArg[1]->GetType() == 'm');
......
This diff is collapsed.
......@@ -219,6 +219,7 @@ public:
* \li ParameterType_Int
* \li ParameterType_Bool
* \li ParameterType_Float
* \li ParameterType_Double
* \li ParameterType_Radius
* \li ParameterType_Choice
*/
......@@ -228,9 +229,18 @@ public:
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
void SetParameterFloat(std::string const& parameter, float value, bool hasUserValueFlag = true);
/* Set a double precision floating value
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
void SetParameterDouble(std::string const& parameter, double value, bool hasUserValueFlag = true);
/* Set a string value
*
* Can be called for types :
......@@ -253,6 +263,7 @@ public:
* \li ParameterType_Directory
* \li ParameterType_Choice
* \li ParameterType_Float
* \li ParameterType_Double
* \li ParameterType_Int
* \li ParameterType_Radius
* \li ParameterType_InputImageParameter
......@@ -285,6 +296,7 @@ public:
* Can be called for types :
* \li ParameterType_Int
* \li ParameterType_Float
* \li ParameterType_Double
* \li ParameterType_Radius
* \li ParameterType_Choice
*/
......@@ -295,6 +307,7 @@ public:
* Can be called for types :
* \li ParameterType_Int
* \li ParameterType_Float
* \li ParameterType_Double
* \li ParameterType_Radius
* \li ParameterType_Choice
*/
......@@ -306,6 +319,7 @@ public:
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
void SetDefaultParameterFloat(std::string const& parameter, float value);
......@@ -313,9 +327,28 @@ public:
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
float GetDefaultParameterFloat(std::string const& parameter);
/* Set a default double precision floating value, must be used in the
* DoInit when setting a value by default
* for the parameter
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
void SetDefaultParameterDouble(std::string const& parameter, double value);
/* Get the default double precision floating value of a parameter
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
double GetDefaultParameterDouble(std::string const& parameter);
/** Set a default pixel type for an output image parameter
*
* \param[in] parameter Name of the output image parameter
......@@ -348,7 +381,7 @@ public:
*/
void SetMaximumParameterIntValue(std::string const& parameter, int value);
/* Set a minimum int value, must used in the
/* Set a minimum float value, must used in the
* DoInit when setting a value by default
* for the parameter
*
......@@ -357,7 +390,7 @@ public:
*/
void SetMinimumParameterFloatValue(std::string const& parameter, float value);
/* Set a maximum int value, must used in the
/* Set a maximum float value, must used in the
* DoInit when setting a value by default
* for the parameter
*
......@@ -366,6 +399,26 @@ public:
*/
void SetMaximumParameterFloatValue(std::string const& parameter, float value);
/* Set a minimum double precision float value, must used in the
* DoInit when setting a value by default
* for the parameter
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
void SetMinimumParameterDoubleValue(std::string const& parameter, double value);
/* Set a maximum double precision value, must used in the
* DoInit when setting a value by default
* for the parameter
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
void SetMaximumParameterDoubleValue(std::string const& parameter, double value);
/**
* Enable single selection mode for list view if status is true
......@@ -411,6 +464,7 @@ public:
* \li ParameterType_Int
* \li ParameterType_Bool
* \li ParameterType_Float
* \li ParameterType_Double
* \li ParameterType_Radius
* \li ParameterType_Choice
*/
......@@ -420,9 +474,18 @@ public:
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
float GetParameterFloat(std::string const& parameter) const;
/* Get a double precision floating parameter value
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
*/
double GetParameterDouble(std::string const& parameter) const;
/* Get a string parameter value
*
* Can be called for types :
......@@ -609,6 +672,7 @@ public:
*
* Can be called for types :
* \li ParameterType_Float
* \li ParameterType_Double
* \li ParameterType_Int
* \li ParameterType_Choice
* \li ParameterType_Radius
......
......@@ -127,6 +127,15 @@ public:
return static_cast<float>(*m_Value);
}
double ToDouble() const override
{
if (!HasValue())
{
itkExceptionMacro("Cannot convert parameter " << GetKey() << " to double (no value).");
}
return static_cast<double>(*m_Value);
}
void FromInt(int value) override
{
SetValue(value);
......@@ -185,7 +194,7 @@ public:
itkNewMacro(Self);
itkTypeMacro(NumericalParameter, Parameter);
virtual ParameterType GetType() const override
ParameterType GetType() const override
{
return ParameterType_Float;
}
......@@ -196,6 +205,28 @@ public:
}
};
class OTBApplicationEngine_EXPORT DoubleParameter : public NumericalParameter<double>
{
public:
/** Standard class typedef */
typedef DoubleParameter Self;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkNewMacro(Self);
itkTypeMacro(NumericalParameter, Parameter);
ParameterType GetType() const override
{
return ParameterType_Double;
}
void FromDouble(double value) override
{
SetValue(value);
}
};
class OTBApplicationEngine_EXPORT IntParameter : public NumericalParameter<int>
{
public:
......@@ -207,7 +238,7 @@ public:
itkNewMacro(Self);
itkTypeMacro(NumericalParameter, Parameter);
virtual ParameterType GetType() const override
ParameterType GetType() const override
{
return ParameterType_Int;
}
......@@ -228,7 +259,7 @@ public:
/** RTTI support */
itkTypeMacro(RAMParameter, Parameter);
virtual ParameterType GetType() const override
ParameterType GetType() const override
{
return ParameterType_RAM;
}
......@@ -260,7 +291,7 @@ public:
return true;
}
virtual ParameterType GetType() const override
ParameterType GetType() const override
{
return ParameterType_Radius;
}
......
......@@ -147,11 +147,13 @@ public:
*/
virtual int ToInt() const;
virtual float ToFloat() const;
virtual double ToDouble() const;
virtual std::string ToString() const;
virtual std::vector<std::string> ToStringList() const;
virtual void FromInt(int);
virtual void FromFloat(float);
virtual void FromDouble(double);
virtual void FromString(const std::string&);
virtual void FromStringList(const std::vector<std::string>&);
......
......@@ -37,6 +37,7 @@ namespace Wrapper
typedef enum {
ParameterType_Int,
ParameterType_Float,
ParameterType_Double,
ParameterType_String,
ParameterType_StringList,
ParameterType_InputFilename,
......@@ -64,6 +65,7 @@ namespace
{
constexpr char const* parameterTypesStrings[] = {"Int",
"Float",
"Double",
"String",
"StringList",
"InputFilename",
......
......@@ -411,6 +411,12 @@ void Application::SetParameterFloat(std::string const& key, float value, bool ha
this->SetParameterUserValue(key, hasUserValueFlag);
}
void Application::SetParameterDouble(std::string const& key, double value, bool hasUserValueFlag)
{
GetParameterByKey(key)->FromDouble(value);
this->SetParameterUserValue(key, hasUserValueFlag);
}
void Application::SetParameterString(std::string const& parameter, std::string value, bool hasUserValueFlag)
{
GetParameterByKey(parameter)->FromString(value);
......@@ -1097,6 +1103,13 @@ void Application::SetDefaultParameterInt(std::string const& parameter, int value
if (!hasUserValue)
paramFloat->SetValue(static_cast<float>(value));
}
else if (dynamic_cast<DoubleParameter*>(param))
{
DoubleParameter* paramDouble = dynamic_cast<DoubleParameter*>(param);
paramDouble->SetDefaultValue(static_cast<double>(value));
if (!hasUserValue)
paramDouble->SetValue(static_cast<double>(value));
}
else if (dynamic_cast<RAMParameter*>(param))
{
RAMParameter* paramRAM = dynamic_cast<RAMParameter*>(param);
......@@ -1125,6 +1138,11 @@ int Application::GetDefaultParameterInt(std::string const& parameter)
FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param);
ret = paramFloat->GetDefaultValue();
}
else if (dynamic_cast<DoubleParameter*>(param))
{
DoubleParameter* paramDouble = dynamic_cast<DoubleParameter*>(param);
ret = paramDouble->GetDefaultValue();
}
else if (dynamic_cast<RAMParameter*>(param))
{
RAMParameter* paramRAM = dynamic_cast<RAMParameter*>(param);
......@@ -1154,6 +1172,23 @@ float Application::GetDefaultParameterFloat(std::string const& key)
return param->GetDefaultValue();
}
void Application::SetDefaultParameterDouble(std::string const& key, double value)
{
auto param = downcast_check<DoubleParameter>(GetParameterByKey(key));
param->SetDefaultValue(value);
if (!param->HasUserValue())
{
param->SetValue(value);
}
}
double Application::GetDefaultParameterDouble(std::string const& key)
{
auto param = downcast_check<DoubleParameter>(GetParameterByKey(key));
return param->GetDefaultValue();
}
void Application::SetDefaultOutputPixelType(std::string const& key, ImagePixelType type)
{
auto param = downcast_check<OutputImageParameter>(GetParameterByKey(key));
......@@ -1185,6 +1220,18 @@ void Application::SetMaximumParameterFloatValue(std::string const& key, float va
param->SetMaximumValue(value);
}
void Application::SetMinimumParameterDoubleValue(std::string const& key, double value)
{
auto param = downcast_check<DoubleParameter>(GetParameterByKey(key));
param->SetMinimumValue(value);
}
void Application::SetMaximumParameterDoubleValue(std::string const& key, double value)
{
auto param = downcast_check<DoubleParameter>(GetParameterByKey(key));
param->SetMaximumValue(value);
}
void Application::SetListViewSingleSelectionMode(std::string const& key, bool status)
{
auto param = downcast_check<ListViewParameter>(GetParameterByKey(key));
......@@ -1246,6 +1293,11 @@ float Application::GetParameterFloat(std::string const& key) const
return GetParameterByKey(key)->ToFloat();
}
double Application::GetParameterDouble(std::string const& key) const
{
return GetParameterByKey(key)->ToDouble();
}
std::string Application::GetParameterString(std::string const& key) const
{
return GetParameterByKey(key)->ToString();
......@@ -1413,6 +1465,13 @@ std::vector<std::pair<std::string, std::string>> Application::GetOutputParameter
oss << GetParameterFloat(*it);
keyVal.second = oss.str();
}
else if (type == ParameterType_Double)
{
std::ostringstream oss;
oss << std::setprecision(19);
oss << GetParameterDouble(*it);
keyVal.second = oss.str();
}
else
{
keyVal.second = GetParameterAsString(*it);
......
......@@ -132,6 +132,8 @@ void InputImageListParameter::SetNthImage(std::size_t i, ImageBaseType* image)
assert(image != nullptr);
// Check input availability
if (image == nullptr)
itkExceptionMacro("Image number " << i << " is null. Please check the upstream source.");
image->UpdateOutputInformation();
// Build parameter.
......@@ -142,6 +144,12 @@ void InputImageListParameter::SetNthImage(std::size_t i, ImageBaseType* image)
/*****************************************************************************/
void InputImageListParameter::AddImage(ImageBaseType* image)
{
// Check input availability
if (image == nullptr)
itkExceptionMacro("Image is null. Please check the upstream source.");
image->UpdateOutputInformation();
AddData(image, [this](auto i) -> auto { return this->FromImage(i); });
}
......
......@@ -269,6 +269,12 @@ int Read(const std::string& filename, Application::Pointer this_)
std::stringstream(value) >> floatValue;
this_->SetParameterFloat(key, floatValue);
}
else if (type == ParameterType_Double)
{
double doubleValue;
std::stringstream(value) >> doubleValue;
this_->SetParameterDouble(key, doubleValue);
}
else if (type == ParameterType_StringList || type == ParameterType_ListView)
{
this_->SetParameterStringList(key, values);
......
......@@ -250,6 +250,13 @@ void ParseGroup(Application::Pointer app, TiXmlElement* n_App, const std::string
oss << app->GetParameterFloat(key);
value = oss.str();
}
else if (type == ParameterType_Double)
{
std::ostringstream oss;
oss << std::setprecision(std::numeric_limits<double>::digits10 + 1);
oss << app->GetParameterDouble(key);
value = oss.str();
}
else if (type == ParameterType_String || type == ParameterType_InputFilename || type == ParameterType_Directory || type == ParameterType_InputImage ||
type == ParameterType_InputVectorData || type == ParameterType_Choice || type == ParameterType_OutputVectorData ||
type == ParameterType_OutputFilename || type == ParameterType_Bool)
......
......@@ -229,6 +229,11 @@ float Parameter::ToFloat() const
TypeError("float");
}
double Parameter::ToDouble() const
{
TypeError("double");
}
std::string Parameter::ToString() const
{
TypeError("std::string");
......@@ -249,6 +254,11 @@ void Parameter::FromFloat(float)
TypeError("float");
}
void Parameter::FromDouble(double)
{
TypeError("double");
}
void Parameter::FromString(const std::string&)
{
TypeError("std::string");
......
......@@ -231,6 +231,11 @@ void ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std:
newParam = FloatParameter::New();
}
break;
case ParameterType_Double:
{
newParam = DoubleParameter::New();
}
break;
case ParameterType_String:
{
newParam = StringParameter::New();
......
......@@ -56,6 +56,10 @@ otb_add_test(NAME owTvFloatParameter COMMAND otbApplicationEngineTestDriver
otbWrapperFloatParameterTest
)
otb_add_test(NAME owTvDoubleParameter COMMAND otbApplicationEngineTestDriver
otbWrapperDoubleParameterTest
)
otb_add_test(NAME owTvIntParameter COMMAND otbApplicationEngineTestDriver
otbWrapperIntParameterTest
)
......
......@@ -24,6 +24,7 @@ void RegisterTests()
{
REGISTER_TEST(otbWrapperInputImageParameterTest);
REGISTER_TEST(otbWrapperFloatParameterTest);
REGISTER_TEST(otbWrapperDoubleParameterTest);
REGISTER_TEST(otbWrapperIntParameterTest);
REGISTER_TEST(otbWrapperRAMParameterTest);
REGISTER_TEST(otbWrapperStringParameterTest1);
......